"use strict";

exports.__esModule = true;
exports.default = void 0;
var _slice2 = _interopRequireDefault(require("lodash/fp/slice"));
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _types = require("./types");
var _style = _interopRequireDefault(require("./style.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const ICONS = {
  mobilePhone: _novaIcons.NovaLinePhoneMobilePhone,
  chatBubbleCircleQuestionMark: _novaIcons.NovaLineMessagesChatChatBubbleCircleQuestionMark,
  networkAlert: _novaIcons.NovaLineNetworkNetworkAlert,
  binoculaire: _novaIcons.NovaLineObjectsBinoculars,
  contentBook: _novaIcons.NovaLineContentEditionContentBook
};
const MenuLinks = ({
  items,
  title,
  showMoreItem,
  numberOfDisplayedItems,
  isDesktopMode,
  withScroll = false
}) => {
  const [isOpen, setIsOpen] = (0, _react.useState)(false);
  const itemsToDisplay = isDesktopMode || isOpen ? items : (0, _slice2.default)(0, numberOfDisplayedItems, items);
  const handleOnclickShowMore = () => setIsOpen(!isOpen);
  return /*#__PURE__*/_react.default.createElement("nav", {
    className: _style.default.container
  }, /*#__PURE__*/_react.default.createElement("h2", {
    className: _style.default.title
  }, title), /*#__PURE__*/_react.default.createElement("ul", {
    className: _style.default.list,
    "data-name": "menu-links"
  }, itemsToDisplay.map((item, index) => {
    const {
      handleOnclick
    } = item;
    const Icon = item.icon ? ICONS[item.icon] : null;
    const Item = /*#__PURE__*/_react.default.createElement("div", {
      className: _style.default.flexContainer
    }, /*#__PURE__*/_react.default.createElement("span", {
      className: item.isSelected ? _style.default.selectedItem : undefined
    }, item.text), Icon ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionNavigationArrowDown, {
      className: (0, _classnames.default)(_style.default.arrowIcon, item.isSelected ? _style.default.selectedIcon : null)
    }) : null);
    return /*#__PURE__*/_react.default.createElement("li", {
      onClick: handleOnclick,
      key: `menu-link-item-${index}`,
      className: _style.default.item
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: (0, _classnames.default)(_style.default.border, item.isSelected ? _style.default.selectedBorder : null)
    }), /*#__PURE__*/_react.default.createElement("div", {
      className: _style.default.flexContainer
    }, Icon ? /*#__PURE__*/_react.default.createElement(Icon, {
      className: (0, _classnames.default)(_style.default.icon, item.isSelected ? _style.default.selectedIcon : null)
    }) : null, /*#__PURE__*/_react.default.createElement("a", {
      className: _style.default.link,
      href: withScroll ? `#menu-link-item-${index}` : undefined,
      "aria-label": item.ariaLabel
    }, Item)));
  }), !isDesktopMode ? /*#__PURE__*/_react.default.createElement("li", {
    // eslint-disable-next-line react/jsx-no-bind
    onClick: handleOnclickShowMore,
    key: `menu-link-item-show-more`,
    className: (0, _classnames.default)(_style.default.showMoreItem, _style.default.item)
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.border
  }), /*#__PURE__*/_react.default.createElement("span", null, isOpen ? showMoreItem.showLessText : showMoreItem.showMoreText, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionNavigationArrowDown, {
    className: isOpen ? _style.default.showLessIcon : _style.default.showMoreIcon
  }))) : null));
};
MenuLinks.propTypes = process.env.NODE_ENV !== "production" ? _types.propTypes : {};
var _default = exports.default = MenuLinks;
//# sourceMappingURL=index.js.map