import { notFound } from "next/navigation"

import { getAnnouncementById } from "@/modules/announcements/data-access"
import { getGrades } from "@/modules/school/data-access"
import { AnnouncementForm } from "@/modules/announcements/components/announcement-form"

export const dynamic = "force-dynamic"

export default async function EditAnnouncementPage({
  params,
}: {
  params: Promise<{ id: string }>
}) {
  const { id } = await params

  const [announcement, grades] = await Promise.all([
    getAnnouncementById(id),
    getGrades(),
  ])

  if (!announcement) notFound()

  return (
    <div className="flex h-full flex-col space-y-8 p-8">
      <div>
        <h2 className="text-2xl font-bold tracking-tight">Edit Announcement</h2>
        <p className="text-muted-foreground">Update the announcement details below.</p>
      </div>
      <AnnouncementForm
        mode="edit"
        announcement={announcement}
        grades={grades.map((g) => ({ id: g.id, name: g.name }))}
      />
    </div>
  )
}
