import { useState } from "react"; import { Button } from "~/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger, } from "~/components/ui/popover"; import { Cloud, CloudOff, Wifi, WifiOff } from "lucide-react"; import { cn } from "~/lib/utils"; export function SyncButton({ healthyUntil, lastSync, }: { healthyUntil: Date; lastSync: Date; }) { const healthyUntilDate = new Date(healthyUntil) || new Date(0); const lastSyncDate = new Date(lastSync) || new Date(0); // Determine if the sync is healthy based on the healthyUntil date const isSync = healthyUntilDate > new Date(); const [isOpen, setIsOpen] = useState(false); const getIcon = () => { if (isSync) return ; return ; }; const getStatusColor = () => { if (isSync) return "text-primary"; return "text-muted-foreground"; }; const formatLastSync = (date: Date | null) => { if (!date) return "N/A"; const now = new Date(); const diff = now.getTime() - date.getTime(); const seconds = Math.floor(diff / 1000); const minutes = Math.floor(diff / 60000); const hours = Math.floor(minutes / 60); const days = Math.floor(hours / 24); if (minutes < 1) return `il y a ${seconds}s`; if (minutes < 60) return `il y a ${minutes}m`; if (hours < 24) return `il y a ${hours}h`; return `il y a ${days}j`; }; return (
{isSync ? ( ) : ( )} Status
{isSync ? "Connecté" : "Hors ligne"}
Dernière mis à jour : {formatLastSync(lastSyncDate)}
{/* TODO: {syncStatus.isOnline && syncStatus.status !== "syncing" && ( )} */}
); }