'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../utils/index.cjs');
require('../../../vue-components/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var FormItemContext = require('../../form/src/FormItemContext.cjs');
require('../../config-provider/index.cjs');
var index = require('../style/index.cjs');
var context = require('./context.cjs');
var props = require('./props.cjs');
var disabledContext = require('../../config-provider/src/context/disabledContext.cjs');
var omit = require('../../../utils/lang/omit.cjs');
var _class = require('../../../utils/dom/class.cjs');
var Checkbox = require('../../../vue-components/vc-checkbox/src/Checkbox.cjs');

var ARadio = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ARadio",
  inheritAttrs: false,
  props: props.radioProps(),
  setup(props, {
    emit,
    expose,
    slots,
    attrs
  }) {
    const formItemContext = FormItemContext.useInjectFormItemContext();
    const formItemInputContext = FormItemContext.FormItemInputContext.useInject();
    const radioOptionTypeContext = context.useInjectRadioOptionTypeContext();
    const radioGroupContext = context.useInjectRadioGroupContext();
    const vcCheckbox = vue.ref();
    const {
      prefixCls: radioPrefixCls,
      direction,
      disabled
    } = useConfigInject.default("radio", props);
    const disabledContext$1 = disabledContext.useInjectDisabled();
    const mergedDisabled = vue.computed(() => {
      var _a;
      return (_a = disabled.value) != null ? _a : disabledContext$1.value;
    });
    const prefixCls = vue.computed(() => (radioGroupContext == null ? void 0 : radioGroupContext.optionType.value) === "button" || radioOptionTypeContext === "button" ? `${radioPrefixCls.value}-button` : radioPrefixCls.value);
    const contextDisabled = disabledContext.useInjectDisabled();
    const [wrapSSR, hashId] = index.default(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.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 = _class.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(vue.createVNode("label", {
        ...attrs,
        "class": wrapperClassString
      }, [vue.createVNode(Checkbox.default, {
        ...rProps,
        "type": "radio",
        "ref": vcCheckbox
      }, null), slots.default && vue.createVNode("span", null, [slots.default()])]));
    };
  }
});

exports.default = ARadio;
//# sourceMappingURL=Radio.cjs.map
