import { notFound } from "next/navigation"
import { getReviewPageInitData } from "./action"
import { OptimizationReviewClient } from "./review-client"

interface ReviewPageProps {
  params: Promise<{ traceId: string }>
}

export default async function OptimizationReviewPage({ params }: ReviewPageProps) {
  const { traceId } = await params

  const initData = await getReviewPageInitData(traceId)

  // No session — auth middleware will redirect
  if (!initData) {
    return null
  }

  // Event not found
  if (!initData.event) {
    notFound()
  }

  return (
    <OptimizationReviewClient
      traceId={traceId}
      initialEvent={initData.event as any}
      initialComments={initData.comments as any}
      initialStagingCode={initData.stagingCode as any}
    />
  )
}
