import { useEffect, useState } from "react"; import { WifiOff } from "lucide-react"; import { useOnlineStatus } from "../hooks/useOnlineStatus"; interface OfflineBannerProps { queuedCount?: number; } /** * Amber offline status banner shown at the top of the screen when offline. * Auto-dismisses 3 seconds after reconnection when the queue is empty. */ export function OfflineBanner({ queuedCount = 0 }: OfflineBannerProps) { const isOnline = useOnlineStatus(); const [visible, setVisible] = useState(!isOnline); useEffect(() => { if (!isOnline) { setVisible(true); return; } // Online transition: hide after 3s if no queued messages if (queuedCount === 0) { const timer = setTimeout(() => setVisible(false), 3000); return () => clearTimeout(timer); } }, [isOnline, queuedCount]); if (!visible) return null; const text = queuedCount > 0 ? `You're offline — ${queuedCount} message${queuedCount === 1 ? "" : "s"} queued` : "You're offline — messages will send when you reconnect"; return (