import { notFound } from "next/navigation";
import { getPublicSurveyBySlug } from "@/lib/queries/filler-queries";
import { SurveyFiller } from "@/components/features/filler/SurveyFiller";

export const dynamic = "force-dynamic";

interface PublicSurveyPageProps {
  params: { surveySlug: string };
  searchParams: { embed?: string };
}

export default async function PublicSurveyPage({
  params,
  searchParams,
}: PublicSurveyPageProps) {
  const data = await getPublicSurveyBySlug(params.surveySlug);

  if (!data) {
    notFound();
  }

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

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