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));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
import { mergeProps as _mergeProps, createVNode as _createVNode, Fragment as _Fragment } from "vue";
import ProProvider, { ProConfigProvider } from "@antdv/pro-provider";
import { arrayType, classNames, funcType, isValidElement, objectType, omitUndefined, oneOfType, stringType, vNodeType } from "@antdv/pro-utils";
import { Affix, Breadcrumb, Tabs } from "ant-design-vue";
import { breadcrumbProps } from "ant-design-vue/es/breadcrumb/Breadcrumb";
import { useConfigContextInject } from "ant-design-vue/lib/config-provider/context";
import { omit } from "lodash-es";
import { computed, defineComponent, onMounted, onUnmounted } from "vue";
import { RouteContext } from "../../context/RouteContext.mjs";
import { FooterToolbar } from "../FooterToolbar/index.mjs";
import { GridContent } from "../GridContent/index.mjs";
import { PageHeader, pageHeaderProps } from "../PageHeader/index.mjs";
import { PageLoading } from "../PageLoading/index.mjs";
import { WaterMark } from "../WaterMark/index.mjs";
import { useStyle } from "./style/index.mjs";
import { useStylish } from "./style/stylish.mjs";
const pageHeaderTabConfigProps = {
  /** @name tabs 的列表 */
  tabList: arrayType(),
  /** @name tabActiveKey 当前选中 tab 的 key */
  tabActiveKey: oneOfType([String, Number]),
  /** @name tab 修改时触发 */
  onTabChange: funcType(),
  /** @name tab 上额外的区域 */
  tabBarExtraContent: vNodeType(),
  /** @name tabs 的其他配置 */
  tabProps: objectType(),
  /**
   * @deprecated 请使用 fixedHeader
   * @name fixHeader 固定 PageHeader 到页面顶部
   */
  fixHeader: Boolean,
  /** @name fixedHeader 固定 PageHeader 到页面顶部 */
  fixedHeader: Boolean
};
const pageContainerProps = __spreadValues(__spreadValues({
  title: oneOfType([Array, Boolean]).def(void 0),
  content: vNodeType(),
  extraContent: vNodeType(),
  prefixCls: String,
  footer: arrayType(),
  /**
   * @name token 自定义的 token
   */
  token: objectType(),
  /**
   * 与 antd 完全相同
   *
   * @name PageHeader 的配置
   */
  header: objectType(),
  /** @name pageHeaderRender 自定义 pageHeader */
  pageHeaderRender: oneOfType([Function, Boolean]).def(void 0),
  /**
   * 与 antd 完全相同
   *
   * @name affixProps 固钉的配置
   */
  affixProps: objectType(),
  /**
   * 只加载内容区域
   *
   * @name loading 是否加载
   */
  loading: oneOfType([Boolean, Object, Array]).def(false),
  /**
   * 自定义 breadcrumb,
   * @name breadcrumbRender 返回false不展示
   */
  breadcrumbRender: oneOfType([Object, Boolean]).def(void 0),
  /** @name WaterMarkProps 水印的配置 */
  waterMarkProps: objectType(),
  /** @name BreadcrumbProps 配置面包屑 */
  breadcrumb: objectType(),
  children: vNodeType(),
  stylish: objectType(),
  footerStylish: objectType(),
  footerToolBarProps: objectType()
}, pageHeaderTabConfigProps), omit(pageHeaderProps, ["title", "footer", "breadcrumbRender", "prefixCls", "children", "breadcrumb"]));
function genLoading(spinProps) {
  if (typeof spinProps === "object") return spinProps;
  return {
    spinning: spinProps
  };
}
function renderFooter({
  tabList,
  tabActiveKey,
  onTabChange,
  hashId,
  tabBarExtraContent,
  tabProps,
  prefixedClassName
}) {
  if (Array.isArray(tabList) || tabBarExtraContent) {
    return _createVNode(Tabs, _mergeProps({
      "class": `${prefixedClassName}-tabs ${hashId}`.trim(),
      "activeKey": tabActiveKey,
      "onChange": (key) => {
        if (onTabChange) {
          onTabChange(key);
        }
      },
      "tabBarExtraContent": tabBarExtraContent
    }, tabProps), {
      default: () => [tabList == null ? void 0 : tabList.map((item, index) => {
        return _createVNode(Tabs.TabPane, _mergeProps({
          "key": item.key || index,
          "tab": item.tab
        }, item), null);
      })]
    });
  }
  return null;
}
function renderPageHeader(content, extraContent, prefixedClassName, hashId) {
  if (!content && !extraContent) {
    return null;
  }
  return _createVNode("div", {
    "class": `${prefixedClassName}-detail ${hashId}`.trim()
  }, [_createVNode("div", {
    "class": `${prefixedClassName}-main ${hashId}`.trim()
  }, [_createVNode("div", {
    "class": `${prefixedClassName}-row ${hashId}`.trim()
  }, [content && _createVNode("div", {
    "class": `${prefixedClassName}-content ${hashId}`.trim()
  }, [content]), extraContent && _createVNode("div", {
    "class": `${prefixedClassName}-extraContent ${hashId}`.trim()
  }, [extraContent])])])]);
}
const ProBreadcrumb = defineComponent({
  name: "ProBreadcrumb",
  props: breadcrumbProps(),
  setup(props) {
    const {
      breadcrumb,
      breadcrumbProps: breadcrumbPropsContext
    } = RouteContext.useContext();
    return () => {
      return _createVNode("div", {
        "style": {
          height: "100%",
          display: "flex",
          alignItems: "center"
        }
      }, [_createVNode(Breadcrumb, _mergeProps(breadcrumb, breadcrumbPropsContext, props), null)]);
    };
  }
});
function memoRenderPageHeader(props) {
  var _b;
  const _a = props, {
    title,
    content,
    pageHeaderRender,
    header,
    prefixedClassName,
    extraContent,
    childrenContentStyle,
    style,
    prefixCls,
    hashId,
    value,
    breadcrumbRender
  } = _a, restProps = __objRest(_a, [
    "title",
    "content",
    "pageHeaderRender",
    "header",
    "prefixedClassName",
    "extraContent",
    "childrenContentStyle",
    "style",
    "prefixCls",
    "hashId",
    "value",
    "breadcrumbRender"
  ]);
  const getBreadcrumbRender = () => {
    if (!breadcrumbRender) {
      return void 0;
    }
    return breadcrumbRender;
  };
  if (pageHeaderRender === false) {
    return null;
  }
  if (pageHeaderRender) {
    return _createVNode(_Fragment, null, [" ", pageHeaderRender(props)]);
  }
  let pageHeaderTitle = title;
  if (!title && title !== false) {
    pageHeaderTitle = value.title;
  }
  const getPageHeaderProps = __spreadValues(__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, value), {
    title: pageHeaderTitle
  }), restProps), {
    footer: renderFooter(__spreadProps(__spreadValues({}, restProps), {
      hashId,
      breadcrumbRender,
      prefixedClassName
    }))
  }), header);
  const {
    breadcrumb
  } = getPageHeaderProps;
  const noHasBreadCrumb = (!breadcrumb || !(breadcrumb == null ? void 0 : breadcrumb.itemRender) && !((_b = breadcrumb == null ? void 0 : breadcrumb.routes) == null ? void 0 : _b.length)) && !breadcrumbRender;
  if (["title", "subTitle", "extra", "tags", "footer", "avatar", "backIcon"].every((item) => !getPageHeaderProps[item]) && noHasBreadCrumb && !content && !extraContent) {
    return null;
  }
  return _createVNode(PageHeader, _mergeProps(getPageHeaderProps, {
    "className": `${prefixedClassName}-warp-page-header ${hashId}`.trim(),
    "breadcrumb": breadcrumbRender === false ? void 0 : __spreadValues(__spreadValues({}, getPageHeaderProps.breadcrumb), value.breadcrumbProps),
    "breadcrumbRender": getBreadcrumbRender(),
    "prefixCls": prefixCls
  }), {
    default: () => [(header == null ? void 0 : header.children) || renderPageHeader(content, extraContent, prefixedClassName, hashId)]
  });
}
const PageContainerBase = defineComponent({
  name: "PageContainerBase",
  inheritAttrs: false,
  props: pageContainerProps,
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const value = RouteContext.useContext();
    const {
      token
    } = ProProvider.useContext();
    const {
      getPrefixCls
    } = useConfigContextInject();
    const prefixCls = props.prefixCls || getPrefixCls("pro");
    const basePageContainer = computed(() => `${prefixCls}-page-container`);
    const {
      wrapSSR,
      hashId
    } = useStyle(basePageContainer, props.token);
    const stylish = useStylish(computed(() => `${basePageContainer.value}.${basePageContainer.value}-stylish`), {
      stylish: props.stylish
    });
    onMounted(() => {
      var _a;
      if (value && (value == null ? void 0 : value.setHasPageContainer)) {
        (_a = value.setHasPageContainer) == null ? void 0 : _a.call(value, (num) => num + 1);
      }
    });
    onUnmounted(() => {
      var _a;
      if (value && (value == null ? void 0 : value.setHasPageContainer)) {
        (_a = value.setHasPageContainer) == null ? void 0 : _a.call(value, (num) => num - 1);
      }
    });
    const memoBreadcrumbRender = computed(() => {
      var _a;
      if (props.breadcrumbRender === false) return false;
      return props.breadcrumbRender || ((_a = props == null ? void 0 : props.header) == null ? void 0 : _a.breadcrumbRender);
    });
    return () => {
      var _a, _b, _c, _e, _f;
      const _d = props, {
        children = (_a = slots.default) == null ? void 0 : _a.call(slots),
        loading = (_b = slots.loading) == null ? void 0 : _b.call(slots),
        className,
        footer = (_c = slots.footer) == null ? void 0 : _c.call(slots),
        affixProps,
        token: propsToken,
        fixedHeader,
        breadcrumbRender,
        footerToolBarProps,
        childrenContentStyle
      } = _d, restProps = __objRest(_d, [
        "children",
        "loading",
        "className",
        "footer",
        "affixProps",
        "token",
        "fixedHeader",
        "breadcrumbRender",
        "footerToolBarProps",
        "childrenContentStyle"
      ]);
      const pageHeaderDom = memoRenderPageHeader(__spreadProps(__spreadValues({}, omitUndefined(restProps)), {
        breadcrumbRender: memoBreadcrumbRender.value,
        ghost: true,
        hashId: hashId.value,
        prefixCls: void 0,
        prefixedClassName: basePageContainer.value,
        value
      }));
      const renderLoadingDom = () => {
        if (isValidElement(props.loading)) {
          return props.loading;
        }
        if (typeof props.loading === "boolean" && !props.loading) {
          return null;
        }
        const spinProps = genLoading(props.loading);
        return spinProps.spinning ? _createVNode(PageLoading, spinProps, null) : null;
      };
      const loadingDom = renderLoadingDom();
      const content = children ? _createVNode(_Fragment, null, [_createVNode("div", {
        "class": classNames(hashId.value, `${basePageContainer.value}-children-container`, {
          [`${basePageContainer.value}-children-container-no-header`]: !pageHeaderDom
        }),
        "style": props.childrenContentStyle
      }, [children])]) : null;
      const renderContentDom = () => {
        const dom = loadingDom || content;
        if (props.waterMarkProps || value.waterMarkProps) {
          const getWaterMarkProps = __spreadValues(__spreadValues({}, value.waterMarkProps), props.waterMarkProps);
          return _createVNode(WaterMark, getWaterMarkProps, {
            default: () => [dom]
          });
        }
        return dom;
      };
      const contentDom = renderContentDom();
      const containerClassName = classNames(basePageContainer.value, hashId.value, className, {
        [`${basePageContainer.value}-with-footer`]: footer,
        [`${basePageContainer.value}-with-affix`]: fixedHeader && pageHeaderDom,
        [`${basePageContainer.value}-stylish`]: !!restProps.stylish
      });
      return wrapSSR(stylish.wrapSSR(_createVNode(_Fragment, null, [_createVNode("div", {
        "style": attrs.style,
        "class": containerClassName
      }, [fixedHeader && pageHeaderDom ? (
        // 在 hasHeader 且 fixedHeader 的情况下，才需要设置高度
        _createVNode(Affix, _mergeProps({
          "offsetTop": value.hasHeader && fixedHeader ? (_f = (_e = token == null ? void 0 : token.layout) == null ? void 0 : _e.header) == null ? void 0 : _f.heightLayoutHeader : 1
        }, omit(affixProps, ["target"]), {
          "target": (affixProps == null ? void 0 : affixProps.target) || (() => window),
          "class": `${basePageContainer.value}-affix ${hashId.value}`.trim()
        }), {
          default: () => [_createVNode("div", {
            "class": `${basePageContainer.value}-warp ${hashId.value}`.trim()
          }, [pageHeaderDom])]
        })
      ) : pageHeaderDom, contentDom && _createVNode(GridContent, null, {
        default: () => [contentDom]
      })]), footer && _createVNode(FooterToolbar, _mergeProps({
        "stylish": restProps.footerStylish,
        "prefixCls": prefixCls
      }, footerToolBarProps), {
        default: () => [footer]
      })])));
    };
  }
});
const PageContainer = defineComponent({
  name: "PageContainer",
  props: pageContainerProps,
  setup(props, {
    slots
  }) {
    return () => _createVNode(ProConfigProvider, {
      "needDeps": true
    }, {
      default: () => [_createVNode(PageContainerBase, props, slots)]
    });
  }
});
const ProPageHeader = defineComponent({
  name: "ProPageHeader",
  inheritAttrs: false,
  props: __spreadProps(__spreadValues({}, pageContainerProps), {
    prefixedClassName: stringType().isRequired
  }),
  setup(props, {
    attrs
  }) {
    const value = RouteContext.useContext();
    return () => memoRenderPageHeader(__spreadProps(__spreadValues({}, props), {
      hashId: "",
      style: attrs.style,
      value
    }));
  }
});
export {
  PageContainer,
  ProBreadcrumb,
  ProPageHeader,
  pageContainerProps,
  pageHeaderTabConfigProps
};
