import { UpdateAssignmentFormType } from "@/lib/schemas/assignment.schemas"
import { AssetService } from "@/services/asset.service"
import { AssignmentService } from "@/services/assignment.service"
import { ItemService } from "@/services/item.service"
import { RecipientService } from "@/services/recipient.service"

import AssignmentForm from "../../_components/edit.assignment.form"
export default async function EditAssignmentPage({
  params,
}: {
  params: Promise<{ assignamentId: string }>
}) {
  const { assignamentId } = await params
  const assignment = await AssignmentService.findById(assignamentId)
  const recipients = await RecipientService.findAll()
  const items = await ItemService.findAllWithStock()
  const assets = await AssetService.findAll()

  if (!assignment) {
    return <div>Assignment not found</div>
  }

  return (
    <div>
      <AssignmentForm
        recipients={recipients}
        items={items}
        assets={assets}
        initialData={assignment as UpdateAssignmentFormType}
      />
    </div>
  )
}
