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