import { defineComponent, shallowRef, computed, createVNode } from 'vue';
import { ArrowRightOutlined, ArrowLeftOutlined } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import '../../../hooks/index.mjs';
import '../../../vue-components/index.mjs';
import { Breadcrumb } from '../../breadcrumb/index.mjs';
import { Avatar } from '../../avatar/index.mjs';
import LocaleReceiver from '../../locale-provider/src/LocaleReceiver.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import { Space } from '../../space/index.mjs';
import useStyle from '../style/index.mjs';
import { pageHeaderProps } from './props.mjs';
import { useDestroyed } from '../../../hooks/use-destroyed/index.mjs';
import { TransButton } from '../../../vue-components/transition/src/transButton.mjs';
import { filterEmpty, flattenChildren } from '../../../utils/vue/props.mjs';
import { isEmptyContent } from '../../../utils/is.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import ResizeObserver from '../../../vue-components/vc-resize-observer/src/index.mjs';

var pageHeader = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "APageHeader",
  inheritAttrs: false,
  props: pageHeaderProps(),
  // emits: ['back'],
  slots: Object,
  setup(props, {
    emit,
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction,
      pageHeader
    } = useConfigInject("page-header", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const compact = shallowRef(false);
    const isDestroyed = useDestroyed();
    const onResize = ({
      width
    }) => {
      if (!isDestroyed.value)
        compact.value = width < 768;
    };
    const ghost = 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" ? createVNode(ArrowRightOutlined, null, null) : createVNode(ArrowLeftOutlined, null, null);
    };
    const renderBack = (backIcon) => {
      if (!backIcon || !props.onBack)
        return null;
      return createVNode(LocaleReceiver, {
        "componentName": "PageHeader",
        "children": ({
          back
        }) => createVNode("div", {
          "class": `${prefixCls.value}-back`
        }, [createVNode(TransButton, {
          "onClick": (e) => {
            emit("back", e);
          },
          "class": `${prefixCls.value}-back-button`,
          "aria-label": back
        }, {
          default: () => [backIcon]
        })])
      }, null);
    };
    const renderBreadcrumb = () => {
      var _a;
      return props.breadcrumb ? createVNode(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 createVNode("div", {
        "class": headingPrefixCls
      }, [hasTitle && createVNode("div", {
        "class": `${headingPrefixCls}-left`
      }, [backIconDom, avatar ? createVNode(Avatar, avatar, null) : (_i = slots.avatar) == null ? void 0 : _i.call(slots), title && createVNode("span", {
        "class": `${headingPrefixCls}-title`,
        "title": typeof title === "string" ? title : void 0
      }, [title]), subTitle && createVNode("span", {
        "class": `${headingPrefixCls}-sub-title`,
        "title": typeof subTitle === "string" ? subTitle : void 0
      }, [subTitle]), tags && createVNode("span", {
        "class": `${headingPrefixCls}-tags`
      }, [tags])]), extra && createVNode("span", {
        "class": `${headingPrefixCls}-extra`
      }, [createVNode(Space, null, {
        default: () => [extra]
      })])]);
    };
    const renderFooter = () => {
      var _a, _b;
      const footer = (_b = props.footer) != null ? _b : filterEmpty((_a = slots.footer) == null ? void 0 : _a.call(slots));
      return isEmptyContent(footer) ? null : createVNode("div", {
        "class": `${prefixCls.value}-footer`
      }, [footer]);
    };
    const renderChildren = (children) => {
      return 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 = flattenChildren((_b = slots.default) == null ? void 0 : _b.call(slots));
      const className = 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(createVNode(ResizeObserver, {
        "onResize": onResize
      }, {
        default: () => [createVNode("div", {
          ...attrs,
          "class": className
        }, [renderBreadcrumb(), renderTitle(), children.length ? renderChildren(children) : null, renderFooter()])]
      }));
    };
  }
});

export { pageHeader as default };
//# sourceMappingURL=PageHeader.mjs.map
