import { isLocale, type Locale } from "@/i18n/routes";
import { getDict } from "@/i18n/dictionaries";
import { getDb } from "@/lib/db";
import { listProjects, getProfile } from "@/lib/models";
import { AdminShell } from "@/components/admin/admin-shell";

export default async function DashboardPage() {
  const locale: Locale = "de"; // Admin ist sprach-neutral über die Texte in DE/EN, Render in DE.
  const dict = getDict(locale);
  const db = getDb();
  const projects = listProjects(db, locale);
  const profile = getProfile(db, locale);
  const featured = projects.filter((p) => p.featured).length;
  return (
    <AdminShell locale={locale} title={dict.admin.dashboardTitle} active="dashboard">
      <div className="grid gap-4 md:grid-cols-3">
        <div className="ascii-box">
          <p className="font-mono text-xs uppercase text-muted">{dict.admin.dashboardProfile}</p>
          <p className="mt-2 font-mono text-sm">{profile.handle} · {profile.realName}</p>
          <p className="mt-1 text-xs text-muted">{profile.role}</p>
        </div>
        <div className="ascii-box">
          <p className="font-mono text-xs uppercase text-muted">{dict.admin.dashboardProjects}</p>
          <p className="mt-2 font-mono text-2xl">{projects.length}</p>
          <p className="mt-1 text-xs text-muted">{featured} featured</p>
        </div>
        <div className="ascii-box">
          <p className="font-mono text-xs uppercase text-muted">{dict.home.lastUpdatedLabel}</p>
          <p className="mt-2 font-mono text-sm">{profile.updatedAt}</p>
        </div>
      </div>
      <p className="mt-6 text-sm text-muted">{dict.admin.dashboardSeed}</p>
    </AdminShell>
  );
}
