"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                                                                  */
;/* empty css                                                                 */
;/* empty css                                                                     */
;/* empty css                                                                  */
;/* empty css                                                                             */
require("../../../../../node_modules/element-plus/theme-chalk/el-date-picker.css.js");
;/* empty css                                                               */
;/* empty css                                                                  */
;/* empty css                                                                        */
;/* empty css                                                                  */
;/* empty css                                                                    */
;/* empty css                                                                          */
;/* empty css                                                                           */
;/* empty css                                                                */
;/* empty css                                                                */
require("../../../../../node_modules/element-plus/theme-chalk/el-tab-pane.css.js");
const Vue = require("vue");
const common = require("../../utils/common.js");
const index$1 = require("../../../../../node_modules/@element-plus/icons-vue/dist/index.js");
const vueDraggablePlus = require("../../../../../node_modules/vue-draggable-plus/dist/vue-draggable-plus.js");
const _default = require("../default.js");
const optionLoader = require("../../../utils/optionLoader.js");
;/* empty css                        */
const _pluginVue_exportHelper = require("../../../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../../../node_modules/element-plus/es/components/icon/index.js");
const index$2 = require("../../../../../node_modules/element-plus/es/components/tabs/index.js");
const index$3 = require("../../../../../node_modules/element-plus/es/components/input/index.js");
const index$4 = require("../../../../../node_modules/element-plus/es/components/button/index.js");
const index$5 = require("../../../../../node_modules/element-plus/es/components/link/index.js");
const index$6 = require("../../../../../node_modules/element-plus/es/components/collapse-transition/index.js");
const index$7 = require("../../../../../node_modules/element-plus/es/components/form/index.js");
const index$8 = require("../../../../../node_modules/element-plus/es/components/checkbox/index.js");
const index$9 = require("../../../../../node_modules/element-plus/es/components/select/index.js");
const index$a = require("../../../../../node_modules/element-plus/es/components/date-picker/index.js");
const _hoisted_1 = { class: "dynamic-mode-config" };
const _hoisted_2 = { class: "dynamic-row" };
const _hoisted_3 = {
  key: 0,
  class: "back-icon"
};
const _hoisted_4 = {
  key: 1,
  class: "template-name"
};
const _hoisted_5 = {
  key: 2,
  class: "tab-display-section"
};
const _hoisted_6 = { class: "search-display-section" };
const _hoisted_7 = {
  key: 0,
  class: "search-input-group"
};
const _hoisted_8 = ["onMouseenter", "onClick"];
const _hoisted_9 = {
  key: 0,
  class: "expand-filter-section"
};
const _hoisted_10 = { class: "filter-form-section" };
const _hoisted_11 = { class: "form-item-label" };
const _sfc_main = {
  __name: "DynamicModeConfig",
  props: {
    modelValue: {
      type: Object,
      default: () => ({})
    },
    enabled: {
      type: Boolean,
      default: false
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const editConfigData = Vue.computed(() => common.getEditConfigData());
    const dynamicConfig = Vue.computed({
      get: () => props.modelValue,
      set: (val) => emit("update:modelValue", val)
    });
    const tabConfigs = Vue.computed(() => {
      var _a;
      return ((_a = dynamicConfig.value) == null ? void 0 : _a.tabConfigs) || [];
    });
    const activeTab = Vue.computed({
      get: () => {
        var _a;
        if (dynamicConfig.value.tabActive) {
          return dynamicConfig.value.tabActive;
        }
        if (tabConfigs.value.length > 0) {
          return ((_a = tabConfigs.value[0]) == null ? void 0 : _a.id) || "";
        }
        return "";
      },
      set: (val) => {
        dynamicConfig.value.tabActive = val;
      }
    });
    Vue.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 btnTypeConfig = {
      custom: { type: "primary" },
      refresh: { icon: index$1.Refresh },
      export: { icon: index$1.Download },
      personalize: { icon: index$1.Setting }
    };
    function getBtnProps(item) {
      const data = btnTypeConfig[item.btnType] || {};
      if (!item.label) {
        data.class = "system";
      } else {
        data.class = "";
      }
      return data;
    }
    function addOptBtns(state) {
      const newBtn = {
        id: Date.now(),
        ..._default.defaultCustomBtn
      };
      {
        editConfigData.value.customBtns[state].unshift(newBtn);
      }
    }
    function removeOptBtns(state, item) {
      const index2 = editConfigData.value.customBtns[state].findIndex(
        (i) => i.id === item.id
      );
      if (index2 !== -1) {
        editConfigData.value.customBtns[state].splice(index2, 1);
      }
    }
    const filterFields = Vue.computed({
      get: () => {
        var _a, _b;
        return ((_b = (_a = editConfigData.value) == null ? void 0 : _a.queryConfig) == null ? void 0 : _b.filterFields) || [];
      },
      set: (val) => {
        editConfigData.value.queryConfig.filterFields = val;
      }
    });
    const formData = Vue.reactive({});
    function getFieldInfo(filterField) {
      var _a, _b;
      const allFields = [
        ...((_a = editConfigData.value) == null ? void 0 : _a.fieldsData) || [],
        ...((_b = editConfigData.value) == null ? void 0 : _b.hiddenFields) || []
      ];
      const field = allFields.find((f) => f.id == filterField.fieldId);
      return field;
    }
    function getFieldLabel(filterField) {
      const fieldInfo = getFieldInfo(filterField);
      return (fieldInfo == null ? void 0 : fieldInfo.label) || "";
    }
    const optionsMap = Vue.reactive({});
    Vue.watch(
      filterFields,
      (fields) => {
        fields.forEach((filterField) => {
          const fieldInfo = getFieldInfo(filterField);
          if (fieldInfo && !(fieldInfo.fieldName in formData)) {
            formData[fieldInfo.fieldName] = fieldInfo.fieldType == "daterange" ? [] : "";
          }
        });
        const currentFieldNames = fields.map((filterField) => {
          const fieldInfo = getFieldInfo(filterField);
          return fieldInfo == null ? void 0 : fieldInfo.fieldName;
        }).filter(Boolean);
        Object.keys(formData).forEach((key) => {
          if (!currentFieldNames.includes(key)) {
            delete formData[key];
          }
        });
        fields.forEach((filterField) => {
          if (filterField.isButtonStyle) {
            getOptions(filterField);
          }
        });
      },
      { immediate: true, deep: true }
    );
    function removeField(field) {
      var _a, _b, _c, _d;
      const index2 = filterFields.value.findIndex((f) => f.id == field.id);
      if (index2 !== -1) {
        if ((_a = editConfigData.value.queryConfig) == null ? void 0 : _a.filterFields) {
          (_b = editConfigData.value.queryConfig) == null ? void 0 : _b.filterFields.splice(index2, 1);
        }
        let fieldItem = (_c = editConfigData.value) == null ? void 0 : _c.fieldsData.find(
          (item) => item.id == field.fieldId
        );
        if (!fieldItem) {
          fieldItem = (_d = editConfigData.value) == null ? void 0 : _d.hiddenFields.find(
            (item) => item.id == field.fieldId
          );
        }
        if (fieldItem) {
          fieldItem.isFilter = false;
        }
      }
    }
    function isInputType(field) {
      const inputTypes = ["text", "textarea", "number"];
      return inputTypes.includes(field.fieldType);
    }
    function isSelectType(field) {
      const selectTypes = [
        "select",
        "radio",
        "checkbox",
        "switch",
        "multipleSelection"
      ];
      return selectTypes.includes(field.fieldType);
    }
    function isDateType(field) {
      const dateTypes = [
        "date",
        "datetime",
        "time",
        "month",
        "year",
        "dates",
        "week"
      ];
      return dateTypes.includes(field.fieldType);
    }
    function getOptions(filterField) {
      var _a, _b;
      const allFields = [
        ...((_a = editConfigData.value) == null ? void 0 : _a.fieldsData) || [],
        ...((_b = editConfigData.value) == null ? void 0 : _b.hiddenFields) || []
      ];
      const field = allFields.find((f) => f.id == filterField.fieldId);
      if (field) {
        optionLoader.loadOptions(field).then((data) => {
          optionsMap[filterField.fieldId] = data;
        });
      } else {
        optionsMap[filterField.fieldId] = [];
      }
    }
    const dynamicPlaceholder = Vue.computed(() => {
      const searchFields = dynamicConfig.value.searchFields || [];
      if (searchFields.length == 0) {
        return "请输入筛选条件";
      }
      const labelArr = searchFields.map((item) => item.label);
      return `搜索${labelArr.join("/")}`;
    });
    return (_ctx, _cache) => {
      const _component_el_icon = index.ElIcon;
      const _component_el_tab_pane = index$2.ElTabPane;
      const _component_el_tabs = index$2.ElTabs;
      const _component_el_button = index$4.ElButton;
      const _component_el_input = index$3.ElInput;
      const _component_el_link = index$5.ElLink;
      const _component_el_checkbox_button = index$8.ElCheckboxButton;
      const _component_el_checkbox_group = index$8.ElCheckboxGroup;
      const _component_el_option = index$9.ElOption;
      const _component_el_select = index$9.ElSelect;
      const _component_el_date_picker = index$a.ElDatePicker;
      const _component_el_form_item = index$7.ElFormItem;
      const _component_el_form = index$7.ElForm;
      const _component_el_collapse_transition = index$6.ElCollapseTransition;
      return Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
        Vue.createElementVNode("div", _hoisted_2, [
          editConfigData.value.showReturn ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_3, [
            Vue.createVNode(_component_el_icon, null, {
              default: Vue.withCtx(() => [
                Vue.createVNode(Vue.unref(index$1.ArrowLeftBold))
              ]),
              _: 1
            })
          ])) : Vue.createCommentVNode("", true),
          editConfigData.value.showTitle ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_4, Vue.toDisplayString(editConfigData.value.templateName), 1)) : Vue.createCommentVNode("", true),
          __props.enabled && tabConfigs.value.length > 0 ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_5, [
            Vue.createVNode(_component_el_tabs, {
              modelValue: activeTab.value,
              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => activeTab.value = $event),
              class: "dynamic-tabs"
            }, {
              default: Vue.withCtx(() => [
                (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(tabConfigs.value, (tab) => {
                  return Vue.openBlock(), Vue.createBlock(_component_el_tab_pane, {
                    key: tab.id,
                    label: tab.label,
                    name: tab.id
                  }, null, 8, ["label", "name"]);
                }), 128))
              ]),
              _: 1
            }, 8, ["modelValue"])
          ])) : Vue.createCommentVNode("", true),
          Vue.createElementVNode("div", _hoisted_6, [
            __props.enabled ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_7, [
              Vue.createVNode(_component_el_input, {
                placeholder: dynamicPlaceholder.value,
                title: dynamicPlaceholder.value,
                class: "search-input"
              }, Vue.createSlots({
                suffix: Vue.withCtx(() => [
                  Vue.createVNode(_component_el_icon, {
                    class: "el-input__icon",
                    style: { "cursor": "pointer" }
                  }, {
                    default: Vue.withCtx(() => [
                      Vue.createVNode(Vue.unref(index$1.Search))
                    ]),
                    _: 1
                  })
                ]),
                _: 2
              }, [
                dynamicConfig.value.advancedSearch ? {
                  name: "append",
                  fn: Vue.withCtx(() => [
                    Vue.createVNode(_component_el_button, { type: "primary" }, {
                      default: Vue.withCtx(() => _cache[6] || (_cache[6] = [
                        Vue.createTextVNode(Vue.toDisplayString("高级搜索"))
                      ])),
                      _: 1
                    })
                  ]),
                  key: "0"
                } : void 0
              ]), 1032, ["placeholder", "title"])
            ])) : Vue.createCommentVNode("", true),
            Vue.createVNode(Vue.unref(vueDraggablePlus.VueDraggable), {
              modelValue: editConfigData.value.customBtns.right,
              "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => editConfigData.value.customBtns.right = $event),
              animation: 150,
              group: { name: "tableBtn" },
              ghostClass: "ghost",
              class: "optBtnDraggable"
            }, {
              default: Vue.withCtx(() => [
                (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(editConfigData.value.customBtns.right, (item) => {
                  return Vue.openBlock(), Vue.createElementBlock("div", {
                    class: Vue.normalizeClass(["optBtn", Vue.unref(common.getCurrentClass)(item)]),
                    onMouseenter: ($event) => Vue.unref(common.setHoverItem)(item),
                    onMouseleave: _cache[1] || (_cache[1] = ($event) => Vue.unref(common.setHoverItem)()),
                    onClick: Vue.withModifiers(($event) => Vue.unref(common.setSelectedItem)(item), ["stop"])
                  }, [
                    Vue.createVNode(_component_el_button, Vue.mergeProps({
                      class: "elBtn",
                      ref_for: true
                    }, getBtnProps(item)), {
                      default: Vue.withCtx(() => [
                        Vue.createTextVNode(Vue.toDisplayString(item.label), 1)
                      ]),
                      _: 2
                    }, 1040),
                    Vue.createVNode(_component_el_icon, {
                      class: "delete-icon",
                      onClick: Vue.withModifiers(($event) => removeOptBtns("right", item), ["stop"])
                    }, {
                      default: Vue.withCtx(() => [
                        Vue.createVNode(Vue.unref(index$1.Close))
                      ]),
                      _: 2
                    }, 1032, ["onClick"])
                  ], 42, _hoisted_8);
                }), 256))
              ]),
              _: 1
            }, 8, ["modelValue"]),
            Vue.createVNode(_component_el_link, {
              class: "optBtn addLink",
              underline: "never",
              type: "primary",
              icon: Vue.unref(index$1.Plus),
              onClick: _cache[3] || (_cache[3] = Vue.withModifiers(($event) => addOptBtns("right"), ["stop"]))
            }, {
              default: Vue.withCtx(() => _cache[7] || (_cache[7] = [
                Vue.createTextVNode("按钮")
              ])),
              _: 1
            }, 8, ["icon"])
          ])
        ]),
        Vue.createVNode(_component_el_collapse_transition, null, {
          default: Vue.withCtx(() => [
            dynamicConfig.value.advancedSearch && filterFields.value.length > 0 ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_9, [
              Vue.createElementVNode("div", _hoisted_10, [
                Vue.createVNode(_component_el_form, {
                  ref: "formRef",
                  model: formData,
                  class: "filter-form",
                  "label-width": "100px",
                  inline: ""
                }, {
                  default: Vue.withCtx(() => [
                    Vue.createVNode(Vue.unref(vueDraggablePlus.VueDraggable), {
                      modelValue: filterFields.value,
                      "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => filterFields.value = $event),
                      animation: 150,
                      group: { name: "filterFields" },
                      ghostClass: "ghost",
                      class: "form-items-draggable"
                    }, {
                      default: Vue.withCtx(() => [
                        (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(filterFields.value, (filterField) => {
                          return Vue.openBlock(), Vue.createElementBlock("div", {
                            key: filterField.id,
                            style: Vue.normalizeStyle(filterField.isExclusiveRow ? "width:100%" : "")
                          }, [
                            Vue.createVNode(_component_el_form_item, {
                              label: getFieldLabel(filterField),
                              onMouseenter: ($event) => Vue.unref(common.setHoverItem)(filterField),
                              onMouseleave: _cache[4] || (_cache[4] = ($event) => Vue.unref(common.setHoverItem)()),
                              onClick: Vue.withModifiers(($event) => Vue.unref(common.setSelectedItem)(filterField), ["stop"]),
                              class: Vue.normalizeClass(Vue.unref(common.getCurrentClass)(filterField))
                            }, {
                              label: Vue.withCtx(() => [
                                Vue.createElementVNode("div", _hoisted_11, [
                                  Vue.createElementVNode("span", null, Vue.toDisplayString(getFieldLabel(filterField)) + ":", 1)
                                ])
                              ]),
                              default: Vue.withCtx(() => [
                                Vue.createVNode(_component_el_icon, {
                                  class: "delete-icon",
                                  onClick: Vue.withModifiers(($event) => removeField(filterField), ["stop"])
                                }, {
                                  default: Vue.withCtx(() => [
                                    Vue.createVNode(Vue.unref(index$1.Close))
                                  ]),
                                  _: 2
                                }, 1032, ["onClick"]),
                                filterField.isButtonStyle ? (Vue.openBlock(), Vue.createBlock(_component_el_checkbox_group, { key: 0 }, {
                                  default: Vue.withCtx(() => [
                                    (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(optionsMap[filterField.fieldId], (option) => {
                                      return Vue.openBlock(), Vue.createBlock(_component_el_checkbox_button, {
                                        key: option.value,
                                        value: option.value
                                      }, {
                                        default: Vue.withCtx(() => [
                                          Vue.createTextVNode(Vue.toDisplayString(option.label), 1)
                                        ]),
                                        _: 2
                                      }, 1032, ["value"]);
                                    }), 128))
                                  ]),
                                  _: 2
                                }, 1024)) : (Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, { key: 1 }, [
                                  isInputType(getFieldInfo(filterField)) ? (Vue.openBlock(), Vue.createBlock(_component_el_input, {
                                    key: 0,
                                    modelValue: formData[getFieldInfo(filterField).fieldName],
                                    "onUpdate:modelValue": ($event) => formData[getFieldInfo(filterField).fieldName] = $event,
                                    class: "filter-item"
                                  }, null, 8, ["modelValue", "onUpdate:modelValue"])) : isSelectType(getFieldInfo(filterField)) ? (Vue.openBlock(), Vue.createBlock(_component_el_select, {
                                    key: 1,
                                    modelValue: formData[getFieldInfo(filterField).fieldName],
                                    "onUpdate:modelValue": ($event) => formData[getFieldInfo(filterField).fieldName] = $event,
                                    class: "filter-item"
                                  }, {
                                    default: Vue.withCtx(() => [
                                      Vue.createVNode(_component_el_option, {
                                        label: "选项1",
                                        value: "1"
                                      }),
                                      Vue.createVNode(_component_el_option, {
                                        label: "选项2",
                                        value: "2"
                                      })
                                    ]),
                                    _: 2
                                  }, 1032, ["modelValue", "onUpdate:modelValue"])) : isDateType(getFieldInfo(filterField)) ? (Vue.openBlock(), Vue.createBlock(_component_el_date_picker, {
                                    key: 2,
                                    modelValue: formData[getFieldInfo(filterField).fieldName],
                                    "onUpdate:modelValue": ($event) => formData[getFieldInfo(filterField).fieldName] = $event,
                                    type: "daterange",
                                    "range-separator": "至",
                                    "start-placeholder": "开始日期",
                                    "end-placeholder": "结束日期",
                                    class: "filter-item"
                                  }, null, 8, ["modelValue", "onUpdate:modelValue"])) : (Vue.openBlock(), Vue.createBlock(_component_el_input, {
                                    key: 3,
                                    modelValue: formData[getFieldInfo(filterField).fieldName],
                                    "onUpdate:modelValue": ($event) => formData[getFieldInfo(filterField).fieldName] = $event,
                                    class: "filter-item"
                                  }, null, 8, ["modelValue", "onUpdate:modelValue"]))
                                ], 64))
                              ]),
                              _: 2
                            }, 1032, ["label", "onMouseenter", "onClick", "class"])
                          ], 4);
                        }), 128))
                      ]),
                      _: 1
                    }, 8, ["modelValue"])
                  ]),
                  _: 1
                }, 8, ["model"])
              ])
            ])) : Vue.createCommentVNode("", true)
          ]),
          _: 1
        })
      ]);
    };
  }
};
const DynamicModeConfig = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-93791225"]]);
exports.default = DynamicModeConfig;
