import { GraduationCap } from "lucide-react";
import { UserRole } from "@prisma/client";

import { requireRole } from "@/lib/auth-utils";
import { prisma } from "@/lib/prisma";
import { ErzieherList } from "./_components/erzieher-list";

export const metadata = { title: "ErzieherInnen · Kita-Planer" };

export default async function ErzieherPage() {
  const session = await requireRole([UserRole.ADMIN]);

  const educators = await prisma.educator.findMany({
    where: { kitaId: session.user.kitaId! },
    select: {
      id: true,
      firstName: true,
      lastName: true,
      active: true,
    },
    orderBy: [{ lastName: "asc" }, { firstName: "asc" }],
  });

  return (
    <div className="flex h-full flex-col gap-6 p-6">
      <div className="flex items-start justify-between gap-4">
        <div>
          <h1 className="flex items-center gap-2 text-2xl font-bold tracking-tight">
            <GraduationCap className="h-6 w-6 text-primary" />
            ErzieherInnen-Verwaltung
          </h1>
          <p className="mt-1 max-w-2xl text-sm text-muted-foreground">
            Stammdaten des Kita-Personals für interne Planung und spätere
            Notdienst-Alarmierung.
          </p>
        </div>
      </div>

      <ErzieherList educators={educators} />
    </div>
  );
}
