import Image from "next/image"; import Link from "next/link"; import { notFound } from "next/navigation"; import type { Metadata } from "next"; import { getPlantWithDiseases } from "@/lib/api/diseases-db"; import { getPlantDescription } from "@/lib/display-helpers"; import BetaNotice from "@/components/BetaNotice"; import DiseaseCards from "./DiseaseCards"; import PlantViewTracker from "@/components/PlantViewTracker"; import FlagPlantImage from "@/components/FlagPlantImage"; interface Props { params: Promise<{ plantId: string }>; } export async function generateStaticParams() { const { getDb } = await import("@/lib/db/index"); const { plants } = await import("@/lib/db/schema"); const db = getDb(); const rows = await db.select({ id: plants.id }).from(plants); return rows.map((p: { id: string }) => ({ plantId: p.id, })); } export async function generateMetadata({ params }: Props): Promise { const { plantId } = await params; const result = await getPlantWithDiseases(plantId); if (!result) { return { title: "Plant Not Found" }; } return { title: `${result.plant.commonName} — Diseases & Care`, description: `Learn about ${result.plant.commonName} (${result.plant.scientificName}) diseases, symptoms, causes, and treatments. ${result.diseases.length} diseases documented.`, }; } // ─── Plant Detail Page ─── export default async function PlantDetailPage({ params }: Props) { const { plantId } = await params; const result = await getPlantWithDiseases(plantId); if (!result) { notFound(); } const { plant, diseases } = result; const description = getPlantDescription( plant.commonName, plant.scientificName, plant.category, plant.family, ); return ( <>
{/* Breadcrumb */} {/* Plant hero */}
{/* Plant image */}
{plant.imageUrl ? ( {plant.commonName} ) : (
)}

{plant.commonName}

{plant.scientificName}

Family: {plant.family} {" · "} Category: {plant.category}

{description}

{plant.careSummary}
{/* Identify disease CTA */}

🧐 Spot a problem on your {plant.commonName.toLowerCase()}?

Upload a photo for AI-powered disease identification.

📸 Identify a Disease
{/* Disease list */}

Known Diseases

{diseases.length === 0 ? "No diseases currently documented for this plant." : `${diseases.length} ${ diseases.length === 1 ? "disease" : "diseases" } documented for ${plant.commonName}.`}

{diseases.length > 0 ? ( ) : (

Disease data for {plant.commonName} is being researched and will be added soon.

)}
); }