"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const event = require("../../../constants/event.js");
const error = require("../../../utils/error.js");
const index = require("../../../hooks/use-namespace/index.js");
const index$1 = require("../../../hooks/use-id/index.js");
const useFormItem = require("../../form/src/hooks/use-form-item.js");
const constants = require("./constants.js");
const radio2 = require("./radio2.js");
const radioButton2 = require("./radio-button2.js");
const radioGroup = require("./radio-group.js");
const vue = require("vue");
const isEqual = require("../../../../../lodash-es/isEqual.js");
const omit = require("../../../../../lodash-es/omit.js");
const _hoisted_1 = [
  "id",
  "aria-label",
  "aria-labelledby"
];
var radio_group_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ vue.defineComponent({
  name: "ElRadioGroup",
  __name: "radio-group",
  props: radioGroup.radioGroupProps,
  emits: radioGroup.radioGroupEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const ns = index.useNamespace("radio");
    const radioId = index$1.useId();
    const radioGroupRef = vue.ref();
    const { formItem } = useFormItem.useFormItem();
    const { inputId: groupId, isLabeledByFormItem } = useFormItem.useFormItemInputId(props, { formItemContext: formItem });
    const changeEvent = (value) => {
      emit(event.UPDATE_MODEL_EVENT, value);
      vue.nextTick(() => emit(event.CHANGE_EVENT, value));
    };
    vue.onMounted(() => {
      const radios = radioGroupRef.value.querySelectorAll("[type=radio]");
      const firstLabel = radios[0];
      if (!Array.from(radios).some((radio) => radio.checked) && firstLabel) firstLabel.tabIndex = 0;
    });
    const name = vue.computed(() => {
      return props.name || radioId.value;
    });
    const aliasProps = vue.computed(() => ({
      ...radioGroup.radioDefaultProps,
      ...props.props
    }));
    const getOptionProps = (option) => {
      const { label, value, disabled } = aliasProps.value;
      const base = {
        label: option[label],
        value: option[value],
        disabled: option[disabled]
      };
      return {
        ...omit.default(option, [
          label,
          value,
          disabled
        ]),
        ...base
      };
    };
    const optionComponent = vue.computed(() => props.type === "button" ? radioButton2.default : radio2.default);
    vue.provide(constants.radioGroupKey, vue.reactive({
      ...vue.toRefs(props),
      changeEvent,
      name
    }));
    vue.watch(() => props.modelValue, (newVal, oldValue) => {
      if (props.validateEvent && !isEqual.default(newVal, oldValue)) formItem == null ? void 0 : formItem.validate("change").catch((err) => error.debugWarn(err));
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", {
        id: vue.unref(groupId),
        ref_key: "radioGroupRef",
        ref: radioGroupRef,
        class: vue.normalizeClass(vue.unref(ns).b("group")),
        role: "radiogroup",
        "aria-label": !vue.unref(isLabeledByFormItem) ? __props.ariaLabel || "radio-group" : void 0,
        "aria-labelledby": vue.unref(isLabeledByFormItem) ? vue.unref(formItem).labelId : void 0
      }, [vue.renderSlot(_ctx.$slots, "default", {}, () => [(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.options, (item, index2) => {
        return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(optionComponent.value), vue.mergeProps({ key: index2 }, { ref_for: true }, getOptionProps(item)), null, 16);
      }), 128))])], 10, _hoisted_1);
    };
  }
});
exports.default = radio_group_vue_vue_type_script_setup_true_lang_default;
