import "../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                          */
/* empty css                                                             */
/* empty css                                                               */
import { computed, resolveComponent, createElementBlock, openBlock, createElementVNode, createCommentVNode, createVNode, withCtx, toDisplayString, unref, Fragment, renderList, withModifiers, normalizeClass, mergeProps, createTextVNode } from "vue";
import { defaultCustomBtn } from "./default.mjs";
import { VueDraggable as lo } from "../../../../node_modules/vue-draggable-plus/dist/vue-draggable-plus.mjs";
import { Close as close_default, Plus as plus_default, Setting as setting_default, Download as download_default, Refresh as refresh_default } from "../../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
import { getEditConfigData, setSelectedItem, setHoverItem, getCurrentClass } from "../utils/common.mjs";
/* empty css               */
import _export_sfc from "../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElIcon } from "../../../../node_modules/element-plus/es/components/icon/index.mjs";
import { ElButton } from "../../../../node_modules/element-plus/es/components/button/index.mjs";
import { ElLink } from "../../../../node_modules/element-plus/es/components/link/index.mjs";
const _hoisted_1 = { class: "table-work-btns" };
const _hoisted_2 = { class: "left" };
const _hoisted_3 = {
  key: 0,
  class: "back-icon"
};
const _hoisted_4 = {
  key: 1,
  class: "template-name"
};
const _hoisted_5 = ["onMouseenter", "onClick"];
const _hoisted_6 = { class: "right" };
const _hoisted_7 = ["onMouseenter", "onClick"];
const _sfc_main = {
  __name: "tableBtn",
  setup(__props) {
    const editConfigData = computed(() => {
      return getEditConfigData();
    });
    const btnTypeConfig = {
      custom: { type: "primary" },
      refresh: { icon: refresh_default },
      export: { icon: download_default },
      personalize: { icon: setting_default }
    };
    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(),
        ...defaultCustomBtn
      };
      if (state === "right") {
        editConfigData.value.customBtns[state].unshift(newBtn);
      } else {
        editConfigData.value.customBtns[state].push(newBtn);
      }
    }
    function removeOptBtns(state, item) {
      const index = editConfigData.value.customBtns[state].findIndex(
        (i) => i.id === item.id
      );
      if (index !== -1) {
        editConfigData.value.customBtns[state].splice(index, 1);
      }
    }
    return (_ctx, _cache) => {
      const _component_ArrowLeftBold = resolveComponent("ArrowLeftBold");
      const _component_el_icon = ElIcon;
      const _component_el_button = ElButton;
      const _component_el_link = ElLink;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", _hoisted_2, [
          editConfigData.value.showReturn ? (openBlock(), createElementBlock("div", _hoisted_3, [
            createVNode(_component_el_icon, null, {
              default: withCtx(() => [
                createVNode(_component_ArrowLeftBold)
              ]),
              _: 1
            })
          ])) : createCommentVNode("", true),
          editConfigData.value.showTitle ? (openBlock(), createElementBlock("div", _hoisted_4, toDisplayString(editConfigData.value.templateName), 1)) : createCommentVNode("", true),
          createVNode(unref(lo), {
            modelValue: editConfigData.value.customBtns.left,
            "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => editConfigData.value.customBtns.left = $event),
            animation: 150,
            group: { name: "tableBtn" },
            ghostClass: "ghost",
            class: "optBtnDraggable"
          }, {
            default: withCtx(() => [
              (openBlock(true), createElementBlock(Fragment, null, renderList(editConfigData.value.customBtns.left, (item) => {
                return openBlock(), createElementBlock("div", {
                  class: normalizeClass(["optBtn", unref(getCurrentClass)(item)]),
                  onMouseenter: ($event) => unref(setHoverItem)(item),
                  onMouseleave: _cache[0] || (_cache[0] = ($event) => unref(setHoverItem)()),
                  onClick: withModifiers(($event) => unref(setSelectedItem)(item), ["stop"])
                }, [
                  createVNode(_component_el_button, mergeProps({
                    class: "elBtn",
                    ref_for: true
                  }, getBtnProps(item)), {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(item.label), 1)
                    ]),
                    _: 2
                  }, 1040),
                  createVNode(_component_el_icon, {
                    class: "delete-icon",
                    onClick: withModifiers(($event) => removeOptBtns("left", item), ["stop"])
                  }, {
                    default: withCtx(() => [
                      createVNode(unref(close_default))
                    ]),
                    _: 2
                  }, 1032, ["onClick"])
                ], 42, _hoisted_5);
              }), 256))
            ]),
            _: 1
          }, 8, ["modelValue"]),
          createVNode(_component_el_link, {
            class: "optBtn addLink",
            underline: "never",
            type: "primary",
            icon: unref(plus_default),
            onClick: _cache[2] || (_cache[2] = withModifiers(($event) => addOptBtns("left"), ["stop"]))
          }, {
            default: withCtx(() => _cache[6] || (_cache[6] = [
              createTextVNode("按钮")
            ])),
            _: 1
          }, 8, ["icon"])
        ]),
        createElementVNode("div", _hoisted_6, [
          createVNode(_component_el_link, {
            class: "optBtn addLink",
            underline: "never",
            type: "primary",
            icon: unref(plus_default),
            onClick: _cache[3] || (_cache[3] = withModifiers(($event) => addOptBtns("right"), ["stop"]))
          }, {
            default: withCtx(() => _cache[7] || (_cache[7] = [
              createTextVNode("按钮")
            ])),
            _: 1
          }, 8, ["icon"]),
          createVNode(unref(lo), {
            modelValue: editConfigData.value.customBtns.right,
            "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => editConfigData.value.customBtns.right = $event),
            animation: 150,
            group: { name: "tableBtn" },
            ghostClass: "ghost",
            class: "optBtnDraggable"
          }, {
            default: withCtx(() => [
              (openBlock(true), createElementBlock(Fragment, null, renderList(editConfigData.value.customBtns.right, (item) => {
                return openBlock(), createElementBlock("div", {
                  class: normalizeClass(["optBtn", unref(getCurrentClass)(item)]),
                  onMouseenter: ($event) => unref(setHoverItem)(item),
                  onMouseleave: _cache[4] || (_cache[4] = ($event) => unref(setHoverItem)()),
                  onClick: withModifiers(($event) => unref(setSelectedItem)(item), ["stop"])
                }, [
                  createVNode(_component_el_button, mergeProps({
                    class: "elBtn",
                    ref_for: true
                  }, getBtnProps(item)), {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(item.label), 1)
                    ]),
                    _: 2
                  }, 1040),
                  createVNode(_component_el_icon, {
                    class: "delete-icon",
                    onClick: withModifiers(($event) => removeOptBtns("right", item), ["stop"])
                  }, {
                    default: withCtx(() => [
                      createVNode(unref(close_default))
                    ]),
                    _: 2
                  }, 1032, ["onClick"])
                ], 42, _hoisted_7);
              }), 256))
            ]),
            _: 1
          }, 8, ["modelValue"])
        ])
      ]);
    };
  }
};
const TableBtn = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-c16f2646"]]);
export {
  TableBtn as default
};
