File size: 3,251 Bytes
6711fd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { Button } from "./button";
import { Card, CardContent, CardHeader, CardTitle } from "./card";
import { Badge } from "./badge";
import { AlertTriangle, RefreshCw, Home, Bug } from "lucide-react";

interface ErrorFallbackProps {
  error?: Error;
  resetErrorBoundary?: () => void;
  title?: string;
  description?: string;
}

export const ErrorFallback = ({ 
  error, 
  resetErrorBoundary, 
  title = "حدث خطأ غير متوقع",
  description = "نعتذر عن هذا الخطأ. يرجى المحاولة مرة أخرى."
}: ErrorFallbackProps) => {
  
  const handleReload = () => {
    window.location.reload();
  };

  const handleGoHome = () => {
    window.location.href = '/';
  };

  return (
    <div className="min-h-screen flex items-center justify-center p-4">
      <Card className="max-w-md w-full card-elegant border-destructive/20">
        <CardHeader className="text-center pb-4">
          <div className="flex justify-center mb-4">
            <div className="p-4 bg-destructive/10 rounded-full">
              <AlertTriangle className="w-12 h-12 text-destructive animate-pulse" />
            </div>
          </div>
          
          <Badge variant="destructive" className="mx-auto mb-3">
            <Bug className="w-3 h-3 mr-1" />
            خطأ في النظام
          </Badge>
          
          <CardTitle className="text-xl text-foreground">{title}</CardTitle>
        </CardHeader>

        <CardContent className="text-center space-y-4">
          <p className="text-muted-foreground leading-relaxed">
            {description}
          </p>
          
          {error && (
            <details className="text-left">
              <summary className="cursor-pointer text-xs text-muted-foreground hover:text-foreground">
                تفاصيل الخطأ التقنية
              </summary>
              <pre className="text-xs mt-2 p-2 bg-secondary/20 rounded text-destructive overflow-auto max-h-32">
                {error.message}
              </pre>
            </details>
          )}
          
          <div className="flex flex-col gap-3 pt-4">
            {resetErrorBoundary && (
              <Button 
                onClick={resetErrorBoundary}
                variant="default"
                className="w-full"
              >
                <RefreshCw className="w-4 h-4 mr-2" />
                المحاولة مرة أخرى
              </Button>
            )}
            
            <Button 
              onClick={handleReload}
              variant="outline"
              className="w-full"
            >
              <RefreshCw className="w-4 h-4 mr-2" />
              إعادة تحميل الصفحة
            </Button>
            
            <Button 
              onClick={handleGoHome}
              variant="ghost"
              className="w-full"
            >
              <Home className="w-4 h-4 mr-2" />
              العودة للرئيسية
            </Button>
          </div>
          
          <p className="text-xs text-muted-foreground pt-2">
            إذا استمر الخطأ، يرجى التواصل مع الدعم الفني
          </p>
        </CardContent>
      </Card>
    </div>
  );
};