import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
import { computed, toRef } from "vue";
import { getUid } from "@veno-ui/utils";
import { defineComponent } from "../../utils";
import { FormControl } from "../form-control";
import { SelectionGroupControl } from "../selection-group-control";
import { makeSelectionGroupControlProps } from "../selection-group-control/selection-group-control";
import { Radio } from "../radio";
import { makeSizeProps } from "../../composables/size";
import { makeDensityProps } from "../../composables/density";
import { provideDefaults } from "../../composables/defaults";
import { useProxiedModel } from "../../composables/proxied-model";
const RadioGroup = defineComponent({
  name: "VeRadioGroup",
  props: {
    /**
     * @zh 单选组的所有可选项
     */
    items: Array,
    ...makeSelectionGroupControlProps({
      type: "radio",
      trueIcon: "$radioOn",
      falseIcon: "$radioOff"
    }),
    ...makeSizeProps(),
    ...makeDensityProps()
  },
  emits: {
    "update:modelValue": (_modelValue) => true
  },
  setup(props, {
    slots
  }) {
    const id = computed(() => props.id || `ve-radio-group-${getUid()}`);
    const model = useProxiedModel(props, "modelValue");
    const items = computed(() => {
      return props.items?.map((itemProps) => typeof itemProps === "string" ? {
        value: itemProps
      } : itemProps);
    });
    provideDefaults({
      VeRadio: {
        size: toRef(props, "size"),
        density: toRef(props, "density"),
        readonly: toRef(props, "readonly"),
        disabled: toRef(props, "disabled")
      }
    });
    return () => {
      const {
        density,
        size,
        ...restProps
      } = props;
      return _createVNode(FormControl, {
        "class": "ve-radio-group",
        "density": density,
        "name": props.name,
        "size": size,
        "modelValue": model.value,
        "onUpdate:modelValue": ($event) => model.value = $event
      }, {
        ...slots,
        default: ({
          isDisabled,
          isReadonly,
          props: controlProps
        }) => _createVNode(SelectionGroupControl, _mergeProps(restProps, controlProps, {
          "id": id.value,
          "disabled": isDisabled.value,
          "readonly": isReadonly.value,
          "modelValue": model.value,
          "onUpdate:modelValue": ($event) => model.value = $event
        }), {
          default: () => [items.value?.map((itemProps) => _createVNode(Radio, itemProps, null)), slots.default?.()]
        })
      });
    };
  }
});
export {
  RadioGroup
};
//# sourceMappingURL=radio-group.mjs.map
