import { useState, useEffect } from 'react'; import { WifiOff, RefreshCw, X, Eye } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; interface NetworkErrorBannerProps { isOffline: boolean; pendingCount?: number; onRetryNow?: () => Promise; onViewQueue?: () => void; estimatedRetryTime?: Date; } export function NetworkErrorBanner({ isOffline, pendingCount = 0, onRetryNow, onViewQueue, estimatedRetryTime, }: NetworkErrorBannerProps) { const [isVisible, setIsVisible] = useState(false); const [isRetrying, setIsRetrying] = useState(false); const [countdown, setCountdown] = useState(null); useEffect(() => { setIsVisible(isOffline || pendingCount > 0); }, [isOffline, pendingCount]); useEffect(() => { if (!estimatedRetryTime) { setCountdown(null); return; } const interval = setInterval(() => { const now = Date.now(); const remaining = Math.max(0, estimatedRetryTime.getTime() - now); setCountdown(Math.ceil(remaining / 1000)); if (remaining <= 0) { clearInterval(interval); setCountdown(null); } }, 1000); return () => clearInterval(interval); }, [estimatedRetryTime]); const handleRetryNow = async () => { if (!onRetryNow) return; setIsRetrying(true); try { await onRetryNow(); } finally { setIsRetrying(false); } }; if (!isVisible) return null; return (

{isOffline ? 'You are offline' : 'Network Issue Detected'}

{pendingCount > 0 ? ( <> {pendingCount} submission{pendingCount !== 1 ? 's' : ''} pending {countdown !== null && countdown > 0 && ( ยท Retrying in {countdown}s )} ) : ( 'Changes will sync when connection is restored' )}

{pendingCount > 0 && onViewQueue && ( )} {onRetryNow && ( )}
); }