import React, { useState } from "react"; import { ChevronsDownUp, ChevronsUpDown, AlertTriangle, FileText, } from "lucide-react"; import type { Problem } from "@/ipc/ipc_types"; type ProblemWithoutSnippet = Omit; interface MoreMinimoreProblemSummaryProps { summary?: string; children?: React.ReactNode; } interface ProblemItemProps { problem: ProblemWithoutSnippet; index: number; } const ProblemItem: React.FC = ({ problem, index }) => { return (
{index + 1}
{problem.file} {problem.line}:{problem.column} TS{problem.code}

{problem.message}

); }; export const MoreMinimoreProblemSummary: React.FC = ({ summary, children, }) => { const [isContentVisible, setIsContentVisible] = useState(false); // Parse problems from children content if available const problems: ProblemWithoutSnippet[] = React.useMemo(() => { if (!children || typeof children !== "string") return []; // Parse structured format with tags const problemTagRegex = /([^<]+)<\/problem>/g; const problems: ProblemWithoutSnippet[] = []; let match; while ((match = problemTagRegex.exec(children)) !== null) { try { problems.push({ file: match[1], line: parseInt(match[2], 10), column: parseInt(match[3], 10), message: match[5].trim(), code: parseInt(match[4], 10), }); } catch { return [ { file: "unknown", line: 0, column: 0, message: children, code: 0, }, ]; } } return problems; }, [children]); const totalProblems = problems.length; const displaySummary = summary || `${totalProblems} problems found (TypeScript errors)`; return (
setIsContentVisible(!isContentVisible)} data-testid="problem-summary" >
Auto-fix {displaySummary}
{isContentVisible ? ( ) : ( )}
{/* Content area - show individual problems */} {isContentVisible && totalProblems > 0 && (
{problems.map((problem, index) => ( ))}
)} {/* Fallback content area for raw children */} {isContentVisible && totalProblems === 0 && children && (
            {children}
          
)}
); };