"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                                                                     */
;/* empty css                                                                 */
require("../../../../node_modules/element-plus/theme-chalk/el-dropdown-menu.css.js");
require("../../../../node_modules/element-plus/theme-chalk/el-dropdown-item.css.js");
;/* empty css                                                              */
;/* empty css                                                                     */
;/* empty css                                                               */
;/* empty css                                                               */
;/* empty css                                                                     */
;/* empty css                                                               */
;/* empty css                                                                    */
;/* empty css                                                                     */
const Vue = require("vue");
const common = require("../utils/common.js");
const index$6 = require("../../../../node_modules/@element-plus/icons-vue/dist/index.js");
const useDataSourceDialog = require("../dataSource/useDataSourceDialog.js");
const vueDraggablePlus = require("../../../../node_modules/vue-draggable-plus/dist/vue-draggable-plus.js");
;/* empty css                   */
const _pluginVue_exportHelper = require("../../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../../node_modules/element-plus/es/components/radio/index.js");
const index$1 = require("../../../../node_modules/element-plus/es/components/select/index.js");
const index$2 = require("../../../../node_modules/element-plus/es/components/switch/index.js");
const index$3 = require("../../../../node_modules/element-plus/es/components/input-number/index.js");
const index$4 = require("../../../../node_modules/element-plus/es/components/dropdown/index.js");
const index$5 = require("../../../../node_modules/element-plus/es/components/button/index.js");
const index$7 = require("../../../../node_modules/element-plus/es/components/tag/index.js");
const index$8 = require("../../../../node_modules/element-plus/es/components/icon/index.js");
const index$9 = require("../../../../node_modules/element-plus/es/components/empty/index.js");
const index$a = require("../../../../node_modules/element-plus/es/components/checkbox/index.js");
const _hoisted_1 = { class: "table-setting" };
const _hoisted_2 = { class: "setting-left" };
const _hoisted_3 = { class: "setting-right" };
const _hoisted_4 = {
  key: 0,
  class: "sort-panel"
};
const _hoisted_5 = { class: "sort-header" };
const _hoisted_6 = { class: "sort-rules-list" };
const _hoisted_7 = { class: "drag-handle" };
const _hoisted_8 = { class: "col-display-btn" };
const _hoisted_9 = { style: { "text-align": "left", "max-height": "300px", "overflow-y": "auto" } };
const _sfc_main = {
  __name: "TableSetting",
  setup(__props) {
    const sortConfigDropdownVisible = Vue.ref(false);
    const { dataSourceDialogVisible, openDataSourceDialog, DataSourceDialog } = useDataSourceDialog.useDataSourceDialog();
    const tableConfig = Vue.computed(() => {
      return common.getEditConfigData();
    });
    const hiddenFields = Vue.computed(() => {
      var _a;
      const fields = ((_a = tableConfig.value) == null ? void 0 : _a.hiddenFields) || [];
      return fields.map((item) => ({
        id: item == null ? void 0 : item.id,
        fieldName: item == null ? void 0 : item.fieldName,
        label: item == null ? void 0 : item.label
      }));
    });
    const dataSources = Vue.computed(() => {
      return tableConfig.value.dataSources || [];
    });
    const selectedDataSource = Vue.computed({
      get: () => tableConfig.value.dataSourceId,
      set: (val) => {
        tableConfig.value.dataSourceId = val;
      }
    });
    const selectedDataSourceName = Vue.computed(() => {
      if (!selectedDataSource.value) return "";
      const dataSource = dataSources.value.find(
        (ds) => ds.id === selectedDataSource.value
      );
      return dataSource ? dataSource.name : "";
    });
    const handleAddDataSource = () => {
      openDataSourceDialog();
    };
    const sortRules = Vue.computed({
      get: () => tableConfig.value.sortRules || [],
      set: (val) => {
        tableConfig.value.sortRules = val;
      }
    });
    function getVisibleColCount() {
      return tableConfig.value.fieldsData.filter((col) => col.isShow).length;
    }
    function handleDataSourceSelect(dataSourceId) {
      if (dataSourceId != "add") {
        tableConfig.value.dataSourceId = dataSourceId;
      }
    }
    function addSortRule() {
      sortRules.value = [
        ...sortRules.value,
        {
          field: "",
          order: "asc"
        }
      ];
    }
    function removeSortRule(index2) {
      sortRules.value = sortRules.value.filter((_, i) => i !== index2);
    }
    return (_ctx, _cache) => {
      const _component_el_radio_button = index.ElRadioButton;
      const _component_el_radio_group = index.ElRadioGroup;
      const _component_el_option = index$1.ElOption;
      const _component_el_option_group = index$1.ElOptionGroup;
      const _component_el_select = index$1.ElSelect;
      const _component_el_switch = index$2.ElSwitch;
      const _component_el_input_number = index$3.ElInputNumber;
      const _component_el_button = index$5.ElButton;
      const _component_el_dropdown_item = index$4.ElDropdownItem;
      const _component_el_dropdown_menu = index$4.ElDropdownMenu;
      const _component_el_dropdown = index$4.ElDropdown;
      const _component_el_tag = index$7.ElTag;
      const _component_el_icon = index$8.ElIcon;
      const _component_el_radio = index.ElRadio;
      const _component_el_empty = index$9.ElEmpty;
      const _component_el_checkbox = index$a.ElCheckbox;
      return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
        Vue.createElementVNode("div", _hoisted_1, [
          Vue.createElementVNode("div", _hoisted_2, [
            Vue.createVNode(_component_el_radio_group, {
              modelValue: Vue.unref(tableConfig).selectMode,
              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => Vue.unref(tableConfig).selectMode = $event),
              size: "small"
            }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_radio_button, { value: "none" }, {
                  default: Vue.withCtx(() => _cache[8] || (_cache[8] = [
                    Vue.createTextVNode("无")
                  ])),
                  _: 1
                }),
                Vue.createVNode(_component_el_radio_button, { value: "single" }, {
                  default: Vue.withCtx(() => _cache[9] || (_cache[9] = [
                    Vue.createTextVNode("单选")
                  ])),
                  _: 1
                }),
                Vue.createVNode(_component_el_radio_button, { value: "multiple" }, {
                  default: Vue.withCtx(() => _cache[10] || (_cache[10] = [
                    Vue.createTextVNode("多选")
                  ])),
                  _: 1
                })
              ]),
              _: 1
            }, 8, ["modelValue"]),
            Vue.unref(tableConfig).selectMode == "multiple" ? (Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, { key: 0 }, [
              _cache[11] || (_cache[11] = Vue.createElementVNode("div", { class: "setting-divider" }, null, -1)),
              _cache[12] || (_cache[12] = Vue.createElementVNode("span", { class: "text-label" }, "主键字段", -1)),
              Vue.createVNode(_component_el_select, {
                modelValue: Vue.unref(tableConfig).pkFieldName,
                "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => Vue.unref(tableConfig).pkFieldName = $event),
                size: "small",
                style: { "width": "100px" }
              }, {
                default: Vue.withCtx(() => [
                  Vue.unref(tableConfig).fieldsData.length > 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_option_group, {
                    key: 0,
                    label: "列表字段"
                  }, {
                    default: Vue.withCtx(() => [
                      (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(tableConfig).fieldsData, (field) => {
                        return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                          key: field.fieldName,
                          label: field.label,
                          value: field.fieldName
                        }, null, 8, ["label", "value"]);
                      }), 128))
                    ]),
                    _: 1
                  })) : Vue.createCommentVNode("", true),
                  Vue.unref(hiddenFields).length > 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_option_group, {
                    key: 1,
                    label: "隐藏域"
                  }, {
                    default: Vue.withCtx(() => [
                      (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(hiddenFields), (hidden) => {
                        return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                          key: hidden.id,
                          label: hidden.label,
                          value: hidden.fieldName
                        }, null, 8, ["label", "value"]);
                      }), 128))
                    ]),
                    _: 1
                  })) : Vue.createCommentVNode("", true)
                ]),
                _: 1
              }, 8, ["modelValue"])
            ], 64)) : Vue.createCommentVNode("", true),
            _cache[17] || (_cache[17] = Vue.createElementVNode("div", { class: "setting-divider" }, null, -1)),
            _cache[18] || (_cache[18] = Vue.createElementVNode("span", { class: "text-label" }, "序号", -1)),
            Vue.createVNode(_component_el_switch, {
              modelValue: Vue.unref(tableConfig).showIndex,
              "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => Vue.unref(tableConfig).showIndex = $event),
              size: "small"
            }, null, 8, ["modelValue"]),
            _cache[19] || (_cache[19] = Vue.createElementVNode("div", { class: "setting-divider" }, null, -1)),
            _cache[20] || (_cache[20] = Vue.createElementVNode("span", { class: "text-label" }, "高度", -1)),
            Vue.createVNode(_component_el_radio_group, {
              modelValue: Vue.unref(tableConfig).heightMode,
              "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => Vue.unref(tableConfig).heightMode = $event),
              size: "small"
            }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_radio_button, { value: "auto" }, {
                  default: Vue.withCtx(() => _cache[13] || (_cache[13] = [
                    Vue.createTextVNode("自适应")
                  ])),
                  _: 1
                }),
                Vue.createVNode(_component_el_radio_button, { value: "fixed" }, {
                  default: Vue.withCtx(() => _cache[14] || (_cache[14] = [
                    Vue.createTextVNode("固定")
                  ])),
                  _: 1
                })
              ]),
              _: 1
            }, 8, ["modelValue"]),
            Vue.unref(tableConfig).heightMode === "fixed" ? (Vue.openBlock(), Vue.createBlock(_component_el_input_number, {
              key: 1,
              modelValue: Vue.unref(tableConfig).height,
              "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => Vue.unref(tableConfig).height = $event),
              min: 100,
              size: "small",
              "controls-position": "right",
              class: "height-input"
            }, {
              append: Vue.withCtx(() => _cache[15] || (_cache[15] = [
                Vue.createTextVNode("px")
              ])),
              _: 1
            }, 8, ["modelValue"])) : Vue.createCommentVNode("", true),
            _cache[21] || (_cache[21] = Vue.createElementVNode("div", { class: "setting-divider" }, null, -1)),
            _cache[22] || (_cache[22] = Vue.createElementVNode("span", { class: "text-label" }, "数据源", -1)),
            Vue.createVNode(_component_el_dropdown, {
              trigger: "click",
              onCommand: handleDataSourceSelect
            }, {
              dropdown: Vue.withCtx(() => [
                Vue.createVNode(_component_el_dropdown_menu, null, {
                  default: Vue.withCtx(() => [
                    (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(dataSources), (ds) => {
                      return Vue.openBlock(), Vue.createBlock(_component_el_dropdown_item, {
                        key: ds.id,
                        command: ds.id
                      }, {
                        default: Vue.withCtx(() => [
                          Vue.createTextVNode(Vue.toDisplayString(ds.name), 1)
                        ]),
                        _: 2
                      }, 1032, ["command"]);
                    }), 128)),
                    Vue.createVNode(_component_el_dropdown_item, { command: "add" }, {
                      default: Vue.withCtx(() => [
                        Vue.createVNode(_component_el_button, {
                          type: "primary",
                          size: "small",
                          icon: Vue.unref(index$6.Plus),
                          link: "",
                          onClick: handleAddDataSource
                        }, {
                          default: Vue.withCtx(() => _cache[16] || (_cache[16] = [
                            Vue.createTextVNode(" 新增数据源 ")
                          ])),
                          _: 1
                        }, 8, ["icon"])
                      ]),
                      _: 1
                    })
                  ]),
                  _: 1
                })
              ]),
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_button, {
                  icon: Vue.unref(index$6.Coin),
                  size: "small",
                  class: Vue.normalizeClass(["data-source-btn", { "is-configured": Vue.unref(selectedDataSource) }])
                }, {
                  default: Vue.withCtx(() => [
                    Vue.createTextVNode(Vue.toDisplayString(Vue.unref(selectedDataSourceName) ? `已配置 (${Vue.unref(selectedDataSourceName)})` : "配置数据源"), 1)
                  ]),
                  _: 1
                }, 8, ["icon", "class"])
              ]),
              _: 1
            })
          ]),
          Vue.createElementVNode("div", _hoisted_3, [
            Vue.createVNode(_component_el_dropdown, {
              "max-height": 500,
              trigger: "click",
              "popper-class": "sort-config-dropdown",
              onVisibleChange: _cache[6] || (_cache[6] = (visible) => sortConfigDropdownVisible.value = visible)
            }, {
              dropdown: Vue.withCtx(() => [
                Vue.unref(sortConfigDropdownVisible) ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_4, [
                  Vue.createElementVNode("div", _hoisted_5, [
                    _cache[25] || (_cache[25] = Vue.createElementVNode("span", { class: "sort-tip" }, "以下排序规则从上到下按序执行", -1)),
                    Vue.createVNode(_component_el_button, {
                      type: "primary",
                      size: "small",
                      onClick: addSortRule,
                      icon: "Plus"
                    }, {
                      default: Vue.withCtx(() => _cache[24] || (_cache[24] = [
                        Vue.createTextVNode(" 添加排序规则 ")
                      ])),
                      _: 1
                    })
                  ]),
                  Vue.createElementVNode("div", _hoisted_6, [
                    Vue.createVNode(Vue.unref(vueDraggablePlus.VueDraggable), {
                      modelValue: Vue.unref(sortRules),
                      "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => Vue.isRef(sortRules) ? sortRules.value = $event : null),
                      animation: 150,
                      handle: ".drag-handle"
                    }, {
                      default: Vue.withCtx(() => [
                        (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(sortRules), (rule, index2) => {
                          return Vue.openBlock(), Vue.createElementBlock("div", {
                            key: index2,
                            class: "sort-rule-item"
                          }, [
                            Vue.createElementVNode("div", _hoisted_7, [
                              Vue.createVNode(_component_el_icon, null, {
                                default: Vue.withCtx(() => [
                                  Vue.createVNode(Vue.unref(index$6.Rank))
                                ]),
                                _: 1
                              })
                            ]),
                            Vue.createVNode(_component_el_select, {
                              modelValue: rule.field,
                              "onUpdate:modelValue": ($event) => rule.field = $event,
                              size: "small",
                              placeholder: "选择字段",
                              style: { "width": "150px" },
                              "append-to": ".sort-config-dropdown"
                            }, {
                              default: Vue.withCtx(() => [
                                Vue.unref(tableConfig).fieldsData.length > 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_option_group, {
                                  key: 0,
                                  label: "列表字段"
                                }, {
                                  default: Vue.withCtx(() => [
                                    (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(tableConfig).fieldsData, (col) => {
                                      return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                        key: col.id,
                                        label: col.label,
                                        value: col.fieldName
                                      }, null, 8, ["label", "value"]);
                                    }), 128))
                                  ]),
                                  _: 1
                                })) : Vue.createCommentVNode("", true),
                                Vue.unref(hiddenFields).length > 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_option_group, {
                                  key: 1,
                                  label: "隐藏域"
                                }, {
                                  default: Vue.withCtx(() => [
                                    (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(hiddenFields), (hidden) => {
                                      return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                        key: hidden.id,
                                        label: hidden.label,
                                        value: hidden.fieldName
                                      }, null, 8, ["label", "value"]);
                                    }), 128))
                                  ]),
                                  _: 1
                                })) : Vue.createCommentVNode("", true)
                              ]),
                              _: 2
                            }, 1032, ["modelValue", "onUpdate:modelValue"]),
                            Vue.createVNode(_component_el_radio_group, {
                              modelValue: rule.order,
                              "onUpdate:modelValue": ($event) => rule.order = $event,
                              size: "small"
                            }, {
                              default: Vue.withCtx(() => [
                                Vue.createVNode(_component_el_radio, { value: "asc" }, {
                                  default: Vue.withCtx(() => _cache[26] || (_cache[26] = [
                                    Vue.createTextVNode("升序")
                                  ])),
                                  _: 1
                                }),
                                Vue.createVNode(_component_el_radio, { value: "desc" }, {
                                  default: Vue.withCtx(() => _cache[27] || (_cache[27] = [
                                    Vue.createTextVNode("降序")
                                  ])),
                                  _: 1
                                })
                              ]),
                              _: 2
                            }, 1032, ["modelValue", "onUpdate:modelValue"]),
                            Vue.createVNode(_component_el_button, {
                              icon: Vue.unref(index$6.Delete),
                              link: "",
                              type: "danger",
                              class: "delete-btn",
                              onClick: ($event) => removeSortRule(index2)
                            }, null, 8, ["icon", "onClick"])
                          ]);
                        }), 128))
                      ]),
                      _: 1
                    }, 8, ["modelValue"]),
                    Vue.unref(sortRules).length === 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_empty, {
                      key: 0,
                      description: "暂无排序规则",
                      "image-size": 60
                    })) : Vue.createCommentVNode("", true)
                  ])
                ])) : Vue.createCommentVNode("", true)
              ]),
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_button, {
                  icon: Vue.unref(index$6.Filter),
                  size: "small"
                }, {
                  default: Vue.withCtx(() => [
                    _cache[23] || (_cache[23] = Vue.createTextVNode(" 配置排序 ")),
                    Vue.unref(sortRules).length > 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_tag, {
                      key: 0,
                      size: "small",
                      type: "primary",
                      class: "sort-count-tag"
                    }, {
                      default: Vue.withCtx(() => [
                        Vue.createTextVNode(Vue.toDisplayString(Vue.unref(sortRules).length), 1)
                      ]),
                      _: 1
                    })) : Vue.createCommentVNode("", true)
                  ]),
                  _: 1
                }, 8, ["icon"])
              ]),
              _: 1
            }),
            _cache[29] || (_cache[29] = Vue.createElementVNode("div", { class: "setting-divider" }, null, -1)),
            Vue.createVNode(_component_el_dropdown, {
              size: "small",
              "hide-on-click": false,
              trigger: "click"
            }, {
              dropdown: Vue.withCtx(() => [
                Vue.createVNode(_component_el_dropdown_menu, null, {
                  default: Vue.withCtx(() => [
                    Vue.createElementVNode("div", _hoisted_9, [
                      (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(tableConfig).fieldsData, (col) => {
                        return Vue.openBlock(), Vue.createBlock(_component_el_dropdown_item, {
                          key: col.id,
                          class: "optCol"
                        }, {
                          default: Vue.withCtx(() => [
                            Vue.createVNode(_component_el_checkbox, {
                              modelValue: col.isShow,
                              "onUpdate:modelValue": ($event) => col.isShow = $event,
                              disabled: col.isShow && getVisibleColCount() === 1
                            }, {
                              default: Vue.withCtx(() => [
                                Vue.createTextVNode(Vue.toDisplayString(col.label), 1)
                              ]),
                              _: 2
                            }, 1032, ["modelValue", "onUpdate:modelValue", "disabled"])
                          ]),
                          _: 2
                        }, 1024);
                      }), 128))
                    ])
                  ]),
                  _: 1
                })
              ]),
              default: Vue.withCtx(() => [
                Vue.createElementVNode("div", _hoisted_8, [
                  Vue.createVNode(_component_el_button, {
                    icon: Vue.unref(index$6.Hide),
                    size: "small"
                  }, {
                    default: Vue.withCtx(() => [
                      _cache[28] || (_cache[28] = Vue.createTextVNode("列显隐 ")),
                      Vue.createVNode(_component_el_tag, {
                        size: "small",
                        type: "primary",
                        class: "col-count"
                      }, {
                        default: Vue.withCtx(() => [
                          Vue.createTextVNode(Vue.toDisplayString(getVisibleColCount()) + "/" + Vue.toDisplayString(Vue.unref(tableConfig).fieldsData.length), 1)
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  }, 8, ["icon"])
                ])
              ]),
              _: 1
            })
          ])
        ]),
        Vue.createVNode(Vue.unref(DataSourceDialog), {
          modelValue: Vue.unref(dataSourceDialogVisible),
          "onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => Vue.isRef(dataSourceDialogVisible) ? dataSourceDialogVisible.value = $event : null)
        }, null, 8, ["modelValue"])
      ], 64);
    };
  }
};
const TableSetting = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-c4cad8e4"]]);
exports.default = TableSetting;
