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