'use strict';

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

var vue = require('vue');
var index = require('../_util/vue-types/index.js');
var Checkbox = require('../vc-checkbox/Checkbox.js');
var classNames = require('../_util/classNames.js');
require('../hooks/index.js');
var FormItemContext = require('../form/FormItemContext.js');
var omit = require('../_util/omit.js');
var type = require('../_util/type.js');
var DisabledContext = require('../config-provider/DisabledContext.js');
var index$1 = require('./style/index.js');
var context = require('./context.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

const radioProps = () => ({
  "prefixCls": String,
  "checked": type.booleanType(),
  "disabled": type.booleanType(),
  "isGroup": type.booleanType(),
  "value": index.default.any,
  "name": String,
  "id": String,
  "autofocus": type.booleanType(),
  "onChange": type.functionType(),
  "onFocus": type.functionType(),
  "onBlur": type.functionType(),
  "onClick": type.functionType(),
  "onUpdate:checked": type.functionType(),
  "onUpdate:value": type.functionType()
});
var Radio = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ARadio",
  inheritAttrs: false,
  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 = DisabledContext.useInjectDisabled();
    const mergedDisabled = vue.computed(() => {
      var _a;
      return (_a = disabled.value) != null ? _a : disabledContext.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$1.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.default(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.default({
        [`${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", vue.mergeProps(attrs, {
        "class": wrapperClassString
      }), [vue.createVNode(Checkbox.default, vue.mergeProps(rProps, {
        "type": "radio",
        "ref": vcCheckbox
      }), null), slots.default && vue.createVNode("span", null, [slots.default()])]));
    };
  }
});

exports.default = Radio;
exports.radioProps = radioProps;
//# sourceMappingURL=Radio.js.map
