import { redirect } from 'next/navigation';
import { getCurrentUser } from '@/lib/auth';
import LoginForm from '@/components/LoginForm';
import Image from 'next/image';

export default async function LoginPage() {
  const user = await getCurrentUser();
  
  if (user) {
    redirect('/dashboard');
  }

  return (
    <div className="min-h-screen flex items-center justify-center bg-cwhite px-4 sm:px-6 lg:px-8 py-8 sm:py-12">
      <div className="w-full max-w-lg bg-white rounded-2xl sm:rounded-3xl shadow-lg py-6 sm:py-8 px-6 sm:px-8 md:px-12">
        {/* Logo */}
        <div className="flex justify-center mb-4 sm:mb-6">
          <Image
            src="/logo.svg"
            alt="MAD Logo"
            width={100}
            height={100}
            className="w-20 h-20 sm:w-24 sm:h-24 md:w-[120px] md:h-[120px]"
            priority
          />
        </div>

        {/* Heading */}
        <div className="text-center mb-5 sm:mb-6">
          <h2 className="text-xl sm:text-2xl font-bold text-gray-900 mb-2">
            Content de vous revoir
          </h2>
          <p className="text-xs sm:text-sm text-gray-600 px-2">
            Connectez-vous pour accéder à la plateforme.
          </p>
        </div>

        {/* Login Form */}
        <LoginForm />

        {/* Footer */}
        <div className="mt-6 sm:mt-8 text-center text-[10px] sm:text-xs text-gray-500 px-2">
          © {new Date().getFullYear()} MAD - <a href="https://legouix.dev" target="_blank" className="text-lblue hover:text-dblue">Propulsé par LGX</a>
        </div>
      </div>
    </div>
  );
}
