import "../../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                                */
/* empty css                                                                      */
/* empty css                                                                          */
/* empty css                                                                     */
import { computed, resolveDirective, createBlock, createCommentVNode, unref, openBlock, normalizeClass, createSlots, withCtx, createElementVNode, toDisplayString, createElementBlock, Fragment, renderList, withDirectives, createTextVNode } from "vue";
import { ArrowLeftBold as arrow_left_bold_default } from "../../../../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
import { getCurrentVueInstance } from "../../../utils/getInstance.mjs";
/* empty css             */
import _export_sfc from "../../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElPageHeader } from "../../../../../../node_modules/element-plus/es/components/page-header/index.mjs";
import { ElButton } from "../../../../../../node_modules/element-plus/es/components/button/index.mjs";
import { ElMessageBox } from "../../../../../../node_modules/element-plus/es/components/message-box/index.mjs";
const _hoisted_1 = { class: "fec-header__title" };
const _hoisted_2 = { class: "fec-header__subtitle" };
const _sfc_main = {
  __name: "Header",
  props: {
    pageHeaderConfig: {
      type: Object,
      required: true
    },
    isApproval: {
      type: Boolean,
      default: false
    },
    showBack: {
      type: Boolean,
      default: false
    }
  },
  emits: ["action-click"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const ctx = getCurrentVueInstance();
    const emit = __emit;
    const canBack = computed(() => {
      var _a;
      if (props.showBack) {
        return !props.isApproval && ((_a = props.pageHeaderConfig) == null ? void 0 : _a.canBack);
      }
      return false;
    });
    const getButtonType = (btnStyle) => {
      return "primary";
    };
    const handleBack = async () => {
      var _a;
      if ((_a = props.pageHeaderConfig) == null ? void 0 : _a.backConfirm) {
        try {
          await ElMessageBox.confirm(
            props.pageHeaderConfig.backMessage || "确定要返回吗？",
            props.pageHeaderConfig.backTitle || "确认返回",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
              draggable: true,
              showClose: false
            }
          );
        } catch (error) {
          return;
        }
      }
      ctx.$router.go(-1);
    };
    const handleActionClick = (action) => {
      emit("action-click", action);
    };
    return (_ctx, _cache) => {
      var _a, _b, _c, _d, _e;
      const _component_el_button = ElButton;
      const _component_el_page_header = ElPageHeader;
      const _directive_fec_auth = resolveDirective("fec-auth");
      return ((_a = __props.pageHeaderConfig) == null ? void 0 : _a.enabled) && (unref(canBack) || ((_c = (_b = __props.pageHeaderConfig) == null ? void 0 : _b.actions) == null ? void 0 : _c.length) > 0) ? (openBlock(), createBlock(_component_el_page_header, {
        key: 0,
        icon: unref(canBack) ? unref(arrow_left_bold_default) : null,
        onBack: handleBack,
        class: normalizeClass(["fec-header", { "can-not-back": !unref(canBack) }])
      }, createSlots({
        content: withCtx(() => {
          var _a2, _b2;
          return [
            createElementVNode("div", _hoisted_1, toDisplayString((_a2 = __props.pageHeaderConfig) == null ? void 0 : _a2.title), 1),
            createElementVNode("div", _hoisted_2, toDisplayString((_b2 = __props.pageHeaderConfig) == null ? void 0 : _b2.subTitle), 1)
          ];
        }),
        _: 2
      }, [
        ((_e = (_d = __props.pageHeaderConfig) == null ? void 0 : _d.actions) == null ? void 0 : _e.length) ? {
          name: "extra",
          fn: withCtx(() => {
            var _a2;
            return [
              (openBlock(true), createElementBlock(Fragment, null, renderList((_a2 = __props.pageHeaderConfig) == null ? void 0 : _a2.actions, (action) => {
                return withDirectives((openBlock(), createBlock(_component_el_button, {
                  key: action.id,
                  type: getButtonType(action.btnStyle),
                  onClick: ($event) => handleActionClick(action)
                }, {
                  default: withCtx(() => [
                    createTextVNode(toDisplayString(action.label), 1)
                  ]),
                  _: 2
                }, 1032, ["type", "onClick"])), [
                  [_directive_fec_auth, action.permission]
                ]);
              }), 128))
            ];
          }),
          key: "0"
        } : void 0
      ]), 1032, ["icon", "class"])) : createCommentVNode("", true);
    };
  }
};
const component = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a55fc4ab"]]);
export {
  component as default
};
