"use client";

import { AuthView } from "@neondatabase/auth/react";
import { useRouter } from "next/navigation";
import { useEffect } from "react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { ThemeToggle } from "@/components/ui/theme-toggle";
import { authClient } from "@/lib/auth/client";

export default function PlatformLoginPage() {
  const router = useRouter();
  const { data, isPending } = authClient.useSession();

  useEffect(() => {
    if (!isPending && data?.session) {
      router.push("/platform/dashboard");
    }
  }, [data, isPending, router]);

  if (isPending) {
    return (
      <div className="min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900">
        <div className="text-center">Loading...</div>
      </div>
    );
  }

  return (
    <div className="min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900 relative">
      <div className="absolute top-4 right-4">
        <ThemeToggle />
      </div>
      <Card className="w-full max-w-md">
        <CardHeader className="text-center">
          <CardTitle className="text-2xl font-bold">Platform Login</CardTitle>
          <p className="text-muted-foreground">
            Sign in to the Notso AI platform management dashboard
          </p>
        </CardHeader>
        <CardContent>
          <AuthView pathname="sign-in" />
        </CardContent>
      </Card>
    </div>
  );
}
