import React, { useState } from 'react'; import { Head, router } from '@inertiajs/react'; import AdminLayout from '@/Layouts/AdminLayout'; import { Search, FileText, Eye, CheckCircle, XCircle, Clock, Edit2, ZoomIn, X, AlertTriangle, ShieldCheck, Edit3, History, Sparkles, CheckSquare } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; export default function Verifications({ verifications, status }) { const [selectedItem, setSelectedItem] = useState(null); const [isDialogOpen, setIsDialogOpen] = useState(false); const [lightboxImage, setLightboxImage] = useState(null); // Vetting form overrides const [ocrOverrides, setOcrOverrides] = useState({}); const [isEditingOcr, setIsEditingOcr] = useState(false); const [rejectionReason, setRejectionReason] = useState(''); const [showRejectionForm, setShowRejectionForm] = useState(false); // Local mock verification queue containing OCR score mismatches const localQueue = [ { id: 101, worker_name: 'Fatima Zahra', nationality: 'Morocco', passport_number: 'MA9823471', processed_at: '2026-05-23 14:15', status: 'approved', confidence: 98, verification_method: 'Auto-OCR', document_type: 'Passport & Visa Scan', warnings: [], document_images: [ 'https://images.unsplash.com/photo-1544717305-2782549b5136?q=80&w=600&auto=format&fit=crop', ], ocr_data: { 'Name': 'Fatima Zahra', 'DOB': '1992-08-14', 'Nationality': 'Morocco', 'Passport No.': 'MA9823471', 'Expiry': '2030-11-20', } }, { id: 103, worker_name: 'Amina Diop', nationality: 'Senegal', passport_number: 'SN8765432', processed_at: '2026-05-23 11:30', status: 'flagged', confidence: 58, verification_method: 'Auto-OCR', document_type: 'Passport Scan', warnings: ['Blurry text region', 'Signature discrepancy flagged'], document_images: [ 'https://images.unsplash.com/photo-1580489944761-15a19d654956?q=80&w=600&auto=format&fit=crop' ], ocr_data: { 'Name': 'Amina Diop', 'DOB': '1994-12-01', 'Nationality': 'Senegal', 'Passport No.': 'SN8765432', 'Expiry': '2031-08-10', } }, { id: 104, worker_name: 'Siti Aminah', nationality: 'Indonesia', passport_number: 'B76543210', processed_at: '2026-05-22 16:40', status: 'flagged', confidence: 62, verification_method: 'Auto-OCR', document_type: 'Visa scan details', warnings: ['Document expiration alert (Expires in 5 days)'], document_images: [ 'https://images.unsplash.com/photo-1534528741775-53994a69daeb?q=80&w=600&auto=format&fit=crop' ], ocr_data: { 'Name': 'Siti Aminah', 'DOB': '1988-03-25', 'Nationality': 'Indonesia', 'Passport No.': 'B76543210', 'Expiry': '2026-05-28', } } ]; const activeList = localQueue.filter(item => { if (status === 'approved') return item.status === 'approved'; if (status === 'rejected') return item.status === 'flagged'; return true; }); const openReview = (item) => { setSelectedItem(item); setOcrOverrides(item.ocr_data || {}); setIsEditingOcr(false); setShowRejectionForm(false); setRejectionReason(''); setIsDialogOpen(true); }; const handleVerifySubmit = (action) => { router.post(`/admin/workers/${selectedItem.id}/verify`, { action, rejection_reason: action === 'reject' ? rejectionReason : null, ocr_overrides: ocrOverrides }, { onSuccess: () => { setIsDialogOpen(false); } }); }; return (
{/* Header overview and status */}

OCR Vetting Queue & Verification System

High-confidence auto-approvals, low-confidence warning audits, and inline OCR override triggers.

{/* Filter Tabs */}
{[ { label: 'All Audits', value: 'all' }, { label: 'Auto-Approved (High Confidence)', value: 'approved' }, { label: 'Vetting Flags (Low Confidence)', value: 'rejected' }, ].map((tab) => ( ))}
{/* Queue Summary widgets */}
System Auto-Approve Rate 92.4%
OCR Average Confidence Score 91.8%
Vetting Queue Flags 2 Pending review
{/* Verification Queue Datagrid */}
{activeList.map((item) => ( ))}
Worker Name Passport ID OCR Confidence Score Vetting Warnings Processed Date Action
{item.worker_name}
{item.nationality} • {item.document_type}
{item.passport_number}
90 ? 'bg-emerald-500' : item.confidence > 70 ? 'bg-blue-500' : 'bg-amber-500' }`} style={{ width: `${item.confidence}%` }} />
90 ? 'text-emerald-600' : item.confidence > 70 ? 'text-blue-600' : 'text-amber-600' }`}>{item.confidence}%
{item.warnings.length > 0 ? (
{item.warnings.map((w, idx) => ( {w} ))}
) : ( None (Safe) )}
{item.processed_at}
{/* Audit logs details grid */}

OCR Vetting Action Audit Logs

{[ { time: '2026-05-23 15:20', text: 'Admin Vetting Officer manually approved passport scan verification for Leila Bekri', ip: '192.168.1.5' }, { time: '2026-05-23 14:15', text: 'System OCR Passport auto-verification completed successfully for Fatima Zahra', ip: 'Auto-System' }, { time: '2026-05-23 13:42', text: 'System flagged passport scan of Grace Omondi due to blurred signature signature check failure', ip: 'Auto-System' }, ].map((log, idx) => (
{log.text}
{log.time} • IP: {log.ip}
))}
{/* Vetting Vetting Audit Dialog */} Vetting Manual Audit: {selectedItem?.worker_name}
80 ? 'bg-emerald-500 text-white shadow-emerald-500/20' : 'bg-amber-500 text-white shadow-amber-500/20' }`}> OCR Confidence: {selectedItem?.confidence}%
{/* Scanned proof & Warnings Column */}

Scanned Passport Scan Document

setLightboxImage(selectedItem?.document_images[0])} className="relative rounded-xl overflow-hidden border border-slate-200 bg-slate-100 cursor-zoom-in shadow-inner aspect-[4/3] max-h-72 group" > Verification Scan
Click to Zoom Document

Type: {selectedItem?.document_type}

{/* Warnings Box */} {selectedItem?.warnings?.length > 0 ? (
Suspicious Document Vetting Warning
    {selectedItem.warnings.map((w, idx) => (
  • {w}
  • ))}
) : (
Vetting passed checks. System matches signature algorithms perfectly.
)}
{/* OCR Data Extraction Form Column - Supports editing */}

Extracted Text Vitals

{Object.entries(ocrOverrides).map(([key, value]) => (
{isEditingOcr ? ( { const newVal = e.target.value; setOcrOverrides(prev => ({ ...prev, [key]: newVal })); }} /> ) : (
{value}
)}
))}
{/* Manual Rejection reason input */} {showRejectionForm ? (