import React, { useState, useEffect } from 'react'; import { ZoomIn, ZoomOut, Plus, Trash2, Info } from 'lucide-react'; import { cacheUrl } from '../../cacheUrl'; const ImageWithRetry = ({ src, alt, style, isArabic }) => { const [retryKey, setRetryKey] = useState(0); const [loading, setLoading] = useState(true); // Reset loading state when src changes useEffect(() => { setLoading(true); setRetryKey(0); }, [src]); return (
{loading && (
{isArabic ? 'جاري تجهيز الصورة...' : 'Processing image...'}
)} {alt} setLoading(false)} onError={() => { setLoading(true); // If image 404s (background task still running), retry after 1.5s setTimeout(() => setRetryKey(prev => prev + 1), 1500); }} />
); }; export default function ClassifyStep({ classifiedPages, setClassifiedPages, selectedPageIndex, setSelectedPageIndex, zoom, setZoom, isArabic, handleSaveClassifications, loading }) { const handleDuplicate = (e, idx) => { e.stopPropagation(); const updated = [...classifiedPages]; const newPage = { ...updated[idx], detected_type: 'unknown' }; updated.splice(idx + 1, 0, newPage); setClassifiedPages(updated); }; const handleRemove = (e, idx, pageNum) => { e.stopPropagation(); const count = classifiedPages.filter(p => p.page_num === pageNum).length; if (count > 1) { const updated = [...classifiedPages]; updated.splice(idx, 1); setClassifiedPages(updated); } }; return (
{/* Step Instructions */}

{isArabic ? ( <>ما المطلوب في هذه الخطوة؟ (المراجعة اليدوية لتصنيف الصفحات إلزامية) ) : ( <>What to do in this step? (manual checking the pages classification is must ) )}

{isArabic ? 'قام الذكاء الاصطناعي بمحاولة التعرف على صفحات المخطط وتصنيفها. المطلوب منك هو مراجعة هذه القائمة بالنظر للصفحة على اليسار، وتأكيد نوع المخطط (قواعد، أعمدة، معماري... إلخ) أو تغييره من القائمة المنسدلة إذا كان غير صحيح. يمكنك تكرار الصفحة لتصنيفها بأكثر من نوع بالضغط على (+).' : 'The AI has attempted to automatically classify your drawings. Please review the list on the right while looking at the preview on the left. Correct any misclassified pages using the dropdown menu. You can also duplicate a page using (+) if it contains multiple schedules.'}

{/* Left Page Image Viewer */}
{isArabic ? 'معاينة المخطط' : 'Drawing Preview'} (Page {selectedPageIndex + 1})
{classifiedPages[selectedPageIndex] && ( )}
{/* Right Classify Options */}

{isArabic ? '2. نتائج التصنيف التلقائي للصفحات' : '2. Page Classification Results'}

{isArabic ? 'يرجى مراجعة وتأكيد تصنيف الصفحات. اختر الصفحة لمشاهدة المخطط على اليسار وتعديل نوعه.' : 'Review classifications. Select a page, review its image on the left, and adjust the category if needed.'}

{classifiedPages.map((page, idx) => (
setSelectedPageIndex(idx)} style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '10px 14px', borderRadius: '8px', border: '1px solid var(--border-color)', backgroundColor: idx === selectedPageIndex ? 'var(--primary-glow)' : 'var(--bg-secondary)', cursor: 'pointer' }} >
{page.pdf === 'structural' ? (isArabic ? 'إنشائي' : 'Structural') : (isArabic ? 'معماري' : 'Architectural')} P{page.page_num}
{classifiedPages.filter(p => p.page_num === page.page_num).length > 1 && ( )}
))}
); }