import _keys from "lodash/fp/keys";
import _isNil from "lodash/fp/isNil";
import _get from "lodash/fp/get";
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { NovaCompositionCoorpacademyAdaptive as AdaptivIcon, NovaSolidStatusCheckCircle2 as CheckIcon, NovaCompositionCoorpacademyTimer as TimerIcon } from '@coorpacademy/nova-icons';
import { isExternalContent, EXTERNAL_CONTENT_ICONS } from '../../util/external-content';
import Provider from '../../atom/provider';
import ContentBadge from '../../atom/content-badge';
import style from './style.css';
export const MODES = {
  HERO: 'hero',
  CARD: 'card'
};
export const THEMES = {
  default: null,
  coorpmanager: style.coorpmanager
};
const ContentTypeInfo = ({
  mode,
  type,
  externalContent
}, context) => {
  const {
    translate
  } = context;
  if (mode !== MODES.CARD) {
    return null;
  }
  if (type === 'chapter') {
    return /*#__PURE__*/React.createElement("div", {
      className: style.microLearningIcon
    }, /*#__PURE__*/React.createElement(TimerIcon, {
      className: style.timerIcon
    }), /*#__PURE__*/React.createElement("span", {
      className: style.microLearninglabel
    }, "5' learning"));
  }
  if (externalContent && EXTERNAL_CONTENT_ICONS[type]) {
    const textColor = EXTERNAL_CONTENT_ICONS[type].color;
    return /*#__PURE__*/React.createElement("div", {
      className: style.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.childContextTypes.skin,
  translate: Provider.childContextTypes.translate
};
ContentTypeInfo.propTypes = process.env.NODE_ENV !== "production" ? {
  externalContent: PropTypes.bool,
  type: PropTypes.string,
  mode: PropTypes.string
} : {};
const CardTitle = ({
  title,
  empty,
  courseContent
}) => {
  return /*#__PURE__*/React.createElement("div", {
    className: classnames(style.title, style.innerHTML, courseContent ? style.lightTitle : style.darkTitle, empty ? style.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.string,
  empty: PropTypes.bool,
  courseContent: PropTypes.bool
} : {};
const AuthorName = ({
  author,
  empty,
  courseContent,
  certifiedAuthor,
  'aria-label': ariaLabel
}) => {
  const checkIcon = certifiedAuthor ? /*#__PURE__*/React.createElement(CheckIcon, {
    className: classnames(style.authorIcon, courseContent ? style.iconShadow : null)
  }) : null;
  return /*#__PURE__*/React.createElement("div", {
    "data-name": "author",
    title: author,
    "aria-label": ariaLabel,
    className: classnames(style.author, courseContent ? style.lightTitle : style.darkAuthorTitle, empty ? style.empty : null)
  }, /*#__PURE__*/React.createElement("span", null, author), checkIcon);
};
AuthorName.propTypes = process.env.NODE_ENV !== "production" ? {
  author: PropTypes.string,
  empty: PropTypes.bool,
  courseContent: PropTypes.bool,
  certifiedAuthor: PropTypes.bool,
  'aria-label': PropTypes.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 = isExternalContent(type);
  const courseContent = type === 'course';
  const chapterContent = type === 'chapter';
  const progressBar = mode === MODES.HERO || !empty && !disabled ? /*#__PURE__*/React.createElement("div", {
    className: !_isNil(progress) ? style.progressWrapper : style.hideProgressBar
  }, !disabled ? /*#__PURE__*/React.createElement("div", {
    "data-name": "progress",
    className: style.progress,
    style: inlineProgressValueStyle,
    role: "progressbar",
    "aria-label": _get('progression', ariaLabel)
  }) : null) : null;
  const adaptiveIcon = adaptiv ? /*#__PURE__*/React.createElement("div", {
    className: classnames(style.adaptiveIcon, courseContent ? style.iconShadow : null)
  }, /*#__PURE__*/React.createElement(AdaptivIcon, {
    height: 25,
    "aria-label": _get('adaptive', ariaLabel)
  })) : null;
  return /*#__PURE__*/React.createElement("div", {
    "data-name": "info",
    className: classnames(THEMES[theme], style.infoWrapper, mode === MODES.HERO ? style.hero : style.card, disabled ? style.progressBarDisabled : null, externalContent ? style.externalContent : null)
  }, /*#__PURE__*/React.createElement(ContentTypeInfo, {
    mode: mode,
    type: type,
    externalContent: externalContent
  }), /*#__PURE__*/React.createElement("div", {
    className: classnames(style.cardInfo, chapterContent ? style.microLearningCardInfo : null)
  }, /*#__PURE__*/React.createElement("div", {
    className: style.iconWrapper
  }, adaptiveIcon, !empty && badgeLabel && badgeCategory && courseContent ? /*#__PURE__*/React.createElement(ContentBadge, {
    category: badgeCategory,
    label: badgeLabel
  }) : null), /*#__PURE__*/React.createElement(CardTitle, {
    title: title,
    empty: empty,
    courseContent: courseContent
  }), /*#__PURE__*/React.createElement(AuthorName, {
    author: author,
    empty: empty,
    courseContent: courseContent,
    certifiedAuthor: certifiedAuthor,
    "aria-label": _get('author', ariaLabel)
  })), progressBar);
};
ContentInfo.contextTypes = {
  skin: Provider.childContextTypes.skin
};
ContentInfo.propTypes = process.env.NODE_ENV !== "production" ? {
  adaptiv: PropTypes.bool,
  author: PropTypes.string,
  certifiedAuthor: PropTypes.bool,
  disabled: PropTypes.bool,
  empty: PropTypes.bool,
  progress: PropTypes.number,
  title: PropTypes.string,
  type: PropTypes.string,
  mode: PropTypes.string,
  badgeCategory: ContentBadge.propTypes.category,
  badgeLabel: ContentBadge.propTypes.label,
  theme: PropTypes.oneOf(_keys(THEMES)),
  'aria-label': PropTypes.shape({
    author: PropTypes.string,
    progression: PropTypes.string,
    adaptive: PropTypes.string
  })
} : {};
export default ContentInfo;
//# sourceMappingURL=index.js.map