import "../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                             */
/* empty css                                                                  */
import { computed, resolveDirective, createElementBlock, openBlock, createCommentVNode, createBlock, createVNode, withCtx, unref, createElementVNode, createTextVNode, toDisplayString, Fragment, renderList, withDirectives } from "vue";
import { VxeToolbar } from "vxe-table";
import { ArrowLeftBold as arrow_left_bold_default, Search as search_default, Edit as edit_default, Delete as delete_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 { getCurrentVueInstance } from "../../utils/getInstance.mjs";
import { checkFilterMatch } from "../../utils/parseFilterConfig.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";
const _hoisted_1 = { class: "custom-buttons" };
const _hoisted_2 = {
  key: 1,
  class: "template-name"
};
const _sfc_main = {
  __name: "CustomButtons",
  props: {
    customBtns: {
      type: Object,
      default: () => ({
        left: [],
        right: []
      })
    },
    localConfig: {
      type: Object,
      default: {}
    },
    readOnly: {
      type: Boolean,
      default: false
    },
    isSubTable: {
      type: Boolean,
      default: false
    },
    hiddenFormData: {
      type: Object,
      default: {}
    }
  },
  emits: ["click"],
  setup(__props, { emit: __emit }) {
    const ctx = getCurrentVueInstance();
    const props = __props;
    const emit = __emit;
    const fieldsData = computed(() => {
      var _a, _b;
      return [
        ...((_a = props.localConfig) == null ? void 0 : _a.fieldsData) || [],
        ...((_b = props.localConfig) == null ? void 0 : _b.hiddenFields) || []
      ];
    });
    const leftButtons = computed(() => {
      return (props.customBtns.left || []).filter((item) => {
        if (!item.showCondition) return true;
        return checkFilterMatch(
          item.showCondition,
          props.hiddenFormData,
          fieldsData.value
        );
      });
    });
    const rightButtons = computed(() => {
      return (props.customBtns.right || []).filter((item) => {
        if (!item.showCondition) return true;
        return checkFilterMatch(
          item.showCondition,
          props.hiddenFormData,
          fieldsData.value
        );
      });
    });
    const hasButtons = computed(() => {
      return leftButtons.value.length > 0 || rightButtons.value.length > 0;
    });
    const getBtnIcon = (btnType) => {
      const iconMap = {
        refresh: refresh_default,
        export: download_default,
        personalize: setting_default,
        add: plus_default,
        delete: delete_default,
        edit: edit_default,
        search: search_default
      };
      return iconMap[btnType] || null;
    };
    const getBtnType = (btn) => {
      if (btn.btnType === "custom") {
        return "primary";
      }
      return btn.btnStyle || "default";
    };
    const handleClick = (btn, event) => {
      emit("click", {
        btn,
        event,
        type: "custom"
      });
    };
    function goBack() {
      ctx.$router.go(-1);
    }
    return (_ctx, _cache) => {
      const _component_el_icon = ElIcon;
      const _component_el_button = ElButton;
      const _directive_fec_auth = resolveDirective("fec-auth");
      return openBlock(), createElementBlock("div", _hoisted_1, [
        __props.localConfig.showReturn ? (openBlock(), createElementBlock("div", {
          key: 0,
          class: "back-icon",
          onClick: goBack
        }, [
          createVNode(_component_el_icon, null, {
            default: withCtx(() => [
              createVNode(unref(arrow_left_bold_default))
            ]),
            _: 1
          })
        ])) : createCommentVNode("", true),
        __props.localConfig.showTitle ? (openBlock(), createElementBlock("div", _hoisted_2, [
          _cache[0] || (_cache[0] = createElementVNode("div", { class: "template-name-line" }, null, -1)),
          createTextVNode(" " + toDisplayString(__props.localConfig.templateName), 1)
        ])) : createCommentVNode("", true),
        !__props.readOnly && !__props.isSubTable && hasButtons.value ? (openBlock(), createBlock(unref(VxeToolbar), {
          key: 2,
          ref: "toolbarRef",
          style: { "flex": "1", "margin-bottom": "0", "padding": "0" }
        }, {
          buttons: withCtx(() => [
            leftButtons.value.length ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(leftButtons.value, (btn) => {
              return withDirectives((openBlock(), createBlock(_component_el_button, {
                key: btn.id,
                type: getBtnType(btn),
                icon: getBtnIcon(btn.btnType),
                onClick: ($event) => handleClick(btn, $event)
              }, {
                default: withCtx(() => [
                  createTextVNode(toDisplayString(btn.label), 1)
                ]),
                _: 2
              }, 1032, ["type", "icon", "onClick"])), [
                [_directive_fec_auth, btn.permission]
              ]);
            }), 128)) : createCommentVNode("", true)
          ]),
          tools: withCtx(() => [
            rightButtons.value.length ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(rightButtons.value, (btn) => {
              return withDirectives((openBlock(), createBlock(_component_el_button, {
                key: btn.id,
                type: getBtnType(btn),
                icon: getBtnIcon(btn.btnType),
                onClick: ($event) => handleClick(btn, $event)
              }, {
                default: withCtx(() => [
                  createTextVNode(toDisplayString(btn.label), 1)
                ]),
                _: 2
              }, 1032, ["type", "icon", "onClick"])), [
                [_directive_fec_auth, btn.permission]
              ]);
            }), 128)) : createCommentVNode("", true)
          ]),
          _: 1
        }, 512)) : createCommentVNode("", true)
      ]);
    };
  }
};
const CustomButtons = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-8d29fa72"]]);
export {
  CustomButtons as default
};
