var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
import { createVNode as _createVNode, mergeProps as _mergeProps } from "vue";
import ArrowLeftOutlined from "@ant-design/icons-vue/ArrowLeftOutlined";
import ArrowRightOutlined from "@ant-design/icons-vue/ArrowRightOutlined";
import { boolType, classNames, funcType, objectType, oneOf, oneOfType, stringType, useState, vNodeType } from "@antdv/pro-utils";
import { Avatar, Breadcrumb, Space } from "ant-design-vue";
import { useConfigContextInject } from "ant-design-vue/lib/config-provider/context";
import ResizeObserver from "ant-design-vue/lib/vc-resize-observer";
import { computed, defineComponent } from "vue";
import useStyle from "./style/index.mjs";
const pageHeaderProps = {
  backIcon: vNodeType(),
  prefixCls: stringType(),
  title: vNodeType(),
  subTitle: vNodeType(),
  childrenContentStyle: objectType(),
  breadcrumb: oneOfType([Array, Object]),
  breadcrumbClassName: stringType(),
  breadcrumbRender: funcType(),
  tags: vNodeType(),
  footer: vNodeType(),
  extra: vNodeType(),
  avatar: objectType(),
  onBack: funcType(),
  className: stringType(),
  contentWidth: oneOf(["Fluid", "Fixed"]),
  layout: stringType(),
  ghost: boolType(),
  children: vNodeType()
};
function renderBack(prefixCls, hashId, backIcon, onBack) {
  if (!backIcon || !onBack) {
    return null;
  }
  return _createVNode("div", {
    "class": `${prefixCls}-back ${hashId}`.trim()
  }, [_createVNode("div", {
    "role": "button",
    "onClick": (e) => {
      onBack == null ? void 0 : onBack(e);
    },
    "class": `${prefixCls}-back-button ${hashId}`.trim(),
    "aria-label": "back"
  }, [backIcon])]);
}
function renderBreadcrumb(breadcrumb, prefixCls) {
  var _a;
  if (!((_a = breadcrumb.routes) == null ? void 0 : _a.length)) return null;
  return _createVNode(Breadcrumb, _mergeProps(breadcrumb, {
    "class": classNames(`${prefixCls}-breadcrumb`, breadcrumb.className)
  }), null);
}
function getBackIcon(props, direction = "ltr") {
  if (props.backIcon !== void 0) {
    return props.backIcon;
  }
  return direction === "rtl" ? _createVNode(ArrowRightOutlined, null, null) : _createVNode(ArrowLeftOutlined, null, null);
}
function renderTitle(prefixCls, props, direction = "ltr", hashId) {
  const {
    title,
    avatar,
    subTitle,
    tags,
    extra,
    onBack
  } = props;
  const headingPrefixCls = `${prefixCls}-heading`;
  const hasHeading = title || subTitle || tags || extra;
  if (!hasHeading) {
    return null;
  }
  const backIcon = getBackIcon(props, direction);
  const backIconDom = renderBack(prefixCls, hashId, backIcon, onBack);
  const hasTitle = backIconDom || avatar || hasHeading;
  return _createVNode("div", {
    "class": `${headingPrefixCls} ${hashId}`
  }, [hasTitle && _createVNode("div", {
    "class": `${headingPrefixCls}-left ${hashId}`.trim()
  }, [backIconDom, avatar && _createVNode(Avatar, _mergeProps({
    "class": classNames(`${headingPrefixCls}-avatar`, hashId, avatar.className)
  }, avatar), null), title && _createVNode("span", {
    "class": `${headingPrefixCls}-title ${hashId}`.trim(),
    "title": typeof title === "string" ? title : void 0
  }, [title]), subTitle && _createVNode("span", {
    "class": `${headingPrefixCls}-sub-title ${hashId}`.trim(),
    "title": typeof subTitle === "string" ? subTitle : void 0
  }, [subTitle]), tags && _createVNode("span", {
    "class": `${headingPrefixCls}-tags ${hashId}`.trim()
  }, [tags])]), extra && _createVNode("span", {
    "class": `${headingPrefixCls}-extra ${hashId}`.trim()
  }, [_createVNode(Space, null, {
    default: () => [extra]
  })])]);
}
function renderFooter(prefixCls, footer, hashId) {
  if (footer) {
    return _createVNode("div", {
      "class": `${prefixCls}-footer ${hashId}`.trim()
    }, [footer]);
  }
  return null;
}
function renderChildren(prefixCls, children, hashId) {
  return _createVNode("div", {
    "class": `${prefixCls}-content ${hashId}`.trim()
  }, [children]);
}
const PageHeader = defineComponent({
  name: "PageHeader",
  props: pageHeaderProps,
  inheritAttrs: false,
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      getPrefixCls,
      direction
    } = useConfigContextInject();
    const prefixCls = computed(() => getPrefixCls("page-header", props.prefixCls));
    const {
      wrapSSR,
      hashId
    } = useStyle(prefixCls);
    const [compact, updateCompact] = useState(false);
    const onResize = ({
      width
    }) => updateCompact(width < 768);
    return () => {
      var _a, _b, _c;
      const {
        footer = (_a = slots.footer) == null ? void 0 : _a.call(slots),
        children = (_b = slots.default) == null ? void 0 : _b.call(slots),
        breadcrumb,
        breadcrumbRender,
        className: customizeClassName,
        breadcrumbClassName,
        contentWidth,
        layout,
        ghost = true
      } = props;
      const getDefaultBreadcrumbDom = () => {
        if (breadcrumb && (breadcrumb == null ? void 0 : breadcrumb.routes)) {
          return renderBreadcrumb(__spreadProps(__spreadValues({}, breadcrumb), {
            className: breadcrumbClassName
          }), prefixCls.value);
        }
        return null;
      };
      const defaultBreadcrumbDom = getDefaultBreadcrumbDom();
      const breadcrumbRenderDomFromProps = (_c = breadcrumbRender == null ? void 0 : breadcrumbRender(__spreadProps(__spreadValues({}, props), {
        prefixCls: prefixCls.value
      }), defaultBreadcrumbDom)) != null ? _c : defaultBreadcrumbDom;
      const breadcrumbDom = (slots == null ? void 0 : slots.breadcrumb) ? slots == null ? void 0 : slots.breadcrumb() : breadcrumbRenderDomFromProps;
      const className = classNames(prefixCls.value, hashId.value, customizeClassName, {
        [`${prefixCls.value}-has-breadcrumb`]: !!breadcrumbDom,
        [`${prefixCls.value}-has-footer`]: !!footer,
        [`${prefixCls.value}-rtl`]: (direction == null ? void 0 : direction.value) === "rtl",
        [`${prefixCls.value}-compact`]: compact,
        [`${prefixCls.value}-wide`]: contentWidth === "Fixed" && layout === "top",
        [`${prefixCls.value}-ghost`]: ghost
      });
      const title = renderTitle(prefixCls.value, props, direction == null ? void 0 : direction.value, hashId.value);
      const childDom = children && renderChildren(prefixCls.value, children, hashId.value);
      const footerDom = renderFooter(prefixCls.value, footer, hashId.value);
      if (!breadcrumbDom && !title && !footerDom && !childDom) {
        return _createVNode("div", {
          "class": classNames(hashId.value, [`${prefixCls.value}-no-children`])
        }, null);
      }
      return wrapSSR(_createVNode(ResizeObserver, {
        "onResize": onResize
      }, {
        default: () => [_createVNode("div", {
          "class": className,
          "style": attrs.style
        }, [breadcrumbDom, title, childDom, footerDom])]
      }));
    };
  }
});
export {
  PageHeader,
  pageHeaderProps
};
