import _multiply from "lodash/fp/multiply";
import _parseInt2 from "lodash/fp/parseInt";
import _round from "lodash/fp/round";
import _pipe from "lodash/fp/pipe";
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, { useEffect, useState } from 'react';
import classnames from 'classnames';
import { NovaCompositionCoorpacademyStar as StarIcon, NovaSolidVoteRewardsRewardsBadge5 as RankIcon } from '@coorpacademy/nova-icons';
import LottieWrapper from '../../atom/lottie-wrapper';
import Animation, { EASE_OUT_CUBIC } from '../../hoc/animation';
import AnimationScheduler from '../../hoc/animation-scheduler';
import style from './style.css';
import propTypes from './prop-types';
export const setAnimations = (setIsAnimationVisible, setIsAnimated) => () => {
  setIsAnimationVisible('play');
  setIsAnimated(true);
};
const ReviewCardCongrats = props => {
  const {
    'aria-label': ariaLabel,
    'data-name': dataName,
    animationLottie,
    cardType,
    iconAriaLabel,
    className,
    reviewCardTitle,
    reviewCardValue,
    rankSuffix,
    timerAnimation
  } = props;
  const [isAnimationVisible, setIsAnimationVisible] = useState('loading');
  const [isAnimated, setIsAnimated] = useState(false);
  useEffect(() => {
    let timer;
    // istanbul ignore else
    if (!isAnimationVisible || !isAnimated) {
      timer = setTimeout(setAnimations(setIsAnimationVisible, setIsAnimated), timerAnimation);
    }
    return () => timer && clearTimeout(timer);
  }, [timerAnimation, isAnimated, isAnimationVisible]);
  const wrapperClassName = classnames(className, style.cardContainer, cardType === 'card-star' ? style.cardStar : style.cardRank);
  return /*#__PURE__*/React.createElement("div", {
    className: wrapperClassName,
    "data-name": dataName
  }, /*#__PURE__*/React.createElement("div", {
    className: style.mainIcon
  }, /*#__PURE__*/React.createElement(LottieWrapper, _extends({}, animationLottie, {
    loop: false,
    animationControl: isAnimationVisible,
    autoplay: false,
    "data-name": "lottie-wrapper",
    className: style.wrapperLottie,
    backupImageClassName: style.ie11Backup
  }))), /*#__PURE__*/React.createElement("div", {
    className: style.title,
    role: "status",
    "aria-label": ariaLabel
  }, reviewCardTitle), /*#__PURE__*/React.createElement("div", {
    className: cardType === 'card-star' ? style.textContainerStar : style.textContainerRank
  }, cardType === 'card-rank' ? /*#__PURE__*/React.createElement(RankIcon, {
    className: style.iconRank,
    width: 40,
    height: 40,
    "aria-label": iconAriaLabel
  }) : null, /*#__PURE__*/React.createElement(AnimationScheduler, {
    animated: isAnimated
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    className: cardType === 'card-star' ? style.textStar : style.textRank
  }, /*#__PURE__*/React.createElement(Animation, {
    name: "counter",
    bezier: EASE_OUT_CUBIC,
    duration: 2000
  }, progress => _pipe(_parseInt2(10), _multiply(progress), _round)(reviewCardValue))))), cardType === 'card-star' ? /*#__PURE__*/React.createElement(StarIcon, {
    className: style.iconStar,
    width: 53,
    height: 53,
    "aria-label": iconAriaLabel
  }) : /*#__PURE__*/React.createElement("div", {
    className: style.rankSuffix
  }, rankSuffix)));
};
ReviewCardCongrats.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
export default ReviewCardCongrats;
//# sourceMappingURL=index.js.map