"use strict";

exports.__esModule = true;
exports.default = void 0;
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _get2 = _interopRequireDefault(require("lodash/fp/get"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _provider = _interopRequireWildcard(require("../../atom/provider"));
var _progressBar = _interopRequireDefault(require("../../molecule/progress-bar"));
var _link = _interopRequireDefault(require("../../atom/link"));
var _progressionItem = _interopRequireDefault(require("./progression-item.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 = {
  chapter: _novaIcons.NovaCompositionCoorpacademyTimer,
  course: _novaIcons.NovaSolidContentContentBook1,
  battle: _novaIcons.NovaCompositionCoorpacademyBolt,
  certification: _novaIcons.NovaSolidSchoolScienceGraduationHat,
  article: _novaIcons.NovaCompositionCoorpacademyArticle,
  scorm: _novaIcons.NovaCompositionCoorpacademyScorm,
  video: _novaIcons.NovaCompositionCoorpacademyVideo,
  podcast: _novaIcons.NovaCompositionCoorpacademyMicrophone,
  review: _novaIcons.NovaCompositionCoorpacademyRevision
};
const ProgressionItem = (props, legacyContext) => {
  const skin = (0, _provider.GetSkinFromContext)(legacyContext);
  const {
    disabled = false,
    adaptive,
    completion,
    label,
    level,
    onClick = _noop2.default,
    stars,
    maxStars,
    state,
    type,
    steps = 0,
    adaptiveAriaLabel
  } = props;
  const dark = (0, _get2.default)('common.dark', skin);
  const primary = (0, _get2.default)('common.primary', skin);
  const white = (0, _get2.default)('common.white', skin);
  const IconType = ICONS[type];
  const adaptiveIcon = adaptive ? /*#__PURE__*/_react.default.createElement("div", {
    className: _progressionItem.default.adaptiveIcon,
    style: {
      backgroundColor: primary
    }
  }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyAdaptive, {
    style: {
      color: white
    },
    height: 14,
    "aria-label": adaptiveAriaLabel
  })) : null;
  const handleCTAClick = (0, _react.useMemo)(() => e => {
    e.stopPropagation();
    e.preventDefault();
    onClick(e);
  }, [onClick]);
  const link = disabled ? null : /*#__PURE__*/_react.default.createElement(_link.default, {
    style: {
      color: primary
    },
    onClick: handleCTAClick,
    "data-progression-state": state
  }, /*#__PURE__*/_react.default.createElement("span", {
    className: _progressionItem.default.cta
  }, state, " ", /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionNavigationArrowRight, {
    style: {
      color: primary
    },
    height: 12,
    width: 20
  })));
  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(_progressionItem.default.progressionItem, disabled ? _progressionItem.default.disabled : '')
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _progressionItem.default.wrapperTitle
  }, /*#__PURE__*/_react.default.createElement(IconType, {
    className: _progressionItem.default.iconType,
    style: {
      color: dark
    }
  }), /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "activityLabel",
    className: _progressionItem.default.label,
    title: label
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _progressionItem.default.innerHTML
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: label
    }
  }), adaptiveIcon), /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "activityStars",
    role: "progressbar",
    className: _progressionItem.default.stars,
    style: {
      color: primary
    }
  }, stars, maxStars ? ' /' : null, maxStars ? /*#__PURE__*/_react.default.createElement("span", {
    className: _progressionItem.default.smallStars
  }, maxStars) : null, ' ', /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyStar, {
    className: _progressionItem.default.iconStar,
    style: {
      color: primary
    }
  }))), /*#__PURE__*/_react.default.createElement(_progressBar.default, {
    className: _progressionItem.default.completion,
    value: completion * 100,
    max: 100,
    steps: steps,
    style: {
      backgroundColor: primary,
      borderRadius: 0
    },
    displayInfo: false
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: _progressionItem.default.state
  }, link, /*#__PURE__*/_react.default.createElement("span", {
    className: _progressionItem.default.level
  }, level)));
};
ProgressionItem.propTypes = process.env.NODE_ENV !== "production" ? {
  completion: _propTypes.default.number.isRequired,
  stars: _propTypes.default.number.isRequired,
  maxStars: _propTypes.default.number,
  steps: _propTypes.default.number,
  disabled: _propTypes.default.bool,
  label: _propTypes.default.string.isRequired,
  level: _propTypes.default.string.isRequired,
  state: _propTypes.default.string.isRequired,
  adaptiveAriaLabel: _propTypes.default.string,
  type: _propTypes.default.string.isRequired,
  adaptive: _propTypes.default.bool.isRequired,
  onClick: _propTypes.default.func
} : {};
ProgressionItem.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
var _default = exports.default = ProgressionItem;
//# sourceMappingURL=progression-item.js.map