<script setup lang="ts">
// ---------------------------------------------------------------------
// 🔒 AUTOGENERATED @synergy-design-system/vue wrappers for @synergy-design-system/components
// Please do not edit this file directly!
// It will get recreated when running pnpm build.
// ---------------------------------------------------------------------

/**
 * @summary Radios allow the user to select a single option from a group.
 * @documentation https://synergy-design-system.github.io/?path=/docs/components-syn-radio--docs
 * @status stable
 * @since 1.0.0
 *
 * @dependency syn-icon
 *
 * @slot - The radio's label.
 *
 * @event syn-blur - Emitted when the control loses focus.
 * @event syn-focus - Emitted when the control gains focus.
 *
 * @csspart base - The component's base wrapper.
 * @csspart control - The circular container that wraps the radio's checked state.
 * @csspart control--checked - The radio control when the radio is checked.
 * @csspart checked-icon - The checked icon, an `<syn-icon>` element.
 * @csspart label - The container that wraps the radio's label.
 */
import { computed, ref } from 'vue';
import '@synergy-design-system/components/components/radio/radio.js';

import type { SynBlurEvent } from '@synergy-design-system/components';
import type { SynFocusEvent } from '@synergy-design-system/components';
import type SynRadio from '@synergy-design-system/components/components/radio/radio.component.js';

// DOM Reference to the element
const nativeElement = ref<SynRadio>();

defineExpose({
  nativeElement,
});

// Map attributes
const props = defineProps<{
  /**
   * The radio's value.
   * When selected, the radio group will receive this value.
   */
  value?: SynRadio['value'];

  /**
* The radio's size.
* When used inside a radio group, the size will be determined by the radio group's size so this
attribute can typically be omitted.
 */
  size?: SynRadio['size'];

  /**
   * Disables the radio.
   */
  disabled?: SynRadio['disabled'];

  /**
   * Sets the radio to a readonly state.
   */
  readonly?: SynRadio['readonly'];
}>();

// Make sure prop binding only forwards the props that are actually there.
// This is needed because :param="param" also adds an empty attribute
// when using web-components, which breaks optional arguments like size in SynInput
// @see https://github.com/vuejs/core/issues/5190#issuecomment-1003112498
const visibleProps = computed(() =>
  Object.fromEntries(
    Object.entries(props).filter(([, value]) => typeof value !== 'undefined'),
  ),
);

// Map events
defineEmits<{
  /**
   * Emitted when the control loses focus.
   */
  'syn-blur': [e: SynBlurEvent];

  /**
   * Emitted when the control gains focus.
   */
  'syn-focus': [e: SynFocusEvent];
}>();
</script>

<script lang="ts">
export type { SynBlurEvent } from '@synergy-design-system/components';
export type { SynFocusEvent } from '@synergy-design-system/components';
</script>

<template>
  <syn-radio
    @syn-blur="$emit('syn-blur', $event)"
    @syn-focus="$emit('syn-focus', $event)"
    v-bind="visibleProps"
    ref="nativeElement">
    <slot></slot>
  </syn-radio>
</template>
