import { usePage } from '@inertiajs/react';
import { useEffect, useRef } from 'react';
import { Toaster as SonnerToaster, toast } from 'sonner';
export function Toaster() {
    return (
        <SonnerToaster
            position="top-right"
            toastOptions={{
                classNames: {
                    toast: 'group toast shadow-lg border border-border',
                    title: 'text-sm font-medium',
                    description: 'text-sm text-muted-foreground',
                },
            }}
        />
    );
}
export function FlashToaster() {
    const flash = usePage<{ flash?: Record<string, string> }>().props.flash;
    const shown = useRef(new Set<string>());
    useEffect(() => {
        if (!flash) return;
        Object.entries(flash).forEach(([key, message]) => {
            if (!message || shown.current.has(key + message)) return;
            shown.current.add(key + message);
            switch (key) {
                case 'success':
                    toast.success(message);
                    break;
                case 'error':
                case 'danger':
                    toast.error(message);
                    break;
                case 'warning':
                    toast.warning(message);
                    break;
                default:
                    toast(message);
            }
        });
    }, [flash]);
    return null;
}
