import DashboardLayout from "@/components/DashboardLayout"
import { auth } from "@/lib/auth"
import { prisma } from "@/lib/prisma"
import ReportForm from "@/components/ReportForm"

export default async function ReportPage({ params }: { params: Promise<{ shiftId: string; machineId: string }> }) {
  const { shiftId, machineId } = await params
  const session = await auth()
  const worker = await prisma.worker.findFirst({
    where: { email: session?.user?.email || "" }
  })

  if (!worker) return <div>Worker not found</div>

  const report = await prisma.machineShiftReport.findFirst({
    where: {
      shiftId,
      machineId,
      workerId: worker.id
    },
    include: {
      shift: true,
      machine: true,
      worker: true
    }
  })

  if (!report) return <div>Report not found</div>

  return (
    <DashboardLayout requiredRole="operator">
      <ReportForm report={report} />
    </DashboardLayout>
  )
}
