import { useStyles } from './styles';
import { Animated } from 'react-native';
import { SvgXml } from 'react-native-svg';
import { useToast } from '../../../core/stores/slices/toastSlice';
import { memo, useEffect, useRef } from 'react';
import { Typography } from '../../../core/components/Typography/Typography';
import { informative, failed, success } from '../../../core/assets/icons';
import { CircularProgressIndicator } from '../CircularProgressIndicator';
const Toast = () => {
  const {
    hideToast,
    toast
  } = useToast();
  const {
    styles,
    theme
  } = useStyles(toast.bottomPosition);
  const timeoutRef = useRef(null);
  const fadeIn = useRef(new Animated.Value(0)).current;
  useEffect(() => {
    if (toast.visible) {
      Animated.timing(fadeIn, {
        toValue: 1,
        duration: toast.type === 'loading' ? toast.duration : 500,
        useNativeDriver: false
      }).start(() => {
        timeoutRef.current = setTimeout(() => {
          Animated.timing(fadeIn, {
            toValue: 0,
            duration: toast.type === 'loading' ? toast.duration : 500,
            useNativeDriver: false
          }).start(hideToast);
        }, toast.duration);
      });
    }
    return () => {
      fadeIn.setValue(0);
      fadeIn.stopAnimation();
      clearTimeout(timeoutRef.current);
    };
  }, [fadeIn, hideToast, toast]);
  if (!toast.visible) return null;
  return /*#__PURE__*/React.createElement(Animated.View, {
    style: styles.toast
  }, toast.type === 'loading' && /*#__PURE__*/React.createElement(CircularProgressIndicator, {
    size: 24,
    strokeWidth: 2.3,
    progressColor: theme.colors.primary,
    backgroundColor: theme.colors.background
  }), toast.type === 'success' && /*#__PURE__*/React.createElement(SvgXml, {
    xml: success(),
    width: "24",
    height: "24",
    color: theme.colors.background
  }), toast.type === 'failed' && /*#__PURE__*/React.createElement(SvgXml, {
    width: "24",
    height: "24",
    xml: failed(),
    color: theme.colors.background
  }), toast.type === 'informative' && /*#__PURE__*/React.createElement(SvgXml, {
    width: "24",
    height: "24",
    xml: informative(),
    color: theme.colors.background
  }), /*#__PURE__*/React.createElement(Typography.Body, {
    style: styles.message
  }, toast.message));
};
export default /*#__PURE__*/memo(Toast);
//# sourceMappingURL=index.js.map