"use strict";

exports.__esModule = true;
exports.default = exports.cardPropTypes = exports.THEMES = void 0;
var _keys2 = _interopRequireDefault(require("lodash/fp/keys"));
var _pick2 = _interopRequireDefault(require("lodash/fp/pick"));
var _isUndefined2 = _interopRequireDefault(require("lodash/fp/isUndefined"));
var _isEmpty2 = _interopRequireDefault(require("lodash/fp/isEmpty"));
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 _externalContent = require("../../util/external-content");
var _provider = _interopRequireDefault(require("../../atom/provider"));
var _cardContent = _interopRequireWildcard(require("../card-content"));
var _customer = _interopRequireDefault(require("./customer"));
var _favorite = _interopRequireDefault(require("./favorite"));
var _selectable = _interopRequireDefault(require("./selectable"));
var _notification = _interopRequireDefault(require("./notification"));
var _style = _interopRequireDefault(require("./style.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 }; }
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 THEMES = exports.THEMES = {
  default: null,
  coorpmanager: _style.default.coorpmanager
};
const CardBackground = ({
  type,
  image,
  empty,
  'aria-label': ariaLabel
}, {
  skin
}) => {
  const externalContent = (0, _externalContent.isExternalContent)(type);
  const primaryColor = (0, _get2.default)('common.primary', skin);
  const whiteColor = (0, _get2.default)('common.white', skin);
  if (externalContent && _externalContent.EXTERNAL_CONTENT_ICONS[type]) {
    const IconType = _externalContent.EXTERNAL_CONTENT_ICONS[type].icon;
    const iconColor = _externalContent.EXTERNAL_CONTENT_ICONS[type].color;
    const backgroundIcon = /*#__PURE__*/_react.default.createElement("div", {
      className: _style.default.externalIconCircleWrapper
    }, /*#__PURE__*/_react.default.createElement(IconType, {
      className: _style.default.externalIcon
    }));
    if (image) {
      const _backgroundIcon = /*#__PURE__*/_react.default.createElement("div", {
        className: (0, _classnames.default)(_style.default.externalIconCircleWrapper, _style.default.externalIconCircleWithImageWrapper),
        style: {
          backgroundColor: iconColor
        }
      }, /*#__PURE__*/_react.default.createElement(IconType, {
        className: _style.default.externalIconWithImage
      }));
      return /*#__PURE__*/_react.default.createElement("div", {
        className: _style.default.imageWrapper
      }, /*#__PURE__*/_react.default.createElement("div", {
        "data-name": "cover",
        "aria-label": ariaLabel,
        style: {
          backgroundColor: iconColor,
          backgroundImage: `url('${image}')`
        },
        className: (0, _classnames.default)(_style.default.externalContentHeader, _style.default.externalBackground)
      }, _backgroundIcon));
    }
    return /*#__PURE__*/_react.default.createElement("div", {
      className: _style.default.imageWrapper
    }, /*#__PURE__*/_react.default.createElement("div", {
      "data-name": "cover",
      "aria-label": ariaLabel,
      style: {
        backgroundColor: iconColor
      },
      className: _style.default.externalContentHeader
    }, backgroundIcon));
  }
  const emptyIcon = empty ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyPictures, {
    className: _style.default.emptyIcon,
    style: {
      color: whiteColor
    }
  }) : null;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(_style.default.imageWrapper, type === 'chapter' ? _style.default.chapterImageWrapper : null)
  }, /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "cover",
    "aria-label": ariaLabel,
    className: _style.default.image,
    style: {
      backgroundColor: primaryColor,
      backgroundImage: image ? `url('${image}')` : 'none'
    }
  }, emptyIcon));
};
CardBackground.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
CardBackground.propTypes = process.env.NODE_ENV !== "production" ? {
  type: _propTypes.default.string,
  image: _propTypes.default.string,
  empty: _propTypes.default.bool,
  'aria-label': _propTypes.default.string
} : {};
const Card = /*#__PURE__*/(0, _react.memo)(function Card(props, context) {
  const {
    skin
  } = context;
  const {
    image,
    badge,
    adaptiv,
    disabled: hidden = false,
    type = 'course',
    title,
    author,
    customer,
    certifiedAuthor,
    progress,
    favorite,
    addFavoriteToolTip,
    removeFavoriteToolTip,
    onClick,
    onFavoriteClick,
    isSelected,
    notification,
    badgeCategory,
    badgeLabel,
    theme = 'default',
    disabledContent,
    'aria-label': cardArialabel,
    'background-aria-label': backgroundAriaLabel,
    'favorite-aria-label': favoriteAriaLabel,
    'selectable-aria-label': selectableAriaLabel,
    'customer-aria-label': customerAriaLabel,
    'badge-aria-label': badgeAriaLabel,
    'disabled-aria-label': disabledArialabel,
    'card-content-aria-label': cardContentLabelAriaLabel
  } = props;
  const empty = (0, _isEmpty2.default)((0, _pick2.default)(['title', 'type', 'author', 'image'], props));
  const primaryColor = (0, _get2.default)('common.primary', skin);
  const cardStyle = (0, _classnames.default)(THEMES[theme], type === 'chapter' ? _style.default.chapter : _style.default.course, title ? null : _style.default.lazy, _style.default.grid, empty ? _style.default.empty : null);
  const disabled = hidden && (!isSelected || (0, _isUndefined2.default)(isSelected));
  const handleClick = (0, _react.useMemo)(() => e => onClick(e), [onClick]);
  const lock = disabled ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.lockContent
  }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyPadlock, {
    className: _style.default.lockIcon,
    height: 48
  }), /*#__PURE__*/_react.default.createElement("span", {
    "aria-label": disabledArialabel
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: disabledContent
    }
  })) : null;
  const inlineBadgeStyle = {
    color: primaryColor
  };
  const getType = contentType => {
    switch (contentType) {
      case 'chapter':
        return 'microlearning';
      case 'course':
        return 'learner';
      default:
        return contentType;
    }
  };
  return /*#__PURE__*/_react.default.createElement("div", {
    className: cardStyle,
    "data-name": "card",
    "data-lock": disabled,
    "data-type": getType(type),
    disabled: disabled,
    onClick: handleClick,
    "aria-label": cardArialabel
  }, /*#__PURE__*/_react.default.createElement(CardBackground, {
    type: type,
    image: image,
    empty: empty,
    "aria-label": backgroundAriaLabel
  }), (0, _isUndefined2.default)(isSelected) && !(0, _isUndefined2.default)(favorite) ? /*#__PURE__*/_react.default.createElement(_favorite.default, {
    className: _style.default.favorite,
    favorite: favorite,
    disabled: disabled,
    onFavoriteClick: onFavoriteClick,
    addFavoriteToolTip: addFavoriteToolTip,
    removeFavoriteToolTip: removeFavoriteToolTip,
    "aria-label": favoriteAriaLabel
  }) : null, /*#__PURE__*/_react.default.createElement(_selectable.default, {
    isSelected: isSelected,
    hidden: hidden,
    "aria-label": selectableAriaLabel
  }), notification ? /*#__PURE__*/_react.default.createElement(_notification.default, notification) : null, customer ? /*#__PURE__*/_react.default.createElement(_customer.default, _extends({}, customer, {
    theme: theme,
    type: type,
    disabled: disabled,
    "aria-label": customerAriaLabel
  })) : null, /*#__PURE__*/_react.default.createElement(_cardContent.default, {
    mode: _cardContent.MODES.CARD,
    adaptiv: adaptiv,
    author: author,
    certifiedAuthor: certifiedAuthor,
    disabled: disabled,
    empty: empty,
    progress: progress,
    title: title,
    type: type,
    badgeCategory: badgeCategory,
    badgeLabel: badgeLabel,
    theme: theme,
    "aria-label": cardContentLabelAriaLabel
  }), badge ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.badge,
    style: inlineBadgeStyle,
    "aria-label": badgeAriaLabel
  }, badge) : null, disabled ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.lockWrapper,
    "aria-label": disabledArialabel
  }, lock) : null);
});
Card.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
const cardPropTypes = exports.cardPropTypes = {
  badge: _propTypes.default.string,
  image: _propTypes.default.string,
  disabled: _propTypes.default.bool,
  adaptiv: _propTypes.default.bool,
  type: _propTypes.default.string,
  title: _propTypes.default.string,
  author: _propTypes.default.string,
  certifiedAuthor: _propTypes.default.bool,
  customer: _propTypes.default.shape(_customer.default.propTypes),
  progress: _propTypes.default.number,
  favorite: _propTypes.default.bool,
  addFavoriteToolTip: _propTypes.default.string,
  removeFavoriteToolTip: _propTypes.default.string,
  onClick: _propTypes.default.func,
  onFavoriteClick: _propTypes.default.func,
  isSelected: _propTypes.default.bool,
  notification: _propTypes.default.shape(_notification.default.propTypes),
  badgeCategory: _cardContent.default.propTypes.badgeCategory,
  badgeLabel: _cardContent.default.propTypes.badgeLabel,
  theme: _propTypes.default.oneOf((0, _keys2.default)(THEMES)),
  disabledContent: _propTypes.default.string,
  'aria-label': _propTypes.default.string,
  'background-aria-label': _propTypes.default.string,
  'favorite-aria-label': _favorite.default.propTypes['aria-label'],
  'selectable-aria-label': _selectable.default.propTypes['aria-label'],
  'customer-aria-label': _customer.default.propTypes['aria-label'],
  'badge-aria-label': _propTypes.default.string,
  'disabled-aria-label': _propTypes.default.string,
  'card-content-aria-label': _cardContent.default.propTypes['aria-label']
};
Card.propTypes = process.env.NODE_ENV !== "production" ? cardPropTypes : {};
var _default = exports.default = Card;
//# sourceMappingURL=index.js.map