import { defineComponent, ref, computed, createVNode } from 'vue';
import '../../../utils/index.mjs';
import '../../../vue-components/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import { useInjectFormItemContext, FormItemInputContext } from '../../form/src/FormItemContext.mjs';
import '../../config-provider/index.mjs';
import useStyle from '../style/index.mjs';
import { useInjectRadioOptionTypeContext, useInjectRadioGroupContext } from './context.mjs';
import { radioProps } from './props.mjs';
import { useInjectDisabled } from '../../config-provider/src/context/disabledContext.mjs';
import { omit } from '../../../utils/lang/omit.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import VcCheckbox from '../../../vue-components/vc-checkbox/src/Checkbox.mjs';

var ARadio = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ARadio",
  inheritAttrs: false,
  props: radioProps(),
  setup(props, {
    emit,
    expose,
    slots,
    attrs
  }) {
    const formItemContext = useInjectFormItemContext();
    const formItemInputContext = FormItemInputContext.useInject();
    const radioOptionTypeContext = useInjectRadioOptionTypeContext();
    const radioGroupContext = useInjectRadioGroupContext();
    const vcCheckbox = ref();
    const {
      prefixCls: radioPrefixCls,
      direction,
      disabled
    } = useConfigInject("radio", props);
    const disabledContext = useInjectDisabled();
    const mergedDisabled = computed(() => {
      var _a;
      return (_a = disabled.value) != null ? _a : disabledContext.value;
    });
    const prefixCls = computed(() => (radioGroupContext == null ? void 0 : radioGroupContext.optionType.value) === "button" || radioOptionTypeContext === "button" ? `${radioPrefixCls.value}-button` : radioPrefixCls.value);
    const contextDisabled = useInjectDisabled();
    const [wrapSSR, hashId] = useStyle(radioPrefixCls);
    const focus = () => {
      vcCheckbox.value.focus();
    };
    const blur = () => {
      vcCheckbox.value.blur();
    };
    expose({
      focus,
      blur
    });
    const handleChange = (event) => {
      const targetChecked = event.target.checked;
      emit("update:checked", targetChecked);
      emit("update:value", targetChecked);
      emit("change", event);
      formItemContext.onFieldChange();
    };
    const onChange = (e) => {
      emit("change", e);
      if (radioGroupContext && radioGroupContext.onChange)
        radioGroupContext.onChange(e);
    };
    return () => {
      var _a;
      const radioGroup = radioGroupContext;
      const {
        prefixCls: customizePrefixCls,
        id = formItemContext.id.value,
        ...restProps
      } = props;
      const rProps = {
        prefixCls: prefixCls.value,
        id,
        ...omit(restProps, ["onUpdate:checked", "onUpdate:value"]),
        disabled: (_a = disabled.value) != null ? _a : contextDisabled.value
      };
      if (radioGroup) {
        rProps.name = radioGroup.name.value;
        rProps.onChange = onChange;
        rProps.checked = props.value === radioGroup.value.value;
        rProps.disabled = mergedDisabled.value || radioGroup.disabled.value;
      } else {
        rProps.onChange = handleChange;
      }
      const wrapperClassString = classNames({
        [`${prefixCls.value}-wrapper`]: true,
        [`${prefixCls.value}-wrapper-checked`]: rProps.checked,
        [`${prefixCls.value}-wrapper-disabled`]: rProps.disabled,
        [`${prefixCls.value}-wrapper-rtl`]: direction.value === "rtl",
        [`${prefixCls.value}-wrapper-in-form-item`]: formItemInputContext.isFormItemInput
      }, attrs.class, hashId.value);
      return wrapSSR(createVNode("label", {
        ...attrs,
        "class": wrapperClassString
      }, [createVNode(VcCheckbox, {
        ...rProps,
        "type": "radio",
        "ref": vcCheckbox
      }, null), slots.default && createVNode("span", null, [slots.default()])]));
    };
  }
});

export { ARadio as default };
//# sourceMappingURL=Radio.mjs.map
