"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _styles = require("./styles");
var _reactNative = require("react-native");
var _reactNativeSvg = require("react-native-svg");
var _toastSlice = require("../../../core/stores/slices/toastSlice");
var _react = require("react");
var _Typography = require("../../../core/components/Typography/Typography");
var _icons = require("../../../core/assets/icons");
var _CircularProgressIndicator = require("../CircularProgressIndicator");
const Toast = () => {
  const {
    hideToast,
    toast
  } = (0, _toastSlice.useToast)();
  const {
    styles,
    theme
  } = (0, _styles.useStyles)(toast.bottomPosition);
  const timeoutRef = (0, _react.useRef)(null);
  const fadeIn = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
  (0, _react.useEffect)(() => {
    if (toast.visible) {
      _reactNative.Animated.timing(fadeIn, {
        toValue: 1,
        duration: toast.type === 'loading' ? toast.duration : 500,
        useNativeDriver: false
      }).start(() => {
        timeoutRef.current = setTimeout(() => {
          _reactNative.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(_reactNative.Animated.View, {
    style: styles.toast
  }, toast.type === 'loading' && /*#__PURE__*/React.createElement(_CircularProgressIndicator.CircularProgressIndicator, {
    size: 24,
    strokeWidth: 2.3,
    progressColor: theme.colors.primary,
    backgroundColor: theme.colors.background
  }), toast.type === 'success' && /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    xml: (0, _icons.success)(),
    width: "24",
    height: "24",
    color: theme.colors.background
  }), toast.type === 'failed' && /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    width: "24",
    height: "24",
    xml: (0, _icons.failed)(),
    color: theme.colors.background
  }), toast.type === 'informative' && /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    width: "24",
    height: "24",
    xml: (0, _icons.informative)(),
    color: theme.colors.background
  }), /*#__PURE__*/React.createElement(_Typography.Typography.Body, {
    style: styles.message
  }, toast.message));
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(Toast);
//# sourceMappingURL=index.js.map