'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
require('../../../hooks/index.cjs');
require('../../../vue-components/index.cjs');
var index$2 = require('../../breadcrumb/index.cjs');
var index$3 = require('../../avatar/index.cjs');
var LocaleReceiver = require('../../locale-provider/src/LocaleReceiver.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index$4 = require('../../space/index.cjs');
var index = require('../style/index.cjs');
var props = require('./props.cjs');
var index$1 = require('../../../hooks/use-destroyed/index.cjs');
var transButton = require('../../../vue-components/transition/src/transButton.cjs');
var props$1 = require('../../../utils/vue/props.cjs');
var is = require('../../../utils/is.cjs');
var _class = require('../../../utils/dom/class.cjs');
var index$5 = require('../../../vue-components/vc-resize-observer/src/index.cjs');

var pageHeader = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "APageHeader",
  inheritAttrs: false,
  props: props.pageHeaderProps(),
  // emits: ['back'],
  slots: Object,
  setup(props, {
    emit,
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction,
      pageHeader
    } = useConfigInject.default("page-header", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    const compact = vue.shallowRef(false);
    const isDestroyed = index$1.useDestroyed();
    const onResize = ({
      width
    }) => {
      if (!isDestroyed.value)
        compact.value = width < 768;
    };
    const ghost = vue.computed(() => {
      var _a, _b, _c;
      return (_c = (_b = props.ghost) != null ? _b : (_a = pageHeader == null ? void 0 : pageHeader.value) == null ? void 0 : _a.ghost) != null ? _c : true;
    });
    const getBackIcon = () => {
      var _a, _b, _c;
      return (_c = (_b = props.backIcon) != null ? _b : (_a = slots.backIcon) == null ? void 0 : _a.call(slots)) != null ? _c : direction.value === "rtl" ? vue.createVNode(iconsVue.ArrowRightOutlined, null, null) : vue.createVNode(iconsVue.ArrowLeftOutlined, null, null);
    };
    const renderBack = (backIcon) => {
      if (!backIcon || !props.onBack)
        return null;
      return vue.createVNode(LocaleReceiver.default, {
        "componentName": "PageHeader",
        "children": ({
          back
        }) => vue.createVNode("div", {
          "class": `${prefixCls.value}-back`
        }, [vue.createVNode(transButton.TransButton, {
          "onClick": (e) => {
            emit("back", e);
          },
          "class": `${prefixCls.value}-back-button`,
          "aria-label": back
        }, {
          default: () => [backIcon]
        })])
      }, null);
    };
    const renderBreadcrumb = () => {
      var _a;
      return props.breadcrumb ? vue.createVNode(index$2.Breadcrumb, props.breadcrumb, null) : (_a = slots.breadcrumb) == null ? void 0 : _a.call(slots);
    };
    const renderTitle = () => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _i;
      const {
        avatar
      } = props;
      const title = (_b = props.title) != null ? _b : (_a = slots.title) == null ? void 0 : _a.call(slots);
      const subTitle = (_d = props.subTitle) != null ? _d : (_c = slots.subTitle) == null ? void 0 : _c.call(slots);
      const tags = (_f = props.tags) != null ? _f : (_e = slots.tags) == null ? void 0 : _e.call(slots);
      const extra = (_h = props.extra) != null ? _h : (_g = slots.extra) == null ? void 0 : _g.call(slots);
      const headingPrefixCls = `${prefixCls.value}-heading`;
      const hasHeading = title || subTitle || tags || extra;
      if (!hasHeading)
        return null;
      const backIcon = getBackIcon();
      const backIconDom = renderBack(backIcon);
      const hasTitle = backIconDom || avatar || hasHeading;
      return vue.createVNode("div", {
        "class": headingPrefixCls
      }, [hasTitle && vue.createVNode("div", {
        "class": `${headingPrefixCls}-left`
      }, [backIconDom, avatar ? vue.createVNode(index$3.Avatar, avatar, null) : (_i = slots.avatar) == null ? void 0 : _i.call(slots), title && vue.createVNode("span", {
        "class": `${headingPrefixCls}-title`,
        "title": typeof title === "string" ? title : void 0
      }, [title]), subTitle && vue.createVNode("span", {
        "class": `${headingPrefixCls}-sub-title`,
        "title": typeof subTitle === "string" ? subTitle : void 0
      }, [subTitle]), tags && vue.createVNode("span", {
        "class": `${headingPrefixCls}-tags`
      }, [tags])]), extra && vue.createVNode("span", {
        "class": `${headingPrefixCls}-extra`
      }, [vue.createVNode(index$4.Space, null, {
        default: () => [extra]
      })])]);
    };
    const renderFooter = () => {
      var _a, _b;
      const footer = (_b = props.footer) != null ? _b : props$1.filterEmpty((_a = slots.footer) == null ? void 0 : _a.call(slots));
      return is.isEmptyContent(footer) ? null : vue.createVNode("div", {
        "class": `${prefixCls.value}-footer`
      }, [footer]);
    };
    const renderChildren = (children) => {
      return vue.createVNode("div", {
        "class": `${prefixCls.value}-content`
      }, [children]);
    };
    return () => {
      var _a, _b;
      const hasBreadcrumb = ((_a = props.breadcrumb) == null ? void 0 : _a.routes) || slots.breadcrumb;
      const hasFooter = props.footer || slots.footer;
      const children = props$1.flattenChildren((_b = slots.default) == null ? void 0 : _b.call(slots));
      const className = _class.classNames(prefixCls.value, {
        "has-breadcrumb": hasBreadcrumb,
        "has-footer": hasFooter,
        [`${prefixCls.value}-ghost`]: ghost.value,
        [`${prefixCls.value}-rtl`]: direction.value === "rtl",
        [`${prefixCls.value}-compact`]: compact.value
      }, attrs.class, hashId.value);
      return wrapSSR(vue.createVNode(index$5.default, {
        "onResize": onResize
      }, {
        default: () => [vue.createVNode("div", {
          ...attrs,
          "class": className
        }, [renderBreadcrumb(), renderTitle(), children.length ? renderChildren(children) : null, renderFooter()])]
      }));
    };
  }
});

exports.default = pageHeader;
//# sourceMappingURL=PageHeader.cjs.map
