import { getQuestion } from "@/lib/api";
import { QuestionDetail } from "@/components/questions/question-detail";
import { ProblemWorkspace } from "@/components/editor";
import { notFound } from "next/navigation";

export default async function QuestionDetailPage({
  params,
}: {
  params: Promise<{ slug: string }>;
}) {
  const { slug } = await params;

  let question;
  try {
    question = await getQuestion(slug);
  } catch {
    notFound();
  }

  // Show interactive workspace if the question has test cases
  if (question.function_signature && question.visible_test_cases) {
    return <ProblemWorkspace question={question} />;
  }

  // Fall back to read-only view for questions without test cases
  return <QuestionDetail question={question} />;
}
