import React, { useState } from 'react'; import { FileUp, BarChart2, Eye, Download, Info } from 'lucide-react'; export default function PlanComparison({ token, isArabic }) { const [file1, setFile1] = useState(null); const [file2, setFile2] = useState(null); const [pageNum, setPageNum] = useState(1); const [dpi, setDpi] = useState(150); const [diffUrl, setDiffUrl] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleCompare = async (e) => { e.preventDefault(); if (!file1 || !file2) return; setLoading(true); setError(''); setDiffUrl(''); const formData = new FormData(); formData.append('pdf_1', file1); formData.append('pdf_2', file2); formData.append('page_num', pageNum); formData.append('dpi', dpi); try { const res = await fetch("/api/workflow/compare", { method: 'POST', headers: { 'Authorization': `Bearer ${token}` }, body: formData }); if (!res.ok) { const errData = await res.json(); let errMsg = 'Failed to compare drawings.'; if (errData.detail) { if (typeof errData.detail === 'string') { errMsg = errData.detail; } else if (Array.isArray(errData.detail)) { errMsg = errData.detail.map(e => e.msg || JSON.stringify(e)).join(', '); } else if (typeof errData.detail === 'object') { errMsg = errData.detail.message || JSON.stringify(errData.detail); } } throw new Error(errMsg); } const blob = await res.blob(); const url = URL.createObjectURL(blob); setDiffUrl(url); } catch (err) { setError(err.message); } finally { setLoading(false); } }; return (

{isArabic ? 'مقارنة المخططات بصرياً' : 'Visual Plan Comparison Overlay'}

{isArabic ? 'قارن نسختين من المخطط لإظهار التعديلات والإضافات هندسياً. يتم تمييز العناصر المحذوفة باللون الأحمر، والعناصر المضافة باللون الأخضر.' : 'Compare two versions of architectural drawings to show edits. Deleted elements in Red, additions in Green.'}


{error && (
{error}
)}
{/* File 1 */}

{isArabic ? 'النسخة السابقة/القديمة (PDF)' : 'Version 1: Old Drawing (PDF)'}

setFile1(e.target.files[0])} style={{ fontSize: '0.85rem' }} /> {file1 &&

✓ {file1.name}

}
{/* File 2 */}

{isArabic ? 'النسخة الجديدة/المعدلة (PDF)' : 'Version 2: New Drawing (PDF)'}

setFile2(e.target.files[0])} style={{ fontSize: '0.85rem' }} /> {file2 &&

✓ {file2.name}

}
{/* Options */}
setPageNum(parseInt(e.target.value))} />
setDpi(parseInt(e.target.value))} style={{ width: '100%', marginTop: '12px' }} /> {dpi} DPI
{/* Comparison Output Display */} {diffUrl && (

{isArabic ? 'تراكب المقارنة البصرية' : 'Visual Comparison Output'}

{/* Color Code Legend */}
{isArabic ? 'العناصر المحذوفة (النسخة السابقة)' : 'Deletions (items removed)'}
{isArabic ? 'العناصر المضافة (النسخة الجديدة)' : 'Additions (new elements)'}
{isArabic ? 'العناصر غير المعدلة' : 'Unchanged elements'}
Visual plan diff overlay
{isArabic ? 'تحميل صورة الفروقات البصرية' : 'Download Visual Diff Image'}
)}
); }