"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const event = require("../../../constants/event.js");
const types = require("../../../utils/types.js");
const index = require("../../../hooks/use-deprecated/index.js");
const useFormCommonProps = require("../../form/src/hooks/use-form-common-props.js");
const constants = require("./constants.js");
const Vue = require("vue");
const useRadio = (props, emit) => {
  const radioRef = Vue.ref();
  const radioGroup = Vue.inject(constants.radioGroupKey, void 0);
  const isGroup = Vue.computed(() => !!radioGroup);
  const actualValue = Vue.computed(() => {
    if (!types.isPropAbsent(props.value)) return props.value;
    return props.label;
  });
  const modelValue = Vue.computed({
    get() {
      return isGroup.value ? radioGroup.modelValue : props.modelValue;
    },
    set(val) {
      if (isGroup.value) radioGroup.changeEvent(val);
      else emit && emit(event.UPDATE_MODEL_EVENT, val);
      radioRef.value.checked = props.modelValue === actualValue.value;
    }
  });
  const size = useFormCommonProps.useFormSize(Vue.computed(() => radioGroup == null ? void 0 : radioGroup.size));
  const disabled = useFormCommonProps.useFormDisabled(Vue.computed(() => radioGroup == null ? void 0 : radioGroup.disabled));
  const focus = Vue.ref(false);
  const tabIndex = Vue.computed(() => {
    return disabled.value || isGroup.value && modelValue.value !== actualValue.value ? -1 : 0;
  });
  index.useDeprecated({
    from: "label act as value",
    replacement: "value",
    version: "3.0.0",
    scope: "el-radio",
    ref: "https://element-plus.org/en-US/component/radio.html"
  }, Vue.computed(() => isGroup.value && types.isPropAbsent(props.value)));
  return {
    radioRef,
    isGroup,
    radioGroup,
    focus,
    size,
    disabled,
    tabIndex,
    modelValue,
    actualValue
  };
};
exports.useRadio = useRadio;
