import _keys from "lodash/fp/keys";
import _pick from "lodash/fp/pick";
import _isUndefined from "lodash/fp/isUndefined";
import _isEmpty from "lodash/fp/isEmpty";
import _get from "lodash/fp/get";
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); }
import React, { useMemo, memo } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { NovaCompositionCoorpacademyPadlock as LockIcon, NovaCompositionCoorpacademyPictures as PicturesIcon } from '@coorpacademy/nova-icons';
import { isExternalContent, EXTERNAL_CONTENT_ICONS } from '../../util/external-content';
import Provider from '../../atom/provider';
import CardContentInfo, { MODES } from '../card-content';
import Customer from './customer';
import Favorite from './favorite';
import Selectable from './selectable';
import Notification from './notification';
import style from './style.css';
export const THEMES = {
  default: null,
  coorpmanager: style.coorpmanager
};
const CardBackground = ({
  type,
  image,
  empty,
  'aria-label': ariaLabel
}, {
  skin
}) => {
  const externalContent = isExternalContent(type);
  const primaryColor = _get('common.primary', skin);
  const whiteColor = _get('common.white', skin);
  if (externalContent && EXTERNAL_CONTENT_ICONS[type]) {
    const IconType = EXTERNAL_CONTENT_ICONS[type].icon;
    const iconColor = EXTERNAL_CONTENT_ICONS[type].color;
    const backgroundIcon = /*#__PURE__*/React.createElement("div", {
      className: style.externalIconCircleWrapper
    }, /*#__PURE__*/React.createElement(IconType, {
      className: style.externalIcon
    }));
    if (image) {
      const _backgroundIcon = /*#__PURE__*/React.createElement("div", {
        className: classnames(style.externalIconCircleWrapper, style.externalIconCircleWithImageWrapper),
        style: {
          backgroundColor: iconColor
        }
      }, /*#__PURE__*/React.createElement(IconType, {
        className: style.externalIconWithImage
      }));
      return /*#__PURE__*/React.createElement("div", {
        className: style.imageWrapper
      }, /*#__PURE__*/React.createElement("div", {
        "data-name": "cover",
        "aria-label": ariaLabel,
        style: {
          backgroundColor: iconColor,
          backgroundImage: `url('${image}')`
        },
        className: classnames(style.externalContentHeader, style.externalBackground)
      }, _backgroundIcon));
    }
    return /*#__PURE__*/React.createElement("div", {
      className: style.imageWrapper
    }, /*#__PURE__*/React.createElement("div", {
      "data-name": "cover",
      "aria-label": ariaLabel,
      style: {
        backgroundColor: iconColor
      },
      className: style.externalContentHeader
    }, backgroundIcon));
  }
  const emptyIcon = empty ? /*#__PURE__*/React.createElement(PicturesIcon, {
    className: style.emptyIcon,
    style: {
      color: whiteColor
    }
  }) : null;
  return /*#__PURE__*/React.createElement("div", {
    className: classnames(style.imageWrapper, type === 'chapter' ? style.chapterImageWrapper : null)
  }, /*#__PURE__*/React.createElement("div", {
    "data-name": "cover",
    "aria-label": ariaLabel,
    className: style.image,
    style: {
      backgroundColor: primaryColor,
      backgroundImage: image ? `url('${image}')` : 'none'
    }
  }, emptyIcon));
};
CardBackground.contextTypes = {
  skin: Provider.childContextTypes.skin
};
CardBackground.propTypes = process.env.NODE_ENV !== "production" ? {
  type: PropTypes.string,
  image: PropTypes.string,
  empty: PropTypes.bool,
  'aria-label': PropTypes.string
} : {};
const Card = /*#__PURE__*/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 = _isEmpty(_pick(['title', 'type', 'author', 'image'], props));
  const primaryColor = _get('common.primary', skin);
  const cardStyle = classnames(THEMES[theme], type === 'chapter' ? style.chapter : style.course, title ? null : style.lazy, style.grid, empty ? style.empty : null);
  const disabled = hidden && (!isSelected || _isUndefined(isSelected));
  const handleClick = useMemo(() => e => onClick(e), [onClick]);
  const lock = disabled ? /*#__PURE__*/React.createElement("div", {
    className: style.lockContent
  }, /*#__PURE__*/React.createElement(LockIcon, {
    className: style.lockIcon,
    height: 48
  }), /*#__PURE__*/React.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.createElement("div", {
    className: cardStyle,
    "data-name": "card",
    "data-lock": disabled,
    "data-type": getType(type),
    disabled: disabled,
    onClick: handleClick,
    "aria-label": cardArialabel
  }, /*#__PURE__*/React.createElement(CardBackground, {
    type: type,
    image: image,
    empty: empty,
    "aria-label": backgroundAriaLabel
  }), _isUndefined(isSelected) && !_isUndefined(favorite) ? /*#__PURE__*/React.createElement(Favorite, {
    className: style.favorite,
    favorite: favorite,
    disabled: disabled,
    onFavoriteClick: onFavoriteClick,
    addFavoriteToolTip: addFavoriteToolTip,
    removeFavoriteToolTip: removeFavoriteToolTip,
    "aria-label": favoriteAriaLabel
  }) : null, /*#__PURE__*/React.createElement(Selectable, {
    isSelected: isSelected,
    hidden: hidden,
    "aria-label": selectableAriaLabel
  }), notification ? /*#__PURE__*/React.createElement(Notification, notification) : null, customer ? /*#__PURE__*/React.createElement(Customer, _extends({}, customer, {
    theme: theme,
    type: type,
    disabled: disabled,
    "aria-label": customerAriaLabel
  })) : null, /*#__PURE__*/React.createElement(CardContentInfo, {
    mode: 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.createElement("div", {
    className: style.badge,
    style: inlineBadgeStyle,
    "aria-label": badgeAriaLabel
  }, badge) : null, disabled ? /*#__PURE__*/React.createElement("div", {
    className: style.lockWrapper,
    "aria-label": disabledArialabel
  }, lock) : null);
});
Card.contextTypes = {
  skin: Provider.childContextTypes.skin
};
export const cardPropTypes = {
  badge: PropTypes.string,
  image: PropTypes.string,
  disabled: PropTypes.bool,
  adaptiv: PropTypes.bool,
  type: PropTypes.string,
  title: PropTypes.string,
  author: PropTypes.string,
  certifiedAuthor: PropTypes.bool,
  customer: PropTypes.shape(Customer.propTypes),
  progress: PropTypes.number,
  favorite: PropTypes.bool,
  addFavoriteToolTip: PropTypes.string,
  removeFavoriteToolTip: PropTypes.string,
  onClick: PropTypes.func,
  onFavoriteClick: PropTypes.func,
  isSelected: PropTypes.bool,
  notification: PropTypes.shape(Notification.propTypes),
  badgeCategory: CardContentInfo.propTypes.badgeCategory,
  badgeLabel: CardContentInfo.propTypes.badgeLabel,
  theme: PropTypes.oneOf(_keys(THEMES)),
  disabledContent: PropTypes.string,
  'aria-label': PropTypes.string,
  'background-aria-label': PropTypes.string,
  'favorite-aria-label': Favorite.propTypes['aria-label'],
  'selectable-aria-label': Selectable.propTypes['aria-label'],
  'customer-aria-label': Customer.propTypes['aria-label'],
  'badge-aria-label': PropTypes.string,
  'disabled-aria-label': PropTypes.string,
  'card-content-aria-label': CardContentInfo.propTypes['aria-label']
};
Card.propTypes = process.env.NODE_ENV !== "production" ? cardPropTypes : {};
export default Card;
//# sourceMappingURL=index.js.map