import { PosReconV2DetailPage } from "@/components/xml-apis/pos-recon-v2/pos-recon-v2-detail-page"
import { fetchPosReconV2View } from "../_lib/pos-recon-v2-server-api"

type PageProps = {
  params: Promise<{ id: string }>
  searchParams: Promise<{ status?: string; corporate_id?: string }>
}

export default async function PosReconV2DetailRoute({ params, searchParams }: PageProps) {
  const { id } = await params
  const sp = await searchParams
  const runId = Number(id) || 0
  // Always load the full run so cards can filter client-side without reloads.
  const result = await fetchPosReconV2View({
    id: runId,
    status: "",
    corporateId: Number(sp.corporate_id || 0) || 0,
  })

  return (
    <PosReconV2DetailPage
      runId={runId}
      initialRun={result.run}
      initialGroups={result.groups}
      initialCounts={result.counts}
      statusLabels={result.statusLabels}
      initialStatus={sp.status || ""}
      corporateId={result.corporateId}
      initialErrorMessage={result.errorMessage}
    />
  )
}
