"use strict";

exports.__esModule = true;
exports.default = void 0;
var _size2 = _interopRequireDefault(require("lodash/fp/size"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _provider = _interopRequireDefault(require("../../../atom/provider"));
var _slide = _interopRequireDefault(require("../../../atom/slide"));
var _hero = _interopRequireDefault(require("../../../molecule/hero"));
var _battleRequestList = _interopRequireDefault(require("../../../molecule/dashboard/battle-request-list"));
var _cardsList = _interopRequireDefault(require("../../../molecule/dashboard/cards-list"));
var _newsList = _interopRequireDefault(require("../../../molecule/dashboard/news-list"));
var _startBattle = _interopRequireDefault(require("../../../molecule/dashboard/start-battle"));
var _cmPopin = _interopRequireDefault(require("../../../molecule/cm-popin"));
var _reviewBanner = _interopRequireDefault(require("../../../molecule/dashboard/review-banner"));
var _learningProfileBanner = _interopRequireDefault(require("../../../molecule/dashboard/learning-profile-banner"));
var _title = _interopRequireDefault(require("../../../atom/title"));
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const Hero = /*#__PURE__*/_react.default.memo(function Hero({
  hero,
  welcome
}) {
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.hero
  }, hero ? /*#__PURE__*/_react.default.createElement(_hero.default, hero) : /*#__PURE__*/_react.default.createElement(_slide.default, welcome));
});
Hero.propTypes = process.env.NODE_ENV !== "production" ? {
  hero: _propTypes.default.shape(_hero.default.propTypes),
  welcome: _propTypes.default.shape(_slide.default.propTypes)
} : {};
const Dashboard = (props, context) => {
  const {
    translate
  } = context;
  const {
    sections = [],
    hero,
    welcome,
    cookie,
    popinWithCards,
    'arrows-aria-label': showMoreOnLeftOrRightAriaLabel
  } = props;
  const buildSectionComponent = section => {
    const {
      type
    } = section;
    switch (type) {
      case 'hero':
        return /*#__PURE__*/_react.default.createElement(Hero, {
          hero: hero,
          welcome: welcome
        });
      case 'battleRequests':
        return /*#__PURE__*/_react.default.createElement(_battleRequestList.default, section);
      case 'learningPrioritiesCards':
        {
          return /*#__PURE__*/_react.default.createElement(_cardsList.default, _extends({}, section, {
            title: /*#__PURE__*/_react.default.createElement(_title.default, {
              type: 'form-group',
              title: translate('learning_priorities'),
              subtitle: translate('learning_priorities_description'),
              icon: {
                iconName: 'sign-post',
                iconColor: '#A32700',
                borderRadius: '12px',
                backgroundColor: '#FFDCD1'
              },
              tag: {
                label: `${(0, _size2.default)(section.cards)}`,
                size: 'S'
              }
            }),
            "arrows-aria-label": showMoreOnLeftOrRightAriaLabel
          }));
        }
      case 'cards':
        return /*#__PURE__*/_react.default.createElement(_cardsList.default, _extends({}, section, {
          "arrows-aria-label": showMoreOnLeftOrRightAriaLabel
        }));
      case 'news':
        return /*#__PURE__*/_react.default.createElement(_newsList.default, section);
      case 'battle':
        return /*#__PURE__*/_react.default.createElement(_startBattle.default, section);
      case 'review':
        return /*#__PURE__*/_react.default.createElement(_reviewBanner.default, section);
      case 'learningProfile':
        return /*#__PURE__*/_react.default.createElement(_learningProfileBanner.default, section);
      default:
        return null;
    }
  };
  const buildSection = (section, index) => {
    const sectionView = buildSectionComponent(section);
    return /*#__PURE__*/_react.default.createElement("div", {
      key: index
    }, sectionView);
  };
  const sectionsList = [{
    type: 'hero',
    key: 'hero'
  }, ...sections].map(section => /*#__PURE__*/_react.default.createElement("div", {
    key: section.key
  }, buildSection(section)));
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.wrapper,
    "data-name": "dashboard"
  }, sectionsList, cookie ? /*#__PURE__*/_react.default.createElement(_cmPopin.default, cookie) : null, popinWithCards ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.popinWithCards
  }, /*#__PURE__*/_react.default.createElement(_cmPopin.default, popinWithCards)) : null);
};
Dashboard.contextTypes = {
  translate: _provider.default.childContextTypes.translate
};
Dashboard.propTypes = process.env.NODE_ENV !== "production" ? {
  hero: Hero.propTypes.hero,
  welcome: Hero.propTypes.welcome,
  sections: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape(_battleRequestList.default.propTypes), _propTypes.default.shape(_cardsList.default.propTypes), _propTypes.default.shape(_newsList.default.propTypes), _propTypes.default.shape(_startBattle.default.propTypes), _propTypes.default.shape(_reviewBanner.default.propTypes), _propTypes.default.shape(_learningProfileBanner.default.propTypes)])),
  cookie: _propTypes.default.shape(_cmPopin.default.propTypes),
  'arrows-aria-label': _cardsList.default.propTypes['arrows-aria-label'],
  popinWithCards: _propTypes.default.shape(_cmPopin.default.propTypes)
} : {};
var _default = exports.default = Dashboard;
//# sourceMappingURL=index.js.map