import { useEffect } from 'react';
import { toast } from 'sonner';

export interface Flash {
  success?: string | null;
  error?: string | null;
  info?: string | null;
  warning?: string | null;
}

// Hook simple para mostrar errores automáticamente
export function useFlashToasts({ errors }: { errors?: Record<string, string> }) {
  useEffect(() => {
    if (errors) {
      Object.values(errors).forEach((msg) => {
        if (msg) toast.error(msg);
      });
    }
  }, [errors]);
}

// Función simple para mostrar flash cuando TÚ quieras
export function showFlash(flash: Flash) {
  if (flash.success) toast.success(flash.success);
  if (flash.error) toast.error(flash.error);
  if (flash.info) toast.info(flash.info);
  if (flash.warning) toast.warning(flash.warning);
}
