"use strict";

exports.__esModule = true;
exports.default = void 0;
var _isEmpty2 = _interopRequireDefault(require("lodash/fp/isEmpty"));
var _keys2 = _interopRequireDefault(require("lodash/fp/keys"));
var _getOr2 = _interopRequireDefault(require("lodash/fp/getOr"));
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 _provider = _interopRequireDefault(require("../../../atom/provider"));
var _button = _interopRequireDefault(require("../../../atom/button"));
var _link = _interopRequireDefault(require("../../../atom/link"));
var _discussion = _interopRequireDefault(require("../../../organism/discussion"));
var _loader = _interopRequireDefault(require("../../../atom/loader"));
var _card = _interopRequireDefault(require("../../../molecule/card"));
var _feedback = _interopRequireDefault(require("../../../molecule/feedback"));
var _cardsList = _interopRequireDefault(require("../../../molecule/dashboard/cards-list"));
var _popinHeader = _interopRequireDefault(require("../popin-header"));
var _lottieWrapper = _interopRequireDefault(require("../../../atom/lottie-wrapper"));
var _summary = _interopRequireDefault(require("./summary.css"));
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 Header = props => /*#__PURE__*/_react.default.createElement(_popinHeader.default, props);
const SimpleAction = ({
  color,
  prefix,
  title,
  button
}) => {
  const {
    title: buttonTitle,
    ...linkProps
  } = button;
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "simpleAction",
    className: _summary.default.simpleWrapper
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.simpleTexts
  }, /*#__PURE__*/_react.default.createElement("span", {
    "data-name": "simplePrefix",
    className: _summary.default.simplePrefix
  }, prefix), /*#__PURE__*/_react.default.createElement("span", {
    "data-name": "simpleTitle",
    className: (0, _classnames.default)(_summary.default.simpleTitle, _summary.default.innerHTML)
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: title
    }
  })), /*#__PURE__*/_react.default.createElement(_button.default, _extends({}, linkProps, {
    type: "link",
    style: {
      backgroundColor: color
    },
    className: _summary.default.simpleButton,
    submitValue: buttonTitle
  })));
};
SimpleAction.propTypes = process.env.NODE_ENV !== "production" ? {
  color: _propTypes.default.string,
  prefix: _propTypes.default.string,
  title: _propTypes.default.string,
  button: _propTypes.default.shape(_button.default.propTypes)
} : {};
const NextCourse = ({
  title,
  prefix,
  card
}) => /*#__PURE__*/_react.default.createElement("div", {
  "data-name": "nextCourse",
  className: _summary.default.nextCourseWrapper
}, /*#__PURE__*/_react.default.createElement("div", {
  className: _summary.default.nextCourseTexts
}, /*#__PURE__*/_react.default.createElement("div", {
  className: _summary.default.nextCoursePrefix
}, prefix), /*#__PURE__*/_react.default.createElement("div", {
  className: (0, _classnames.default)(_summary.default.nextCourseTitle, _summary.default.innerHTML)
  // eslint-disable-next-line react/no-danger
  ,
  dangerouslySetInnerHTML: {
    __html: title
  }
})), /*#__PURE__*/_react.default.createElement("div", {
  className: _summary.default.nextCourseCard
}, /*#__PURE__*/_react.default.createElement(_card.default, _extends({}, card, {
  dataName: 'popin-end-next-course'
}))));
NextCourse.propTypes = process.env.NODE_ENV !== "production" ? {
  title: _propTypes.default.string,
  prefix: _propTypes.default.string,
  card: _propTypes.default.shape(_cardsList.default.propTypes)
} : {};
const Subscribe = ({
  title,
  description,
  button,
  card
}) => {
  const {
    title: buttonTitle,
    ...linkProps
  } = button;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.subscribeWrapper
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.subscribeTexts
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.subscribeDescription
  }, description), /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(_summary.default.subscribeTitle, _summary.default.innerHTML)
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: title
    }
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.subscribeButtonWrapper
  }, /*#__PURE__*/_react.default.createElement(_button.default, _extends({}, linkProps, {
    type: "link",
    className: _summary.default.subscribeButton,
    submitValue: buttonTitle
  })))), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_card.default, _extends({}, card, {
    dataName: 'popin-end-subscribe'
  }))));
};
Subscribe.propTypes = process.env.NODE_ENV !== "production" ? {
  ..._button.default.propTypes.propTypes,
  title: _button.default.propTypes.submitValue
} : {};
const actions = {
  simple: SimpleAction,
  subscribe: Subscribe,
  nextCourse: NextCourse
};
const Action = props => {
  const {
    type,
    ...actionProps
  } = props;
  const Type = (0, _get2.default)(type, actions);
  return Type ? /*#__PURE__*/_react.default.createElement(Type, actionProps) : null;
};
Action.propTypes = process.env.NODE_ENV !== "production" ? {
  type: _propTypes.default.oneOf((0, _keys2.default)(actions))
} : {};
const CardsLoader = () => /*#__PURE__*/_react.default.createElement("div", {
  className: _summary.default.loaderWrapper
}, /*#__PURE__*/_react.default.createElement(_loader.default, null));
const CommentConfirmation = (props, context) => {
  const {
    onClick,
    commentSectionTitle,
    confirmationLinkText
  } = props;
  const {
    skin
  } = context;
  const dark = (0, _get2.default)('common.dark', skin);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.commentSection
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.commentSectionIconWrapper
  }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaSolidStatusCheckCircle2, {
    className: _summary.default.commentSectionIcon,
    style: {
      color: dark
    }
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.commentSectionTexts
  }, /*#__PURE__*/_react.default.createElement("p", null, commentSectionTitle), /*#__PURE__*/_react.default.createElement(_link.default, {
    onClick: onClick,
    className: _summary.default.commentSectionLink
  }, confirmationLinkText)));
};
CommentConfirmation.propTypes = process.env.NODE_ENV !== "production" ? {
  commentSectionTitle: _propTypes.default.node,
  confirmationLinkText: _link.default.propTypes.children,
  onClick: _link.default.propTypes.onClick
} : {};
CommentConfirmation.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
const CommentSection = props => {
  const {
    isSent,
    edition,
    confirmation
  } = props;
  if (isSent) {
    const {
      onClick,
      commentSectionTitle,
      confirmationLinkText
    } = confirmation;
    return /*#__PURE__*/_react.default.createElement(CommentConfirmation, {
      onClick: onClick,
      commentSectionTitle: commentSectionTitle,
      confirmationLinkText: confirmationLinkText
    });
  }
  return /*#__PURE__*/_react.default.createElement(_discussion.default, edition);
};
CommentSection.propTypes = process.env.NODE_ENV !== "production" ? {
  isSent: _propTypes.default.bool,
  edition: _propTypes.default.shape(_discussion.default.propTypes),
  confirmation: _propTypes.default.shape(CommentConfirmation.propTypes)
} : {};
const Cards = props => {
  const {
    cards
  } = props;
  return (0, _get2.default)('cards', props) === null ? /*#__PURE__*/_react.default.createElement(CardsLoader, null) : ((0, _isEmpty2.default)(cards) ? null : /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.cardsWrapper
  }, /*#__PURE__*/_react.default.createElement(_cardsList.default, _extends({}, props, {
    dataName: 'popin-end-recommendation'
  })))) || null;
};
Cards.propTypes = process.env.NODE_ENV !== "production" ? _cardsList.default.propTypes : {};
const Footer = ({
  title,
  color,
  ...linkProps
}) => /*#__PURE__*/_react.default.createElement(_link.default, _extends({}, linkProps, {
  style: {
    color
  },
  className: _summary.default.footer,
  "data-name": "nextLink",
  "data-popin": "popinEnd",
  "data-next": "home"
}), title);
Footer.propTypes = process.env.NODE_ENV !== "production" ? {
  ..._link.default.propTypes,
  title: _link.default.propTypes.children,
  color: _propTypes.default.string
} : {};
const Summary = (props, context) => {
  const {
    header,
    recommendation,
    comment,
    footer,
    action,
    feedback,
    mode
  } = props;
  const {
    skin
  } = context;
  const primary = (0, _getOr2.default)('#f0f', 'common.primary', skin);
  const commentView = mode !== 'scorm' && comment && header ? /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.discussionWrapper
  }, /*#__PURE__*/_react.default.createElement(CommentSection, comment)) : null;
  const footerView = mode !== 'scorm' && footer && header ? /*#__PURE__*/_react.default.createElement(Footer, _extends({}, footer, {
    color: primary
  })) : null;
  const feedbackView = feedback ? /*#__PURE__*/_react.default.createElement(_feedback.default, _extends({}, feedback, {
    mode: mode
  })) : null;
  return /*#__PURE__*/_react.default.createElement(BackgroundScorm, {
    mode: mode,
    failed: header.failed
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: mode !== 'scorm' ? _summary.default.summaryWrapper : null
  }, /*#__PURE__*/_react.default.createElement(Header, _extends({}, header, {
    mode: mode
  })), feedbackView, /*#__PURE__*/_react.default.createElement(Action, _extends({}, action, {
    color: primary
  })), /*#__PURE__*/_react.default.createElement(Cards, recommendation), commentView, footerView));
};
const BackgroundScorm = props => {
  const {
    mode = 'default',
    children,
    failed
  } = props;
  if (mode === 'scorm') return /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.organismPlayerResultContainerScorm
  }, failed === false ? /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.animationContainer
  }, /*#__PURE__*/_react.default.createElement(_lottieWrapper.default, {
    'aria-label': 'aria lottie',
    'data-name': 'default-lottie',
    className: undefined,
    animationSrc: 'https://static-staging.coorpacademy.com/animations/review/confetti.json',
    loop: undefined,
    autoplay: true,
    rendererSettings: {
      hideOnTransparent: false,
      animationClassName: ''
    },
    animationControl: undefined,
    loop: false,
    animationControl: 'play',
    autoplay: true,
    "data-name": "lottie-wrapper",
    className: _summary.default.lottie,
    backupImageClassName: _summary.default.ie11Backup
  })) : null, /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.background
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.largeCircle
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.mediumCircle
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.smallCircle
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: _summary.default.content
  }, children));
  return children;
};
Summary.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
Summary.propTypes = process.env.NODE_ENV !== "production" ? {
  header: _propTypes.default.shape(_popinHeader.default.propTypes),
  footer: _propTypes.default.shape({
    title: _propTypes.default.string,
    href: _link.default.propTypes.href,
    onClick: _propTypes.default.func
  }),
  comment: _propTypes.default.shape(CommentSection.propTypes),
  action: _propTypes.default.shape({
    type: _propTypes.default.oneOf((0, _keys2.default)(actions)).isRequired
  }),
  recommendation: _propTypes.default.shape(_cardsList.default.propTypes),
  feedback: _propTypes.default.shape(_feedback.default.propTypes),
  mode: _propTypes.default.oneOf(['scorm', 'default'])
} : {};
var _default = exports.default = Summary;
//# sourceMappingURL=summary.js.map