var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
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));
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  PageHeader: () => PageHeader,
  pageHeaderProps: () => pageHeaderProps
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_ArrowLeftOutlined = __toESM(require("@ant-design/icons-vue/ArrowLeftOutlined"));
var import_ArrowRightOutlined = __toESM(require("@ant-design/icons-vue/ArrowRightOutlined"));
var import_pro_utils = require("@antdv/pro-utils");
var import_ant_design_vue = require("ant-design-vue");
var import_context = require("ant-design-vue/lib/config-provider/context");
var import_vc_resize_observer = __toESM(require("ant-design-vue/lib/vc-resize-observer"));
var import_vue2 = require("vue");
var import_style = __toESM(require("./style/index"));
const pageHeaderProps = {
  backIcon: (0, import_pro_utils.vNodeType)(),
  prefixCls: (0, import_pro_utils.stringType)(),
  title: (0, import_pro_utils.vNodeType)(),
  subTitle: (0, import_pro_utils.vNodeType)(),
  childrenContentStyle: (0, import_pro_utils.objectType)(),
  breadcrumb: (0, import_pro_utils.oneOfType)([Array, Object]),
  breadcrumbClassName: (0, import_pro_utils.stringType)(),
  breadcrumbRender: (0, import_pro_utils.funcType)(),
  tags: (0, import_pro_utils.vNodeType)(),
  footer: (0, import_pro_utils.vNodeType)(),
  extra: (0, import_pro_utils.vNodeType)(),
  avatar: (0, import_pro_utils.objectType)(),
  onBack: (0, import_pro_utils.funcType)(),
  className: (0, import_pro_utils.stringType)(),
  contentWidth: (0, import_pro_utils.oneOf)(["Fluid", "Fixed"]),
  layout: (0, import_pro_utils.stringType)(),
  ghost: (0, import_pro_utils.boolType)(),
  children: (0, import_pro_utils.vNodeType)()
};
function renderBack(prefixCls, hashId, backIcon, onBack) {
  if (!backIcon || !onBack) {
    return null;
  }
  return (0, import_vue.createVNode)("div", {
    "class": `${prefixCls}-back ${hashId}`.trim()
  }, [(0, import_vue.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 (0, import_vue.createVNode)(import_ant_design_vue.Breadcrumb, (0, import_vue.mergeProps)(breadcrumb, {
    "class": (0, import_pro_utils.classNames)(`${prefixCls}-breadcrumb`, breadcrumb.className)
  }), null);
}
function getBackIcon(props, direction = "ltr") {
  if (props.backIcon !== void 0) {
    return props.backIcon;
  }
  return direction === "rtl" ? (0, import_vue.createVNode)(import_ArrowRightOutlined.default, null, null) : (0, import_vue.createVNode)(import_ArrowLeftOutlined.default, 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 (0, import_vue.createVNode)("div", {
    "class": `${headingPrefixCls} ${hashId}`
  }, [hasTitle && (0, import_vue.createVNode)("div", {
    "class": `${headingPrefixCls}-left ${hashId}`.trim()
  }, [backIconDom, avatar && (0, import_vue.createVNode)(import_ant_design_vue.Avatar, (0, import_vue.mergeProps)({
    "class": (0, import_pro_utils.classNames)(`${headingPrefixCls}-avatar`, hashId, avatar.className)
  }, avatar), null), title && (0, import_vue.createVNode)("span", {
    "class": `${headingPrefixCls}-title ${hashId}`.trim(),
    "title": typeof title === "string" ? title : void 0
  }, [title]), subTitle && (0, import_vue.createVNode)("span", {
    "class": `${headingPrefixCls}-sub-title ${hashId}`.trim(),
    "title": typeof subTitle === "string" ? subTitle : void 0
  }, [subTitle]), tags && (0, import_vue.createVNode)("span", {
    "class": `${headingPrefixCls}-tags ${hashId}`.trim()
  }, [tags])]), extra && (0, import_vue.createVNode)("span", {
    "class": `${headingPrefixCls}-extra ${hashId}`.trim()
  }, [(0, import_vue.createVNode)(import_ant_design_vue.Space, null, {
    default: () => [extra]
  })])]);
}
function renderFooter(prefixCls, footer, hashId) {
  if (footer) {
    return (0, import_vue.createVNode)("div", {
      "class": `${prefixCls}-footer ${hashId}`.trim()
    }, [footer]);
  }
  return null;
}
function renderChildren(prefixCls, children, hashId) {
  return (0, import_vue.createVNode)("div", {
    "class": `${prefixCls}-content ${hashId}`.trim()
  }, [children]);
}
const PageHeader = (0, import_vue2.defineComponent)({
  name: "PageHeader",
  props: pageHeaderProps,
  inheritAttrs: false,
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      getPrefixCls,
      direction
    } = (0, import_context.useConfigContextInject)();
    const prefixCls = (0, import_vue2.computed)(() => getPrefixCls("page-header", props.prefixCls));
    const {
      wrapSSR,
      hashId
    } = (0, import_style.default)(prefixCls);
    const [compact, updateCompact] = (0, import_pro_utils.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 = (0, import_pro_utils.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 (0, import_vue.createVNode)("div", {
          "class": (0, import_pro_utils.classNames)(hashId.value, [`${prefixCls.value}-no-children`])
        }, null);
      }
      return wrapSSR((0, import_vue.createVNode)(import_vc_resize_observer.default, {
        "onResize": onResize
      }, {
        default: () => [(0, import_vue.createVNode)("div", {
          "class": className,
          "style": attrs.style
        }, [breadcrumbDom, title, childDom, footerDom])]
      }));
    };
  }
});
