import { StyleSheet, Text, Animated, ActivityIndicator } from 'react-native';
import { memo, useEffect, useRef } from 'react';
import uiSlice from '../../../../core/stores/slices/uiSlice';
import { useUIKitDispatch, useUIKitSelector } from '../../../../core/stores/store';
import { toastIcon, toastSuccess } from '../../../../core/assets/icons/xml';
import { SvgXml } from 'react-native-svg';
const Toast = () => {
  const dispatch = useUIKitDispatch();
  const {
    hideToastMessage
  } = uiSlice.actions;
  const {
    toastMessage,
    showToastMessage,
    isLoadingToast,
    isSuccessToast
  } = useUIKitSelector(state => state.ui);
  const fadeAnim = useRef(new Animated.Value(0)).current;
  const timeoutRef = useRef(null);
  useEffect(() => {
    if (showToastMessage) {
      Animated.timing(fadeAnim, {
        toValue: 1,
        duration: isLoadingToast ? 2500 : 500,
        useNativeDriver: false
      }).start(() => {
        timeoutRef.current = setTimeout(() => {
          Animated.timing(fadeAnim, {
            toValue: 0,
            duration: isLoadingToast ? 2500 : 500,
            useNativeDriver: false
          }).start(() => {
            dispatch(hideToastMessage());
          });
        }, 2000);
      });
    }
    return () => {
      fadeAnim.setValue(0);
      fadeAnim.stopAnimation();
      clearTimeout(timeoutRef.current);
    };
  }, [dispatch, fadeAnim, hideToastMessage, isLoadingToast, showToastMessage]);
  const styles = StyleSheet.create({
    toastContainer: {
      width: '90%',
      position: 'absolute',
      bottom: 100,
      backgroundColor: '#292b32',
      borderRadius: 16,
      padding: 16,
      alignSelf: 'center',
      flexDirection: 'row',
      alignItems: 'center',
      gap: 12
    },
    message: {
      lineHeight: 24,
      flex: 1,
      marginLeft: 4,
      color: '#ffffff'
    },
    toastVisible: {
      opacity: 1
    },
    loadingIndicator: {
      marginRight: 5
    }
  });
  if (!showToastMessage) return null;
  return /*#__PURE__*/React.createElement(Animated.View, {
    style: [styles.toastContainer, styles.toastVisible]
  }, isLoadingToast ? /*#__PURE__*/React.createElement(ActivityIndicator, {
    style: styles.loadingIndicator,
    animating: isLoadingToast,
    color: "lightblue",
    size: "small"
  }) : isSuccessToast ? /*#__PURE__*/React.createElement(SvgXml, {
    xml: toastSuccess(),
    width: "24",
    height: "24"
  }) : /*#__PURE__*/React.createElement(SvgXml, {
    xml: toastIcon(),
    width: "24",
    height: "24"
  }), /*#__PURE__*/React.createElement(Text, {
    style: styles.message
  }, toastMessage));
};
export default /*#__PURE__*/memo(Toast);
//# sourceMappingURL=Toast.js.map