import "../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                          */
/* empty css                                                            */
/* empty css                                                                  */
/* empty css                                                             */
/* empty css                                                              */
/* empty css                                                                 */
import { computed, ref, resolveComponent, createElementBlock, openBlock, Fragment, createVNode, createElementVNode, unref, createCommentVNode, createBlock, withCtx, renderList, withDirectives, normalizeStyle, withModifiers, normalizeClass, createTextVNode, toDisplayString, vShow } from "vue";
import { defaultOptBtn } from "./default.mjs";
import { VueDraggable as lo } from "../../../../node_modules/vue-draggable-plus/dist/vue-draggable-plus.mjs";
import { Hide as hide_default, Delete as delete_default, Plus as plus_default } from "../../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
import TableSetting from "./TableSetting.vue.mjs";
import QueryModule from "./queryModule/index.vue.mjs";
import TablePagination from "./tablePagination.vue.mjs";
import TableSummary from "./tableSummary.vue.mjs";
import { getEditConfigData, setSelectedItem, setHoverItem, getCurrentClass } from "../utils/common.mjs";
/* empty css                                                              */
/* empty css                                                                */
/* empty css            */
import _export_sfc from "../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElCheckbox } from "../../../../node_modules/element-plus/es/components/checkbox/index.mjs";
import { ElRadio } from "../../../../node_modules/element-plus/es/components/radio/index.mjs";
import { ElScrollbar } from "../../../../node_modules/element-plus/es/components/scrollbar/index.mjs";
import { ElIcon } from "../../../../node_modules/element-plus/es/components/icon/index.mjs";
import { ElLink } from "../../../../node_modules/element-plus/es/components/link/index.mjs";
import { ElTag } from "../../../../node_modules/element-plus/es/components/tag/index.mjs";
import { ElMessage } from "../../../../node_modules/element-plus/es/components/message/index.mjs";
const _hoisted_1 = { class: "table-work-area" };
const _hoisted_2 = {
  key: 0,
  class: "table-selectMode"
};
const _hoisted_3 = { class: "widgets" };
const _hoisted_4 = { class: "field-label" };
const _hoisted_5 = {
  key: 1,
  class: "table-indexMode"
};
const _hoisted_6 = ["name", "onMouseenter", "onClick"];
const _hoisted_7 = { class: "widgets" };
const _hoisted_8 = { class: "field-label" };
const _hoisted_9 = { key: 1 };
const _hoisted_10 = { class: "quick-operation" };
const _hoisted_11 = { class: "widgets" };
const _sfc_main = {
  __name: "index",
  setup(__props) {
    function getItemStyle(item) {
      const style = {};
      if (item.widthMode === "fixed" && item.width) {
        style.width = item.width + "px";
      }
      if (item.widthMode === "auto" && item.minWidth) {
        style.minWidth = item.minWidth + "px";
      }
      if (!item.widthMode && item.width) {
        style.width = item.width + "px";
      }
      return style;
    }
    function getAlignClass(item) {
      const alignClass = {};
      if (item.headerAlign) {
        alignClass[`align-header-${item.headerAlign}`] = true;
      }
      if (item.align) {
        alignClass[`align-${item.align}`] = true;
      }
      return alignClass;
    }
    const tableOptions = computed(() => {
      return getEditConfigData();
    });
    ref(/* @__PURE__ */ new Map());
    function addOptBtns() {
      tableOptions.value.optBtns.push({
        id: Date.now(),
        ...defaultOptBtn
      });
    }
    function deleteOptBtn(btn) {
      const index = tableOptions.value.optBtns.findIndex(
        (item) => item.id === btn.id
      );
      if (index !== -1) {
        tableOptions.value.optBtns.splice(index, 1);
      }
      setSelectedItem();
    }
    function deleteWidgets(item) {
      var _a;
      const index = tableOptions.value.fieldsData.findIndex(
        (col) => col.id === item.id
      );
      if (index !== -1) {
        const deletedItem = tableOptions.value.fieldsData[index];
        if (!tableOptions.value.deletedFields) {
          tableOptions.value.deletedFields = [];
        }
        const deletedField = {
          label: (deletedItem == null ? void 0 : deletedItem.label) || "",
          fieldName: (deletedItem == null ? void 0 : deletedItem.fieldName) || "",
          fieldType: (deletedItem == null ? void 0 : deletedItem.fieldType) || "",
          deleteTime: (/* @__PURE__ */ new Date()).toLocaleString("zh-CN"),
          data: deletedItem
        };
        tableOptions.value.deletedFields.push(deletedField);
        tableOptions.value.fieldsData.splice(index, 1);
        const filterIndex = (_a = tableOptions.value.queryConfig) == null ? void 0 : _a.filterFields.findIndex(
          (field) => field.fieldId == item.id
        );
        if (filterIndex !== -1) {
          tableOptions.value.queryConfig.filterFields.splice(filterIndex, 1);
        }
        ElMessage.success("字段已移至回收站");
      }
      setSelectedItem();
    }
    function handleHide(item) {
      const index = tableOptions.value.fieldsData.findIndex(
        (cell) => cell.id == item.id
      );
      if (index !== -1) {
        if (!tableOptions.value.hiddenFields) {
          tableOptions.value.hiddenFields = [];
        }
        tableOptions.value.hiddenFields.push(item);
        tableOptions.value.fieldsData.splice(index, 1);
      }
    }
    function getVisibleColCount() {
      return tableOptions.value.fieldsData.filter((col) => col.isShow).length;
    }
    function onDragEnd(event) {
    }
    return (_ctx, _cache) => {
      const _component_el_checkbox = ElCheckbox;
      const _component_el_radio = ElRadio;
      const _component_DCaret = resolveComponent("DCaret");
      const _component_el_icon = ElIcon;
      const _component_el_link = ElLink;
      const _component_CopyDocument = resolveComponent("CopyDocument");
      const _component_el_scrollbar = ElScrollbar;
      const _component_el_tag = ElTag;
      return openBlock(), createElementBlock(Fragment, null, [
        createVNode(unref(QueryModule)),
        createVNode(TableSetting),
        createElementVNode("div", _hoisted_1, [
          unref(tableOptions).selectMode !== "none" ? (openBlock(), createElementBlock("div", _hoisted_2, [
            createElementVNode("div", _hoisted_3, [
              unref(tableOptions).selectMode === "multiple" ? (openBlock(), createBlock(_component_el_checkbox, {
                key: 0,
                disabled: ""
              })) : (openBlock(), createBlock(_component_el_radio, {
                key: 1,
                disabled: ""
              }))
            ]),
            createElementVNode("div", _hoisted_4, [
              unref(tableOptions).selectMode === "multiple" ? (openBlock(), createBlock(_component_el_checkbox, {
                key: 0,
                disabled: ""
              })) : (openBlock(), createBlock(_component_el_radio, {
                key: 1,
                disabled: ""
              }))
            ])
          ])) : createCommentVNode("", true),
          unref(tableOptions).showIndex ? (openBlock(), createElementBlock("div", _hoisted_5, _cache[5] || (_cache[5] = [
            createElementVNode("div", { class: "widgets" }, "序号", -1),
            createElementVNode("div", { class: "field-label" }, "1", -1)
          ]))) : createCommentVNode("", true),
          createVNode(_component_el_scrollbar, { style: { "flex": "1" } }, {
            default: withCtx(() => [
              createVNode(unref(lo), {
                modelValue: unref(tableOptions).fieldsData,
                "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => unref(tableOptions).fieldsData = $event),
                animation: 150,
                group: "dev",
                ghostClass: "ghost",
                class: "edit-table-draggable",
                onEnd: onDragEnd
              }, {
                default: withCtx(() => [
                  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(tableOptions).fieldsData, (item) => {
                    return withDirectives((openBlock(), createElementBlock("div", {
                      class: normalizeClass(["table-item", [
                        unref(getCurrentClass)(item),
                        getAlignClass(item),
                        { "flex-auto": item.widthMode === "auto" }
                      ]]),
                      name: item.fieldName,
                      onMouseenter: ($event) => unref(setHoverItem)(item),
                      onMouseleave: _cache[0] || (_cache[0] = ($event) => unref(setHoverItem)()),
                      onClick: withModifiers(($event) => unref(setSelectedItem)(item), ["stop"]),
                      style: normalizeStyle(getItemStyle(item))
                    }, [
                      createElementVNode("div", _hoisted_7, [
                        createTextVNode(toDisplayString(item.label) + " ", 1),
                        item.sortRule == "static" ? (openBlock(), createBlock(_component_el_icon, { key: 0 }, {
                          default: withCtx(() => [
                            createVNode(_component_DCaret)
                          ]),
                          _: 1
                        })) : item.sortRule == "server" ? (openBlock(), createBlock(_component_el_icon, {
                          key: 1,
                          style: { "color": "#8dd0f0" }
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_DCaret)
                          ]),
                          _: 1
                        })) : createCommentVNode("", true)
                      ]),
                      createElementVNode("div", _hoisted_8, [
                        item.isLink ? (openBlock(), createBlock(_component_el_link, {
                          key: 0,
                          type: "primary",
                          underline: "always",
                          style: { "height": "20px" }
                        }, {
                          default: withCtx(() => [
                            createTextVNode(toDisplayString(item.fieldName), 1)
                          ]),
                          _: 2
                        }, 1024)) : (openBlock(), createElementBlock("span", _hoisted_9, toDisplayString(item.fieldName), 1)),
                        item.canCopy ? (openBlock(), createBlock(_component_el_icon, { key: 2 }, {
                          default: withCtx(() => [
                            createVNode(_component_CopyDocument)
                          ]),
                          _: 1
                        })) : createCommentVNode("", true)
                      ]),
                      createElementVNode("div", _hoisted_10, [
                        getVisibleColCount() > 1 ? (openBlock(), createBlock(_component_el_icon, {
                          key: 0,
                          class: "icon-action setting-icon",
                          onClick: withModifiers(($event) => handleHide(item), ["stop"])
                        }, {
                          default: withCtx(() => [
                            createVNode(unref(hide_default))
                          ]),
                          _: 2
                        }, 1032, ["onClick"])) : createCommentVNode("", true),
                        getVisibleColCount() > 1 ? (openBlock(), createBlock(_component_el_icon, {
                          key: 1,
                          class: "icon-action delete",
                          onClick: withModifiers(($event) => deleteWidgets(item), ["stop"])
                        }, {
                          default: withCtx(() => [
                            createVNode(unref(delete_default))
                          ]),
                          _: 2
                        }, 1032, ["onClick"])) : createCommentVNode("", true)
                      ])
                    ], 46, _hoisted_6)), [
                      [vShow, item.isShow]
                    ]);
                  }), 256))
                ]),
                _: 1
              }, 8, ["modelValue"]),
              _cache[6] || (_cache[6] = createElementVNode("div", { class: "widgets-opt-tools" }, null, -1))
            ]),
            _: 1
          }),
          createElementVNode("div", {
            class: normalizeClass(["table-item table-btn", { close: !unref(tableOptions).isOptBtns }])
          }, [
            createElementVNode("div", _hoisted_11, [
              createVNode(_component_el_checkbox, {
                class: "isOptBtns",
                modelValue: unref(tableOptions).isOptBtns,
                "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => unref(tableOptions).isOptBtns = $event)
              }, null, 8, ["modelValue"]),
              _cache[8] || (_cache[8] = createElementVNode("span", { class: "widgets-label" }, "操作", -1)),
              createVNode(_component_el_link, {
                class: "addLink",
                underline: "never",
                type: "primary",
                icon: unref(plus_default),
                onClick: withModifiers(addOptBtns, ["stop"])
              }, {
                default: withCtx(() => _cache[7] || (_cache[7] = [
                  createTextVNode("按钮")
                ])),
                _: 1
              }, 8, ["icon"])
            ]),
            createVNode(unref(lo), {
              modelValue: unref(tableOptions).optBtns,
              "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => unref(tableOptions).optBtns = $event),
              animation: 150,
              ghostClass: "ghost",
              class: "table-btn-option"
            }, {
              default: withCtx(() => [
                (openBlock(true), createElementBlock(Fragment, null, renderList(unref(tableOptions).optBtns, (btn) => {
                  return openBlock(), createBlock(_component_el_tag, {
                    class: normalizeClass(["opt-btn", unref(getCurrentClass)(btn)]),
                    closable: "",
                    effect: "plain",
                    size: "small",
                    onClose: ($event) => deleteOptBtn(btn),
                    onMouseenter: ($event) => unref(setHoverItem)(btn),
                    onMouseleave: _cache[3] || (_cache[3] = ($event) => unref(setHoverItem)()),
                    onClick: withModifiers(($event) => unref(setSelectedItem)(btn), ["stop"])
                  }, {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(btn.label), 1)
                    ]),
                    _: 2
                  }, 1032, ["class", "onClose", "onMouseenter", "onClick"]);
                }), 256))
              ]),
              _: 1
            }, 8, ["modelValue"])
          ], 2)
        ]),
        createVNode(TableSummary),
        createVNode(TablePagination)
      ], 64);
    };
  }
};
const tableWorkArea = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-87fe3266"]]);
export {
  tableWorkArea as default
};
