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 __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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  DefaultHeader: () => DefaultHeader,
  headerViewProps: () => headerViewProps
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_pro_provider = require("@antdv/pro-provider");
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_vue2 = require("vue");
var import_utils = require("../../utils/utils");
var import_GlobalHeader = require("../GlobalHeader");
var import_props = require("../GlobalHeader/props");
var import_SiderMenu = require("../SiderMenu/SiderMenu");
var import_TopNavHeader = require("../TopNavHeader");
var import_header = require("./style/header");
var import_stylish = require("./style/stylish");
const {
  Header
} = import_ant_design_vue.Layout;
function headerViewProps() {
  return __spreadProps(__spreadValues({}, (0, import_props.globalHeaderProps)()), {
    isMobile: (0, import_pro_utils.boolType)(),
    logo: (0, import_pro_utils.vNodeType)(),
    headerRender: (0, import_pro_utils.oneOfType)([Function, Boolean]).def(void 0),
    headerTitleRender: (0, import_pro_utils.oneOfType)([Function, Boolean]).def(void 0),
    headerContentRender: (0, import_pro_utils.oneOfType)([Function, Boolean]).def(void 0),
    siderWidth: (0, import_pro_utils.numberType)(),
    hasSiderMenu: (0, import_pro_utils.boolType)()
  });
}
const DefaultHeader = (0, import_vue2.defineComponent)({
  name: "DefaultHeader",
  inheritAttrs: false,
  props: __spreadValues(__spreadValues({}, headerViewProps()), (0, import_SiderMenu.privateSiderMenuProps)()),
  slots: Object,
  setup(props, {
    attrs
  }) {
    const {
      token
    } = import_pro_provider.ProProvider.useContext();
    const {
      getTargetContainer
    } = (0, import_context.useConfigContextInject)();
    const needFixedHeader = (0, import_vue2.computed)(() => props.fixedHeader || props.layout === "mix");
    const dom = (0, import_vue2.computed)(() => {
      var _a;
      return ((_a = getTargetContainer == null ? void 0 : getTargetContainer.value) == null ? void 0 : _a.call(getTargetContainer)) || document.body;
    });
    const [isFixedHeaderScroll, setIsFixedHeaderScroll] = (0, import_pro_utils.useState)(false);
    const isFixedHeaderFn = () => {
      var _a, _b;
      const scrollTop = dom.value.scrollTop;
      if (scrollTop > (((_b = (_a = token == null ? void 0 : token.layout) == null ? void 0 : _a.header) == null ? void 0 : _b.heightLayoutHeader) || 56) && !isFixedHeaderScroll.value) {
        setIsFixedHeaderScroll(true);
        return true;
      }
      if (isFixedHeaderScroll.value) {
        setIsFixedHeaderScroll(false);
      }
      return false;
    };
    const baseClassName = (0, import_vue2.computed)(() => `${props.prefixCls}-layout-header`);
    const {
      wrapSSR,
      hashId
    } = (0, import_header.useStyle)(baseClassName);
    const stylish = (0, import_stylish.useStylish)((0, import_vue2.computed)(() => `${baseClassName.value}.${baseClassName.value}-stylish`), {
      proLayoutCollapsedWidth: 64,
      stylish: props.stylish
    });
    (0, import_vue2.onMounted)(() => {
      var _a;
      if (!needFixedHeader.value) return;
      if (typeof window === "undefined") return;
      (_a = dom.value) == null ? void 0 : _a.addEventListener("scroll", isFixedHeaderFn, {
        passive: true
      });
    });
    (0, import_vue2.onUnmounted)(() => {
      var _a;
      (_a = dom.value) == null ? void 0 : _a.removeEventListener("scroll", isFixedHeaderFn);
    });
    return () => {
      const {
        isMobile,
        collapsed,
        onCollapse,
        layout,
        headerRender,
        headerContentRender
      } = props;
      const mergeProps = __spreadValues(__spreadValues({}, (0, import_pro_utils.omit)(props, ["onCollapse"])), attrs);
      const renderContent = () => {
        const isTop = layout === "top";
        const clearMenuData = (0, import_utils.clearMenuItem)(props.menuData || []);
        let defaultDom = (0, import_vue.createVNode)(import_GlobalHeader.GlobalHeader, (0, import_vue.mergeProps)({
          "onCollapse": onCollapse
        }, mergeProps, {
          "menuData": clearMenuData
        }), {
          default: () => [headerContentRender && headerContentRender()]
        });
        if (isTop && !isMobile) {
          defaultDom = (0, import_vue.createVNode)(import_TopNavHeader.TopNavHeader, (0, import_vue.mergeProps)({
            "mode": "horizontal",
            "onCollapse": onCollapse
          }, mergeProps, {
            "menuData": clearMenuData
          }), null);
        }
        if (headerRender && typeof headerRender === "function") {
          return headerRender(props, defaultDom);
        }
        return defaultDom;
      };
      const className = (0, import_pro_utils.classNames)(attrs.class || "", hashId.value, baseClassName.value, {
        [`${baseClassName.value}-fixed-header`]: needFixedHeader.value,
        [`${baseClassName.value}-fixed-header-scroll`]: isFixedHeaderScroll.value,
        [`${baseClassName.value}-mix`]: layout === "mix",
        [`${baseClassName.value}-fixed-header-action`]: !collapsed,
        [`${baseClassName.value}-top-menu`]: layout === "top",
        [`${baseClassName.value}-header`]: true,
        [`${baseClassName.value}-stylish`]: !!props.stylish
      });
      if (layout === "side" && !isMobile) return null;
      return stylish.wrapSSR(wrapSSR((0, import_vue.createVNode)(import_ant_design_vue.ConfigProvider, {
        "theme": {
          hashed: (0, import_pro_provider.isNeedOpenHash)(),
          components: {
            Layout: {
              // @ts-expect-error
              headerBg: "transparent",
              bodyBg: "transparent"
            }
          }
        }
      }, {
        default: () => {
          var _a, _b, _c, _d;
          return [needFixedHeader.value && (0, import_vue.createVNode)(Header, {
            "style": __spreadValues({
              height: `${((_b = (_a = token == null ? void 0 : token.layout) == null ? void 0 : _a.header) == null ? void 0 : _b.heightLayoutHeader) || 56}px`,
              lineHeight: `${((_d = (_c = token == null ? void 0 : token.layout) == null ? void 0 : _c.header) == null ? void 0 : _d.heightLayoutHeader) || 56}px`,
              backgroundColor: "transparent",
              zIndex: 19
            }, attrs.style || {})
          }, null), (0, import_vue.createVNode)(Header, {
            "class": className,
            "style": attrs.style
          }, {
            default: () => [renderContent()]
          })];
        }
      })));
    };
  }
});
