"use client"

import { useEffect } from "react"
import { Button } from "@/components/ui/button"
import { AlertTriangle, RefreshCcw, Home } from "lucide-react"

export default function GlobalError({
  error,
  reset,
}: {
  error: Error & { digest?: string }
  reset: () => void
}) {
  useEffect(() => {
    console.error("[v0] Global application error:", error)
  }, [error])

  return (
    <html lang="fr">
      <body>
        <div className="flex min-h-screen flex-col items-center justify-center bg-background p-4">
          <div className="w-full max-w-md space-y-6 text-center">
            <div className="flex justify-center">
              <AlertTriangle className="h-16 w-16 text-destructive" />
            </div>

            <div className="space-y-2">
              <h1 className="text-2xl font-bold text-foreground">Erreur de l'application</h1>
              <p className="text-muted-foreground">
                Une erreur critique s'est produite. Veuillez réessayer ou retourner à l'accueil.
              </p>
            </div>

            <div className="space-y-3">
              <Button onClick={reset} className="w-full gap-2">
                <RefreshCcw className="h-4 w-4" />
                Réessayer
              </Button>

              <Button variant="outline" onClick={() => (window.location.href = "/")} className="w-full gap-2">
                <Home className="h-4 w-4" />
                Retour à l'accueil
              </Button>
            </div>

            {process.env.NODE_ENV === "development" && error.message && (
              <details className="mt-6 rounded-lg bg-secondary p-4 text-left text-sm">
                <summary className="cursor-pointer font-medium">Détails de l'erreur</summary>
                <pre className="mt-2 overflow-auto text-xs text-muted-foreground whitespace-pre-wrap">
                  {error.message}
                </pre>
              </details>
            )}
          </div>
        </div>
      </body>
    </html>
  )
}
