import React from 'react';
import { Link } from 'react-router-dom';
import { cn } from '@/lib/utils';

import { Card } from '@/components/ui/card';

interface AuthLayoutProps {
  title: string;
  subtitle?: string;
  children: React.ReactNode;
  footerLinks?: Array<{ label: string; to: string }>;
  className?: string;
}

export function AuthLayout({
  title,
  subtitle,
  children,
  footerLinks,
  className,
}: AuthLayoutProps) {
  return (
    <div
      className={cn(
        'min-h-screen flex items-center justify-center bg-background py-12 px-4 sm:px-6 lg:px-8 relative overflow-hidden',
        className,
      )}
      role="main"
      aria-label="Page d'authentification"
    >
      {/* Background Effects */}
      <div className="absolute inset-0 overflow-hidden pointer-events-none">
        <div className="absolute top-0 right-0 w-96 h-96 bg-cyan/10 rounded-full blur-3xl animate-pulse" />
        <div className="absolute bottom-0 left-0 w-96 h-96 bg-magenta/10 rounded-full blur-3xl animate-pulse" style={{ animationDelay: '1s' }} />
      </div>

      <div className="max-w-[440px] w-full mx-auto space-y-8 relative z-10 animate-fade-in">
        {/* Logo and Title */}
        <header className="text-center">
          <div className="flex items-center justify-center mb-6">
            <div
              className="h-12 w-12 rounded-xl bg-gradient-to-br from-cyan-500 to-cyan-600 flex items-center justify-center shadow-[0_0_20px_rgba(var(--cyan-500),0.5)]"
              aria-hidden="true"
            >
              <span className="text-background font-bold text-2xl">V</span>
            </div>
            <span className="ml-3 font-bold text-3xl text-foreground">Veza</span>
          </div>
          <h1
            id="auth-form-title"
            className="text-3xl font-bold text-foreground mb-2"
          >
            {title}
          </h1>
          {subtitle && (
            <p className="text-sm text-muted-foreground" role="doc-subtitle">
              {subtitle}
            </p>
          )}
        </header>

        {/* Content Card */}
        <Card
          variant="glass"
          padding="lg"
          className="w-full shadow-2xl"
          aria-labelledby="auth-form-title"
        >
          {children}
        </Card>

        {/* Footer Links */}
        {footerLinks && footerLinks.length > 0 && (
          <nav
            className="text-center space-x-4"
            aria-label="Navigation d'authentification"
          >
            {footerLinks.map((link) => (
              <Link
                key={link.to}
                to={link.to}
                className="text-sm text-kodo-steel dark:text-kodo-steel hover:text-white dark:hover:text-white transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 rounded"
              >
                {link.label}
              </Link>
            ))}
          </nav>
        )}
      </div>
    </div>
  );
}
