"use strict";

exports.__esModule = true;
exports.default = void 0;
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _lottieReactNative = _interopRequireDefault(require("lottie-react-native"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _reactNativeAnimation = require("@coorpacademy/react-native-animation");
var _templateContext = require("../../template/app-review/template-context");
var _index = _interopRequireDefault(require("../../atom/button/index.native"));
var _shadow = require("../../variables/shadow");
var _index2 = _interopRequireDefault(require("../../molecule/card-congrats/index.native"));
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 }; }
const createStyleSheet = theme => _reactNative.StyleSheet.create({
  congrats: {
    position: 'absolute',
    width: '100%',
    height: '100%',
    flexDirection: 'column',
    alignItems: 'center',
    paddingVertical: 90,
    flex: 1
  },
  buttons: {
    width: '100%',
    paddingHorizontal: 20,
    flexDirection: 'column',
    justifyContent: 'space-between',
    height: 114
  },
  title: {
    fontWeight: '400',
    fontSize: 32,
    lineHeight: 40,
    marginVertical: 20,
    color: theme.colors.text.primary
  },
  confettis: {
    flexGrow: 1,
    position: 'absolute',
    width: '100%',
    height: '100%',
    pointerEvents: 'box-none'
  },
  scrollView: {
    height: 300
  },
  scrollViewContent: {
    alignItems: 'center',
    paddingHorizontal: 40
  }
});
const fadeIn = {
  property: 'opacity',
  fromValue: 0,
  toValue: 1,
  duration: 350
};
const translateHorizontally = {
  property: 'translateX',
  fromValue: 180,
  toValue: 0,
  duration: 800
};
const ReviewCongrats = props => {
  const {
    'aria-label': ariaLabel,
    animationLottie,
    title,
    cardCongratsStar,
    cardCongratsRank,
    buttonRevising,
    buttonRevisingSkill
  } = props;
  const {
    theme
  } = (0, _templateContext.useTemplateContext)();
  const [styleSheet, setStylesheet] = (0, _react.useState)(null);
  const [isCongratsTranslationDone, setCongratsTranslationDone] = (0, _react.useState)(false);
  const [isRankShown, setRankShown] = (0, _react.useState)(false);
  const scrollViewRef = (0, _react.useRef)(null);
  const showCongrats = (0, _reactNativeAnimation.useAnimateProp)({
    property: 'opacity',
    fromValue: 0,
    toValue: 1,
    duration: 950,
    onComplete: () => {
      setCongratsTranslationDone(true);
    }
  });
  const translateCongrats = (0, _reactNativeAnimation.useTranslateY)({
    fromValue: 100,
    toValue: 0,
    duration: 550
  });
  const showConfettis = (0, _reactNativeAnimation.useAnimateProp)(fadeIn);
  const fadeInRank = (0, _reactNativeAnimation.useAnimateProp)(fadeIn);
  const translateRank = (0, _reactNativeAnimation.useTranslateX)({
    ...translateHorizontally,
    onComplete: () => {
      setRankShown(true);
      setTimeout(() => {
        scrollViewRef?.current?.scrollToEnd();
      }, 700);
    }
  });
  const animatedRank = [fadeInRank.animatedStyle, translateRank.animatedStyle];
  const fadeInStars = (0, _reactNativeAnimation.useAnimateProp)({
    ...fadeIn,
    delay: cardCongratsRank ? 1000 : 0
  });
  const translateStars = (0, _reactNativeAnimation.useTranslateX)({
    ...translateHorizontally,
    delay: cardCongratsRank ? 1000 : 0
  });
  const showButton1 = (0, _reactNativeAnimation.useAnimateProp)(fadeIn);
  const showButton2 = (0, _reactNativeAnimation.useAnimateProp)(fadeIn);
  const congratsSequence = (0, _reactNativeAnimation.sequence)([(0, _reactNativeAnimation.parallel)([showCongrats, translateCongrats]), (0, _reactNativeAnimation.parallel)([showConfettis, cardCongratsRank ? (0, _reactNativeAnimation.sequence)([(0, _reactNativeAnimation.parallel)([fadeInRank, translateRank]), (0, _reactNativeAnimation.parallel)([fadeInStars, translateStars])]) : (0, _reactNativeAnimation.parallel)([fadeInStars, translateStars])]), (0, _reactNativeAnimation.sequence)([showButton1, showButton2])]);
  (0, _react.useEffect)(() => {
    congratsSequence.start();
    // (required only once on mount)
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  (0, _react.useEffect)(() => {
    const _stylesheet = createStyleSheet(theme);
    setStylesheet(_stylesheet);
  }, [theme]);
  if (!styleSheet) {
    return null;
  }
  const handleContinueRevisingPress = buttonRevising?.onClick || _noop2.default;
  const handleReviseAnotherSkillPress = buttonRevisingSkill?.onClick || _noop2.default;
  const showStarLottieAnimation = !cardCongratsRank || isRankShown;
  return /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    style: [styleSheet.congrats, translateCongrats.animatedStyle, showCongrats.animatedStyle],
    accessibilityLabel: ariaLabel
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: styleSheet.title
  }, title), /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
    ref: scrollViewRef,
    horizontal: true,
    showsHorizontalScrollIndicator: false,
    style: styleSheet.scrollView,
    contentContainerStyle: styleSheet.scrollViewContent
  }, cardCongratsRank ? /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    style: animatedRank
  }, /*#__PURE__*/_react.default.createElement(_index2.default, {
    animationUri: cardCongratsRank.animationLottie.animationSrc,
    text: cardCongratsRank.reviewCardTitle,
    value: `${cardCongratsRank.reviewCardValue} ${cardCongratsRank.rankSuffix}`,
    Icon: _novaIcons.NovaSolidVoteRewardsRewardsBadge5,
    iconColor: theme.colors.positive,
    textColor: theme.colors.text.primary,
    direction: "row-reverse"
  })) : null, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    style: [fadeInStars.animatedStyle, translateStars.animatedStyle]
  }, /*#__PURE__*/_react.default.createElement(_index2.default, {
    animationUri: showStarLottieAnimation ? cardCongratsStar.animationLottie.animationSrc : null,
    Icon: _novaIcons.NovaCompositionCoorpacademyStar,
    text: cardCongratsStar.reviewCardTitle,
    value: cardCongratsStar.reviewCardValue,
    iconColor: theme.colors.battle,
    textColor: theme.colors.battle,
    direction: "row"
  }))), /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    style: styleSheet.buttons
  }, buttonRevisingSkill ? /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    style: showButton1.animatedStyle
  }, /*#__PURE__*/_react.default.createElement(_index.default, {
    onPress: handleReviseAnotherSkillPress,
    accessibilityLabel: buttonRevisingSkill['aria-label'],
    submitValue: buttonRevisingSkill.label,
    style: {
      ..._shadow.BOX_STYLE,
      backgroundColor: '#fff'
    },
    textStyle: {
      color: '#123'
    }
  })) : null, buttonRevising ? /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    style: showButton2.animatedStyle
  }, /*#__PURE__*/_react.default.createElement(_index.default, {
    onPress: handleContinueRevisingPress,
    accessibilityLabel: buttonRevising['aria-label'],
    submitValue: buttonRevising.label
  })) : null), isCongratsTranslationDone ? /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    pointerEvents: "none",
    style: [styleSheet.confettis, showConfettis.animatedStyle]
  }, /*#__PURE__*/_react.default.createElement(_lottieReactNative.default, {
    source: {
      uri: animationLottie.animationSrc
    },
    autoPlay: true,
    loop: false
  })) : null);
};
var _default = exports.default = ReviewCongrats;
//# sourceMappingURL=index.native.js.map