import Link from "next/link"; import { logCare } from "../server/actions"; import type { CareDueWidgetRow, GardenOverviewStats } from "../server/queries"; const CARE_ICONS: Record = { watering: "💧", fertilizing: "ðŸŒą", repotting: "ðŸŠī", pruning: "✂ïļ", "pest-control": "🐛", other: "📋", }; function urgencyLabel(days: number): { text: string; cls: string } { if (days < 0) return { text: `${Math.abs(days)}d overdue`, cls: "text-red-600 dark:text-red-400" }; if (days === 0) return { text: "due today", cls: "text-amber-600 dark:text-amber-400" }; return { text: `in ${days}d`, cls: "text-[var(--ink-mute)]" }; } // ─── Care-due widget ────────────────────────────────────────────────────────── export function CareDueWidget({ rows }: { rows: CareDueWidgetRow[] }) { if (rows.length === 0) { return

All plants are on schedule.

; } const displayed = rows.slice(0, 10); return (
{displayed.map((row) => { const { text, cls } = urgencyLabel(row.daysUntilDue); const icon = CARE_ICONS[row.careType] ?? "📋"; return (
{icon} {row.plantName} {text}
); })} {rows.length > 10 && ( View all ({rows.length}) → )}
); } function InlineLogButton({ plantId, careType }: { plantId: string; careType: string }) { async function action() { "use server"; await logCare({ plantId, careType }); } return (
); } // ─── Overview widget ────────────────────────────────────────────────────────── export function GardenOverviewWidget({ stats }: { stats: GardenOverviewStats }) { function nextCareLabel(): string { const n = stats.nextCare; if (!n) return "No upcoming care scheduled."; const dayText = n.daysUntilDue < 0 ? "overdue" : n.daysUntilDue === 0 ? "today" : `in ${n.daysUntilDue} day${n.daysUntilDue !== 1 ? "s" : ""}`; const careLabel = n.careType.charAt(0).toUpperCase() + n.careType.slice(1); return `${careLabel} ${n.plantName} — ${dayText}`; } return (
{stats.plantCount} {stats.plantCount === 1 ? "plant" : "plants"}
{stats.containerCount} {stats.containerCount === 1 ? "container" : "containers"}
{stats.overdueCount > 0 && (
{stats.overdueCount} overdue
)}

{nextCareLabel()}

View garden →
); }