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 { mergeProps as _mergeProps, createVNode as _createVNode, Fragment as _Fragment } from "vue";
import { MenuOutlined } from "@ant-design/icons-vue";
import { classNames } from "@antdv/pro-utils";
import { useConfigContextInject } from "ant-design-vue/lib/config-provider/context";
import { computed, defineComponent } from "vue";
import { clearMenuItem } from "../../utils/utils.mjs";
import { AppsLogoComponents, defaultRenderLogo } from "../AppsLogoComponents/index.mjs";
import { privateSiderMenuProps, renderLogoAndTitle } from "../SiderMenu/SiderMenu.mjs";
import { TopNavHeader } from "../TopNavHeader/index.mjs";
import { ActionsContent } from "./ActionsContent.mjs";
import { globalHeaderProps } from "./props.mjs";
import { useStyle } from "./style.mjs";
function renderLogo(menuHeaderRender, logoDom) {
  if (menuHeaderRender === false) {
    return null;
  }
  if (menuHeaderRender) {
    return menuHeaderRender(logoDom, null);
  }
  return logoDom;
}
const GlobalHeader = defineComponent({
  name: "GlobalHeader",
  props: __spreadValues(__spreadValues({}, globalHeaderProps()), privateSiderMenuProps()),
  inheritAttrs: false,
  slots: Object,
  setup(props, {
    attrs,
    slots
  }) {
    const {
      getPrefixCls,
      direction
    } = useConfigContextInject();
    const baseClassName = computed(() => `${props.prefixCls || getPrefixCls("pro")}-global-header`);
    const {
      wrapSSR,
      hashId
    } = useStyle(baseClassName);
    const className = classNames(attrs.class || "", baseClassName.value, hashId.value);
    return () => {
      var _a, _b;
      const {
        isMobile,
        logo = (_a = slots.logo) == null ? void 0 : _a.call(slots),
        collapsed,
        onCollapse,
        menuHeaderRender,
        onMenuHeaderClick,
        layout,
        children = (_b = slots.default) == null ? void 0 : _b.call(slots),
        splitMenus,
        menuData
      } = props;
      const mergeProps = __spreadValues(__spreadValues({}, props), attrs);
      if (layout === "mix" && !isMobile && splitMenus) {
        const noChildrenMenuData = (menuData || []).map((item) => __spreadProps(__spreadValues({}, item), {
          children: void 0,
          routes: void 0
        }));
        const clearMenuData = clearMenuItem(noChildrenMenuData);
        return _createVNode(TopNavHeader, _mergeProps({
          "mode": "horizontal"
        }, mergeProps, {
          "splitMenus": false,
          "menuData": clearMenuData
        }), null);
      }
      const logoClassNames = classNames(`${baseClassName.value}-logo`, hashId.value, {
        [`${baseClassName.value}-logo-rtl`]: (direction == null ? void 0 : direction.value) === "rtl",
        [`${baseClassName.value}-logo-mix`]: layout === "mix",
        [`${baseClassName.value}-logo-mobile`]: isMobile
      });
      const logoDom = _createVNode("span", {
        "class": logoClassNames,
        "key": "logo"
      }, [_createVNode("a", null, [defaultRenderLogo(logo)])]);
      return _createVNode(_Fragment, null, [wrapSSR(_createVNode("div", {
        "class": className,
        "style": __spreadValues({}, attrs.style || {})
      }, [isMobile && _createVNode("span", {
        "class": `${baseClassName.value}-collapsed-button ${hashId.value}`.trim(),
        "onClick": () => {
          onCollapse == null ? void 0 : onCollapse(!collapsed);
        }
      }, [_createVNode(MenuOutlined, null, null)]), isMobile && renderLogo(menuHeaderRender, logoDom), layout === "mix" && !isMobile && _createVNode(_Fragment, null, [_createVNode(AppsLogoComponents, props, null), _createVNode("div", {
        "class": logoClassNames,
        "onClick": onMenuHeaderClick
      }, [renderLogoAndTitle(__spreadProps(__spreadValues({}, props), {
        collapsed: false
      }), "headerTitleRender")])]), _createVNode("div", {
        "style": {
          flex: 1
        }
      }, [children]), (props.actionsRender || props.avatarProps) && _createVNode(ActionsContent, props, null)]))]);
    };
  }
});
export {
  GlobalHeader
};
