import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { useSyncContext } from '@/contexts/sync-context'; import { __ } from '@/utils/i18n'; import { formatDistanceToNow } from 'date-fns'; import { CloudAlert, CloudCheck, CloudOff, RefreshCw } from 'lucide-react'; import { useState } from 'react'; export function SyncStatusButton() { const { syncStatus, lastSyncTime, isOnline, sync, error } = useSyncContext(); const [isMenuOpen, setIsMenuOpen] = useState(false); const getIcon = () => { if (syncStatus === 'syncing') { return ; } if (syncStatus === 'error') { return ; } if (!isOnline) { return ; } return ; }; const getLastSyncText = () => { if (lastSyncTime) { return `Synced ${formatDistanceToNow(lastSyncTime, { addSuffix: true })}`; } return 'Not synced yet'; }; const getStatusText = () => { if (syncStatus === 'syncing') { return 'Syncing...'; } if (!isOnline) { return 'Offline'; } if (syncStatus === 'error') { return error || 'Sync failed'; } return getLastSyncText(); }; const handleSyncNow = () => { sync(); }; return (

{getStatusText()}

{ e.preventDefault(); handleSyncNow(); }} disabled={syncStatus === 'syncing' || !isOnline} > {__('Sync now')}
); }