import React, { useState } from 'react'; import { Head, Link, router } from '@inertiajs/react'; import EmployerLayout from '../../../Layouts/EmployerLayout'; import { useTranslation } from '../../../lib/LanguageContext'; import { CheckCircle2, Globe2, Briefcase, DollarSign, Calendar, HeartHandshake, Languages, MessageSquare, Bookmark, ArrowLeft, Sparkles, FileText, ShieldCheck, Search, Star, Share2, Flag, X, UserCheck, AlertTriangle, User, Phone, MapPin } from 'lucide-react'; import { toast } from 'sonner'; const getLanguageFlag = (lang) => { const flags = { 'English': '🇬🇧', 'Arabic': '🇦🇪', 'Tagalog': '🇵🇭', 'Hindi': '🇮🇳', 'Swahili': '🇰🇪', 'French': '🇫🇷', 'Indonesian': '🇮🇩' }; return flags[lang] || '🌐'; }; const getExpiryStatus = (expiryDate) => { if (!expiryDate) return { text: 'Expiry Pending', color: 'text-slate-500 bg-slate-50 border-slate-200' }; const expiry = new Date(expiryDate); const today = new Date(); expiry.setHours(0,0,0,0); today.setHours(0,0,0,0); const diffTime = expiry.getTime() - today.getTime(); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); if (diffDays < 0) { return { text: `Expired \${Math.abs(diffDays)} days ago`, color: 'text-rose-700 bg-rose-50 border-rose-200 font-black' }; } else if (diffDays === 0) { return { text: 'Expires today', color: 'text-amber-700 bg-amber-50 border-amber-200 font-black' }; } else { return { text: `Valid until \${expiryDate} (Expires in \${diffDays} days)`, color: 'text-emerald-700 bg-emerald-50 border-emerald-150 font-black' }; } }; const safeRender = (value) => { if (value === null || value === undefined) return 'N/A'; if (typeof value === 'object') { if (value.name) return String(value.name); if (value.full_name) return String(value.full_name); return JSON.stringify(value); } return String(value); }; export default function Show({ worker }) { const { t } = useTranslation(); const passportDoc = worker.documents?.find(d => d.type === 'passport'); const visaDoc = worker.documents?.find(d => d.type === 'visa'); const [showReportModal, setShowReportModal] = useState(false); const [reportReason, setReportReason] = useState(''); const [reportDetails, setReportDetails] = useState(''); const [isShortlisted, setIsShortlisted] = useState(false); // Hiring flow states const [availabilityStatus, setAvailabilityStatus] = useState(worker.availability_status); const [showHiredModal, setShowHiredModal] = useState(false); const [showHireConfirmModal, setShowHireConfirmModal] = useState(false); // Reviews state const [showReviewModal, setShowReviewModal] = useState(false); const [newRating, setNewRating] = useState(5); const [newComment, setNewComment] = useState(''); const [workerReviews, setWorkerReviews] = useState(worker.reviews || []); const handleShare = () => { navigator.clipboard.writeText(window.location.href); toast.success(t('profile_link_copied', 'Profile link copied to clipboard!'), { description: t('profile_link_copied_desc', 'You can now share this URL with your family or sponsor contacts.') }); }; const handleReportSubmit = (e) => { e.preventDefault(); if (!reportReason) { toast.error(t('select_report_reason', 'Please select a reason for reporting.')); return; } toast.success(t('report_submitted', 'Worker report submitted successfully'), { description: t('report_submitted_desc', "Our admin compliance team will investigate this worker's credentials within 24 hours.") }); setShowReportModal(false); setReportReason(''); setReportDetails(''); }; const handleReviewSubmit = (e) => { e.preventDefault(); if (!newComment.trim()) { toast.error(t('add_comment', 'Please add a comment.')); return; } const newReview = { id: Date.now(), employer_name: t('you_verified_sponsor', 'You (Verified Sponsor)'), rating: newRating, date: t('today', 'Today'), comment: newComment, }; setWorkerReviews([newReview, ...workerReviews]); toast.success(t('review_posted', 'Review posted successfully!'), { description: t('review_posted_desc', 'Your trust feedback is live and helps other sponsors hire securely.') }); setShowReviewModal(false); setNewComment(''); }; const handleToggleShortlist = () => { setIsShortlisted(!isShortlisted); router.post('/employer/shortlist/toggle', { worker_id: worker.id }, { preserveScroll: true, onSuccess: () => { toast.success(isShortlisted ? t('removed_from_shortlist', 'Removed from Shortlist') : t('added_to_shortlist', 'Added to Shortlist')); } }); }; const handleMarkHired = () => { router.post(`/employer/workers/${worker.id}/mark-hired`, {}, { preserveScroll: true, onSuccess: () => { setAvailabilityStatus('Hired'); setShowHiredModal(true); toast.success(t('marked_hired', 'Worker successfully marked as Hired!'), { description: t('marked_hired_desc', 'Sponsorship direct match finalized. Please leave an anonymous trust review!') }); } }); }; return (
{/* Back Link */}
{t('back_to_find_workers', 'BACK TO FIND WORKERS')}
{/* Header Card with Clean Premium White BG */}
{worker.photo ? ( {worker.name} ) : ( )}

{worker.name}

{/* Passport verification status bar & Visa Status */}
{worker.visa_expiry_date ? (
Visa Exp: {worker.visa_expiry_date}
) : (
Visa Expiry Pending
)} {worker.visa_status && (worker.visa_status.toLowerCase().includes('tourist') || worker.visa_status.toLowerCase().includes('visit')) ? (
{worker.visa_status} ({t('warning', 'Warning')}: {t('visit_visa', 'Visit Visa')})
) : worker.visa_status && worker.visa_status.toLowerCase().includes('cancelled') ? (
{worker.visa_status} ({t('warning', 'Warning')}: {t('cancelled', 'Cancelled')})
) : (
{worker.visa_status}
)}
{worker.nationality} {worker.age} {t('years_old', 'Years Old')}
{workerReviews.length > 0 && (
{worker.rating} / 5.0 ({workerReviews.length} {t('reviews', 'reviews')})
)}
{/* Sponsor Actions Block */}
{/* Stage 3 Connect: Start In-App Chat */} {t('start_direct_chat', 'Start Direct Chat')} {/* Stage 4 Hire: Mark Hired (Finalize Hiring Direct Flow) */} {availabilityStatus !== 'Hired' && ( )}
{/* Main Details Grid */}
{/* Left Column: Quick Stats */}

{t('worker_details_title', 'Worker Details')}

{t('name', 'Name')}
{worker.name}
{t('mobile', 'Mobile')}
{worker.phone}
{t('gender', 'Gender')}
{worker.gender}
{t('salary_expectations', 'Salary Expectations')}
{worker.salary} {t('aed', 'AED')} / {t('mo', 'mo')}
{t('work_experience', 'Work Experience')}
{worker.experience}
{t('job_type', 'Job Type')}
{worker.preferred_job_type}
{t('accommodation_preference', 'Accommodation Preference')}
{worker.live_in_out}
{t('current_location_status', 'Current Location')}
{worker.in_country ? t('in_country', 'In-Country') : t('out_country', 'Out-of-Country')}
{worker.in_country && (
{t('visa_type', 'Visa Type')}
{worker.visa_status || t('pending', 'Pending')}
)}
{/* Languages Spoken with visual flags */}
{t('languages_spoken', 'Languages Spoken')}
{worker.languages?.map(lang => ( {getLanguageFlag(lang)} {lang} ))}
{/* Right Column: Bio & Skills */}
{/* Verified Skills & Competencies */}

{t('verified_skills_competencies', 'Verified Skills & Competencies')}

{worker.skills?.map(skill => (
{skill}
))}
{/* Verified Documents Section */}

{t('verified_legal_docs', 'Verified Legal Documents (UAE MOHRE Vetted)')}

{/* Document Card: Passport */} {passportDoc ? (
{t('passport_details', 'Passport Details')} {(() => { const expiryStatus = getExpiryStatus(passportDoc.expiry_date); return ( \${expiryStatus.text} ); })()}
{passportDoc.ocr_accuracy && ( {passportDoc.ocr_accuracy}% Match )}
{passportDoc.ocr_data ? (
{t('given_names', 'Given Names')}
{safeRender(passportDoc.ocr_data.given_names)}
{t('surname', 'Surname')}
{safeRender(passportDoc.ocr_data.surname)}
{t('passport_number', 'Passport Number')}
{safeRender(passportDoc.ocr_data.passport_number || passportDoc.number)}
{t('sex', 'Sex')}
{safeRender(passportDoc.ocr_data.sex)}
{t('date_of_birth', 'Date of Birth')}
{safeRender(passportDoc.ocr_data.date_of_birth)}
{t('place_of_birth', 'Place of Birth')}
{safeRender(passportDoc.ocr_data.place_of_birth)}
{t('issue_date', 'Date of Issue')}
{safeRender(passportDoc.ocr_data.date_of_issue || passportDoc.issue_date)}
{t('expiry_date', 'Date of Expiry')}
{safeRender(passportDoc.ocr_data.date_of_expiry || passportDoc.expiry_date)}
{t('issuing_country', 'Issuing Country')}
{safeRender(passportDoc.ocr_data.issuing_country)}
) : (
{t('document_id', 'Document ID')}
{passportDoc.number}
{t('issue_date', 'Issue')}
{passportDoc.issue_date || 'N/A'}
{t('expiry_date', 'Expiry')}
{passportDoc.expiry_date || 'N/A'}
)}
UAE PDPL Compliant Scan Storage (Permanently Purged) {passportDoc.file_path && ( View Passport Scan )}
) : (
{t('passport_pending', 'Passport Pending')}

{t('passport_pending_desc', 'Candidate has not uploaded a passport document yet.')}

)} {/* Document Card: Visa */} {visaDoc ? (
{t('visa_details', 'Entry Visa Details')} {(() => { const expiryStatus = getExpiryStatus(passportDoc.expiry_date); return ( \${expiryStatus.text} ); })()}
{worker.visa_status && (worker.visa_status.toLowerCase().includes('tourist') || worker.visa_status.toLowerCase().includes('visit') || worker.visa_status.toLowerCase().includes('cancelled')) ? ( {t('transfer_required', 'Transfer Required')} ) : ( {t('clear_records', 'Clear Records')} )}
{visaDoc.ocr_data ? (() => { const sponsorObj = visaDoc.ocr_data?.sponsor; const isSponsorObj = sponsorObj && typeof sponsorObj === 'object' && !Array.isArray(sponsorObj); const sponsorName = isSponsorObj ? (sponsorObj.name || sponsorObj.sponsor_name || sponsorObj.full_name) : (visaDoc.ocr_data?.sponsor_name || (typeof sponsorObj === 'string' ? sponsorObj : null)); const sponsorMobile = isSponsorObj ? (sponsorObj.mobile || sponsorObj.mobile_number || sponsorObj.phone) : null; return (
{t('profession', 'Profession')}
{safeRender(visaDoc.ocr_data.profession || worker.visa_status)}
{sponsorName && (
{t('sponsor', 'Sponsor')}
{safeRender(sponsorName)}
)} {sponsorMobile && (
{t('sponsor_mobile', 'Sponsor Mobile')}
{safeRender(sponsorMobile)}
)}
{t('place_of_issue', 'Place of Issue')}
{safeRender(visaDoc.ocr_data.place_of_issue)}
{t('issue_date', 'Date of Issue')}
{safeRender(visaDoc.ocr_data.issue_date || visaDoc.issue_date)}
{t('expiry_date', 'Date of Expiry')}
{safeRender(visaDoc.ocr_data.expiry_date || visaDoc.expiry_date)}
); })() : (
{t('document_id', 'Document ID')}
{visaDoc.number}
{t('issue_date', 'Issue')}
{visaDoc.issue_date || 'N/A'}
{t('expiry_date', 'Expiry')}
{visaDoc.expiry_date || 'N/A'}
)}
UAE PDPL Compliant Scan Storage (Permanently Purged) {visaDoc.file_path && ( View Visa Scan )}
) : (
{t('visa_pending', 'Visa Pending')}

{t('visa_pending_desc', 'Candidate has not uploaded a visa document yet.')}

)}
{/* Star Ratings & Trust Review logs */}

{t('sponsor_reviews_star_ratings', 'Sponsor Reviews & Star Ratings')}

{t('reviews_posted_by_sponsors_desc', 'Ratings can only be posted by verified sponsors who completed verified direct hiring.')}

{/* Reviews List */}
{workerReviews.map((review) => (
{review.employer_name} {review.date}
{[...Array(5)].map((_, i) => ( ))}

"{review.comment}"

))} {workerReviews.length === 0 && (
{t('no_reviews_yet', 'No reviews posted yet.')}
)}
{/* Stage 4/5 Hired Flow Success Modal Overlay */} {showHiredModal && (

{t('direct_sponsoring_finalized', 'Direct Sponsoring Finalized!')}

{t('hired_under_sponsorship_desc', '{name} is successfully marked as Hired under your sponsorship! This direct matching conforms exactly with Stage 4 of our UAE MOHRE zero-middlemen flow.').replace('{name}', worker.name)}

{t('next_step_post_hire_review', 'Next Step: Stage 5 Post-Hire Review')}

{t('help_community_post_review', "Help the UAE community hire safely by posting an anonymous review describing {name}'s childcare, cooking, driving, or domestic skills.").replace('{name}', worker.name)}

{t('back_to_worker_directory', 'Back to Worker Directory')}
)} {/* Report Abuse Modal Overlay */} {showReportModal && (

{t('report_abuse_violation', 'Report Verification Abuse / Terms Violation')}

{t('zero_tolerance_abuse_desc', 'We maintain zero-tolerance for fake documentation, independent recruiters trading cash, or incorrect contact details.')}