import type { Metadata } from "next";
import { redirect } from "next/navigation";
import { LockKeyhole } from "lucide-react";
import { LoginForm } from "@/components/forms/login-form";
import { getCurrentProfile } from "@/lib/auth";
import { isSupabaseConfigured } from "@/lib/supabase/config";

export const metadata: Metadata = { title: "تسجيل الدخول", robots: { index: false, follow: false } };
export const dynamic = "force-dynamic";

export default async function LoginPage() {
  const profile = await getCurrentProfile();
  if (profile?.is_active) redirect(profile.role === "admin" ? "/admin" : "/donor");

  const configured = isSupabaseConfigured();
  return (
    <section className="grid min-h-dvh place-items-center px-3 py-6 sm:px-6">
      <div className="w-full max-w-md rounded-lg border border-[var(--border)] bg-white p-5 sm:p-8">
          <span className="grid size-11 place-items-center rounded-md bg-[#dceeed] text-[var(--primary)]">
            <LockKeyhole size={22} aria-hidden />
          </span>
          <h1 className="mt-5 text-xl font-black leading-8 sm:text-2xl">تسجيل دخول المسؤول والمتبرع</h1>
          <p className="mt-2 mb-7 text-sm leading-7 text-[var(--ink-soft)]">
            استخدم بريد المسؤول أو رقم هاتف المتبرع مع كلمة المرور.
          </p>
          <LoginForm configured={configured} />
      </div>
    </section>
  );
}
