import React, { useEffect, useRef } from "react";
import { View, StyleSheet, Animated } from "react-native";
import { CheckCircle2, AlertCircle, AlertTriangle, Lightbulb, X } from "@/lib/icons";
import { Text } from "@/components/ui/text";
import { useToast, ToastType } from "@/lib/toast-store";
import { useColorScheme } from "nativewind";
import { useSafeAreaInsets } from "react-native-safe-area-context";
const VARIANT_CONFIG: Record<
ToastType,
{ iconColor: string; borderColor: string; icon: React.ReactNode }
> = {
success: {
iconColor: "#16a34a",
borderColor: "#16a34a",
icon: ,
},
error: {
iconColor: "#dc2626",
borderColor: "#dc2626",
icon: ,
},
warning: {
iconColor: "#d97706",
borderColor: "#d97706",
icon: ,
},
info: {
iconColor: "#E46212",
borderColor: "#E46212",
icon: ,
},
};
export function ModalToast() {
const { visible, type, title, message, hide, duration } = useToast();
const isDark = useColorScheme() === "dark";
const insets = useSafeAreaInsets();
const translateX = useRef(new Animated.Value(-40)).current;
const opacity = useRef(new Animated.Value(0)).current;
useEffect(() => {
if (visible) {
translateX.setValue(-40);
opacity.setValue(0);
Animated.parallel([
Animated.spring(translateX, {
toValue: 0,
useNativeDriver: true,
speed: 20,
bounciness: 6,
}),
Animated.timing(opacity, {
toValue: 1,
duration: 180,
useNativeDriver: true,
}),
]).start();
const timer = setTimeout(hide, duration);
return () => clearTimeout(timer);
}
}, [visible]);
if (!visible) return null;
const config = VARIANT_CONFIG[type];
return (
{config.icon}
{title}
{message ? (
{message}
) : null}
);
}
const styles = StyleSheet.create({
absoluteOverlay: {
zIndex: 9999,
elevation: 50,
},
toast: {
marginHorizontal: 16,
borderRadius: 12,
paddingHorizontal: 16,
paddingVertical: 12,
flexDirection: "row",
alignItems: "center",
shadowColor: "#000",
shadowOpacity: 0.18,
shadowRadius: 8,
shadowOffset: { width: 0, height: 4 },
},
iconContainer: {
width: 32,
height: 32,
borderRadius: 16,
alignItems: "center",
justifyContent: "center",
},
textContainer: {
flex: 1,
marginLeft: 12,
},
});