import type { Metadata } from "next";
import { db, ingredients, asc } from "@epicure/db";
import { requireFullAdminPage } from "@/lib/require-admin-page";
import { IngredientsManager } from "@/components/admin/ingredients-manager";

export const metadata: Metadata = {};

export default async function AdminIngredientsPage() {
  await requireFullAdminPage();

  const rows = await db.select().from(ingredients).orderBy(asc(ingredients.name));

  return (
    <div className="space-y-6">
      <div>
        <h1 className="text-2xl font-bold tracking-tight">Ingredients</h1>
        <p className="text-muted-foreground text-sm mt-1">
          Canonical ingredients and their name variants (e.g. &quot;sel&quot;, &quot;sel fin&quot;, &quot;table salt&quot;) — lets pantry items and recipe ingredients written differently still be recognized as the same thing. Used by pantry add/edit, can-cook scoring, auto-deduct on cook, and shopping-list pantry-awareness.
        </p>
      </div>
      <IngredientsManager
        initialIngredients={rows.map((r) => ({
          id: r.id,
          name: r.name,
          aliases: r.aliases,
          category: r.category,
        }))}
      />
    </div>
  );
}
