"use strict";

exports.__esModule = true;
exports.setAnimations = exports.default = void 0;
var _multiply2 = _interopRequireDefault(require("lodash/fp/multiply"));
var _parseInt3 = _interopRequireDefault(require("lodash/fp/parseInt"));
var _round2 = _interopRequireDefault(require("lodash/fp/round"));
var _pipe2 = _interopRequireDefault(require("lodash/fp/pipe"));
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _lottieWrapper = _interopRequireDefault(require("../../atom/lottie-wrapper"));
var _animation = _interopRequireWildcard(require("../../hoc/animation"));
var _animationScheduler = _interopRequireDefault(require("../../hoc/animation-scheduler"));
var _style = _interopRequireDefault(require("./style.css"));
var _propTypes = _interopRequireDefault(require("./prop-types"));
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 setAnimations = (setIsAnimationVisible, setIsAnimated) => () => {
  setIsAnimationVisible('play');
  setIsAnimated(true);
};
exports.setAnimations = setAnimations;
const ReviewCardCongrats = props => {
  const {
    'aria-label': ariaLabel,
    'data-name': dataName,
    animationLottie,
    cardType,
    iconAriaLabel,
    className,
    reviewCardTitle,
    reviewCardValue,
    rankSuffix,
    timerAnimation
  } = props;
  const [isAnimationVisible, setIsAnimationVisible] = (0, _react.useState)('loading');
  const [isAnimated, setIsAnimated] = (0, _react.useState)(false);
  (0, _react.useEffect)(() => {
    let timer;
    // istanbul ignore else
    if (!isAnimationVisible || !isAnimated) {
      timer = setTimeout(setAnimations(setIsAnimationVisible, setIsAnimated), timerAnimation);
    }
    return () => timer && clearTimeout(timer);
  }, [timerAnimation, isAnimated, isAnimationVisible]);
  const wrapperClassName = (0, _classnames.default)(className, _style.default.cardContainer, cardType === 'card-star' ? _style.default.cardStar : _style.default.cardRank);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: wrapperClassName,
    "data-name": dataName
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.mainIcon
  }, /*#__PURE__*/_react.default.createElement(_lottieWrapper.default, _extends({}, animationLottie, {
    loop: false,
    animationControl: isAnimationVisible,
    autoplay: false,
    "data-name": "lottie-wrapper",
    className: _style.default.wrapperLottie,
    backupImageClassName: _style.default.ie11Backup
  }))), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.title,
    role: "status",
    "aria-label": ariaLabel
  }, reviewCardTitle), /*#__PURE__*/_react.default.createElement("div", {
    className: cardType === 'card-star' ? _style.default.textContainerStar : _style.default.textContainerRank
  }, cardType === 'card-rank' ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaSolidVoteRewardsRewardsBadge5, {
    className: _style.default.iconRank,
    width: 40,
    height: 40,
    "aria-label": iconAriaLabel
  }) : null, /*#__PURE__*/_react.default.createElement(_animationScheduler.default, {
    animated: isAnimated
  }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("span", {
    className: cardType === 'card-star' ? _style.default.textStar : _style.default.textRank
  }, /*#__PURE__*/_react.default.createElement(_animation.default, {
    name: "counter",
    bezier: _animation.EASE_OUT_CUBIC,
    duration: 2000
  }, progress => (0, _pipe2.default)((0, _parseInt3.default)(10), (0, _multiply2.default)(progress), _round2.default)(reviewCardValue))))), cardType === 'card-star' ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyStar, {
    className: _style.default.iconStar,
    width: 53,
    height: 53,
    "aria-label": iconAriaLabel
  }) : /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.rankSuffix
  }, rankSuffix)));
};
ReviewCardCongrats.propTypes = process.env.NODE_ENV !== "production" ? _propTypes.default : {};
var _default = exports.default = ReviewCardCongrats;
//# sourceMappingURL=index.js.map