"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../node_modules/element-plus/es/index.js");
;/* empty css                                                       */
;/* empty css                                                            */
;/* empty css                                                             */
;/* empty css                                                          */
;/* empty css                                                           */
require("../../../node_modules/element-plus/theme-chalk/el-tab-pane.css.js");
;/* empty css                                                               */
;/* empty css                                                           */
;/* empty css                                                           */
;/* empty css                                                            */
const Vue = require("vue");
const index$7 = require("../../../node_modules/@element-plus/icons-vue/dist/index.js");
const common = require("../packages/utils/common.js");
;/* empty css                          */
const _pluginVue_exportHelper = require("../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../node_modules/element-plus/es/components/popover/index.js");
const index$1 = require("../../../node_modules/element-plus/es/components/tabs/index.js");
const index$2 = require("../../../node_modules/element-plus/es/components/input/index.js");
const index$3 = require("../../../node_modules/element-plus/es/components/scrollbar/index.js");
const index$4 = require("../../../node_modules/element-plus/es/components/empty/index.js");
const index$5 = require("../../../node_modules/element-plus/es/components/alert/index.js");
const index$6 = require("../../../node_modules/element-plus/es/components/button/index.js");
const _hoisted_1 = { class: "value-selector-tabs" };
const _hoisted_2 = { key: 0 };
const _hoisted_3 = { class: "field-group-label" };
const _hoisted_4 = { class: "field-list" };
const _hoisted_5 = ["onClick"];
const _hoisted_6 = { class: "field-label" };
const _hoisted_7 = { class: "field-code" };
const _hoisted_8 = {
  key: 1,
  class: "no-data"
};
const _hoisted_9 = { class: "user-info-list" };
const _hoisted_10 = { class: "popover-footer" };
const _sfc_main = {
  __name: "ValueSelectorPopover",
  props: {
    availableFields: {
      type: Array,
      default: () => []
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  emits: ["confirm"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const showSelector = Vue.ref(false);
    const activeTab = Vue.ref("fields");
    const fieldSearchText = Vue.ref("");
    const urlParamInput = Vue.ref("");
    const selectedFieldId = Vue.ref(null);
    const selectedUserInfoKey = Vue.ref(null);
    const hiddenFieldsData = Vue.computed(() => {
      const editConfigData = common.getEditConfigData();
      return (editConfigData == null ? void 0 : editConfigData.hiddenFields) || [];
    });
    const filteredFields = Vue.computed(() => {
      const formFields = (props.availableFields || []).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 allFields = [...formFields, ...hiddenFields];
      if (!fieldSearchText.value.trim()) {
        return allFields;
      }
      const searchLower = fieldSearchText.value.trim().toLowerCase();
      return allFields.filter((field) => {
        const label = (field.label || "").toLowerCase();
        const fieldName = (field.fieldName || "").toLowerCase();
        return label.includes(searchLower) || fieldName.includes(searchLower);
      });
    });
    const groupedFields = Vue.computed(() => {
      if (filteredFields.value.length === 0) {
        return [];
      }
      const result = [];
      const formFields = filteredFields.value.filter((item) => !item.isHidden);
      if (formFields.length > 0) {
        result.push({
          groupLabel: "表单字段",
          items: formFields
        });
      }
      const hiddenFields = filteredFields.value.filter((item) => item.isHidden);
      if (hiddenFields.length > 0) {
        result.push({
          groupLabel: "隐藏域",
          items: hiddenFields
        });
      }
      return result;
    });
    const selectField = (fieldId) => {
      selectedFieldId.value = fieldId;
    };
    const selectUserInfo = (key) => {
      selectedUserInfoKey.value = key;
    };
    const handleConfirm = () => {
      let result = null;
      if (activeTab.value === "fields" && selectedFieldId.value) {
        result = {
          type: "field",
          value: selectedFieldId.value
        };
      } else if (activeTab.value === "userInfo" && selectedUserInfoKey.value) {
        result = {
          type: "userInfo",
          value: selectedUserInfoKey.value
        };
      } else if (activeTab.value === "urlParams" && urlParamInput.value.trim()) {
        result = {
          type: "urlParam",
          value: urlParamInput.value.trim()
        };
      }
      if (result) {
        emit("confirm", result);
      }
      showSelector.value = false;
    };
    Vue.watch(showSelector, (val) => {
      if (val) {
        selectedFieldId.value = null;
        selectedUserInfoKey.value = null;
        urlParamInput.value = "";
        fieldSearchText.value = "";
      }
    });
    return (_ctx, _cache) => {
      const _component_el_button = index$6.ElButton;
      const _component_el_input = index$2.ElInput;
      const _component_el_empty = index$4.ElEmpty;
      const _component_el_scrollbar = index$3.ElScrollbar;
      const _component_el_tab_pane = index$1.ElTabPane;
      const _component_el_alert = index$5.ElAlert;
      const _component_el_tabs = index$1.ElTabs;
      const _component_el_popover = index.ElPopover;
      return Vue.openBlock(), Vue.createBlock(_component_el_popover, {
        visible: showSelector.value,
        "onUpdate:visible": _cache[10] || (_cache[10] = ($event) => showSelector.value = $event),
        placement: "bottom",
        width: 250,
        trigger: "click",
        "close-on-click-modal": false,
        "popper-style": "padding:0px",
        "popper-class": "dev-value-selector"
      }, {
        reference: Vue.withCtx(() => [
          Vue.createVNode(_component_el_button, {
            icon: Vue.unref(index$7.Connection),
            disabled: __props.disabled,
            size: "small",
            class: "dev-value-selector-btn"
          }, null, 8, ["icon", "disabled"])
        ]),
        default: Vue.withCtx(() => [
          Vue.createElementVNode("div", _hoisted_1, [
            Vue.createVNode(_component_el_tabs, {
              modelValue: activeTab.value,
              "onUpdate:modelValue": _cache[8] || (_cache[8] = ($event) => activeTab.value = $event)
            }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_tab_pane, {
                  label: "页面字段",
                  name: "fields"
                }, {
                  default: Vue.withCtx(() => [
                    Vue.createVNode(_component_el_input, {
                      modelValue: fieldSearchText.value,
                      "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => fieldSearchText.value = $event),
                      placeholder: "搜索字段",
                      "prefix-icon": "Search",
                      clearable: "",
                      style: { "margin-bottom": "12px" }
                    }, null, 8, ["modelValue"]),
                    Vue.createVNode(_component_el_scrollbar, { "max-height": "300px" }, {
                      default: Vue.withCtx(() => [
                        groupedFields.value.length > 0 ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_2, [
                          (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(groupedFields.value, (group) => {
                            return Vue.openBlock(), Vue.createElementBlock("div", {
                              key: group.groupLabel
                            }, [
                              Vue.createElementVNode("div", _hoisted_3, Vue.toDisplayString(group.groupLabel), 1),
                              Vue.createElementVNode("ul", _hoisted_4, [
                                (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(group.items, (field) => {
                                  return Vue.openBlock(), Vue.createElementBlock("li", {
                                    key: field.id,
                                    class: Vue.normalizeClass(["field-item", { active: selectedFieldId.value === field.id }]),
                                    onClick: ($event) => selectField(field.id)
                                  }, [
                                    Vue.createElementVNode("span", _hoisted_6, Vue.toDisplayString(field.label || field.fieldName), 1),
                                    Vue.createElementVNode("span", _hoisted_7, "(" + Vue.toDisplayString(field.fieldName) + ")", 1)
                                  ], 10, _hoisted_5);
                                }), 128))
                              ])
                            ]);
                          }), 128))
                        ])) : (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_8, [
                          Vue.createVNode(_component_el_empty, {
                            description: "未找到匹配的字段",
                            "image-size": 80
                          })
                        ]))
                      ]),
                      _: 1
                    })
                  ]),
                  _: 1
                }),
                Vue.createVNode(_component_el_tab_pane, {
                  label: "用户信息",
                  name: "userInfo"
                }, {
                  default: Vue.withCtx(() => [
                    Vue.createVNode(_component_el_scrollbar, { "max-height": "400px" }, {
                      default: Vue.withCtx(() => [
                        Vue.createElementVNode("ul", _hoisted_9, [
                          Vue.createElementVNode("li", {
                            value: "userCode",
                            class: Vue.normalizeClass(["user-info-item", { active: selectedUserInfoKey.value === "userCode" }]),
                            onClick: _cache[1] || (_cache[1] = ($event) => selectUserInfo("userCode"))
                          }, _cache[11] || (_cache[11] = [
                            Vue.createElementVNode("span", { class: "info-label" }, "用户编号", -1),
                            Vue.createElementVNode("span", { class: "info-code" }, "(userCode)", -1)
                          ]), 2),
                          Vue.createElementVNode("li", {
                            value: "userName",
                            class: Vue.normalizeClass(["user-info-item", { active: selectedUserInfoKey.value === "userName" }]),
                            onClick: _cache[2] || (_cache[2] = ($event) => selectUserInfo("userName"))
                          }, _cache[12] || (_cache[12] = [
                            Vue.createElementVNode("span", { class: "info-label" }, "用户名称", -1),
                            Vue.createElementVNode("span", { class: "info-code" }, "(userName)", -1)
                          ]), 2),
                          Vue.createElementVNode("li", {
                            value: "roleCode",
                            class: Vue.normalizeClass(["user-info-item", { active: selectedUserInfoKey.value === "roleCode" }]),
                            onClick: _cache[3] || (_cache[3] = ($event) => selectUserInfo("roleCode"))
                          }, _cache[13] || (_cache[13] = [
                            Vue.createElementVNode("span", { class: "info-label" }, "角色编号", -1),
                            Vue.createElementVNode("span", { class: "info-code" }, "(roleCode)", -1)
                          ]), 2),
                          Vue.createElementVNode("li", {
                            value: "roleName",
                            class: Vue.normalizeClass(["user-info-item", { active: selectedUserInfoKey.value === "roleName" }]),
                            onClick: _cache[4] || (_cache[4] = ($event) => selectUserInfo("roleName"))
                          }, _cache[14] || (_cache[14] = [
                            Vue.createElementVNode("span", { class: "info-label" }, "角色名称", -1),
                            Vue.createElementVNode("span", { class: "info-code" }, "(roleName)", -1)
                          ]), 2),
                          Vue.createElementVNode("li", {
                            value: "orgCode",
                            class: Vue.normalizeClass(["user-info-item", { active: selectedUserInfoKey.value === "orgCode" }]),
                            onClick: _cache[5] || (_cache[5] = ($event) => selectUserInfo("orgCode"))
                          }, _cache[15] || (_cache[15] = [
                            Vue.createElementVNode("span", { class: "info-label" }, "机构编号", -1),
                            Vue.createElementVNode("span", { class: "info-code" }, "(orgCode)", -1)
                          ]), 2),
                          Vue.createElementVNode("li", {
                            value: "orgName",
                            class: Vue.normalizeClass(["user-info-item", { active: selectedUserInfoKey.value === "orgName" }]),
                            onClick: _cache[6] || (_cache[6] = ($event) => selectUserInfo("orgName"))
                          }, _cache[16] || (_cache[16] = [
                            Vue.createElementVNode("span", { class: "info-label" }, "机构名称", -1),
                            Vue.createElementVNode("span", { class: "info-code" }, "(orgName)", -1)
                          ]), 2)
                        ])
                      ]),
                      _: 1
                    })
                  ]),
                  _: 1
                }),
                Vue.createVNode(_component_el_tab_pane, {
                  label: "路由参数",
                  name: "urlParams"
                }, {
                  default: Vue.withCtx(() => [
                    Vue.createVNode(_component_el_alert, {
                      title: "从地址栏获取参数，如: /page?id=123 中的 id",
                      type: "info",
                      closable: false,
                      class: "url-param-alert"
                    }),
                    Vue.createVNode(_component_el_input, {
                      modelValue: urlParamInput.value,
                      "onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => urlParamInput.value = $event),
                      placeholder: "请输入参数名称，如: id",
                      clearable: ""
                    }, null, 8, ["modelValue"])
                  ]),
                  _: 1
                })
              ]),
              _: 1
            }, 8, ["modelValue"])
          ]),
          Vue.createElementVNode("div", _hoisted_10, [
            Vue.createVNode(_component_el_button, {
              onClick: _cache[9] || (_cache[9] = ($event) => showSelector.value = false)
            }, {
              default: Vue.withCtx(() => _cache[17] || (_cache[17] = [
                Vue.createTextVNode("取消")
              ])),
              _: 1
            }),
            Vue.createVNode(_component_el_button, {
              type: "primary",
              onClick: handleConfirm
            }, {
              default: Vue.withCtx(() => _cache[18] || (_cache[18] = [
                Vue.createTextVNode("确定")
              ])),
              _: 1
            })
          ])
        ]),
        _: 1
      }, 8, ["visible"]);
    };
  }
};
const ValueSelectorPopover = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-1cc2af93"]]);
exports.default = ValueSelectorPopover;
