import "../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                          */
/* empty css                                                                  */
/* empty css                                                               */
/* empty css                                                            */
/* empty css                                                               */
/* empty css                                                                     */
/* empty css                                                               */
import { computed, createBlock, openBlock, unref, isRef, withCtx, createElementBlock, Fragment, renderList } from "vue";
import { useVModel } from "../../../../node_modules/@vueuse/core/dist/index.mjs";
import { getEditConfigData } from "../utils/common.mjs";
/* empty css             */
import _export_sfc from "../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElSelect, ElOptionGroup, ElOption } from "../../../../node_modules/element-plus/es/components/select/index.mjs";
const _sfc_main = {
  __name: "Trigger",
  props: {
    modelValue: [String, Number, null],
    options: Array,
    filterRules: Object
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const $props = __props;
    const $emits = __emit;
    const data = useVModel($props, "modelValue", $emits);
    const hiddenFieldsData = computed(() => {
      const editConfigData = getEditConfigData();
      return (editConfigData == null ? void 0 : editConfigData.hiddenFields) || [];
    });
    const groupedOptions = computed(() => {
      const formFields = $props.options.filter((item) => !item.isHidden);
      const hiddenFields = hiddenFieldsData.value.map((item) => ({
        id: item.id,
        label: item.label,
        fieldName: item.fieldName,
        type: "input",
        // 隐藏域默认为 input 类型
        value: item.value || "",
        options: [],
        isHidden: true
      }));
      const result = [];
      if (formFields.length > 0) {
        result.push({
          label: "表单字段",
          options: formFields.map((item) => ({
            id: item.id + "",
            label: item.label,
            value: item.id + ""
          }))
        });
      }
      if (hiddenFields.length > 0) {
        result.push({
          label: "隐藏域",
          options: hiddenFields.map((item) => ({
            id: item.id + "",
            label: item.label,
            value: item.id + ""
          }))
        });
      }
      return result;
    });
    return (_ctx, _cache) => {
      const _component_el_option = ElOption;
      const _component_el_option_group = ElOptionGroup;
      const _component_el_select = ElSelect;
      return openBlock(), createBlock(_component_el_select, {
        class: "trigger-container",
        modelValue: unref(data),
        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(data) ? data.value = $event : null),
        filterable: "",
        placeholder: "选择字段"
      }, {
        default: withCtx(() => [
          (openBlock(true), createElementBlock(Fragment, null, renderList(groupedOptions.value, (group) => {
            return openBlock(), createBlock(_component_el_option_group, {
              key: group.label,
              label: group.label
            }, {
              default: withCtx(() => [
                (openBlock(true), createElementBlock(Fragment, null, renderList(group.options, (item) => {
                  return openBlock(), createBlock(_component_el_option, {
                    key: item.id,
                    label: item.label,
                    value: item.id
                  }, null, 8, ["label", "value"]);
                }), 128))
              ]),
              _: 2
            }, 1032, ["label"]);
          }), 128))
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
};
const Trigger = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-8d97037c"]]);
export {
  Trigger as default
};
