import "../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                             */
import "../../../../../node_modules/element-plus/theme-chalk/el-dropdown-menu.css.mjs";
import "../../../../../node_modules/element-plus/theme-chalk/el-dropdown-item.css.mjs";
/* empty css                                                                    */
/* empty css                                                                     */
/* empty css                                                                  */
/* empty css                                                                  */
/* empty css                                                                        */
/* empty css                                                                    */
/* empty css                                                                 */
/* empty css                                                                 */
/* empty css                                                               */
/* empty css                                                                        */
/* empty css                                                                  */
/* empty css                                                                        */
/* empty css                                                                  */
/* empty css                                                                   */
/* empty css                                                                  */
import { computed, ref, watch, createElementBlock, openBlock, Fragment, createElementVNode, createBlock, createCommentVNode, createVNode, withCtx, unref, createTextVNode, toDisplayString, renderList } from "vue";
import { Filter as filter_default, Rank as rank_default, Delete as delete_default, Plus as plus_default } from "../../../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
import { VueDraggable as lo } from "../../../../../node_modules/vue-draggable-plus/dist/vue-draggable-plus.mjs";
import { getEditConfigData } from "../../utils/common.mjs";
import FixedModeConfig from "./FixedModeConfig.vue.mjs";
import DynamicModeConfig from "./DynamicModeConfig.vue.mjs";
import TableBtn from "../tableBtn.vue.mjs";
/* empty css            */
import _export_sfc from "../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElSwitch } from "../../../../../node_modules/element-plus/es/components/switch/index.mjs";
import { ElDivider } from "../../../../../node_modules/element-plus/es/components/divider/index.mjs";
import { ElSelect, ElOption } from "../../../../../node_modules/element-plus/es/components/select/index.mjs";
import { ElInputNumber } from "../../../../../node_modules/element-plus/es/components/input-number/index.mjs";
import { ElDropdown, ElDropdownMenu, ElDropdownItem } from "../../../../../node_modules/element-plus/es/components/dropdown/index.mjs";
import { ElButton } from "../../../../../node_modules/element-plus/es/components/button/index.mjs";
import { ElTag } from "../../../../../node_modules/element-plus/es/components/tag/index.mjs";
import { ElIcon } from "../../../../../node_modules/element-plus/es/components/icon/index.mjs";
import { ElInput } from "../../../../../node_modules/element-plus/es/components/input/index.mjs";
import { ElEmpty } from "../../../../../node_modules/element-plus/es/components/empty/index.mjs";
import { ElCheckbox } from "../../../../../node_modules/element-plus/es/components/checkbox/index.mjs";
const _hoisted_1 = { class: "table-query-config" };
const _hoisted_2 = { class: "config-row" };
const _hoisted_3 = {
  key: 0,
  class: "tab-panel"
};
const _hoisted_4 = { class: "tab-header" };
const _hoisted_5 = { class: "tab-config-list" };
const _hoisted_6 = { class: "drag-handle" };
const _hoisted_7 = { class: "add-field-label" };
const _hoisted_8 = { class: "add-field-label" };
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const editConfigData = computed(() => getEditConfigData());
    const editConfigDataValue = computed(() => getEditConfigData());
    const queryConfig = computed(() => getEditConfigData().queryConfig);
    const tabConfigDropdownVisible = ref(false);
    const tabConfigs = computed({
      get: () => {
        var _a, _b;
        return ((_b = (_a = queryConfig.value) == null ? void 0 : _a.dynamicConfig) == null ? void 0 : _b.tabConfigs) || [];
      },
      set: (val) => {
        if (!queryConfig.value.dynamicConfig) {
          queryConfig.value.dynamicConfig = {};
        }
        queryConfig.value.dynamicConfig.tabConfigs = val;
      }
    });
    const searchFields = computed({
      get: () => {
        var _a, _b;
        return ((_b = (_a = queryConfig.value) == null ? void 0 : _a.dynamicConfig) == null ? void 0 : _b.searchFields) || [];
      },
      set: (val) => {
        if (!queryConfig.value.dynamicConfig) {
          queryConfig.value.dynamicConfig = {};
        }
        queryConfig.value.dynamicConfig.searchFields = val;
      }
    });
    watch(
      () => {
        var _a;
        return (_a = queryConfig.value) == null ? void 0 : _a.mode;
      },
      (newMode) => {
        if (!queryConfig.value) return;
        if (newMode === "dynamic" && !queryConfig.value.dynamicConfig) {
          queryConfig.value.dynamicConfig = {
            tabConfigs: [],
            searchFields: []
          };
        }
      },
      { immediate: true }
    );
    const availableFields = computed(() => {
      var _a, _b;
      const allFields = [
        ...((_a = editConfigData.value) == null ? void 0 : _a.fieldsData) || [],
        ...((_b = editConfigData.value) == null ? void 0 : _b.hiddenFields) || []
      ];
      return allFields;
    });
    const availableSearchFields = computed(() => {
      const selectedFieldIds = searchFields.value.map((f) => f.id);
      return availableFields.value.map((field) => ({
        ...field,
        isSearchField: selectedFieldIds.includes(field.id)
      }));
    });
    function addTabConfig() {
      const newTab = {
        id: Date.now(),
        label: `标签名${tabConfigs.value.length + 1}`,
        fieldName: "",
        fixedValue: ""
      };
      tabConfigs.value = [...tabConfigs.value, newTab];
    }
    function removeTabConfig(index) {
      const newTabs = [...tabConfigs.value];
      newTabs.splice(index, 1);
      tabConfigs.value = newTabs;
    }
    function handleSearchFieldChange(field, value) {
      if (value) {
        searchFields.value = [
          ...searchFields.value,
          {
            id: field.id,
            fieldName: field.fieldName,
            label: field.label,
            fieldType: field.fieldType
          }
        ];
      } else {
        const newFields = searchFields.value.filter((f) => f.id !== field.id);
        searchFields.value = newFields;
      }
    }
    function handleAddField(field, value) {
      if (!editConfigData.value.queryConfig) {
        editConfigData.value.queryConfig = {};
      }
      if (!editConfigData.value.queryConfig.filterFields) {
        editConfigData.value.queryConfig.filterFields = [];
      }
      if (value) {
        editConfigData.value.queryConfig.filterFields.push({
          id: Date.now(),
          fieldId: field.id,
          type: "filterWidgets",
          queryType: "fuzzy"
        });
      } else {
        const index = editConfigData.value.queryConfig.filterFields.findIndex(
          (f) => f.fieldId == field.id
        );
        if (index !== -1) {
          editConfigData.value.queryConfig.filterFields.splice(index, 1);
        }
      }
    }
    return (_ctx, _cache) => {
      const _component_el_switch = ElSwitch;
      const _component_el_divider = ElDivider;
      const _component_el_option = ElOption;
      const _component_el_select = ElSelect;
      const _component_el_input_number = ElInputNumber;
      const _component_el_tag = ElTag;
      const _component_el_button = ElButton;
      const _component_el_icon = ElIcon;
      const _component_el_input = ElInput;
      const _component_el_empty = ElEmpty;
      const _component_el_dropdown = ElDropdown;
      const _component_el_checkbox = ElCheckbox;
      const _component_el_dropdown_item = ElDropdownItem;
      const _component_el_dropdown_menu = ElDropdownMenu;
      return openBlock(), createElementBlock(Fragment, null, [
        createElementVNode("div", _hoisted_1, [
          createElementVNode("div", _hoisted_2, [
            _cache[20] || (_cache[20] = createElementVNode("span", { class: "config-label" }, "开启筛选", -1)),
            createVNode(_component_el_switch, {
              modelValue: queryConfig.value.enabled,
              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => queryConfig.value.enabled = $event),
              size: "small"
            }, null, 8, ["modelValue"]),
            createVNode(_component_el_divider, { direction: "vertical" }),
            _cache[21] || (_cache[21] = createElementVNode("span", { class: "config-label" }, "显示返回", -1)),
            createVNode(_component_el_switch, {
              modelValue: editConfigDataValue.value.showReturn,
              "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => editConfigDataValue.value.showReturn = $event),
              size: "small"
            }, null, 8, ["modelValue"]),
            createVNode(_component_el_divider, { direction: "vertical" }),
            _cache[22] || (_cache[22] = createElementVNode("span", { class: "config-label" }, "显示标题", -1)),
            createVNode(_component_el_switch, {
              modelValue: editConfigDataValue.value.showTitle,
              "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => editConfigDataValue.value.showTitle = $event),
              size: "small"
            }, null, 8, ["modelValue"]),
            createVNode(_component_el_divider, { direction: "vertical" }),
            _cache[23] || (_cache[23] = createElementVNode("span", { class: "config-label" }, "筛选模式", -1)),
            createVNode(_component_el_select, {
              modelValue: queryConfig.value.mode,
              "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => queryConfig.value.mode = $event),
              size: "small",
              style: { "width": "120px" }
            }, {
              default: withCtx(() => [
                createVNode(_component_el_option, {
                  label: "固定列",
                  value: "fixed"
                }),
                createVNode(_component_el_option, {
                  label: "动态列",
                  value: "dynamic"
                })
              ]),
              _: 1
            }, 8, ["modelValue"]),
            queryConfig.value.mode === "fixed" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
              createVNode(_component_el_divider, { direction: "vertical" }),
              _cache[11] || (_cache[11] = createElementVNode("span", { class: "config-label" }, "筛选列数", -1)),
              createVNode(_component_el_select, {
                modelValue: queryConfig.value.columnCount,
                "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => queryConfig.value.columnCount = $event),
                size: "small",
                style: { "width": "100px" }
              }, {
                default: withCtx(() => [
                  createVNode(_component_el_option, {
                    label: "一列",
                    value: 1
                  }),
                  createVNode(_component_el_option, {
                    label: "二列",
                    value: 2
                  }),
                  createVNode(_component_el_option, {
                    label: "三列",
                    value: 3
                  }),
                  createVNode(_component_el_option, {
                    label: "四列",
                    value: 4
                  })
                ]),
                _: 1
              }, 8, ["modelValue"]),
              createVNode(_component_el_divider, { direction: "vertical" }),
              _cache[12] || (_cache[12] = createElementVNode("span", { class: "config-label" }, "收起行数", -1)),
              createVNode(_component_el_input_number, {
                modelValue: queryConfig.value.collapseRows,
                "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => queryConfig.value.collapseRows = $event),
                min: 1,
                size: "small",
                "controls-position": "right",
                style: { "width": "80px" }
              }, null, 8, ["modelValue"])
            ], 64)) : createCommentVNode("", true),
            queryConfig.value.mode === "dynamic" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
              createVNode(_component_el_divider, { direction: "vertical" }),
              createVNode(_component_el_dropdown, {
                "max-height": 500,
                trigger: "click",
                "popper-class": "tab-config-dropdown",
                onVisibleChange: _cache[7] || (_cache[7] = (visible) => tabConfigDropdownVisible.value = visible)
              }, {
                dropdown: withCtx(() => [
                  tabConfigDropdownVisible.value ? (openBlock(), createElementBlock("div", _hoisted_3, [
                    createElementVNode("div", _hoisted_4, [
                      _cache[15] || (_cache[15] = createElementVNode("span", { class: "tab-tip" }, "配置Tab页签筛选条件", -1)),
                      createVNode(_component_el_button, {
                        type: "primary",
                        size: "small",
                        onClick: addTabConfig,
                        icon: "Plus"
                      }, {
                        default: withCtx(() => _cache[14] || (_cache[14] = [
                          createTextVNode(" 添加Tab页签 ")
                        ])),
                        _: 1
                      })
                    ]),
                    createElementVNode("div", _hoisted_5, [
                      createVNode(unref(lo), {
                        modelValue: tabConfigs.value,
                        "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => tabConfigs.value = $event),
                        animation: 150,
                        handle: ".drag-handle"
                      }, {
                        default: withCtx(() => [
                          (openBlock(true), createElementBlock(Fragment, null, renderList(tabConfigs.value, (tab, index) => {
                            return openBlock(), createElementBlock("div", {
                              key: tab.id,
                              class: "tab-config-item"
                            }, [
                              createElementVNode("div", _hoisted_6, [
                                createVNode(_component_el_icon, null, {
                                  default: withCtx(() => [
                                    createVNode(unref(rank_default))
                                  ]),
                                  _: 1
                                })
                              ]),
                              createVNode(_component_el_input, {
                                modelValue: tab.label,
                                "onUpdate:modelValue": ($event) => tab.label = $event,
                                size: "small",
                                placeholder: "标签名",
                                style: { "width": "120px" }
                              }, null, 8, ["modelValue", "onUpdate:modelValue"]),
                              createVNode(_component_el_select, {
                                modelValue: tab.fieldName,
                                "onUpdate:modelValue": ($event) => tab.fieldName = $event,
                                size: "small",
                                placeholder: "选择字段",
                                style: { "width": "150px" },
                                "append-to": ".tab-config-dropdown"
                              }, {
                                default: withCtx(() => [
                                  (openBlock(true), createElementBlock(Fragment, null, renderList(availableFields.value, (field) => {
                                    return openBlock(), createBlock(_component_el_option, {
                                      key: field.id,
                                      label: field.label,
                                      value: field.fieldName
                                    }, null, 8, ["label", "value"]);
                                  }), 128))
                                ]),
                                _: 2
                              }, 1032, ["modelValue", "onUpdate:modelValue"]),
                              createVNode(_component_el_input, {
                                modelValue: tab.fixedValue,
                                "onUpdate:modelValue": ($event) => tab.fixedValue = $event,
                                size: "small",
                                placeholder: "筛选值",
                                style: { "width": "120px" },
                                disabled: !tab.fieldName
                              }, null, 8, ["modelValue", "onUpdate:modelValue", "disabled"]),
                              createVNode(_component_el_button, {
                                icon: unref(delete_default),
                                link: "",
                                type: "danger",
                                class: "delete-btn",
                                onClick: ($event) => removeTabConfig(index)
                              }, null, 8, ["icon", "onClick"])
                            ]);
                          }), 128))
                        ]),
                        _: 1
                      }, 8, ["modelValue"]),
                      tabConfigs.value.length === 0 ? (openBlock(), createBlock(_component_el_empty, {
                        key: 0,
                        description: "暂无Tab页签配置",
                        "image-size": 60
                      })) : createCommentVNode("", true)
                    ])
                  ])) : createCommentVNode("", true)
                ]),
                default: withCtx(() => [
                  createVNode(_component_el_button, {
                    icon: unref(filter_default),
                    size: "small"
                  }, {
                    default: withCtx(() => [
                      _cache[13] || (_cache[13] = createTextVNode(" 配置Tab页签 ")),
                      tabConfigs.value.length > 0 ? (openBlock(), createBlock(_component_el_tag, {
                        key: 0,
                        size: "small",
                        type: "primary",
                        class: "tab-count-tag"
                      }, {
                        default: withCtx(() => [
                          createTextVNode(toDisplayString(tabConfigs.value.length), 1)
                        ]),
                        _: 1
                      })) : createCommentVNode("", true)
                    ]),
                    _: 1
                  }, 8, ["icon"])
                ]),
                _: 1
              }),
              createVNode(_component_el_divider, { direction: "vertical" }),
              createVNode(_component_el_dropdown, {
                "max-height": 500,
                trigger: "click",
                placement: "bottom",
                "hide-on-click": false
              }, {
                dropdown: withCtx(() => [
                  createVNode(_component_el_dropdown_menu, null, {
                    default: withCtx(() => [
                      (openBlock(true), createElementBlock(Fragment, null, renderList(availableSearchFields.value, (field) => {
                        return openBlock(), createBlock(_component_el_dropdown_item, {
                          key: field.id,
                          command: field
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_el_checkbox, {
                              modelValue: field.isSearchField,
                              "onUpdate:modelValue": ($event) => field.isSearchField = $event,
                              onChange: (value) => {
                                handleSearchFieldChange(field, value);
                              }
                            }, {
                              default: withCtx(() => [
                                createElementVNode("span", _hoisted_7, toDisplayString(field.label), 1)
                              ]),
                              _: 2
                            }, 1032, ["modelValue", "onUpdate:modelValue", "onChange"])
                          ]),
                          _: 2
                        }, 1032, ["command"]);
                      }), 128)),
                      availableSearchFields.value.length === 0 ? (openBlock(), createBlock(_component_el_dropdown_item, {
                        key: 0,
                        disabled: ""
                      }, {
                        default: withCtx(() => _cache[17] || (_cache[17] = [
                          createElementVNode("span", {
                            class: "add-field-label",
                            style: { "text-align": "center" }
                          }, "暂无可用字段", -1)
                        ])),
                        _: 1
                      })) : createCommentVNode("", true)
                    ]),
                    _: 1
                  })
                ]),
                default: withCtx(() => [
                  createVNode(_component_el_button, {
                    size: "small",
                    icon: unref(plus_default)
                  }, {
                    default: withCtx(() => [
                      _cache[16] || (_cache[16] = createTextVNode(" 配置搜索字段 ")),
                      searchFields.value.length > 0 ? (openBlock(), createBlock(_component_el_tag, {
                        key: 0,
                        size: "small",
                        type: "primary",
                        style: { "margin-left": "6px", "height": "16px", "padding": "0 5px" }
                      }, {
                        default: withCtx(() => [
                          createTextVNode(toDisplayString(searchFields.value.length), 1)
                        ]),
                        _: 1
                      })) : createCommentVNode("", true)
                    ]),
                    _: 1
                  }, 8, ["icon"])
                ]),
                _: 1
              }),
              createVNode(_component_el_divider, { direction: "vertical" }),
              _cache[18] || (_cache[18] = createElementVNode("span", { class: "config-label" }, "高级搜索", -1)),
              createVNode(_component_el_switch, {
                modelValue: queryConfig.value.dynamicConfig.advancedSearch,
                "onUpdate:modelValue": _cache[8] || (_cache[8] = ($event) => queryConfig.value.dynamicConfig.advancedSearch = $event),
                size: "small"
              }, null, 8, ["modelValue"])
            ], 64)) : createCommentVNode("", true),
            queryConfig.value.mode === "fixed" || queryConfig.value.mode === "dynamic" && queryConfig.value.dynamicConfig.advancedSearch ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
              createVNode(_component_el_divider, { direction: "vertical" }),
              createVNode(_component_el_dropdown, {
                trigger: "click",
                placement: "bottom",
                "hide-on-click": false
              }, {
                dropdown: withCtx(() => [
                  createVNode(_component_el_dropdown_menu, null, {
                    default: withCtx(() => [
                      (openBlock(true), createElementBlock(Fragment, null, renderList(availableFields.value, (field) => {
                        return openBlock(), createBlock(_component_el_dropdown_item, {
                          key: field.id,
                          command: field
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_el_checkbox, {
                              modelValue: field.isFilter,
                              "onUpdate:modelValue": ($event) => field.isFilter = $event,
                              onChange: (value) => {
                                handleAddField(field, value);
                              }
                            }, {
                              default: withCtx(() => [
                                createElementVNode("span", _hoisted_8, toDisplayString(field.label), 1)
                              ]),
                              _: 2
                            }, 1032, ["modelValue", "onUpdate:modelValue", "onChange"])
                          ]),
                          _: 2
                        }, 1032, ["command"]);
                      }), 128)),
                      availableFields.value.length === 0 ? (openBlock(), createBlock(_component_el_dropdown_item, {
                        key: 0,
                        disabled: ""
                      }, {
                        default: withCtx(() => _cache[19] || (_cache[19] = [
                          createElementVNode("span", {
                            class: "add-field-label",
                            style: { "text-align": "center" }
                          }, "暂无可用字段", -1)
                        ])),
                        _: 1
                      })) : createCommentVNode("", true)
                    ]),
                    _: 1
                  })
                ]),
                default: withCtx(() => [
                  createVNode(_component_el_button, {
                    size: "small",
                    icon: unref(plus_default)
                  }, {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(queryConfig.value.mode === "fixed" ? "新增筛选" : "高级搜索字段") + " ", 1),
                      queryConfig.value.filterFields.length > 0 ? (openBlock(), createBlock(_component_el_tag, {
                        key: 0,
                        size: "small",
                        type: "primary",
                        style: { "margin-left": "6px", "height": "16px", "padding": "0 5px" }
                      }, {
                        default: withCtx(() => [
                          createTextVNode(toDisplayString(queryConfig.value.filterFields.length), 1)
                        ]),
                        _: 1
                      })) : createCommentVNode("", true)
                    ]),
                    _: 1
                  }, 8, ["icon"])
                ]),
                _: 1
              })
            ], 64)) : createCommentVNode("", true)
          ]),
          queryConfig.value.mode === "fixed" && queryConfig.value.enabled ? (openBlock(), createBlock(FixedModeConfig, {
            key: 0,
            modelValue: queryConfig.value.filterFields,
            "onUpdate:modelValue": _cache[9] || (_cache[9] = ($event) => queryConfig.value.filterFields = $event)
          }, null, 8, ["modelValue"])) : queryConfig.value.mode === "dynamic" ? (openBlock(), createBlock(DynamicModeConfig, {
            key: 1,
            modelValue: queryConfig.value.dynamicConfig,
            "onUpdate:modelValue": _cache[10] || (_cache[10] = ($event) => queryConfig.value.dynamicConfig = $event),
            enabled: queryConfig.value.enabled
          }, null, 8, ["modelValue", "enabled"])) : createCommentVNode("", true)
        ]),
        queryConfig.value.mode === "fixed" ? (openBlock(), createBlock(TableBtn, { key: 0 })) : createCommentVNode("", true)
      ], 64);
    };
  }
};
const QueryModule = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-e569e134"]]);
export {
  QueryModule as default
};
