import { notFound } from "next/navigation";
import { DetailBackLink } from "@/components/detail-back-link";
import { getShareLinksForEntity } from "@/modules/_core/share";
import { PlantDetail } from "@/modules/garden/components/plant-detail";
import { listCalendars } from "@/modules/garden/server/calendar-bridge";
import { getCareLogs, getCareSchedules, getPlant } from "@/modules/garden/server/queries";

export default async function PlantPage({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const [plant, careLogs, careSchedules, calendars, shareLinks] = await Promise.all([
    getPlant(id),
    getCareLogs(id),
    getCareSchedules(id),
    listCalendars(),
    getShareLinksForEntity("garden.plant", id),
  ]);
  if (!plant) notFound();

  return (
    <div className="page-content">
      <DetailBackLink href="/garden?tab=plants" label="Plants" className="mb-4" />
      <PlantDetail
        plant={plant}
        careLogs={careLogs}
        careSchedules={careSchedules}
        calendars={calendars}
        shareLinks={shareLinks}
      />
    </div>
  );
}
