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 __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;
};
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, {
  SiderMenu: () => SiderMenu,
  privateSiderMenuProps: () => privateSiderMenuProps,
  renderLogoAndTitle: () => renderLogoAndTitle,
  siderMenuProps: () => siderMenuProps
});
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_vue2 = require("vue");
var import_AppsLogoComponents = require("../AppsLogoComponents");
var import_CollapsedIcon = require("../CollapsedIcon");
var import_BaseMenu = require("./BaseMenu");
var import_stylish = require("./style/stylish");
function renderLogoAndTitle(props, renderKey = "menuHeaderRender") {
  const {
    logo,
    title,
    layout
  } = props;
  const renderFunction = props[renderKey];
  if (renderFunction === false) {
    return null;
  }
  const logoDom = (0, import_AppsLogoComponents.defaultRenderLogo)(logo);
  const titleDom = (0, import_vue.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 (0, import_vue.createVNode)("a", {
      "key": "title"
    }, [logoDom]);
  }
  return (0, import_vue.createVNode)("a", {
    "key": "title"
  }, [logoDom, titleDom]);
}
const siderMenuProps = __spreadProps(__spreadValues({
  logo: (0, import_pro_utils.vNodeType)(),
  appList: (0, import_pro_utils.arrayType)(),
  appListRender: (0, import_pro_utils.funcType)(),
  itemClick: (0, import_pro_utils.funcType)(),
  siderWidth: (0, import_pro_utils.numberType)(),
  avatarProps: (0, import_pro_utils.oneOfType)([Object, Boolean]).def(void 0),
  actionsRender: (0, import_pro_utils.oneOfType)([Function, Boolean]).def(void 0),
  menuHeaderRender: (0, import_pro_utils.oneOfType)([Function, Boolean]).def(void 0),
  menuFooterRender: (0, import_pro_utils.oneOfType)([Function, Boolean]).def(void 0),
  menuContentRender: (0, import_pro_utils.oneOfType)([Function, Boolean]).def(void 0),
  menuExtraRender: (0, import_pro_utils.oneOfType)([Function, Boolean]),
  collapsedButtonRender: (0, import_pro_utils.oneOfType)([Function, Boolean]).def(void 0),
  breakpoint: (0, import_pro_utils.oneOfType)([String, Boolean]).def(void 0),
  onMenuHeaderClick: (0, import_pro_utils.funcType)(),
  links: (0, import_pro_utils.arrayType)(),
  onOpenChange: (0, import_pro_utils.funcType)(),
  getContainer: (0, import_pro_utils.boolType)(),
  logoStyle: (0, import_pro_utils.objectType)(),
  hide: (0, import_pro_utils.boolType)()
}, (0, import_pro_utils.omit)(import_BaseMenu.baseMenuProps, ["onCollapse"])), {
  onCollapse: (0, import_pro_utils.funcType)().isRequired
});
function privateSiderMenuProps() {
  return {
    matchMenuKeys: (0, import_pro_utils.arrayType)().isRequired,
    originCollapsed: (0, import_pro_utils.boolType)().def(void 0),
    menuRenderType: (0, import_pro_utils.oneOf)(["header", "sider"]),
    stylish: (0, import_pro_utils.objectType)()
  };
}
const SiderMenu = (0, import_vue2.defineComponent)({
  name: "SiderMenu",
  props: __spreadValues(__spreadValues({}, siderMenuProps), privateSiderMenuProps()),
  setup(props) {
    const {
      hashId
    } = import_pro_provider.ProProvider.useContext();
    const baseClassName = (0, import_vue2.computed)(() => `${props.prefixCls}-sider`);
    const collapsedWidth = 64;
    const stylishClassName = (0, import_stylish.useStylish)((0, import_vue2.computed)(() => `${baseClassName.value}.${baseClassName.value}-stylish`), {
      stylish: props.stylish,
      proLayoutCollapsedWidth: collapsedWidth
    });
    const showSiderExtraDom = (0, import_vue2.computed)(() => {
      if (props.isMobile) return false;
      if (props.layout === "mix") return false;
      return true;
    });
    const hideMenuWhenCollapsedClassName = (0, import_vue2.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 = (0, import_pro_utils.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 && (0, import_vue.createVNode)(import_BaseMenu.BaseMenu, (0, import_vue.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 = (0, import_vue.createVNode)("div", {
          "class": `${baseClassName.value}-actions-avatar`
        }, [(rest == null ? void 0 : rest.src) || (rest == null ? void 0 : rest.srcset) || rest.icon ? (0, import_vue.createVNode)(import_ant_design_vue.Avatar, (0, import_vue.mergeProps)({
          "size": 28
        }, rest), null) : null, avatarProps.title && !collapsed && (0, import_vue.createVNode)("span", null, [title])]);
        if (render) {
          return render(avatarProps, dom, props);
        }
        return dom;
      };
      const actionsDom = () => {
        if (!actionsRender) return null;
        return (0, import_vue.createVNode)(import_ant_design_vue.Space, {
          "align": "center",
          "size": 4,
          "direction": collapsed ? "vertical" : "horizontal",
          "class": (0, import_pro_utils.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 (0, import_vue.createVNode)("div", {
              "key": index,
              "class": `${baseClassName.value}-actions-list-item ${hashId}`.trim()
            }, [item]);
          })]
        });
      };
      const collapsedDom = () => {
        if (collapsedButtonRender === false) return null;
        const dom = (0, import_vue.createVNode)(import_CollapsedIcon.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 (0, import_vue.createVNode)("div", {
          "class": (0, import_pro_utils.classNames)(`${baseClassName.value}-actions`, hashId, collapsed && `${baseClassName.value}-actions-collapsed`)
        }, [avatarDom(), actionsDom()]);
      };
      const menuFooterDom = menuFooterRender && (menuFooterRender == null ? void 0 : menuFooterRender(props));
      const menuDomItems = (0, import_vue.createVNode)(import_vue.Fragment, null, [headerDom && (0, import_vue.createVNode)("div", {
        "class": (0, import_pro_utils.classNames)([(0, import_pro_utils.classNames)(`${baseClassName.value}-logo`, hashId, {
          [`${baseClassName.value}-logo-collapsed`]: collapsed
        })]),
        "onClick": showSiderExtraDom.value ? onMenuHeaderClick : void 0,
        "id": "logo",
        "style": logoStyle
      }, [headerDom, (0, import_vue.createVNode)(import_AppsLogoComponents.AppsLogoComponents, {
        "onItemClick": props.itemClick,
        "appListRender": props.appListRender,
        "appList": props.appList,
        "prefixCls": props.prefixCls
      }, null)]), extraDom && (0, import_vue.createVNode)("div", {
        "class": (0, import_pro_utils.classNames)([`${baseClassName.value}-extra`, !headerDom && `${baseClassName.value}-extra-no-logo`, hashId])
      }, [extraDom]), (0, import_vue.createVNode)("div", {
        "style": {
          flex: 1,
          overflowY: "auto",
          overflowX: "hidden"
        }
      }, [menuContentRender ? menuContentRender(props, menuDom()) : menuDom()]), links ? (0, import_vue.createVNode)("div", {
        "class": `${baseClassName.value}-links ${hashId}`.trim()
      }, [(0, import_vue.createVNode)(import_ant_design_vue.Menu, {
        "inlineIndent": 16,
        "class": `${baseClassName.value}-link-menu ${hashId}`.trim(),
        "selectedKeys": [],
        "openKeys": [],
        "theme": theme,
        "mode": "inline",
        "items": linksMenuItems
      }, null)]) : null, showSiderExtraDom.value && (0, import_vue.createVNode)(import_vue.Fragment, null, [actionAreaDom(), !actionsRender && rightContentRender ? (0, import_vue.createVNode)("div", {
        "class": (0, import_pro_utils.classNames)(`${baseClassName.value}-actions`, hashId, {
          [`${baseClassName.value}-actions-collapsed`]: collapsed
        })
      }, [rightContentRender == null ? void 0 : rightContentRender(props)]) : null]), menuFooterDom && (0, import_vue.createVNode)("div", {
        "class": (0, import_pro_utils.classNames)([`${baseClassName.value}-footer`, hashId, {
          [`${baseClassName.value}-footer-collapsed`]: collapsed
        }])
      }, [menuFooterDom])]);
      return stylishClassName.wrapSSR((0, import_vue.createVNode)(import_vue.Fragment, null, [fixSiderbar && !isMobile && !hideMenuWhenCollapsedClassName.value && (0, import_vue.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), (0, import_vue.createVNode)(import_ant_design_vue.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": (0, import_pro_utils.classNames)(siderClassName, hashId, hideMenuWhenCollapsedClassName.value)
      }, {
        default: () => [hideMenuWhenCollapsedClassName.value ? (0, import_vue.createVNode)("div", {
          "class": `${baseClassName.value}-hide-when-collapsed ${hashId}`.trim(),
          "style": {
            height: "100%",
            width: "100%",
            opacity: hideMenuWhenCollapsedClassName.value ? 0 : 1
          }
        }, [menuDomItems]) : menuDomItems, collapsedDom()]
      })]));
    };
  }
});
