import React from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { CheckCircle2, AlertCircle, Info, XCircle, X } from 'lucide-react'; import { create } from 'zustand'; // Store to manage global feedback state export const useFeedbackStore = create((set) => ({ notifications: [], notify: (type, title, message) => { const id = Date.now(); set((state) => ({ notifications: [...state.notifications, { id, type, title, message }] })); // Auto remove after 5s setTimeout(() => { set((state) => ({ notifications: state.notifications.filter(n => n.id !== id) })); }, 5000); }, remove: (id) => set((state) => ({ notifications: state.notifications.filter(n => n.id !== id) })) })); const icons = { success: , error: , warning: , info: }; const colors = { success: "border-emerald-500/20 bg-emerald-50/50 dark:bg-emerald-500/10", error: "border-rose-500/20 bg-rose-50/50 dark:bg-rose-500/10", warning: "border-amber-500/20 bg-amber-50/50 dark:bg-amber-500/10", info: "border-blue-500/20 bg-blue-50/50 dark:bg-blue-500/10" }; export const FeedbackContainer = () => { const { notifications, remove } = useFeedbackStore(); return (
{notifications.map((n) => ( {/* Background Glow */}
{icons[n.type]}

{n.title}

{n.message}

{/* Progress Bar (Auto-expire) */} ))}
); }; export const useFeedback = () => { const notify = useFeedbackStore(s => s.notify); return { success: (title, message) => notify('success', title || 'Sucesso!', message), error: (title, message) => notify('error', title || 'Ops!', message), warning: (title, message) => notify('warning', title || 'Atenção!', message), info: (title, message) => notify('info', title || 'Informação', message), // Friendly back-end error parser handleBackendError: (error) => { console.error(error); const msg = error.response?.data?.message || error.message || 'Erro desconhecido na comunicação com o servidor.'; notify('error', 'Erro do Sistema', msg); }, notifyFields: (fields) => { notify('warning', 'Campos Obrigatórios', `Por favor, preencha: ${fields.join(', ')}`); } }; };