import "../../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                                */
/* empty css                                                                        */
/* empty css                                                                     */
/* empty css                                                                  */
/* 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 { ElSelect, ElOption } from "../../../../../../node_modules/element-plus/es/components/select/index.mjs";
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "Select",
  props: {
    config: {
      type: Object,
      required: true
    },
    modelValue: {
      type: null,
      default: ""
    },
    placeholder: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: false
    },
    readonly: {
      type: Boolean,
      default: false
    },
    multiple: {
      type: Boolean,
      default: false
    },
    clearable: {
      type: Boolean,
      default: true
    },
    filterable: {
      type: Boolean,
      default: false
    },
    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(() => {
      if (!props.optionConfig) return [];
      return props.optionConfig.options || [];
    });
    function handlerChange(val) {
      setFormDataByFieldMapping(
        val,
        props.multiple,
        options.value,
        props.optionConfig.fieldMapping,
        formData,
        [...(fieldsData == null ? void 0 : fieldsData.value) || [], ...(hiddenFields == null ? void 0 : hiddenFields.value) || []]
      );
    }
    return (_ctx, _cache) => {
      const _component_el_option = ElOption;
      const _component_el_select = ElSelect;
      return openBlock(), createBlock(_component_el_select, mergeProps({
        modelValue: inputValue.value,
        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => inputValue.value = $event)
      }, toHandlers(__props.config.eventHandlers), {
        placeholder: __props.placeholder,
        disabled: __props.disabled,
        multiple: __props.multiple,
        clearable: __props.clearable,
        filterable: __props.filterable,
        style: [{ "width": "100%" }, {
          pointerEvents: __props.readonly ? "none" : "auto"
        }],
        onChange: handlerChange
      }), {
        default: withCtx(() => [
          (openBlock(true), createElementBlock(Fragment, null, renderList(options.value, (option) => {
            return openBlock(), createBlock(_component_el_option, {
              key: option.value,
              label: option.label,
              value: option.value,
              disabled: option.disabled
            }, null, 8, ["label", "value", "disabled"]);
          }), 128))
        ]),
        _: 1
      }, 16, ["modelValue", "placeholder", "disabled", "multiple", "clearable", "filterable", "style"]);
    };
  }
});
export {
  _sfc_main as default
};
