import { useState } from 'react'; import { useAI } from '../hooks/useAI'; import type { Issue } from '../lib/types'; import { markdownToHtml } from '../lib/markdown'; interface Props { issue: Issue | null; onClose: () => void; } const WCAG_URL: Record = { '1.1.1': 'https://www.w3.org/WAI/WCAG21/Understanding/non-text-content.html', '1.4.3': 'https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html', '2.1.1': 'https://www.w3.org/WAI/WCAG21/Understanding/keyboard.html', '2.4.7': 'https://www.w3.org/WAI/WCAG21/Understanding/focus-visible.html', '3.1.1': 'https://www.w3.org/WAI/WCAG21/Understanding/language-of-page.html', '4.1.2': 'https://www.w3.org/WAI/WCAG21/Understanding/name-role-value.html', }; /** Renders an AI suggestion with full markdown formatting. */ function AiSuggestion({ text }: { text: string }) { return (

Suggested fix

); } export default function DetailPanel({ issue, onClose }: Props) { const { run, hasProvider } = useAI(); const [aiOutput, setAiOutput] = useState(null); const [aiError, setAiError] = useState(null); const [activeAction, setActiveAction] = useState(null); if (!issue) { return (

Select an issue to see details.

); } const wcagUrl = WCAG_URL[issue.wcag]; const callAI = async (task: string) => { setAiOutput(null); setAiError(null); setActiveAction(task); try { const result = await run.mutateAsync({ task, params: { title: issue.title, wcag: issue.wcag, html: issue.element ?? '', context: issue.description, }, }); if (result.error) { setAiError(result.error); } else { setAiOutput(result.text ?? ''); } } catch (e) { setAiError((e as Error).message); } finally { setActiveAction(null); } }; return ( ); }