import { defineComponent, useModel, computed, resolveComponent, createBlock, openBlock, withCtx, createVNode, mergeProps, toHandlers, unref, mergeModels } from 'vue';
import '../../../../../../utils/index.mjs';
import '../../../../base/selectV2/index.mjs';
import { useWatchModelChange } from '../../composables/useWatchModelChange.mjs';
import { searchFormSelectV2Emits, searchFormSelectV2Props, SearchFormSelectV2Name } from './searchFormSelectV2.mjs';
import { getGmEvent } from '../../../../../../utils/src/elementPlus/event.mjs';
import { selectV2Emits } from '../../../../base/selectV2/selectV2.mjs';
import { isString } from '../../../../../../utils/src/is.mjs';

var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: SearchFormSelectV2Name
  },
  __name: "SearchFormSelectV2",
  props: /* @__PURE__ */ mergeModels(searchFormSelectV2Props, {
    "modelValue": {},
    "modelModifiers": {}
  }),
  emits: /* @__PURE__ */ mergeModels(searchFormSelectV2Emits, ["update:modelValue"]),
  setup(__props, { emit: __emit }) {
    const props = __props;
    const modelValue = useModel(__props, "modelValue");
    const emit = __emit;
    const selectV2Events = getGmEvent(selectV2Emits, emit);
    useWatchModelChange(modelValue, { prop: props.prop, noDefaultSync: props.noDefaultSync });
    const optionsList = computed(() => {
      return props.options.map((v, i) => {
        const res = {
          ...v,
          label: v[props.optionLabel],
          value: v[props.optionValue]
        };
        if (props.labelKey === true) {
          res.label = `${v.id}. ${res.label}`;
        } else if (props.labelKey === "index") {
          res.label = `${i + 1}. ${res.label}`;
        } else if (isString(props.labelKey) && Object.prototype.hasOwnProperty.call(v, props.labelKey)) {
          res.label = `${v[props.labelKey]}. ${res.label}`;
        }
        return res;
      });
    });
    return (_ctx, _cache) => {
      const _component_gm_select_v2 = resolveComponent("gm-select-v2");
      const _component_gm_form_item = resolveComponent("gm-form-item");
      return openBlock(), createBlock(_component_gm_form_item, { prop: _ctx.prop }, {
        default: withCtx(() => [
          createVNode(_component_gm_select_v2, mergeProps({
            modelValue: modelValue.value,
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => modelValue.value = $event),
            placeholder: _ctx.label,
            multiple: _ctx.multiple,
            filterable: "",
            clearable: "",
            "collapse-tags": "",
            "collapse-tags-tooltip": "",
            disabled: _ctx.disabled,
            options: optionsList.value,
            class: "gm-w-full"
          }, toHandlers(unref(selectV2Events))), null, 16, ["modelValue", "placeholder", "multiple", "disabled", "options"])
        ]),
        _: 1
        /* STABLE */
      }, 8, ["prop"]);
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=SearchFormSelectV2.vue2.mjs.map
