import { useOnlineStatus, usePendingPostsCount, useSyncPendingPosts } from '@/hooks/useOfflineCache'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { Wifi, WifiOff, Cloud, CloudOff, Loader2 } from 'lucide-react'; import { cn } from '@/lib/utils'; interface OfflineIndicatorProps { className?: string; showWhenOnline?: boolean; } export function OfflineIndicator({ className, showWhenOnline = false }: OfflineIndicatorProps) { const isOnline = useOnlineStatus(); const { data: pendingCount } = usePendingPostsCount(); const { isSyncing } = useSyncPendingPosts(); // Don't show when online (unless explicitly requested or there are pending posts) if (isOnline && !showWhenOnline && !pendingCount && !isSyncing) { return null; } return (
{/* Connection Status */}
{isOnline ? ( ) : ( )}

{isOnline ? 'Connected' : 'Offline Mode'}

{isOnline ? 'All features available' : 'Browsing cached spots'}

{/* Pending Posts */} {pendingCount !== undefined && pendingCount > 0 && (
{pendingCount} pending post{pendingCount > 1 ? 's' : ''} {isSyncing && ( Syncing )}

{isOnline ? 'Publishing when connection stabilizes...' : 'Will be published when back online'}

)} {/* Offline Features Info */} {!isOnline && (

Available offline:

  • Browse previously viewed spots
  • View cached spot details
  • Queue posts for later
)}
); }