import "../../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                                */
/* empty css                                                                    */
/* empty css                                                                          */
import { inject, computed, createBlock, openBlock, mergeProps, toHandlers, withCtx, createElementBlock, Fragment, renderList } from "vue";
import { setFormDataByFieldMapping } from "../../../utils/common.mjs";
import { ElRadioGroup, ElRadio } from "../../../../../../node_modules/element-plus/es/components/radio/index.mjs";
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "Radio",
  props: {
    config: {
      type: Object,
      required: true
    },
    modelValue: {
      type: null,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: false
    },
    readonly: {
      type: Boolean,
      default: false
    },
    options: {
      type: Array,
      default: () => []
    },
    optionConfig: {
      type: Object,
      default: () => ({})
    }
  },
  emits: ["update:modelValue", "change"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const formData = inject("formData", null);
    const fieldsData = inject("fieldsData", []);
    const hiddenFields = inject("hiddenFields", []);
    const emit = __emit;
    const inputValue = computed({
      get: () => props.modelValue,
      set: (val) => {
        emit("update:modelValue", val);
        emit("change", val);
      }
    });
    const options = computed(() => {
      var _a;
      return ((_a = props.optionConfig) == null ? void 0 : _a.options) || [];
    });
    function handlerChange(val) {
      setFormDataByFieldMapping(
        val,
        false,
        options.value,
        props.optionConfig.fieldMapping,
        formData,
        [...fieldsData.value, ...hiddenFields.value]
      );
    }
    return (_ctx, _cache) => {
      const _component_el_radio = ElRadio;
      const _component_el_radio_group = ElRadioGroup;
      return openBlock(), createBlock(_component_el_radio_group, mergeProps({
        modelValue: inputValue.value,
        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => inputValue.value = $event)
      }, toHandlers(__props.config.eventHandlers), {
        disabled: __props.disabled,
        style: {
          pointerEvents: __props.readonly ? "none" : "auto"
        },
        onChange: handlerChange
      }), {
        default: withCtx(() => [
          (openBlock(true), createElementBlock(Fragment, null, renderList(options.value, (option) => {
            return openBlock(), createBlock(_component_el_radio, {
              value: option.value,
              label: option.label
            }, null, 8, ["value", "label"]);
          }), 256))
        ]),
        _: 1
      }, 16, ["modelValue", "disabled", "style"]);
    };
  }
});
export {
  _sfc_main as default
};
