import _isEmpty from "lodash/fp/isEmpty";
import _keys from "lodash/fp/keys";
import _getOr from "lodash/fp/getOr";
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 from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { NovaSolidStatusCheckCircle2 as CheckIcon } from '@coorpacademy/nova-icons';
import Provider from '../../../atom/provider';
import Button from '../../../atom/button';
import Link from '../../../atom/link';
import Discussion from '../../../organism/discussion';
import Loader from '../../../atom/loader';
import Card from '../../../molecule/card';
import Feedback from '../../../molecule/feedback';
import CardsList from '../../../molecule/dashboard/cards-list';
import PopinHeader from '../popin-header';
import AtomLottieWrapper from '../../../atom/lottie-wrapper';
import style from './summary.css';
const Header = props => /*#__PURE__*/React.createElement(PopinHeader, props);
const SimpleAction = ({
  color,
  prefix,
  title,
  button
}) => {
  const {
    title: buttonTitle,
    ...linkProps
  } = button;
  return /*#__PURE__*/React.createElement("div", {
    "data-name": "simpleAction",
    className: style.simpleWrapper
  }, /*#__PURE__*/React.createElement("div", {
    className: style.simpleTexts
  }, /*#__PURE__*/React.createElement("span", {
    "data-name": "simplePrefix",
    className: style.simplePrefix
  }, prefix), /*#__PURE__*/React.createElement("span", {
    "data-name": "simpleTitle",
    className: classnames(style.simpleTitle, style.innerHTML)
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: title
    }
  })), /*#__PURE__*/React.createElement(Button, _extends({}, linkProps, {
    type: "link",
    style: {
      backgroundColor: color
    },
    className: style.simpleButton,
    submitValue: buttonTitle
  })));
};
SimpleAction.propTypes = process.env.NODE_ENV !== "production" ? {
  color: PropTypes.string,
  prefix: PropTypes.string,
  title: PropTypes.string,
  button: PropTypes.shape(Button.propTypes)
} : {};
const NextCourse = ({
  title,
  prefix,
  card
}) => /*#__PURE__*/React.createElement("div", {
  "data-name": "nextCourse",
  className: style.nextCourseWrapper
}, /*#__PURE__*/React.createElement("div", {
  className: style.nextCourseTexts
}, /*#__PURE__*/React.createElement("div", {
  className: style.nextCoursePrefix
}, prefix), /*#__PURE__*/React.createElement("div", {
  className: classnames(style.nextCourseTitle, style.innerHTML)
  // eslint-disable-next-line react/no-danger
  ,
  dangerouslySetInnerHTML: {
    __html: title
  }
})), /*#__PURE__*/React.createElement("div", {
  className: style.nextCourseCard
}, /*#__PURE__*/React.createElement(Card, _extends({}, card, {
  dataName: 'popin-end-next-course'
}))));
NextCourse.propTypes = process.env.NODE_ENV !== "production" ? {
  title: PropTypes.string,
  prefix: PropTypes.string,
  card: PropTypes.shape(CardsList.propTypes)
} : {};
const Subscribe = ({
  title,
  description,
  button,
  card
}) => {
  const {
    title: buttonTitle,
    ...linkProps
  } = button;
  return /*#__PURE__*/React.createElement("div", {
    className: style.subscribeWrapper
  }, /*#__PURE__*/React.createElement("div", {
    className: style.subscribeTexts
  }, /*#__PURE__*/React.createElement("div", {
    className: style.subscribeDescription
  }, description), /*#__PURE__*/React.createElement("div", {
    className: classnames(style.subscribeTitle, style.innerHTML)
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: title
    }
  }), /*#__PURE__*/React.createElement("div", {
    className: style.subscribeButtonWrapper
  }, /*#__PURE__*/React.createElement(Button, _extends({}, linkProps, {
    type: "link",
    className: style.subscribeButton,
    submitValue: buttonTitle
  })))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Card, _extends({}, card, {
    dataName: 'popin-end-subscribe'
  }))));
};
Subscribe.propTypes = process.env.NODE_ENV !== "production" ? {
  ...Button.propTypes.propTypes,
  title: Button.propTypes.submitValue
} : {};
const actions = {
  simple: SimpleAction,
  subscribe: Subscribe,
  nextCourse: NextCourse
};
const Action = props => {
  const {
    type,
    ...actionProps
  } = props;
  const Type = _get(type, actions);
  return Type ? /*#__PURE__*/React.createElement(Type, actionProps) : null;
};
Action.propTypes = process.env.NODE_ENV !== "production" ? {
  type: PropTypes.oneOf(_keys(actions))
} : {};
const CardsLoader = () => /*#__PURE__*/React.createElement("div", {
  className: style.loaderWrapper
}, /*#__PURE__*/React.createElement(Loader, null));
const CommentConfirmation = (props, context) => {
  const {
    onClick,
    commentSectionTitle,
    confirmationLinkText
  } = props;
  const {
    skin
  } = context;
  const dark = _get('common.dark', skin);
  return /*#__PURE__*/React.createElement("div", {
    className: style.commentSection
  }, /*#__PURE__*/React.createElement("div", {
    className: style.commentSectionIconWrapper
  }, /*#__PURE__*/React.createElement(CheckIcon, {
    className: style.commentSectionIcon,
    style: {
      color: dark
    }
  })), /*#__PURE__*/React.createElement("div", {
    className: style.commentSectionTexts
  }, /*#__PURE__*/React.createElement("p", null, commentSectionTitle), /*#__PURE__*/React.createElement(Link, {
    onClick: onClick,
    className: style.commentSectionLink
  }, confirmationLinkText)));
};
CommentConfirmation.propTypes = process.env.NODE_ENV !== "production" ? {
  commentSectionTitle: PropTypes.node,
  confirmationLinkText: Link.propTypes.children,
  onClick: Link.propTypes.onClick
} : {};
CommentConfirmation.contextTypes = {
  skin: Provider.childContextTypes.skin
};
const CommentSection = props => {
  const {
    isSent,
    edition,
    confirmation
  } = props;
  if (isSent) {
    const {
      onClick,
      commentSectionTitle,
      confirmationLinkText
    } = confirmation;
    return /*#__PURE__*/React.createElement(CommentConfirmation, {
      onClick: onClick,
      commentSectionTitle: commentSectionTitle,
      confirmationLinkText: confirmationLinkText
    });
  }
  return /*#__PURE__*/React.createElement(Discussion, edition);
};
CommentSection.propTypes = process.env.NODE_ENV !== "production" ? {
  isSent: PropTypes.bool,
  edition: PropTypes.shape(Discussion.propTypes),
  confirmation: PropTypes.shape(CommentConfirmation.propTypes)
} : {};
const Cards = props => {
  const {
    cards
  } = props;
  return _get('cards', props) === null ? /*#__PURE__*/React.createElement(CardsLoader, null) : (_isEmpty(cards) ? null : /*#__PURE__*/React.createElement("div", {
    className: style.cardsWrapper
  }, /*#__PURE__*/React.createElement(CardsList, _extends({}, props, {
    dataName: 'popin-end-recommendation'
  })))) || null;
};
Cards.propTypes = process.env.NODE_ENV !== "production" ? CardsList.propTypes : {};
const Footer = ({
  title,
  color,
  ...linkProps
}) => /*#__PURE__*/React.createElement(Link, _extends({}, linkProps, {
  style: {
    color
  },
  className: style.footer,
  "data-name": "nextLink",
  "data-popin": "popinEnd",
  "data-next": "home"
}), title);
Footer.propTypes = process.env.NODE_ENV !== "production" ? {
  ...Link.propTypes,
  title: Link.propTypes.children,
  color: PropTypes.string
} : {};
const Summary = (props, context) => {
  const {
    header,
    recommendation,
    comment,
    footer,
    action,
    feedback,
    mode
  } = props;
  const {
    skin
  } = context;
  const primary = _getOr('#f0f', 'common.primary', skin);
  const commentView = mode !== 'scorm' && comment && header ? /*#__PURE__*/React.createElement("div", {
    className: style.discussionWrapper
  }, /*#__PURE__*/React.createElement(CommentSection, comment)) : null;
  const footerView = mode !== 'scorm' && footer && header ? /*#__PURE__*/React.createElement(Footer, _extends({}, footer, {
    color: primary
  })) : null;
  const feedbackView = feedback ? /*#__PURE__*/React.createElement(Feedback, _extends({}, feedback, {
    mode: mode
  })) : null;
  return /*#__PURE__*/React.createElement(BackgroundScorm, {
    mode: mode,
    failed: header.failed
  }, /*#__PURE__*/React.createElement("div", {
    className: mode !== 'scorm' ? style.summaryWrapper : null
  }, /*#__PURE__*/React.createElement(Header, _extends({}, header, {
    mode: mode
  })), feedbackView, /*#__PURE__*/React.createElement(Action, _extends({}, action, {
    color: primary
  })), /*#__PURE__*/React.createElement(Cards, recommendation), commentView, footerView));
};
const BackgroundScorm = props => {
  const {
    mode = 'default',
    children,
    failed
  } = props;
  if (mode === 'scorm') return /*#__PURE__*/React.createElement("div", {
    className: style.organismPlayerResultContainerScorm
  }, failed === false ? /*#__PURE__*/React.createElement("div", {
    className: style.animationContainer
  }, /*#__PURE__*/React.createElement(AtomLottieWrapper, {
    '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: style.lottie,
    backupImageClassName: style.ie11Backup
  })) : null, /*#__PURE__*/React.createElement("div", {
    className: style.background
  }, /*#__PURE__*/React.createElement("div", {
    className: style.largeCircle
  }), /*#__PURE__*/React.createElement("div", {
    className: style.mediumCircle
  }), /*#__PURE__*/React.createElement("div", {
    className: style.smallCircle
  })), /*#__PURE__*/React.createElement("div", {
    className: style.content
  }, children));
  return children;
};
Summary.contextTypes = {
  skin: Provider.childContextTypes.skin
};
Summary.propTypes = process.env.NODE_ENV !== "production" ? {
  header: PropTypes.shape(PopinHeader.propTypes),
  footer: PropTypes.shape({
    title: PropTypes.string,
    href: Link.propTypes.href,
    onClick: PropTypes.func
  }),
  comment: PropTypes.shape(CommentSection.propTypes),
  action: PropTypes.shape({
    type: PropTypes.oneOf(_keys(actions)).isRequired
  }),
  recommendation: PropTypes.shape(CardsList.propTypes),
  feedback: PropTypes.shape(Feedback.propTypes),
  mode: PropTypes.oneOf(['scorm', 'default'])
} : {};
export default Summary;
//# sourceMappingURL=summary.js.map