import React, { useMemo } from 'react'; import { CheckCircle, AlertTriangle, MessageCircleWarning } from 'lucide-react'; import { Alert, AlertDescription } from '@/components/alert/alert'; import type { ValidationResult } from '@/lib/data/sql-import/sql-validator'; import { Separator } from '@/components/separator/separator'; import { ScrollArea } from '@/components/scroll-area/scroll-area'; import { Spinner } from '@/components/spinner/spinner'; interface SQLValidationStatusProps { validation?: ValidationResult | null; errorMessage: string; isAutoFixing?: boolean; onErrorClick?: (line: number) => void; } export const SQLValidationStatus: React.FC = ({ validation, errorMessage, isAutoFixing = false, onErrorClick, }) => { const hasErrors = useMemo( () => validation?.errors.length && validation.errors.length > 0, [validation?.errors] ); const hasWarnings = useMemo( () => validation?.warnings && validation.warnings.length > 0, [validation?.warnings] ); const wasAutoFixed = useMemo( () => validation?.warnings?.some((w) => w.message.includes('Auto-fixed') ) || false, [validation?.warnings] ); if (!validation && !errorMessage && !isAutoFixing) return null; if (isAutoFixing) { return ( <>
Auto-fixing SQL syntax errors...
); } // If we have parser errors (errorMessage) after validation if (errorMessage && !hasErrors) { return ( <>

{errorMessage}

); } return ( <> {hasErrors ? (
{validation?.errors .slice(0, 3) .map((error, idx) => (
: {error.message} {error.suggestion && (
{error.suggestion}
)}
))} {validation?.errors && validation?.errors.length > 3 ? (
{validation.errors.length - 3} more error {validation.errors.length - 3 > 1 ? 's' : ''}
) : null}
) : null} {wasAutoFixed && !hasErrors ? ( SQL syntax errors were automatically fixed. Your SQL is now ready to import. ) : null} {hasWarnings && !hasErrors ? (
Import Info:
{validation?.warnings.map( (warning, idx) => (
• {warning.message}
) )}
) : null} {!hasErrors && !hasWarnings && !errorMessage && validation ? (
SQL syntax validated successfully
) : null} ); };