import { getLeadsNeedingFollowUp } from "@/lib/lead-service"; import Link from "next/link"; const MAX_ROWS = 4; function initials(name: string): string { const parts = name.trim().split(/\s+/).filter(Boolean); if (parts.length === 0) return "?"; if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase(); return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase(); } function relativeDays(date: Date | string | null | undefined): string | null { if (!date) return "Mai contattato"; const d = date instanceof Date ? date : new Date(date); const diffMs = Date.now() - d.getTime(); const days = Math.floor(diffMs / (1000 * 60 * 60 * 24)); if (days <= 0) return "Contattato oggi"; if (days === 1) return "Contattato ieri"; return `Contattato ${days} giorni fa`; } export async function FollowUpWidget() { const leads = await getLeadsNeedingFollowUp(7); if (leads.length === 0) { return (
Tutti i lead sono aggiornati โ
{lead.name}
{lead.next_action ? lead.next_action : [lead.company, relativeDays(lead.last_contact_date)] .filter(Boolean) .join(" ยท ")}