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 { createVNode as _createVNode, mergeProps as _mergeProps, Fragment as _Fragment } from "vue";
import { ProProvider } from "@antdv/pro-provider";
import { arrayType, boolType, classNames, funcType, numberType, objectType, omit, oneOf, oneOfType, vNodeType } from "@antdv/pro-utils";
import { Avatar, Layout, Menu, Space } from "ant-design-vue";
import { computed, defineComponent } from "vue";
import { AppsLogoComponents, defaultRenderLogo } from "../AppsLogoComponents/index.mjs";
import { CollapsedIcon } from "../CollapsedIcon/index.mjs";
import { BaseMenu, baseMenuProps } from "./BaseMenu.mjs";
import { useStylish } from "./style/stylish.mjs";
function renderLogoAndTitle(props, renderKey = "menuHeaderRender") {
  const {
    logo,
    title,
    layout
  } = props;
  const renderFunction = props[renderKey];
  if (renderFunction === false) {
    return null;
  }
  const logoDom = defaultRenderLogo(logo);
  const titleDom = _createVNode("h1", null, [title != null ? title : "Ant Design Pro"]);
  if (renderFunction) {
    return renderFunction(logoDom, props.collapsed ? null : titleDom, props);
  }
  if (props.isMobile) {
    return null;
  }
  if (layout === "mix" && renderKey === "menuHeaderRender") return false;
  if (props.collapsed) {
    return _createVNode("a", {
      "key": "title"
    }, [logoDom]);
  }
  return _createVNode("a", {
    "key": "title"
  }, [logoDom, titleDom]);
}
const siderMenuProps = __spreadProps(__spreadValues({
  logo: vNodeType(),
  appList: arrayType(),
  appListRender: funcType(),
  itemClick: funcType(),
  siderWidth: numberType(),
  avatarProps: oneOfType([Object, Boolean]).def(void 0),
  actionsRender: oneOfType([Function, Boolean]).def(void 0),
  menuHeaderRender: oneOfType([Function, Boolean]).def(void 0),
  menuFooterRender: oneOfType([Function, Boolean]).def(void 0),
  menuContentRender: oneOfType([Function, Boolean]).def(void 0),
  menuExtraRender: oneOfType([Function, Boolean]),
  collapsedButtonRender: oneOfType([Function, Boolean]).def(void 0),
  breakpoint: oneOfType([String, Boolean]).def(void 0),
  onMenuHeaderClick: funcType(),
  links: arrayType(),
  onOpenChange: funcType(),
  getContainer: boolType(),
  logoStyle: objectType(),
  hide: boolType()
}, omit(baseMenuProps, ["onCollapse"])), {
  onCollapse: funcType().isRequired
});
function privateSiderMenuProps() {
  return {
    matchMenuKeys: arrayType().isRequired,
    originCollapsed: boolType().def(void 0),
    menuRenderType: oneOf(["header", "sider"]),
    stylish: objectType()
  };
}
const SiderMenu = defineComponent({
  name: "SiderMenu",
  props: __spreadValues(__spreadValues({}, siderMenuProps), privateSiderMenuProps()),
  setup(props) {
    const {
      hashId
    } = ProProvider.useContext();
    const baseClassName = computed(() => `${props.prefixCls}-sider`);
    const collapsedWidth = 64;
    const stylishClassName = useStylish(computed(() => `${baseClassName.value}.${baseClassName.value}-stylish`), {
      stylish: props.stylish,
      proLayoutCollapsedWidth: collapsedWidth
    });
    const showSiderExtraDom = computed(() => {
      if (props.isMobile) return false;
      if (props.layout === "mix") return false;
      return true;
    });
    const hideMenuWhenCollapsedClassName = computed(() => {
      var _a;
      if (((_a = props == null ? void 0 : props.menu) == null ? void 0 : _a.hideMenuWhenCollapsed) && props.collapsed) {
        return `${baseClassName.value}-hide-menu-collapsed`;
      }
      return null;
    });
    return () => {
      const {
        collapsed,
        originCollapsed,
        fixSiderbar,
        menuFooterRender,
        onCollapse,
        theme,
        siderWidth,
        isMobile,
        onMenuHeaderClick,
        breakpoint = "lg",
        style,
        layout,
        menuExtraRender = false,
        links,
        menuContentRender,
        collapsedButtonRender,
        avatarProps,
        // @ts-expect-error
        rightContentRender,
        actionsRender,
        onOpenChange,
        stylish,
        logoStyle
      } = props;
      const siderClassName = classNames(`${baseClassName.value}`, hashId, {
        [`${baseClassName.value}-fixed`]: fixSiderbar,
        [`${baseClassName.value}-fixed-mix`]: layout === "mix" && !isMobile && fixSiderbar,
        [`${baseClassName.value}-collapsed`]: props.collapsed,
        [`${baseClassName.value}-layout-${layout}`]: layout && !isMobile,
        [`${baseClassName.value}-light`]: theme !== "dark",
        [`${baseClassName.value}-mix`]: layout === "mix" && !isMobile,
        [`${baseClassName.value}-stylish`]: !!stylish
      });
      const headerDom = renderLogoAndTitle(props);
      const extraDom = menuExtraRender && menuExtraRender(props);
      const menuDom = () => menuContentRender !== false && _createVNode(BaseMenu, _mergeProps(props, {
        "key": "base-menu",
        "mode": collapsed && !isMobile ? "vertical" : "inline",
        "handleOpenChange": onOpenChange,
        "style": {
          width: "100%"
        },
        "className": `${baseClassName.value}-menu ${hashId}`.trim()
      }), null);
      const linksMenuItems = (links || []).map((node, index) => ({
        className: `${baseClassName.value}-link`,
        label: node,
        key: index
      }));
      const avatarDom = () => {
        if (!avatarProps) return null;
        const _a = avatarProps, {
          title,
          render
        } = _a, rest = __objRest(_a, [
          "title",
          "render"
        ]);
        const dom = _createVNode("div", {
          "class": `${baseClassName.value}-actions-avatar`
        }, [(rest == null ? void 0 : rest.src) || (rest == null ? void 0 : rest.srcset) || rest.icon ? _createVNode(Avatar, _mergeProps({
          "size": 28
        }, rest), null) : null, avatarProps.title && !collapsed && _createVNode("span", null, [title])]);
        if (render) {
          return render(avatarProps, dom, props);
        }
        return dom;
      };
      const actionsDom = () => {
        if (!actionsRender) return null;
        return _createVNode(Space, {
          "align": "center",
          "size": 4,
          "direction": collapsed ? "vertical" : "horizontal",
          "class": classNames([`${baseClassName.value}-actions-list`, collapsed && `${baseClassName.value}-actions-list-collapsed`, hashId])
        }, {
          default: () => [[actionsRender == null ? void 0 : actionsRender(props)].flat(1).map((item, index) => {
            return _createVNode("div", {
              "key": index,
              "class": `${baseClassName.value}-actions-list-item ${hashId}`.trim()
            }, [item]);
          })]
        });
      };
      const collapsedDom = () => {
        if (collapsedButtonRender === false) return null;
        const dom = _createVNode(CollapsedIcon, {
          "isMobile": isMobile,
          "collapsed": originCollapsed,
          "class": `${baseClassName.value}-collapsed-button`,
          "onClick": () => {
            onCollapse == null ? void 0 : onCollapse(!originCollapsed);
          }
        }, null);
        if (collapsedButtonRender) return collapsedButtonRender(collapsed, dom);
        return dom;
      };
      const actionAreaDom = () => {
        if (!avatarProps && !actionsRender) return null;
        return _createVNode("div", {
          "class": classNames(`${baseClassName.value}-actions`, hashId, collapsed && `${baseClassName.value}-actions-collapsed`)
        }, [avatarDom(), actionsDom()]);
      };
      const menuFooterDom = menuFooterRender && (menuFooterRender == null ? void 0 : menuFooterRender(props));
      const menuDomItems = _createVNode(_Fragment, null, [headerDom && _createVNode("div", {
        "class": classNames([classNames(`${baseClassName.value}-logo`, hashId, {
          [`${baseClassName.value}-logo-collapsed`]: collapsed
        })]),
        "onClick": showSiderExtraDom.value ? onMenuHeaderClick : void 0,
        "id": "logo",
        "style": logoStyle
      }, [headerDom, _createVNode(AppsLogoComponents, {
        "onItemClick": props.itemClick,
        "appListRender": props.appListRender,
        "appList": props.appList,
        "prefixCls": props.prefixCls
      }, null)]), extraDom && _createVNode("div", {
        "class": classNames([`${baseClassName.value}-extra`, !headerDom && `${baseClassName.value}-extra-no-logo`, hashId])
      }, [extraDom]), _createVNode("div", {
        "style": {
          flex: 1,
          overflowY: "auto",
          overflowX: "hidden"
        }
      }, [menuContentRender ? menuContentRender(props, menuDom()) : menuDom()]), links ? _createVNode("div", {
        "class": `${baseClassName.value}-links ${hashId}`.trim()
      }, [_createVNode(Menu, {
        "inlineIndent": 16,
        "class": `${baseClassName.value}-link-menu ${hashId}`.trim(),
        "selectedKeys": [],
        "openKeys": [],
        "theme": theme,
        "mode": "inline",
        "items": linksMenuItems
      }, null)]) : null, showSiderExtraDom.value && _createVNode(_Fragment, null, [actionAreaDom(), !actionsRender && rightContentRender ? _createVNode("div", {
        "class": classNames(`${baseClassName.value}-actions`, hashId, {
          [`${baseClassName.value}-actions-collapsed`]: collapsed
        })
      }, [rightContentRender == null ? void 0 : rightContentRender(props)]) : null]), menuFooterDom && _createVNode("div", {
        "class": classNames([`${baseClassName.value}-footer`, hashId, {
          [`${baseClassName.value}-footer-collapsed`]: collapsed
        }])
      }, [menuFooterDom])]);
      return stylishClassName.wrapSSR(_createVNode(_Fragment, null, [fixSiderbar && !isMobile && !hideMenuWhenCollapsedClassName.value && _createVNode("div", {
        "style": __spreadValues({
          width: `${collapsed ? collapsedWidth : siderWidth}px`,
          overflow: "hidden",
          flex: `0 0 ${collapsed ? collapsedWidth : siderWidth}px`,
          maxWidth: `${collapsed ? collapsedWidth : siderWidth}px`,
          minWidth: `${collapsed ? collapsedWidth : siderWidth}px`,
          transition: "all 0.2s ease 0s"
        }, style)
      }, null), _createVNode(Layout.Sider, {
        "collapsible": true,
        "trigger": null,
        "collapsed": collapsed,
        "breakpoint": breakpoint === false ? void 0 : breakpoint,
        "onCollapse": (collapse) => {
          if (isMobile) return;
          onCollapse == null ? void 0 : onCollapse(collapse);
        },
        "collapsedWidth": collapsedWidth,
        "style": style,
        "theme": theme,
        "width": siderWidth,
        "class": classNames(siderClassName, hashId, hideMenuWhenCollapsedClassName.value)
      }, {
        default: () => [hideMenuWhenCollapsedClassName.value ? _createVNode("div", {
          "class": `${baseClassName.value}-hide-when-collapsed ${hashId}`.trim(),
          "style": {
            height: "100%",
            width: "100%",
            opacity: hideMenuWhenCollapsedClassName.value ? 0 : 1
          }
        }, [menuDomItems]) : menuDomItems, collapsedDom()]
      })]));
    };
  }
});
export {
  SiderMenu,
  privateSiderMenuProps,
  renderLogoAndTitle,
  siderMenuProps
};
