"use server"

import { AssetWithAssignment } from "@/lib/types"
import { AssetService } from "@/services/asset.service"
import { ItemService } from "@/services/item.service"
import { RecipientService } from "@/services/recipient.service"

import EditAssetForm from "../../_components/edit.asset.form"

export default async function EditAssetPage({
  params,
}: {
  params: Promise<{ assetId: string }>
}) {
  const { assetId } = await params
  const items = await ItemService.findAll()
  const recipients = await RecipientService.findAll()
  const asset = await AssetService.findById(assetId)

  if (!asset) {
    return <div>Asset not found</div>
  }

  return (
    <div className="flex flex-col gap-4">
      <div className="flex items-center justify-between gap-4">
        <h1 className="text-2xl font-bold">Edit Asset</h1>
      </div>
      <EditAssetForm
        items={items}
        recipients={recipients}
        asset={asset as unknown as AssetWithAssignment}
      />
    </div>
  )
}
