"use strict";

exports.__esModule = true;
exports.default = exports.THEMES = exports.MODES = void 0;
var _keys2 = _interopRequireDefault(require("lodash/fp/keys"));
var _isNil2 = _interopRequireDefault(require("lodash/fp/isNil"));
var _get2 = _interopRequireDefault(require("lodash/fp/get"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _externalContent = require("../../util/external-content");
var _provider = _interopRequireDefault(require("../../atom/provider"));
var _contentBadge = _interopRequireDefault(require("../../atom/content-badge"));
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const MODES = exports.MODES = {
  HERO: 'hero',
  CARD: 'card'
};
const THEMES = exports.THEMES = {
  default: null,
  coorpmanager: _style.default.coorpmanager
};
const ContentTypeInfo = ({
  mode,
  type,
  externalContent
}, context) => {
  const {
    translate
  } = context;
  if (mode !== MODES.CARD) {
    return null;
  }
  if (type === 'chapter') {
    return /*#__PURE__*/_react.default.createElement("div", {
      className: _style.default.microLearningIcon
    }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyTimer, {
      className: _style.default.timerIcon
    }), /*#__PURE__*/_react.default.createElement("span", {
      className: _style.default.microLearninglabel
    }, "5' learning"));
  }
  if (externalContent && _externalContent.EXTERNAL_CONTENT_ICONS[type]) {
    const textColor = _externalContent.EXTERNAL_CONTENT_ICONS[type].color;
    return /*#__PURE__*/_react.default.createElement("div", {
      className: _style.default.contentTypeInfo,
      style: {
        color: textColor
      }
    }, type === 'scorm' ? translate('external_content_scorm') : '', type === 'video' ? translate('external_content_video') : '', type === 'article' ? translate('external_content_article') : '', type === 'podcast' ? translate('external_content_podcast') : '');
  }
  return null;
};
ContentTypeInfo.contextTypes = {
  skin: _provider.default.childContextTypes.skin,
  translate: _provider.default.childContextTypes.translate
};
ContentTypeInfo.propTypes = process.env.NODE_ENV !== "production" ? {
  externalContent: _propTypes.default.bool,
  type: _propTypes.default.string,
  mode: _propTypes.default.string
} : {};
const CardTitle = ({
  title,
  empty,
  courseContent
}) => {
  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(_style.default.title, _style.default.innerHTML, courseContent ? _style.default.lightTitle : _style.default.darkTitle, empty ? _style.default.empty : null),
    "data-name": "title",
    title: title
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: title
    }
  });
};
CardTitle.propTypes = process.env.NODE_ENV !== "production" ? {
  title: _propTypes.default.string,
  empty: _propTypes.default.bool,
  courseContent: _propTypes.default.bool
} : {};
const AuthorName = ({
  author,
  empty,
  courseContent,
  certifiedAuthor,
  'aria-label': ariaLabel
}) => {
  const checkIcon = certifiedAuthor ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaSolidStatusCheckCircle2, {
    className: (0, _classnames.default)(_style.default.authorIcon, courseContent ? _style.default.iconShadow : null)
  }) : null;
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "author",
    title: author,
    "aria-label": ariaLabel,
    className: (0, _classnames.default)(_style.default.author, courseContent ? _style.default.lightTitle : _style.default.darkAuthorTitle, empty ? _style.default.empty : null)
  }, /*#__PURE__*/_react.default.createElement("span", null, author), checkIcon);
};
AuthorName.propTypes = process.env.NODE_ENV !== "production" ? {
  author: _propTypes.default.string,
  empty: _propTypes.default.bool,
  courseContent: _propTypes.default.bool,
  certifiedAuthor: _propTypes.default.bool,
  'aria-label': _propTypes.default.string
} : {};
const ContentInfo = ({
  adaptiv,
  author,
  certifiedAuthor = false,
  disabled = false,
  empty = false,
  mode = MODES.CARD,
  progress,
  title,
  type,
  badgeCategory,
  badgeLabel,
  theme = 'default',
  'aria-label': ariaLabel
}) => {
  const progressBarColor = '#3EC483';
  const inlineProgressValueStyle = {
    backgroundColor: progressBarColor,
    width: `${progress * 100}%`
  };
  const externalContent = (0, _externalContent.isExternalContent)(type);
  const courseContent = type === 'course';
  const chapterContent = type === 'chapter';
  const progressBar = mode === MODES.HERO || !empty && !disabled ? /*#__PURE__*/_react.default.createElement("div", {
    className: !(0, _isNil2.default)(progress) ? _style.default.progressWrapper : _style.default.hideProgressBar
  }, !disabled ? /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "progress",
    className: _style.default.progress,
    style: inlineProgressValueStyle,
    role: "progressbar",
    "aria-label": (0, _get2.default)('progression', ariaLabel)
  }) : null) : null;
  const adaptiveIcon = adaptiv ? /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(_style.default.adaptiveIcon, courseContent ? _style.default.iconShadow : null)
  }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyAdaptive, {
    height: 25,
    "aria-label": (0, _get2.default)('adaptive', ariaLabel)
  })) : null;
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "info",
    className: (0, _classnames.default)(THEMES[theme], _style.default.infoWrapper, mode === MODES.HERO ? _style.default.hero : _style.default.card, disabled ? _style.default.progressBarDisabled : null, externalContent ? _style.default.externalContent : null)
  }, /*#__PURE__*/_react.default.createElement(ContentTypeInfo, {
    mode: mode,
    type: type,
    externalContent: externalContent
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(_style.default.cardInfo, chapterContent ? _style.default.microLearningCardInfo : null)
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.iconWrapper
  }, adaptiveIcon, !empty && badgeLabel && badgeCategory && courseContent ? /*#__PURE__*/_react.default.createElement(_contentBadge.default, {
    category: badgeCategory,
    label: badgeLabel
  }) : null), /*#__PURE__*/_react.default.createElement(CardTitle, {
    title: title,
    empty: empty,
    courseContent: courseContent
  }), /*#__PURE__*/_react.default.createElement(AuthorName, {
    author: author,
    empty: empty,
    courseContent: courseContent,
    certifiedAuthor: certifiedAuthor,
    "aria-label": (0, _get2.default)('author', ariaLabel)
  })), progressBar);
};
ContentInfo.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
ContentInfo.propTypes = process.env.NODE_ENV !== "production" ? {
  adaptiv: _propTypes.default.bool,
  author: _propTypes.default.string,
  certifiedAuthor: _propTypes.default.bool,
  disabled: _propTypes.default.bool,
  empty: _propTypes.default.bool,
  progress: _propTypes.default.number,
  title: _propTypes.default.string,
  type: _propTypes.default.string,
  mode: _propTypes.default.string,
  badgeCategory: _contentBadge.default.propTypes.category,
  badgeLabel: _contentBadge.default.propTypes.label,
  theme: _propTypes.default.oneOf((0, _keys2.default)(THEMES)),
  'aria-label': _propTypes.default.shape({
    author: _propTypes.default.string,
    progression: _propTypes.default.string,
    adaptive: _propTypes.default.string
  })
} : {};
var _default = exports.default = ContentInfo;
//# sourceMappingURL=index.js.map