import React, { useEffect, useRef, useState } from 'react';
import { Animated, StyleSheet, View } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import { NovaCompositionCoorpacademyLogoCoorp as LogoCoorp, NovaCompositionCoorpacademyQrCode as QrCodeIcon, NovaCompositionCoorpacademyEmail as MailIcon } from '@coorpacademy/nova-icons';
import { useAnimateProp, useTranslateY } from '@coorpacademy/react-native-animation';
import Touchable from '../../../hoc/touchable/index.native';
import { useTemplateContext } from '../../app-review/template-context';
import Text from '../../../atom/text/index.native';
import { COLORS } from '../../../variables/colors';
const {
  cm_primary_blue
} = COLORS;
const createStyleSheet = theme => StyleSheet.create({
  wrapper: {
    top: 0,
    bottom: 0,
    left: 0,
    right: 0,
    flex: 1,
    justifyContent: 'space-around',
    alignItems: 'center',
    paddingHorizontal: 24
  },
  content: {
    width: '100%',
    alignItems: 'flex-start'
  },
  gradients: {
    position: 'absolute',
    top: 400,
    bottom: 400,
    left: 0,
    right: 0,
    flex: 1
  },
  gradient: {
    position: 'absolute',
    top: -730,
    bottom: 0,
    left: -380,
    right: -380,
    opacity: 1,
    transform: [{
      rotate: '35deg'
    }]
  },
  gradient2: {
    position: 'absolute',
    top: -630,
    bottom: -200,
    left: -300,
    right: -400,
    opacity: 0.6,
    transform: [{
      rotate: '-35deg'
    }]
  },
  animatedLogoWrapper: {
    alignItems: 'center'
  },
  animatedLogo: {
    position: 'absolute',
    width: 77,
    height: 100
  },
  logo: {
    padding: 100
  },
  logoBG: {
    backgroundColor: '#fff',
    top: 20,
    width: 60,
    height: 60
  },
  title: {
    color: '#1D1D2B',
    fontWeight: '600',
    fontSize: 28,
    lineHeight: 36,
    paddingVertical: 8
  },
  description: {
    color: '#1D1D2B',
    fontWeight: '400',
    fontSize: 17,
    lineHeight: 24,
    paddingVertical: 8
  },
  actions: {
    width: '100%'
  },
  buttons: {
    paddingVertical: 20,
    alignItems: 'center'
  },
  button: {
    paddingVertical: 12,
    marginVertical: 4,
    width: '100%',
    flexDirection: 'row',
    justifyContent: 'center',
    borderRadius: 12,
    alignItems: 'center',
    overflow: 'hidden'
  },
  ctaQrCode: {
    backgroundColor: theme.colors.cta
  },
  ctaQrCodeText: {
    marginLeft: 8,
    color: '#fff',
    fontWeight: '700',
    fontSize: 14,
    lineHeight: 24
  },
  qrCodeIcon: {
    fill: '#fff',
    height: 14,
    width: 14
  },
  ctaReceiveMail: {
    backgroundColor: '#eaeaeb'
  },
  ctaReceiveMailText: {
    marginLeft: 8,
    color: '#1D1D2B',
    fontWeight: '700',
    fontSize: 14,
    lineHeight: 24
  },
  mailIcon: {
    fill: '#1D1D2B',
    height: 12,
    width: 16
  },
  help: {
    flexDirection: 'row',
    justifyContent: 'center'
  },
  titleHelp: {
    color: '#9999A8'
  },
  ctaHelp: {
    marginLeft: 5,
    textDecorationLine: 'underline',
    color: '#9999A8'
  }
});
const Welcome = props => {
  const {
    locales,
    onDemoPress,
    onQRCodeButtonPress,
    onHelpPress,
    onReceiveEmailButtonPress
  } = props;
  const {
    theme
  } = useTemplateContext();
  const [styleSheet, setStylesheet] = useState(null);
  const translateGradients = useTranslateY({
    fromValue: 0,
    toValue: -200,
    duration: 300,
    delay: 750
  });
  const translateContent = useTranslateY({
    fromValue: 170,
    toValue: 0,
    duration: 450,
    delay: 750
  });
  const fadeInContent = useAnimateProp({
    property: 'opacity',
    fromValue: 0,
    toValue: 1,
    duration: 650,
    delay: 750
  });
  const fadeOutStartLogo = useAnimateProp({
    property: 'opacity',
    fromValue: 1,
    toValue: 0,
    duration: 450,
    delay: 1000
  });
  const fadeInFinalLogo = useAnimateProp({
    property: 'opacity',
    fromValue: 0,
    toValue: 1,
    duration: 250,
    delay: 900
  });
  const scaleAnim = useRef(new Animated.Value(0)).current;
  const interpolateScale = scaleAnim.interpolate({
    inputRange: [0, 0.4, 0.5, 0.6, 1],
    outputRange: [1, 1.7, 1.7, 1.7, 1]
  });
  useEffect(() => {
    const _stylesheet = createStyleSheet(theme);
    setStylesheet(_stylesheet);
  }, [theme]);
  useEffect(() => {
    fadeInContent.start();
    fadeInFinalLogo.start();
    fadeOutStartLogo.start();
    translateContent.start();
    translateGradients.start();
    const animatedScale = Animated.timing(scaleAnim, {
      toValue: 1,
      duration: 1000,
      useNativeDriver: true
    });
    animatedScale.start();

    // on mount only
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  if (!styleSheet) {
    return null;
  }
  return /*#__PURE__*/React.createElement(Animated.View, {
    style: [styleSheet.wrapper, translateContent.animatedStyle],
    testID: "welcome"
  }, /*#__PURE__*/React.createElement(Animated.View, {
    style: [styleSheet.gradients, translateGradients.animatedStyle]
  }, /*#__PURE__*/React.createElement(LinearGradient, {
    colors: [cm_primary_blue, '#fff'],
    locations: [0, 0.95],
    style: styleSheet.gradient
  }), /*#__PURE__*/React.createElement(LinearGradient, {
    colors: ['#2199AB', '#fff'],
    locations: [0, 0.95],
    style: styleSheet.gradient2
  })), /*#__PURE__*/React.createElement(Touchable, {
    onLongPress: onDemoPress,
    style: styleSheet.logo
  }, /*#__PURE__*/React.createElement(Animated.View, {
    style: [styleSheet.animatedLogoWrapper, {
      transform: [{
        scale: interpolateScale
      }]
    }]
  }, /*#__PURE__*/React.createElement(Animated.View, {
    style: [styleSheet.logoBG, fadeInFinalLogo.animatedStyle]
  }), /*#__PURE__*/React.createElement(Animated.View, {
    style: [styleSheet.animatedLogo, fadeInFinalLogo.animatedStyle]
  }, /*#__PURE__*/React.createElement(LogoCoorp, {
    fill: "#0061FF"
  })), /*#__PURE__*/React.createElement(Animated.View, {
    style: [styleSheet.animatedLogo, fadeOutStartLogo.animatedStyle]
  }, /*#__PURE__*/React.createElement(LogoCoorp, {
    fill: "#fff"
  })))), /*#__PURE__*/React.createElement(Animated.View, {
    style: [styleSheet.content, fadeInContent.animatedStyle]
  }, /*#__PURE__*/React.createElement(Text, {
    style: styleSheet.title
  }, locales.title), /*#__PURE__*/React.createElement(Text, {
    style: styleSheet.description
  }, locales.description), /*#__PURE__*/React.createElement(View, {
    style: styleSheet.actions
  }, /*#__PURE__*/React.createElement(View, {
    style: styleSheet.buttons
  }, /*#__PURE__*/React.createElement(Touchable, {
    style: [styleSheet.button, styleSheet.ctaQrCode],
    onPress: onQRCodeButtonPress,
    testID: "qr-code-button"
  }, /*#__PURE__*/React.createElement(QrCodeIcon, {
    style: styleSheet.qrCodeIcon
  }), /*#__PURE__*/React.createElement(Text, {
    style: styleSheet.ctaQrCodeText
  }, locales.ctaQrCode)), /*#__PURE__*/React.createElement(Touchable, {
    style: [styleSheet.button, styleSheet.ctaReceiveMail],
    onPress: onReceiveEmailButtonPress,
    testID: "receive-email-button"
  }, /*#__PURE__*/React.createElement(MailIcon, {
    style: styleSheet.mailIcon
  }), /*#__PURE__*/React.createElement(Text, {
    style: styleSheet.ctaReceiveMailText
  }, locales.ctaReceiveMail))), /*#__PURE__*/React.createElement(Touchable, {
    onPress: onHelpPress,
    style: styleSheet.help
  }, /*#__PURE__*/React.createElement(Text, {
    style: styleSheet.titleHelp
  }, locales.titleHelp), /*#__PURE__*/React.createElement(Text, {
    style: styleSheet.ctaHelp
  }, locales.ctaHelp)))));
};
export default Welcome;
//# sourceMappingURL=index.native.js.map