"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../../../node_modules/element-plus/es/index.js");
;/* empty css                                                             */
;/* empty css                                                                  */
const Vue = require("vue");
const vxeTable = require("vxe-table");
const index$1 = require("../../../../../node_modules/@element-plus/icons-vue/dist/index.js");
const getInstance = require("../../utils/getInstance.js");
const parseFilterConfig = require("../../utils/parseFilterConfig.js");
;/* empty css                    */
const _pluginVue_exportHelper = require("../../../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../../../node_modules/element-plus/es/components/icon/index.js");
const index$2 = require("../../../../../node_modules/element-plus/es/components/button/index.js");
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 = getInstance.getCurrentVueInstance();
    const props = __props;
    const emit = __emit;
    const fieldsData = Vue.computed(() => {
      var _a, _b;
      return [
        ...((_a = props.localConfig) == null ? void 0 : _a.fieldsData) || [],
        ...((_b = props.localConfig) == null ? void 0 : _b.hiddenFields) || []
      ];
    });
    const leftButtons = Vue.computed(() => {
      return (props.customBtns.left || []).filter((item) => {
        if (!item.showCondition) return true;
        return parseFilterConfig.checkFilterMatch(
          item.showCondition,
          props.hiddenFormData,
          fieldsData.value
        );
      });
    });
    const rightButtons = Vue.computed(() => {
      return (props.customBtns.right || []).filter((item) => {
        if (!item.showCondition) return true;
        return parseFilterConfig.checkFilterMatch(
          item.showCondition,
          props.hiddenFormData,
          fieldsData.value
        );
      });
    });
    const hasButtons = Vue.computed(() => {
      return leftButtons.value.length > 0 || rightButtons.value.length > 0;
    });
    const getBtnIcon = (btnType) => {
      const iconMap = {
        refresh: index$1.Refresh,
        export: index$1.Download,
        personalize: index$1.Setting,
        add: index$1.Plus,
        delete: index$1.Delete,
        edit: index$1.Edit,
        search: index$1.Search
      };
      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 = index.ElIcon;
      const _component_el_button = index$2.ElButton;
      const _directive_fec_auth = Vue.resolveDirective("fec-auth");
      return Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
        __props.localConfig.showReturn ? (Vue.openBlock(), Vue.createElementBlock("div", {
          key: 0,
          class: "back-icon",
          onClick: goBack
        }, [
          Vue.createVNode(_component_el_icon, null, {
            default: Vue.withCtx(() => [
              Vue.createVNode(Vue.unref(index$1.ArrowLeftBold))
            ]),
            _: 1
          })
        ])) : Vue.createCommentVNode("", true),
        __props.localConfig.showTitle ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_2, [
          _cache[0] || (_cache[0] = Vue.createElementVNode("div", { class: "template-name-line" }, null, -1)),
          Vue.createTextVNode(" " + Vue.toDisplayString(__props.localConfig.templateName), 1)
        ])) : Vue.createCommentVNode("", true),
        !__props.readOnly && !__props.isSubTable && hasButtons.value ? (Vue.openBlock(), Vue.createBlock(Vue.unref(vxeTable.VxeToolbar), {
          key: 2,
          ref: "toolbarRef",
          style: { "flex": "1", "margin-bottom": "0", "padding": "0" }
        }, {
          buttons: Vue.withCtx(() => [
            leftButtons.value.length ? (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, { key: 0 }, Vue.renderList(leftButtons.value, (btn) => {
              return Vue.withDirectives((Vue.openBlock(), Vue.createBlock(_component_el_button, {
                key: btn.id,
                type: getBtnType(btn),
                icon: getBtnIcon(btn.btnType),
                onClick: ($event) => handleClick(btn, $event)
              }, {
                default: Vue.withCtx(() => [
                  Vue.createTextVNode(Vue.toDisplayString(btn.label), 1)
                ]),
                _: 2
              }, 1032, ["type", "icon", "onClick"])), [
                [_directive_fec_auth, btn.permission]
              ]);
            }), 128)) : Vue.createCommentVNode("", true)
          ]),
          tools: Vue.withCtx(() => [
            rightButtons.value.length ? (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, { key: 0 }, Vue.renderList(rightButtons.value, (btn) => {
              return Vue.withDirectives((Vue.openBlock(), Vue.createBlock(_component_el_button, {
                key: btn.id,
                type: getBtnType(btn),
                icon: getBtnIcon(btn.btnType),
                onClick: ($event) => handleClick(btn, $event)
              }, {
                default: Vue.withCtx(() => [
                  Vue.createTextVNode(Vue.toDisplayString(btn.label), 1)
                ]),
                _: 2
              }, 1032, ["type", "icon", "onClick"])), [
                [_directive_fec_auth, btn.permission]
              ]);
            }), 128)) : Vue.createCommentVNode("", true)
          ]),
          _: 1
        }, 512)) : Vue.createCommentVNode("", true)
      ]);
    };
  }
};
const CustomButtons = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-8d29fa72"]]);
exports.default = CustomButtons;
