"use client" import { AlertTriangle, Check, ChevronDown, ChevronUp, Eye, ImageIcon, RefreshCw, X, } from "lucide-react" import { useState } from "react" import Image from "@/components/image-with-basepath" import { useDictionary } from "@/hooks/use-dictionary" import type { ValidationResult } from "@/lib/diagram-validator" export type ValidationStatus = | "idle" | "capturing" | "validating" | "success" | "success_with_warnings" | "failed" | "error" | "skipped" export interface ValidationState { status: ValidationStatus attempt?: number maxAttempts?: number result?: ValidationResult error?: string imageData?: string // Base64 PNG data URL } interface ValidationCardProps { state: ValidationState onImproveWithSuggestions?: (feedback: string) => void } export function ValidationCard({ state, onImproveWithSuggestions, }: ValidationCardProps) { const dict = useDictionary() const [isExpanded, setIsExpanded] = useState( state.status === "validating" || state.status === "failed", ) const [hasRequestedImprovement, setHasRequestedImprovement] = useState(false) // Generate improvement feedback from validation result const generateImprovementFeedback = (): string => { if (!state.result) return "" const lines: string[] = [] lines.push( "Please improve the diagram based on the following visual analysis feedback:", ) lines.push("") if (state.result.issues.length > 0) { lines.push("Issues to address:") for (const issue of state.result.issues) { lines.push( ` - [${issue.severity}] ${issue.type}: ${issue.description}`, ) } lines.push("") } if (state.result.suggestions.length > 0) { lines.push("Suggestions for improvement:") for (const suggestion of state.result.suggestions) { lines.push(` - ${suggestion}`) } lines.push("") } lines.push("Regenerate the diagram with these improvements applied.") return lines.join("\n") } const handleImproveClick = () => { if ( !onImproveWithSuggestions || !state.result || hasRequestedImprovement ) return setHasRequestedImprovement(true) const feedback = generateImprovementFeedback() onImproveWithSuggestions(feedback) } // Check if we should show the improve button const showImproveButton = onImproveWithSuggestions && state.result && (state.status === "success" || state.status === "success_with_warnings" || state.status === "skipped") && (state.result.issues.length > 0 || state.result.suggestions.length > 0) const getStatusDisplay = () => { switch (state.status) { case "capturing": return { label: dict.validation.capturing, color: "text-blue-600 bg-blue-50", icon: (
), } case "validating": return { label: state.attempt ? dict.validation.validatingWithAttempt .replace("{attempt}", String(state.attempt)) .replace("{max}", String(state.maxAttempts || 3)) : dict.validation.validating, color: "text-blue-600 bg-blue-50", icon: (
), } case "success": return { label: dict.validation.valid, color: "text-green-600 bg-green-50", icon: