import { notFound } from "next/navigation";
import { getPublicElectionBySlug } from "@/lib/queries/election-filler-queries";
import { ElectionBallot } from "@/components/features/elections/ElectionBallot";

export const dynamic = "force-dynamic";

interface PublicElectionPageProps {
  params: { electionSlug: string };
  searchParams: { embed?: string };
}

export default async function PublicElectionPage({
  params,
  searchParams,
}: PublicElectionPageProps) {
  const data = await getPublicElectionBySlug(params.electionSlug);
  if (!data) notFound();

  if (data.positions.length === 0) {
    return (
      <div className="flex min-h-screen items-center justify-center bg-bg p-6 text-center">
        <p className="text-muted">This election has no positions yet.</p>
      </div>
    );
  }

  return (
    <ElectionBallot data={data} embed={searchParams.embed === "1"} />
  );
}
