import { useCallback, useMemo, useState } from 'react'; import { formatShareableErrorReport, getErrorSummary } from '../../api/errors'; import { __ } from '../../lib/i18n'; type Props = { error: unknown; onRetry?: () => void; title?: string; }; /** * Human-readable error + copyable support bundle (Slack / email / ticket). */ export function ApiErrorPanel({ error, onRetry, title = __('Something went wrong', 'sikshya') }: Props) { const report = useMemo(() => formatShareableErrorReport(error), [error]); const summary = useMemo(() => getErrorSummary(error), [error]); const [copied, setCopied] = useState(false); const handleCopy = useCallback(async () => { try { await navigator.clipboard.writeText(report.fullText); setCopied(true); window.setTimeout(() => setCopied(false), 2000); } catch { setCopied(false); } }, [report.fullText]); return (

{title}

{summary}

{__( 'Copy the report below and send it to Sikshya support so we can reproduce the issue.', 'sikshya' )}

          {report.fullText}
        
{onRetry ? ( ) : null}
); }