import Link from "next/link"; import type { PlantListItemDto } from "../server/queries"; type Props = { plants: PlantListItemDto[]; }; function daysAgo(isoString: string): string { const diff = Date.now() - new Date(isoString).getTime(); const days = Math.floor(diff / 86_400_000); if (days === 0) return "today"; if (days === 1) return "yesterday"; return `${days}d ago`; } function healthBadgeClass(status: string): string { if (status === "healthy") return "badge-success"; if (status === "sick") return "badge-danger"; return "badge-warning"; } export function PlantList({ plants }: Props) { if (plants.length === 0) { return (

No plants yet.

Add your first plant
); } const groups = new Map(); for (const plant of plants) { const key = plant.containerId; if (!groups.has(key)) groups.set(key, { name: plant.containerName, items: [] }); groups.get(key)!.items.push(plant); } const entries = [...groups.entries()].sort(([a], [b]) => { if (a === null) return 1; if (b === null) return -1; return 0; }); return (
{plants.length} {plants.length === 1 ? "plant" : "plants"} Add plant
{entries.map(([containerId, group]) => (

{group.name ?? "Unassigned"}

{group.items.map((plant) => (
{plant.primaryImageUrl ? ( ) : (
🌱
)}

{plant.name}

{plant.healthStatus} {plant.lastWateredAt && ( Watered {daysAgo(plant.lastWateredAt)} )}
{plant.hasOverdueCare && (

Care overdue

)}
))}
))}
); }