"use client"; import React, { useState } from "react"; import { AlertTriangle, RotateCcw, ChevronDown, ChevronUp, HelpCircle, WifiOff, ShieldAlert, Clock, } from "lucide-react"; import { parseError, FormattedError } from "@/lib/error-utils"; export interface ErrorStateProps { title?: string; description?: string; error?: Error | unknown; /** Action called when clicking "Try Again" */ onRetry?: () => void; /** Custom action slot */ action?: React.ReactNode; /** Compact presentation for cards/widgets */ compact?: boolean; /** Whether to show technical diagnostic details */ showDiagnostics?: boolean; className?: string; style?: React.CSSProperties; } /** * EasyUI-inspired ErrorState component for widgets, cards, and page sections. * Features Neo-Industrial dark aesthetics, spring-like pulse icon, and collapsible diagnostic trace. */ export function ErrorState({ title: customTitle, description: customDescription, error, onRetry, action, compact = false, showDiagnostics = true, className = "", style, }: ErrorStateProps) { const [showDetails, setShowDetails] = useState(false); const formatted: FormattedError = parseError(error); const displayTitle = customTitle || formatted.title; const displayDescription = customDescription || formatted.message; // Select contextual icon based on error category let IconComponent = AlertTriangle; let accentColor = "var(--color-error, #EF4444)"; if (formatted.isNetworkError) { IconComponent = WifiOff; accentColor = "var(--color-warning, #F59E0B)"; } else if (formatted.isAuthError || formatted.isForbidden) { IconComponent = ShieldAlert; accentColor = "var(--color-secondary, #8B5CF6)"; } else if (formatted.isRateLimit) { IconComponent = Clock; accentColor = "var(--color-warning, #F59E0B)"; } if (compact) { return (
{displayDescription}
{/* Status & Code Pill if available */} {formatted.code && (