import { defineComponent, ref, computed, resolveComponent, openBlock, createElementBlock, normalizeClass, withKeys, withModifiers, withDirectives, createElementVNode, vModelRadio, createVNode, renderSlot, createTextVNode, toDisplayString } from 'vue';
import { ElImage } from '../../image/index.mjs';
import '../../../constants/index.mjs';
import { useRadio } from './radio.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import { UPDATE_MODEL_EVENT } from '../../../constants/event.mjs';

const _sfc_main = defineComponent({
  name: "ElRadioItem",
  components: {
    ElImage
  },
  props: {
    modelValue: {
      type: [String, Number, Boolean],
      default: ""
    },
    label: {
      type: [String, Number, Boolean],
      default: ""
    },
    name: {
      type: String,
      default: ""
    },
    iconUrl: {
      type: String,
      default: ""
    }
  },
  setup(props, { emit }) {
    const { isGroup, radioGroup, focus, disabled: disabled2 } = useRadio(props, emit);
    const radioRef = ref();
    const value = computed({
      get() {
        return isGroup.value ? radioGroup.modelValue : props.modelValue;
      },
      set(value2) {
        if (isGroup.value) {
          radioGroup.changeEvent(value2);
          radioRef.value.checked = radioGroup.modelValue === props.label;
        } else {
          emit(UPDATE_MODEL_EVENT, value2);
        }
      }
    });
    return {
      isDisabled: disabled2,
      focus,
      value,
      radioRef
    };
  }
});
const _hoisted_1 = ["aria-checked", "aria-disabled"];
const _hoisted_2 = ["value", "name"];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  const _component_ElImage = resolveComponent("ElImage");
  return openBlock(), createElementBlock("label", {
    class: normalizeClass(["el-radio-item", {
      "is-checked": _ctx.value === _ctx.label
    }]),
    role: "radio",
    "aria-checked": _ctx.value === _ctx.label,
    "aria-disabled": _ctx.isDisabled,
    onKeydown: _cache[4] || (_cache[4] = withKeys(withModifiers(($event) => _ctx.value = _ctx.isDisabled ? _ctx.value : _ctx.label, ["stop", "prevent"]), ["space"]))
  }, [
    withDirectives(createElementVNode("input", {
      ref: "radioRef",
      "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.value = $event),
      class: "el-radio-item__original-radio",
      value: _ctx.label,
      type: "radio",
      name: _ctx.name,
      onFocus: _cache[1] || (_cache[1] = ($event) => _ctx.focus = true),
      onBlur: _cache[2] || (_cache[2] = ($event) => _ctx.focus = false)
    }, null, 40, _hoisted_2), [
      [vModelRadio, _ctx.value]
    ]),
    createVNode(_component_ElImage, {
      src: _ctx.iconUrl,
      class: "el-radio-item__pic"
    }, null, 8, ["src"]),
    createElementVNode("span", {
      class: "el-radio-item__label",
      onKeydown: _cache[3] || (_cache[3] = withModifiers(() => {
      }, ["stop"]))
    }, [
      renderSlot(_ctx.$slots, "default", {}, () => [
        createTextVNode(toDisplayString(_ctx.label), 1)
      ])
    ], 32)
  ], 42, _hoisted_1);
}
var radioItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/Users/linxinjian/work/element-plus/packages/components/radio/src/radio-item.vue"]]);

export { radioItem as default };
//# sourceMappingURL=radio-item.mjs.map
