"use client"

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

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

  return (
    <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">
          <AlertCircle className="h-16 w-16 text-destructive" />
        </div>

        <div className="space-y-2">
          <h1 className="text-2xl font-bold text-foreground">Une erreur s'est produite</h1>
          <p className="text-muted-foreground">
            L'application a rencontré un problème. Cela peut être dû à une connexion instable.
          </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">
            Retour à l'accueil
          </Button>
        </div>

        {process.env.NODE_ENV === "development" && (
          <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">{error.message}</pre>
          </details>
        )}
      </div>
    </div>
  )
}
