"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _react = require("react");
var _uiSlice = _interopRequireDefault(require("../../../../core/stores/slices/uiSlice"));
var _store = require("../../../../core/stores/store");
var _xml = require("../../../../core/assets/icons/xml");
var _reactNativeSvg = require("react-native-svg");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const Toast = () => {
  const dispatch = (0, _store.useUIKitDispatch)();
  const {
    hideToastMessage
  } = _uiSlice.default.actions;
  const {
    toastMessage,
    showToastMessage,
    isLoadingToast,
    isSuccessToast
  } = (0, _store.useUIKitSelector)(state => state.ui);
  const fadeAnim = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
  const timeoutRef = (0, _react.useRef)(null);
  (0, _react.useEffect)(() => {
    if (showToastMessage) {
      _reactNative.Animated.timing(fadeAnim, {
        toValue: 1,
        duration: isLoadingToast ? 2500 : 500,
        useNativeDriver: false
      }).start(() => {
        timeoutRef.current = setTimeout(() => {
          _reactNative.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 = _reactNative.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(_reactNative.Animated.View, {
    style: [styles.toastContainer, styles.toastVisible]
  }, isLoadingToast ? /*#__PURE__*/React.createElement(_reactNative.ActivityIndicator, {
    style: styles.loadingIndicator,
    animating: isLoadingToast,
    color: "lightblue",
    size: "small"
  }) : isSuccessToast ? /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    xml: (0, _xml.toastSuccess)(),
    width: "24",
    height: "24"
  }) : /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    xml: (0, _xml.toastIcon)(),
    width: "24",
    height: "24"
  }), /*#__PURE__*/React.createElement(_reactNative.Text, {
    style: styles.message
  }, toastMessage));
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(Toast);
//# sourceMappingURL=Toast.js.map