import { CategoryService } from "@/services/category.service"
import { ItemService } from "@/services/item.service"

import UpdateItemForm from "../../_components/update.item.form"

export default async function AddItem({
  params,
}: {
  params: Promise<{ itemId: string }>
}) {
  const { itemId } = await params
  const categories = await CategoryService.findAll()
  const item = await ItemService.findByIdWithAssetCount(itemId)

  if (!item) {
    return <div>Item not found</div>
  }

  return (
    <div className="flex flex-col gap-4">
      {item?._count?.assets && item?._count.assets > 0 && (
        <div className="rounded-sm bg-red-100 p-4 text-red-800">
          <p>{`This item has already assets assigned to it.`}</p>
        </div>
      )}
      <div className="flex items-center justify-between gap-4">
        <h1 className="text-2xl font-bold">Edit Item</h1>
      </div>
      <UpdateItemForm categories={categories} item={item} />
    </div>
  )
}
