import { getTranslations } from "next-intl/server";
import { requireSession } from "@/server/auth";
import { dbForTenant } from "@/server/db";
import { requirePermission } from "@/server/rbac";
import { createAsset } from "@/server/actions/assets";
import { AssetForm } from "@/components/asset-form";

export default async function NewAssetPage() {
  const session = await requireSession();
  requirePermission(session, "asset:write");
  const t = await getTranslations("assets");

  const db = dbForTenant(session.user.tenantId);
  const users = await db.user.findMany({
    where: { status: "ACTIVE" },
    select: { id: true, name: true },
    orderBy: { name: "asc" },
  });

  return (
    <main className="flex-1 p-6">
      <h1 className="text-xl font-semibold">{t("createTitle")}</h1>
      <div className="mt-6">
        <AssetForm action={createAsset} users={users} cancelHref="/assets" />
      </div>
    </main>
  );
}
