import React, { createContext, useContext, useState, ReactNode } from 'react'; import { Modal, View, Text, TouchableOpacity, TouchableWithoutFeedback } from 'react-native'; import { CheckCircle, XCircle, Info, AlertTriangle } from 'lucide-react-native'; type AlertType = 'success' | 'error' | 'info' | 'warning'; interface AlertContextData { showAlert: (type: AlertType, title: string, message: string) => void; hideAlert: () => void; } const AlertContext = createContext({} as AlertContextData); const ALERT_CONFIG = { success: { icon: CheckCircle, color: 'text-green-600', bgColor: 'bg-green-100', btnColor: 'bg-green-600', }, error: { icon: XCircle, color: 'text-red-600', bgColor: 'bg-red-100', btnColor: 'bg-red-600', }, info: { icon: Info, color: 'text-sky-600', bgColor: 'bg-sky-100', btnColor: 'bg-sky-600', }, warning: { icon: AlertTriangle, color: 'text-orange-600', bgColor: 'bg-orange-100', btnColor: 'bg-orange-600', }, }; export const AlertProvider = ({ children }: { children: ReactNode }) => { const [visible, setVisible] = useState(false); const [title, setTitle] = useState(''); const [message, setMessage] = useState(''); const [type, setType] = useState('info'); const showAlert = (newType: AlertType, newTitle: string, newMessage: string) => { setType(newType); setTitle(newTitle); setMessage(newMessage); setVisible(true); }; const hideAlert = () => { setVisible(false); }; const { icon: Icon, color, bgColor, btnColor } = ALERT_CONFIG[type]; return ( {children} {/* IL COMPONENTE ALERT MODALE */} {/* Backdrop scuro */} {/* Contenitore Alert */} {/* Icona Cerchiata */} {/* Testi */} {title} {message} {/* Pulsante OK */} Ok, ho capito ); }; export const useAlert = () => useContext(AlertContext);