'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
var index$3 = require('../_util/props-util/index.js');
require('../breadcrumb/index.js');
require('../avatar/index.js');
var transButton = require('../_util/components/transButton.js');
var LocaleReceiver = require('../locale-provider/LocaleReceiver.js');
var type = require('../_util/type.js');
require('../hooks/index.js');
var classNames = require('../_util/classNames.js');
var index$4 = require('../vc-resize-observer/index.js');
var index$2 = require('../space/index.js');
var index$1 = require('./style/index.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var useDestroyed = require('../hooks/useDestroyed.js');
var Breadcrumb = require('../breadcrumb/Breadcrumb.js');
var Avatar = require('../avatar/Avatar.js');

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
}
const pageHeaderProps = () => ({
  backIcon: type.vNodeType(),
  prefixCls: String,
  title: type.vNodeType(),
  subTitle: type.vNodeType(),
  breadcrumb: Object,
  tags: type.vNodeType(),
  footer: type.vNodeType(),
  extra: type.vNodeType(),
  avatar: type.objectType(),
  ghost: {
    type: Boolean,
    default: void 0
  },
  onBack: Function
});
const PageHeader = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "APageHeader",
  inheritAttrs: false,
  props: pageHeaderProps(),
  // emits: ['back'],
  slots: Object,
  setup(props, {
    emit,
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction,
      pageHeader
    } = useConfigInject.default("page-header", props);
    const [wrapSSR, hashId] = index$1.default(prefixCls);
    const compact = vue.shallowRef(false);
    const isDestroyed = useDestroyed.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(CloseOutlined.ArrowRightOutlined, null, null) : vue.createVNode(CloseOutlined.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.default, {
          "onClick": (e) => {
            emit("back", e);
          },
          "class": `${prefixCls.value}-back-button`,
          "aria-label": back
        }, _isSlot(backIcon) ? backIcon : {
          default: () => [backIcon]
        })])
      }, null);
    };
    const renderBreadcrumb = () => {
      var _a;
      return props.breadcrumb ? vue.createVNode(Breadcrumb.default, 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(Avatar.default, 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$2.default, null, _isSlot(extra) ? extra : {
        default: () => [extra]
      })])]);
    };
    const renderFooter = () => {
      var _a, _b;
      const footer = (_b = props.footer) != null ? _b : index$3.filterEmpty((_a = slots.footer) == null ? void 0 : _a.call(slots));
      return index$3.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 = index$3.flattenChildren((_b = slots.default) == null ? void 0 : _b.call(slots));
      const className = classNames.default(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$4.default, {
        "onResize": onResize
      }, {
        default: () => [vue.createVNode("div", vue.mergeProps(attrs, {
          "class": className
        }), [renderBreadcrumb(), renderTitle(), children.length ? renderChildren(children) : null, renderFooter()])]
      }));
    };
  }
});
var index = type.withInstall(PageHeader);

exports.default = index;
exports.pageHeaderProps = pageHeaderProps;
//# sourceMappingURL=index.js.map
