'use strict';

var core = require('@linaria/core');
var antd = require('antd');
var cs = require('classnames');
var React = require('react');
var index$1 = require('../../core/Icon/index.js');
var index = require('../../core/Typo/index.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var cs__default = /*#__PURE__*/_interopDefault(cs);
var React__default = /*#__PURE__*/_interopDefault(React);

var __defProp = Object.defineProperty;
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;
};
const SiderStyle = "E_s1at6qmn";
const ShrinkStyle = "E_s1wu0lms";
const NavLinkStyle = "E_n1ugzfva";
const NormalWidth = 256;
const ShrinkWidth = 52;
const Sider = ({
  config = [],
  selectedKeys,
  isShrink,
  onClick,
  children,
  antdSiderProps
}) => {
  const renderItem = item => {
    const iconSrc = selectedKeys.includes(item.key || "") ? item.icon.active : item.icon.normal;
    const icon = /* @__PURE__ */React__default.default.createElement(index$1, {
      iconWidth: 24,
      iconHeight: 24,
      src: iconSrc,
      style: {
        opacity: item.disabled ? 0.5 : 1
      }
    });
    const _onClick = () => {
      if (item.onClick) {
        item.onClick(item.key);
      }
      onClick == null ? void 0 : onClick(item.key);
    };
    if (isShrink) {
      return /* @__PURE__ */React__default.default.createElement("div", {
        className: NavLinkStyle,
        onClick: _onClick
      }, /* @__PURE__ */React__default.default.createElement(antd.Tooltip, {
        title: item.title,
        placement: "right"
      }, icon));
    } else {
      return /* @__PURE__ */React__default.default.createElement("div", {
        className: NavLinkStyle,
        onClick: _onClick
      }, icon, /* @__PURE__ */React__default.default.createElement("span", {
        className: "link-title"
      }, item.title));
    }
  };
  return /* @__PURE__ */React__default.default.createElement(antd.Layout.Sider, __spreadValues({
    className: core.cx(SiderStyle, ShrinkStyle, isShrink ? "shrink" : ""),
    width: isShrink ? ShrinkWidth : NormalWidth
  }, antdSiderProps), /* @__PURE__ */React__default.default.createElement(antd.Menu, {
    className: core.cx(index.Typo.Label.l2_regular),
    selectedKeys
  }, config.filter(item => !item.hidden).map(item => {
    if ("items" in item) {
      return /* @__PURE__ */React__default.default.createElement(antd.Menu.ItemGroup, {
        className: cs__default.default({
          split: item.isShowDivider
        }),
        key: item.key,
        title: item.title ? /* @__PURE__ */React__default.default.createElement("span", {
          className: index.Typo.Heading.h3_regular_upper
        }, item.title) : null
      }, (item.items || []).filter(childItem => !childItem.hidden).map(childItem => {
        return /* @__PURE__ */React__default.default.createElement(antd.Menu.Item, {
          key: childItem.key,
          disabled: childItem.disabled
        }, renderItem(childItem));
      }));
    }
    return /* @__PURE__ */React__default.default.createElement(antd.Menu.Item, {
      key: item.key,
      disabled: item.disabled
    }, renderItem(item));
  })), /* @__PURE__ */React__default.default.createElement("footer", null, children));
};
var Sider$1 = Sider;

module.exports = Sider$1;
