import { Head, Link, usePage } from '@inertiajs/react';
import { createPortal } from 'react-dom';
import { dashboard, register } from '@/routes';
import type { SharedData } from '@/types';
import { useInitials } from '@/hooks/use-initials';
import { usePwaInstall } from '@/hooks/use-pwa-install';
import { useMemo, useState, useRef, useEffect, useLayoutEffect } from 'react';

function getDashboardHref(role: string | undefined): string {
    if (role === 'partenaire') return '/dashboard-partenaire';
    if (role === 'livreur') return '/dashboard-livreur';
    return typeof dashboard.url === 'function' ? dashboard.url() : '/dashboard';
}

export default function Welcome({
    canRegister = true,
}: {
    canRegister?: boolean;
}) {
    const { auth, company } = usePage<
        SharedData & {
            company?: {
                name?: string | null;
                logoUrl?: string | null;
                logoPath?: string | null;
            };
        }
    >().props;
    const dashboardHref = useMemo(
        () => getDashboardHref(auth?.user?.role),
        [auth?.user?.role],
    );
    const companyName = company?.name ?? 'Entreprise de livraison';
    const [logoFailed, setLogoFailed] = useState(false);
    const logoUrl = useMemo(() => {
        if (company?.logoPath) {
            return `/storage/${company.logoPath}`;
        }
        return company?.logoUrl ?? null;
    }, [company?.logoPath, company?.logoUrl]);
    const getInitials = useInitials();
    const initials = getInitials(companyName);
    const { canInstall, isInstalled, promptInstall } = usePwaInstall();
    const [loginMenuOpen, setLoginMenuOpen] = useState(false);
    const loginMenuRef = useRef<HTMLDivElement>(null);
    const [dropdownPosition, setDropdownPosition] = useState<{ top: number; left: number; right: number } | null>(null);
    useEffect(() => {
        function handleClickOutside(event: MouseEvent) {
            const target = event.target as HTMLElement;
            if (loginMenuRef.current?.contains(target) || target.closest?.('[data-login-dropdown]')) return;
            setLoginMenuOpen(false);
        }
        if (loginMenuOpen) {
            document.addEventListener('mousedown', handleClickOutside);
        }
        return () => document.removeEventListener('mousedown', handleClickOutside);
    }, [loginMenuOpen]);

    useLayoutEffect(() => {
        if (!loginMenuOpen || !loginMenuRef.current) {
            setDropdownPosition(null);
            return;
        }
        const el = loginMenuRef.current;
        const update = () => {
            const rect = el.getBoundingClientRect();
            const vw = typeof window !== 'undefined' ? window.innerWidth : 400;
            const margin = 16;
            const isMobile = vw < 640;
            setDropdownPosition({
                top: rect.bottom + 8,
                left: isMobile ? margin : Math.max(margin, rect.right - 288),
                right: isMobile ? margin : vw - rect.right,
            });
        };
        update();
        window.addEventListener('scroll', update, true);
        window.addEventListener('resize', update);
        return () => {
            window.removeEventListener('scroll', update, true);
            window.removeEventListener('resize', update);
        };
    }, [loginMenuOpen]);

    return (
        <>
            <Head title="Bienvenue - Plateforme de Livraison">
                <link rel="preconnect" href="https://fonts.bunny.net" />
                <link
                    href="https://fonts.bunny.net/css?family=instrument-sans:400,500,600"
                    rel="stylesheet"
                />
            </Head>
            
            <div className="min-h-screen bg-gradient-to-br from-gray-50 via-white to-blue-50 dark:from-gray-900 dark:via-gray-800 dark:to-gray-900">
                {/* Navigation principale */}
                <header className="sticky top-0 z-50 w-full border-b border-gray-200/50 bg-white/80 backdrop-blur-md dark:border-gray-700/50 dark:bg-gray-900/80">
                    <div className="container mx-auto px-3 py-3 sm:px-4 sm:py-4">
                        <div className="flex min-w-0 flex-wrap items-center justify-between gap-3 sm:flex-nowrap">
                            {/* Logo */}
                            <div className="flex min-w-0 shrink-0 items-center gap-2 sm:space-x-3">
                                <div className="flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-gradient-to-br from-red-600 to-red-500 sm:h-10 sm:w-10 sm:rounded-xl">
                                    {!logoFailed && logoUrl ? (
                                        <img
                                            src={logoUrl}
                                            alt=""
                                            className="h-full w-full object-cover"
                                            onError={() => setLogoFailed(true)}
                                        />
                                    ) : (
                                        <span className="text-base font-bold text-white sm:text-lg">{initials}</span>
                                    )}
                                </div>
                                <div className="min-w-0">
                                    <h1 className="truncate text-base font-bold text-gray-900 dark:text-white sm:text-xl">
                                        {companyName}
                                    </h1>
                                    <p className="hidden text-xs text-gray-500 dark:text-gray-400 sm:block">
                                        Plateforme de livraison intelligente
                                    </p>
                                </div>
                            </div>

                            {/* Navigation */}
                            <nav className="flex shrink-0 flex-wrap items-center justify-end gap-2 sm:gap-4">
                                {canInstall && !isInstalled && (
                                    <button
                                        type="button"
                                        onClick={() => void promptInstall()}
                                        className="inline-flex items-center gap-1.5 rounded-lg border border-gray-300 bg-white px-2.5 py-2 text-xs font-medium text-gray-600 transition hover:bg-gray-50 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700 sm:px-3 sm:text-sm"
                                        title="Installer l’application (raccourci bureau)"
                                    >
                                        <svg className="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
                                        </svg>
                                        <span className="hidden sm:inline">Installer l’app</span>
                                    </button>
                                )}
                        {auth.user ? (
                            <Link
                                        href={dashboardHref}
                                        className="inline-flex items-center justify-center gap-1.5 rounded-lg bg-gradient-to-r from-red-600 to-red-500 px-3 py-2 text-sm font-medium text-white shadow-lg transition-all duration-300 hover:scale-105 hover:shadow-xl sm:gap-2 sm:px-6 sm:py-2.5"
                            >
                                        <svg className="h-4 w-4 shrink-0 sm:h-5 sm:w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" />
                                        </svg>
                                        <span className="whitespace-nowrap">Dashboard</span>
                            </Link>
                        ) : (
                            <>
                                        {/* Menu déroulant Se connecter */}
                                        <div className="relative" ref={loginMenuRef}>
                                            <button
                                                type="button"
                                                onClick={() => setLoginMenuOpen((o) => !o)}
                                                className="inline-flex items-center justify-center gap-1.5 rounded-lg border-2 border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-700 transition-all duration-300 hover:border-gray-400 hover:bg-gray-50 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 dark:hover:border-gray-500 dark:hover:bg-gray-700 sm:gap-2 sm:px-5 sm:py-2.5"
                                            >
                                                <svg className="h-4 w-4 shrink-0 sm:h-5 sm:w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1" />
                                                </svg>
                                                <span className="whitespace-nowrap">Se connecter</span>
                                                <svg className={`h-4 w-4 shrink-0 transition-transform ${loginMenuOpen ? 'rotate-180' : ''}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 9l-7 7-7-7" />
                                                </svg>
                                            </button>
                                            {loginMenuOpen && dropdownPosition && typeof document !== 'undefined' && createPortal(
                                                <div
                                                    data-login-dropdown
                                                    className="fixed z-[9999] max-h-[min(70vh,400px)] overflow-auto rounded-xl border border-gray-200 bg-white shadow-2xl dark:border-gray-700 dark:bg-gray-800 sm:max-w-72"
                                                    style={{
                                                        top: dropdownPosition.top,
                                                        left: dropdownPosition.left,
                                                        right: dropdownPosition.right,
                                                    }}
                                                >
                                                    <div className="p-2">
                                                        <p className="mb-2 px-2 text-xs font-medium text-gray-500 dark:text-gray-400">
                                                            Choisissez votre espace de connexion
                                                        </p>
                                                        <Link
                                                            href="/login-partenaire"
                                                            onClick={() => setLoginMenuOpen(false)}
                                                            className="flex items-center gap-3 rounded-lg border-2 border-blue-200 bg-blue-50/50 px-3 py-3 transition-all duration-200 hover:border-blue-400 hover:bg-blue-50 dark:border-blue-800 dark:bg-blue-900/20 dark:hover:border-blue-600 dark:hover:bg-blue-900/30 sm:px-4"
                                                        >
                                                            <div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-blue-600 text-white">
                                                                <svg className="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
                                                                </svg>
                                                            </div>
                                                            <div className="min-w-0 flex-1 overflow-hidden text-left">
                                                                <span className="block truncate font-semibold text-blue-700 dark:text-blue-300">Partenaire</span>
                                                                <span className="block truncate text-xs text-blue-600/80 dark:text-blue-400/80">E-commerce ou prestataire</span>
                                                            </div>
                                                        </Link>
                                                        <Link
                                                            href="/login-livreur"
                                                            onClick={() => setLoginMenuOpen(false)}
                                                            className="mt-2 flex items-center gap-3 rounded-lg border-2 border-green-200 bg-green-50/50 px-3 py-3 transition-all duration-200 hover:border-green-400 hover:bg-green-50 dark:border-green-800 dark:bg-green-900/20 dark:hover:border-green-600 dark:hover:bg-green-900/30 sm:px-4"
                                                        >
                                                            <div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-green-600 text-white">
                                                                <svg className="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
                                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
                                                                </svg>
                                                            </div>
                                                            <div className="min-w-0 flex-1 overflow-hidden text-left">
                                                                <span className="block truncate font-semibold text-green-700 dark:text-green-300">Livreur</span>
                                                                <span className="block truncate text-xs text-green-600/80 dark:text-green-400/80">Accéder à mes missions</span>
                                                            </div>
                                                        </Link>
                                                    </div>
                                                </div>,
                                                document.body
                                            )}
                                        </div>
                                {canRegister && (
                                    <Link
                                        href={register()}
                                                className="inline-flex items-center justify-center gap-1.5 rounded-lg bg-gradient-to-r from-green-600 to-green-500 px-3 py-2 text-sm font-medium text-white shadow-lg transition-all duration-300 hover:scale-105 hover:shadow-xl sm:gap-2 sm:px-6 sm:py-2.5"
                                    >
                                                <svg className="h-4 w-4 shrink-0 sm:h-5 sm:w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M18 9v3m0 0v3m0-3h3m-3 0h-3m-2-5a4 4 0 11-8 0 4 4 0 018 0zM3 20a6 6 0 0112 0v1H3v-1z" />
                                                </svg>
                                                <span className="whitespace-nowrap">S'inscrire</span>
                                    </Link>
                                )}
                            </>
                        )}
                    </nav>
                        </div>
                    </div>
                </header>

                {/* Contenu principal */}
                <main className="container mx-auto px-4 py-8 md:py-16">
                    <div className="grid lg:grid-cols-2 gap-12 items-center">
                        {/* Section gauche - Contenu textuel */}
                        <div className="space-y-8">
                            {/* Badge d'annonce */}
                            <div className="inline-flex items-center space-x-2 rounded-full bg-red-100 px-4 py-2 dark:bg-red-900/30">
                                <div className="h-2 w-2 animate-pulse rounded-full bg-red-600"></div>
                                <span className="text-sm font-medium text-red-700 dark:text-red-300">
                                    Solution de livraison intelligente
                                </span>
                            </div>

                            {/* Titre principal */}
                            <h1 className="text-4xl font-bold leading-tight md:text-5xl lg:text-6xl">
                                <span className="block text-gray-900 dark:text-white">
                                    Votre partenaire de
                                </span>
                                <span className="block bg-gradient-to-r from-red-600 via-blue-600 to-green-600 bg-clip-text text-transparent">
                                    livraison idéal
                                </span>
                            </h1>

                            {/* Description */}
                            <p className="text-lg text-gray-600 dark:text-gray-300 md:text-xl">
                                Rejoignez notre réseau de livraison premium et bénéficiez d'une expérience 
                                fluide, sécurisée et efficace. Que vous soyez partenaire commercial, 
                                livreur ou client, nous avons la solution adaptée à vos besoins.
                            </p>

                            {/* Section dédiée aux livreurs */}
                            {!auth.user && (
                                <div className="rounded-2xl border-2 border-green-200 bg-gradient-to-br from-green-50 to-emerald-50 p-6 dark:border-green-800 dark:from-green-900/30 dark:to-emerald-900/20">
                                    <div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
                                        <div className="flex items-center gap-3">
                                            <div className="flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-green-600 text-white">
                                                <svg className="h-6 w-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
                                                </svg>
                                            </div>
                                            <div>
                                                <h3 className="font-bold text-green-800 dark:text-green-200">Vous êtes livreur ?</h3>
                                                <p className="text-sm text-green-700/90 dark:text-green-300/80">
                                                    Connectez-vous ou rejoignez notre flotte de livreurs
                                                </p>
                                            </div>
                                        </div>
                                        <div className="flex flex-wrap gap-3">
                                            <Link
                                                href="/login-livreur"
                                                className="inline-flex items-center justify-center gap-2 rounded-xl bg-green-600 px-5 py-2.5 text-sm font-medium text-white shadow-md transition-all duration-300 hover:bg-green-700 hover:shadow-lg"
                                            >
                                                <svg className="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1" />
                                                </svg>
                                                Connexion livreur
                                            </Link>
                                            <Link
                                                href={register()}
                                                className="inline-flex items-center justify-center gap-2 rounded-xl border-2 border-green-600 bg-white px-5 py-2.5 text-sm font-medium text-green-700 transition-all duration-300 hover:bg-green-50 dark:border-green-500 dark:bg-gray-800 dark:text-green-300 dark:hover:bg-gray-700"
                                            >
                                                Devenir livreur
                                            </Link>
                                        </div>
                                    </div>
                                </div>
                            )}

                            {/* Statistiques */}
                            <div className="grid grid-cols-2 gap-6 md:grid-cols-3">
                                <div className="rounded-xl border border-gray-200 bg-white/50 p-4 backdrop-blur-sm dark:border-gray-700 dark:bg-gray-800/50">
                                    <div className="text-2xl font-bold text-red-600 dark:text-red-400">50K+</div>
                                    <div className="text-sm text-gray-600 dark:text-gray-400">Livraisons/mois</div>
                                </div>
                                <div className="rounded-xl border border-gray-200 bg-white/50 p-4 backdrop-blur-sm dark:border-gray-700 dark:bg-gray-800/50">
                                    <div className="text-2xl font-bold text-blue-600 dark:text-blue-400">200+</div>
                                    <div className="text-sm text-gray-600 dark:text-gray-400">Partenaires</div>
                                </div>
                                <div className="rounded-xl border border-gray-200 bg-white/50 p-4 backdrop-blur-sm dark:border-gray-700 dark:bg-gray-800/50">
                                    <div className="text-2xl font-bold text-green-600 dark:text-green-400">98%</div>
                                    <div className="text-sm text-gray-600 dark:text-gray-400">Satisfaction</div>
                                </div>
                            </div>

                            {/* Boutons d'action */}
                            <div className="flex flex-col space-y-4 sm:flex-row sm:space-y-0 sm:space-x-4">
                                {!auth.user && (
                                    <>
                                        <Link
                                            href="/login-partenaire"
                                            className="flex-1 rounded-xl border-2 border-blue-600 bg-white px-6 py-3 text-center font-medium text-blue-600 transition-all duration-300 hover:bg-blue-50 dark:border-blue-500 dark:bg-gray-800 dark:text-blue-400 dark:hover:bg-gray-700"
                                        >
                                            <div className="flex items-center justify-center space-x-2">
                                                <svg className="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1" />
                                                </svg>
                                                <span>Connexion partenaire</span>
                                            </div>
                                        </Link>
                                        {canRegister && (
                                            <Link
                                                href={register()}
                                                className="flex-1 rounded-xl bg-gradient-to-r from-green-600 to-green-500 px-6 py-3 text-center font-medium text-white shadow-lg transition-all duration-300 hover:shadow-xl"
                                            >
                                                <div className="flex items-center justify-center space-x-2">
                                                    <svg className="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M18 9v3m0 0v3m0-3h3m-3 0h-3m-2-5a4 4 0 11-8 0 4 4 0 018 0zM3 20a6 6 0 0112 0v1H3v-1z" />
                                            </svg>
                                                    <span>Créer un compte</span>
                        </div>
                                            </Link>
                                        )}
                                    </>
                                )}
                            </div>
                        </div>

                        {/* Section droite - Carte entreprise */}
                        <div className="relative">
                            <div className="relative overflow-hidden rounded-2xl border border-gray-200 bg-gradient-to-br from-white to-gray-50 shadow-2xl dark:border-gray-700 dark:from-gray-800 dark:to-gray-900">
                                {/* Effets de fond */}
                                <div className="absolute inset-0">
                                    <div className="absolute -right-20 -top-20 h-64 w-64 rounded-full bg-gradient-to-br from-red-500/10 to-transparent blur-3xl"></div>
                                    <div className="absolute -bottom-20 -left-20 h-64 w-64 rounded-full bg-gradient-to-tr from-blue-500/10 to-transparent blur-3xl"></div>
                                    <div className="absolute -bottom-10 -right-10 h-40 w-40 rounded-full bg-gradient-to-tl from-green-500/10 to-transparent blur-3xl"></div>
                                </div>

                                {/* Contenu de la carte */}
                                <div className="relative z-10 p-8">
                                    <div className="space-y-6">
                                        {/* En-tête de la carte */}
                                        <div className="flex items-center justify-between">
                                            <div className="rounded-full bg-gradient-to-r from-red-600 to-blue-600 px-4 py-1.5">
                                                <span className="text-sm font-semibold text-white">
                                                    Entreprise partenaire
                                                </span>
                                            </div>
                                            <div className="flex space-x-1">
                                                <div className="h-2 w-2 animate-pulse rounded-full bg-red-500"></div>
                                                <div className="h-2 w-2 animate-pulse rounded-full bg-blue-500" style={{ animationDelay: '0.2s' }}></div>
                                                <div className="h-2 w-2 animate-pulse rounded-full bg-green-500" style={{ animationDelay: '0.4s' }}></div>
                                            </div>
                                        </div>

                                        {/* Logo de l'entreprise */}
                                        <div className="flex justify-center">
                                            <div className="relative h-64 w-64 overflow-hidden rounded-2xl border-4 border-white bg-gradient-to-br from-gray-100 to-white shadow-2xl dark:border-gray-700 dark:from-gray-800 dark:to-gray-900">
                                    {!logoFailed && logoUrl ? (
                                            <img
                                                src={logoUrl}
                                                alt={companyName}
                                                className="h-full w-full object-cover"
                                            onError={() => setLogoFailed(true)}
                                            />
                                        ) : (
                                                    <div className="flex h-full w-full items-center justify-center bg-gradient-to-br from-red-500/20 via-blue-500/20 to-green-500/20">
                                                        <span className="text-4xl font-bold text-gray-800 dark:text-white">
                                                {initials}
                                            </span>
                                                    </div>
                                                )}
                                                
                                                {/* Overlay dégradé */}
                                                <div className="absolute inset-0 bg-gradient-to-t from-black/10 to-transparent"></div>
                                            </div>
                                        </div>

                                        {/* Informations de l'entreprise */}
                                        <div className="space-y-4 text-center">
                                            <h2 className="text-2xl font-bold text-gray-900 dark:text-white">
                                                {companyName}
                                            </h2>
                                            <p className="text-gray-600 dark:text-gray-300">
                                                Faites partie de notre réseau de confiance et bénéficiez 
                                                d'une solution de livraison complète et performante.
                                            </p>
                                            
                                            {/* Avantages */}
                                            <div className="grid grid-cols-2 gap-3 pt-4">
                                                <div className="rounded-lg bg-red-50 p-3 dark:bg-red-900/20">
                                                    <div className="flex items-center justify-center space-x-2">
                                                        <svg className="h-5 w-5 text-red-600 dark:text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
                                                        </svg>
                                                        <span className="text-sm font-medium text-red-700 dark:text-red-300">Rapide</span>
                                                    </div>
                                                </div>
                                                <div className="rounded-lg bg-blue-50 p-3 dark:bg-blue-900/20">
                                                    <div className="flex items-center justify-center space-x-2">
                                                        <svg className="h-5 w-5 text-blue-600 dark:text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
                                                        </svg>
                                                        <span className="text-sm font-medium text-blue-700 dark:text-blue-300">Sécurisé</span>
                                                    </div>
                                                </div>
                                                <div className="rounded-lg bg-green-50 p-3 dark:bg-green-900/20">
                                                    <div className="flex items-center justify-center space-x-2">
                                                        <svg className="h-5 w-5 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
                                                        </svg>
                                                        <span className="text-sm font-medium text-green-700 dark:text-green-300">Efficace</span>
                                                    </div>
                                                </div>
                                                <div className="rounded-lg bg-gray-100 p-3 dark:bg-gray-700">
                                                    <div className="flex items-center justify-center space-x-2">
                                                        <svg className="h-5 w-5 text-gray-700 dark:text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
                                                        </svg>
                                                        <span className="text-sm font-medium text-gray-700 dark:text-gray-300">Réseau</span>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            {/* Éléments décoratifs flottants */}
                            <div className="absolute -left-4 top-1/4 h-8 w-8 animate-bounce rounded-full bg-red-500/20"></div>
                            <div className="absolute -right-4 bottom-1/4 h-12 w-12 animate-bounce rounded-full bg-blue-500/20" style={{ animationDelay: '0.5s' }}></div>
                            <div className="absolute -bottom-4 left-1/3 h-6 w-6 animate-bounce rounded-full bg-green-500/20" style={{ animationDelay: '1s' }}></div>
                        </div>
                    </div>

                    {/* Section des fonctionnalités */}
                    <div className="mt-20">
                        <div className="text-center">
                            <h2 className="text-3xl font-bold text-gray-900 dark:text-white md:text-4xl">
                                Pourquoi choisir <span className="text-red-600">{companyName}</span> ?
                                    </h2>
                            <p className="mx-auto mt-4 max-w-2xl text-gray-600 dark:text-gray-300">
                                Une plateforme complète conçue pour optimiser votre expérience de livraison
                            </p>
                        </div>

                        <div className="mt-12 grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
                            {/* Fonctionnalité 1 */}
                            <div className="group relative overflow-hidden rounded-2xl border border-gray-200 bg-white p-6 transition-all duration-300 hover:border-red-300 hover:shadow-xl dark:border-gray-700 dark:bg-gray-800">
                                <div className="mb-4 flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-red-500 to-red-600">
                                    <svg className="h-6 w-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
                                    </svg>
                                </div>
                                <h3 className="mb-2 text-xl font-bold text-gray-900 dark:text-white">
                                    Suivi en temps réel
                                </h3>
                                <p className="text-gray-600 dark:text-gray-300">
                                    Suivez vos livraisons minute par minute avec notre système de géolocalisation avancé.
                                </p>
                            </div>

                            {/* Fonctionnalité 2 */}
                            <div className="group relative overflow-hidden rounded-2xl border border-gray-200 bg-white p-6 transition-all duration-300 hover:border-blue-300 hover:shadow-xl dark:border-gray-700 dark:bg-gray-800">
                                <div className="mb-4 flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-blue-500 to-blue-600">
                                    <svg className="h-6 w-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
                                    </svg>
                                </div>
                                <h3 className="mb-2 text-xl font-bold text-gray-900 dark:text-white">
                                    Sécurité maximale
                                </h3>
                                <p className="text-gray-600 dark:text-gray-300">
                                    Vos colis sont assurés et protégés tout au long du processus de livraison.
                                </p>
                            </div>

                            {/* Fonctionnalité 3 */}
                            <div className="group relative overflow-hidden rounded-2xl border border-gray-200 bg-white p-6 transition-all duration-300 hover:border-green-300 hover:shadow-xl dark:border-gray-700 dark:bg-gray-800">
                                <div className="mb-4 flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-green-500 to-green-600">
                                    <svg className="h-6 w-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
                                    </svg>
                                </div>
                                <h3 className="mb-2 text-xl font-bold text-gray-900 dark:text-white">
                                    Livraison express
                                </h3>
                                <p className="text-gray-600 dark:text-gray-300">
                                    Livraison garantie en moins de 24h dans la plupart des zones métropolitaines.
                                </p>
                            </div>
                        </div>
                    </div>
                </main>

                {/* Pied de page */}
                <footer className="mt-20 border-t border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900">
                    <div className="container mx-auto px-4 py-8">
                        <div className="flex flex-col items-center justify-between space-y-4 md:flex-row md:space-y-0">
                            <div className="flex items-center space-x-3">
                                <div className="flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-xl bg-gradient-to-br from-red-600 to-red-500">
                                    {!logoFailed && logoUrl ? (
                                        <img
                                            src={logoUrl}
                                            alt=""
                                            className="h-full w-full object-cover"
                                            onError={() => setLogoFailed(true)}
                                        />
                                    ) : (
                                        <span className="text-lg font-bold text-white">{initials}</span>
                                    )}
                                </div>
                                <div>
                                    <h3 className="font-bold text-gray-900 dark:text-white">{companyName}</h3>
                                    <p className="text-sm text-gray-600 dark:text-gray-400">
                                        © {new Date().getFullYear()} Tous droits réservés
                                    </p>
                                </div>
                            </div>
                            
                            <div className="flex flex-wrap items-center justify-center gap-x-6 gap-y-2">
                                <Link
                                    href="/login-partenaire"
                                    className="font-medium text-blue-600 transition-colors hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300"
                                >
                                    Espace Partenaire
                                </Link>
                                <Link
                                    href="/login-livreur"
                                    className="font-medium text-green-600 transition-colors hover:text-green-700 dark:text-green-400 dark:hover:text-green-300"
                                >
                                    Espace Livreur
                                </Link>
                                <a href="#" className="text-gray-600 transition-colors hover:text-red-600 dark:text-gray-400 dark:hover:text-red-400">
                                    Confidentialité
                                </a>
                                <a href="#" className="text-gray-600 transition-colors hover:text-blue-600 dark:text-gray-400 dark:hover:text-blue-400">
                                    Conditions
                                </a>
                                <a href="#" className="text-gray-600 transition-colors hover:text-green-600 dark:text-gray-400 dark:hover:text-green-400">
                                    Contact
                                </a>
                            </div>
                        </div>
                </div>
                </footer>
            </div>
        </>
    );
}