import { notFound } from "next/navigation";
import { getPollById } from "@/lib/data";
import VoteForm from "@/components/VoteForm";
import type { Metadata } from "next";

interface PageProps {
  params: Promise<{ id: string }>;
}

export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
  const { id } = await params;
  const poll = getPollById(id);

  if (!poll) {
    return { title: "Poll niet gevonden" };
  }

  return {
    title: `${poll.question} — QuickPoll`,
    description: `Stem op: ${poll.options.join(", ")}`,
  };
}

export default async function PollPage({ params }: PageProps) {
  const { id } = await params;
  const poll = getPollById(id);

  if (!poll) {
    notFound();
  }

  return (
    <div className="max-w-2xl mx-auto">
      <h1 className="text-2xl font-bold text-gray-900 mb-6">
        {poll.question}
      </h1>
      <VoteForm poll={poll} />
    </div>
  );
}
