"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _get = _interopRequireDefault(require("lodash/fp/get"));
var _isEmpty = _interopRequireDefault(require("lodash/fp/isEmpty"));
var _map = _interopRequireDefault(require("lodash/fp/map"));
var _noop = _interopRequireDefault(require("lodash/fp/noop"));
var _omit = _interopRequireDefault(require("lodash/fp/omit"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _provider = _interopRequireWildcard(require("../../atom/provider"));
var _button = _interopRequireDefault(require("../../atom/button"));
var _select = _interopRequireDefault(require("../../atom/select"));
var _loader = _interopRequireDefault(require("../../atom/loader"));
var _progressionItem = _interopRequireDefault(require("./progression-item"));
var _engineStars = _interopRequireDefault(require("./engine-stars"));
var _starsSummary = _interopRequireDefault(require("./stars-summary"));
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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 _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 mapWithIndex = _map.default.convert({
  cap: false
});
const Progression = (props, legacyContext) => {
  const {
    mainTitle,
    mainSubtitle,
    recommendation = {},
    progressions = [],
    adaptiveAriaLabel,
    total,
    engines = [],
    themeFilter = {},
    loading,
    'aria-label': ariaLabel
  } = props;
  const skin = (0, _provider.GetSkinFromContext)(legacyContext);
  const {
    onChange: themeFilterOnChange
  } = themeFilter;
  const handleClick = (0, _react.useCallback)(e => {
    e.stopPropagation();
    e.preventDefault();
    const {
      onClick = _noop.default
    } = recommendation;
    onClick(e);
  }, [recommendation]);
  const handleSelectTheme = (0, _react.useCallback)(e => {
    themeFilterOnChange && themeFilterOnChange(e);
  }, [themeFilterOnChange]);
  const primary = (0, _get.default)('common.primary', skin);
  const loader = loading ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.loader
  }, /*#__PURE__*/_react.default.createElement(_loader.default, null)) : null;
  const allProgressions = mapWithIndex((progression, index) => /*#__PURE__*/_react.default.createElement(_progressionItem.default, _extends({}, (0, _omit.default)(['ref'], progression), {
    key: `${index}-${progression.ref}`,
    adaptiveAriaLabel: adaptiveAriaLabel
  })), progressions);
  const coreProgression = /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "activityCore",
    className: _style.default.core
  }, allProgressions);
  const themeSelect = !(0, _isEmpty.default)(themeFilter.options) ? /*#__PURE__*/_react.default.createElement(_select.default, {
    borderClassName: _style.default.selectBorder,
    className: _style.default.select,
    theme: "thematiques",
    options: themeFilter.options,
    onChange: handleSelectTheme,
    "aria-label": ariaLabel
  }) : null;
  const recommendationSection = !(0, _isEmpty.default)(recommendation) ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.recommendationWrapper
  }, /*#__PURE__*/_react.default.createElement("p", {
    className: _style.default.recommendationSection
  }, recommendation.title, " "), /*#__PURE__*/_react.default.createElement("p", {
    className: _style.default.recommendationSection
  }, /*#__PURE__*/_react.default.createElement("span", null, recommendation.subtitle, " "), /*#__PURE__*/_react.default.createElement("span", {
    className: (0, _classnames.default)(_style.default.course, _style.default.innerHTML)
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: recommendation.courseTitle
    }
  })), /*#__PURE__*/_react.default.createElement(_button.default, {
    type: "link",
    onClick: handleClick,
    submitValue: recommendation.cta,
    style: {
      backgroundColor: primary
    },
    className: _style.default.cta,
    "data-testid": "button-link-recommendation"
  })) : null;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.defaultStyle
  }, /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "activity-header",
    tabIndex: 0
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.mainTitle,
    tabIndex: 0
  }, /*#__PURE__*/_react.default.createElement("span", null, mainTitle), " ", mainSubtitle), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.headerProgression,
    tabIndex: 0
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.wrapperCta,
    tabIndex: 0
  }, themeSelect, recommendationSection), /*#__PURE__*/_react.default.createElement(_starsSummary.default, {
    engines: engines,
    total: total
  }))), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.wrapperProgression,
    "data-name": "activityList"
  }, coreProgression, loader));
};
Progression.contextTypes = {
  skin: _provider.default.childContextTypes.skin,
  translate: _provider.default.childContextTypes.translate
};
Progression.propTypes = process.env.NODE_ENV !== "production" ? {
  mainTitle: _propTypes.default.string.isRequired,
  mainSubtitle: _propTypes.default.string.isRequired,
  adaptiveAriaLabel: _propTypes.default.string,
  total: _propTypes.default.shape({
    label: _propTypes.default.string.isRequired,
    stars: _propTypes.default.number.isRequired
  }).isRequired,
  engines: _propTypes.default.arrayOf(_propTypes.default.shape(_engineStars.default.propTypes)),
  loading: _propTypes.default.bool.isRequired,
  progressions: _propTypes.default.arrayOf(_propTypes.default.shape({
    ..._progressionItem.default.propTypes,
    ref: _propTypes.default.string.isRequired
  })),
  themeFilter: _propTypes.default.shape({
    options: _select.default.propTypes.options.isRequired,
    onChange: _select.default.propTypes.onChange
  }),
  recommendation: _propTypes.default.shape({
    cta: _propTypes.default.string.isRequired,
    title: _propTypes.default.string.isRequired,
    subtitle: _propTypes.default.string.isRequired,
    courseTitle: _propTypes.default.string.isRequired,
    onClick: _propTypes.default.func
  }),
  'aria-label': _propTypes.default.string
} : {};
var _default = exports.default = Progression;
//# sourceMappingURL=index.js.map