import _noop from "lodash/fp/noop";
import React, { useEffect, useRef, useState } from 'react';
import { Animated, ScrollView, StyleSheet, Text } from 'react-native';
import LottieView from 'lottie-react-native';
import { NovaCompositionCoorpacademyStar as StarIcon, NovaSolidVoteRewardsRewardsBadge5 as RankIcon } from '@coorpacademy/nova-icons';
import { sequence, parallel, useAnimateProp, useTranslateY, useTranslateX } from '@coorpacademy/react-native-animation';
import { useTemplateContext } from '../../template/app-review/template-context';
import Button from '../../atom/button/index.native';
import { BOX_STYLE } from '../../variables/shadow';
import CardCongrats from '../../molecule/card-congrats/index.native';
const createStyleSheet = theme => 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
  } = useTemplateContext();
  const [styleSheet, setStylesheet] = useState(null);
  const [isCongratsTranslationDone, setCongratsTranslationDone] = useState(false);
  const [isRankShown, setRankShown] = useState(false);
  const scrollViewRef = useRef(null);
  const showCongrats = useAnimateProp({
    property: 'opacity',
    fromValue: 0,
    toValue: 1,
    duration: 950,
    onComplete: () => {
      setCongratsTranslationDone(true);
    }
  });
  const translateCongrats = useTranslateY({
    fromValue: 100,
    toValue: 0,
    duration: 550
  });
  const showConfettis = useAnimateProp(fadeIn);
  const fadeInRank = useAnimateProp(fadeIn);
  const translateRank = useTranslateX({
    ...translateHorizontally,
    onComplete: () => {
      setRankShown(true);
      setTimeout(() => {
        scrollViewRef?.current?.scrollToEnd();
      }, 700);
    }
  });
  const animatedRank = [fadeInRank.animatedStyle, translateRank.animatedStyle];
  const fadeInStars = useAnimateProp({
    ...fadeIn,
    delay: cardCongratsRank ? 1000 : 0
  });
  const translateStars = useTranslateX({
    ...translateHorizontally,
    delay: cardCongratsRank ? 1000 : 0
  });
  const showButton1 = useAnimateProp(fadeIn);
  const showButton2 = useAnimateProp(fadeIn);
  const congratsSequence = sequence([parallel([showCongrats, translateCongrats]), parallel([showConfettis, cardCongratsRank ? sequence([parallel([fadeInRank, translateRank]), parallel([fadeInStars, translateStars])]) : parallel([fadeInStars, translateStars])]), sequence([showButton1, showButton2])]);
  useEffect(() => {
    congratsSequence.start();
    // (required only once on mount)
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  useEffect(() => {
    const _stylesheet = createStyleSheet(theme);
    setStylesheet(_stylesheet);
  }, [theme]);
  if (!styleSheet) {
    return null;
  }
  const handleContinueRevisingPress = buttonRevising?.onClick || _noop;
  const handleReviseAnotherSkillPress = buttonRevisingSkill?.onClick || _noop;
  const showStarLottieAnimation = !cardCongratsRank || isRankShown;
  return /*#__PURE__*/React.createElement(Animated.View, {
    style: [styleSheet.congrats, translateCongrats.animatedStyle, showCongrats.animatedStyle],
    accessibilityLabel: ariaLabel
  }, /*#__PURE__*/React.createElement(Text, {
    style: styleSheet.title
  }, title), /*#__PURE__*/React.createElement(ScrollView, {
    ref: scrollViewRef,
    horizontal: true,
    showsHorizontalScrollIndicator: false,
    style: styleSheet.scrollView,
    contentContainerStyle: styleSheet.scrollViewContent
  }, cardCongratsRank ? /*#__PURE__*/React.createElement(Animated.View, {
    style: animatedRank
  }, /*#__PURE__*/React.createElement(CardCongrats, {
    animationUri: cardCongratsRank.animationLottie.animationSrc,
    text: cardCongratsRank.reviewCardTitle,
    value: `${cardCongratsRank.reviewCardValue} ${cardCongratsRank.rankSuffix}`,
    Icon: RankIcon,
    iconColor: theme.colors.positive,
    textColor: theme.colors.text.primary,
    direction: "row-reverse"
  })) : null, /*#__PURE__*/React.createElement(Animated.View, {
    style: [fadeInStars.animatedStyle, translateStars.animatedStyle]
  }, /*#__PURE__*/React.createElement(CardCongrats, {
    animationUri: showStarLottieAnimation ? cardCongratsStar.animationLottie.animationSrc : null,
    Icon: StarIcon,
    text: cardCongratsStar.reviewCardTitle,
    value: cardCongratsStar.reviewCardValue,
    iconColor: theme.colors.battle,
    textColor: theme.colors.battle,
    direction: "row"
  }))), /*#__PURE__*/React.createElement(Animated.View, {
    style: styleSheet.buttons
  }, buttonRevisingSkill ? /*#__PURE__*/React.createElement(Animated.View, {
    style: showButton1.animatedStyle
  }, /*#__PURE__*/React.createElement(Button, {
    onPress: handleReviseAnotherSkillPress,
    accessibilityLabel: buttonRevisingSkill['aria-label'],
    submitValue: buttonRevisingSkill.label,
    style: {
      ...BOX_STYLE,
      backgroundColor: '#fff'
    },
    textStyle: {
      color: '#123'
    }
  })) : null, buttonRevising ? /*#__PURE__*/React.createElement(Animated.View, {
    style: showButton2.animatedStyle
  }, /*#__PURE__*/React.createElement(Button, {
    onPress: handleContinueRevisingPress,
    accessibilityLabel: buttonRevising['aria-label'],
    submitValue: buttonRevising.label
  })) : null), isCongratsTranslationDone ? /*#__PURE__*/React.createElement(Animated.View, {
    pointerEvents: "none",
    style: [styleSheet.confettis, showConfettis.animatedStyle]
  }, /*#__PURE__*/React.createElement(LottieView, {
    source: {
      uri: animationLottie.animationSrc
    },
    autoPlay: true,
    loop: false
  })) : null);
};
export default ReviewCongrats;
//# sourceMappingURL=index.native.js.map