import _size from "lodash/fp/size";
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); }
import React from 'react';
import PropTypes from 'prop-types';
import Provider from '../../../atom/provider';
import Slide from '../../../atom/slide';
import HeroCard from '../../../molecule/hero';
import BattleRequestList from '../../../molecule/dashboard/battle-request-list';
import CardsList from '../../../molecule/dashboard/cards-list';
import NewsList from '../../../molecule/dashboard/news-list';
import StartBattle from '../../../molecule/dashboard/start-battle';
import CMPopin from '../../../molecule/cm-popin';
import ReviewBanner from '../../../molecule/dashboard/review-banner';
import LearningProfileBanner from '../../../molecule/dashboard/learning-profile-banner';
import Title from '../../../atom/title';
import style from './style.css';
const Hero = /*#__PURE__*/React.memo(function Hero({
  hero,
  welcome
}) {
  return /*#__PURE__*/React.createElement("div", {
    className: style.hero
  }, hero ? /*#__PURE__*/React.createElement(HeroCard, hero) : /*#__PURE__*/React.createElement(Slide, welcome));
});
Hero.propTypes = process.env.NODE_ENV !== "production" ? {
  hero: PropTypes.shape(HeroCard.propTypes),
  welcome: PropTypes.shape(Slide.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.createElement(Hero, {
          hero: hero,
          welcome: welcome
        });
      case 'battleRequests':
        return /*#__PURE__*/React.createElement(BattleRequestList, section);
      case 'learningPrioritiesCards':
        {
          return /*#__PURE__*/React.createElement(CardsList, _extends({}, section, {
            title: /*#__PURE__*/React.createElement(Title, {
              type: 'form-group',
              title: translate('learning_priorities'),
              subtitle: translate('learning_priorities_description'),
              icon: {
                iconName: 'sign-post',
                iconColor: '#A32700',
                borderRadius: '12px',
                backgroundColor: '#FFDCD1'
              },
              tag: {
                label: `${_size(section.cards)}`,
                size: 'S'
              }
            }),
            "arrows-aria-label": showMoreOnLeftOrRightAriaLabel
          }));
        }
      case 'cards':
        return /*#__PURE__*/React.createElement(CardsList, _extends({}, section, {
          "arrows-aria-label": showMoreOnLeftOrRightAriaLabel
        }));
      case 'news':
        return /*#__PURE__*/React.createElement(NewsList, section);
      case 'battle':
        return /*#__PURE__*/React.createElement(StartBattle, section);
      case 'review':
        return /*#__PURE__*/React.createElement(ReviewBanner, section);
      case 'learningProfile':
        return /*#__PURE__*/React.createElement(LearningProfileBanner, section);
      default:
        return null;
    }
  };
  const buildSection = (section, index) => {
    const sectionView = buildSectionComponent(section);
    return /*#__PURE__*/React.createElement("div", {
      key: index
    }, sectionView);
  };
  const sectionsList = [{
    type: 'hero',
    key: 'hero'
  }, ...sections].map(section => /*#__PURE__*/React.createElement("div", {
    key: section.key
  }, buildSection(section)));
  return /*#__PURE__*/React.createElement("div", {
    className: style.wrapper,
    "data-name": "dashboard"
  }, sectionsList, cookie ? /*#__PURE__*/React.createElement(CMPopin, cookie) : null, popinWithCards ? /*#__PURE__*/React.createElement("div", {
    className: style.popinWithCards
  }, /*#__PURE__*/React.createElement(CMPopin, popinWithCards)) : null);
};
Dashboard.contextTypes = {
  translate: Provider.childContextTypes.translate
};
Dashboard.propTypes = process.env.NODE_ENV !== "production" ? {
  hero: Hero.propTypes.hero,
  welcome: Hero.propTypes.welcome,
  sections: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.shape(BattleRequestList.propTypes), PropTypes.shape(CardsList.propTypes), PropTypes.shape(NewsList.propTypes), PropTypes.shape(StartBattle.propTypes), PropTypes.shape(ReviewBanner.propTypes), PropTypes.shape(LearningProfileBanner.propTypes)])),
  cookie: PropTypes.shape(CMPopin.propTypes),
  'arrows-aria-label': CardsList.propTypes['arrows-aria-label'],
  popinWithCards: PropTypes.shape(CMPopin.propTypes)
} : {};
export default Dashboard;
//# sourceMappingURL=index.js.map