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
} from 'lucide-react';
import { toast } from 'sonner';
const getLanguageFlag = (lang) => {
const flags = {
'English': '🇬🇧',
'Arabic': '🇦🇪',
'Tagalog': '🇵🇭',
'Hindi': '🇮🇳',
'Swahili': '🇰🇪',
'French': '🇫🇷',
'Indonesian': '🇮🇩'
};
return flags[lang] || '🌐';
};
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);
// 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')}
{/* Quick Profile Actions */}
{t('share_profile', 'Share Profile')}
setShowReportModal(true)}
className="p-2.5 bg-white border border-slate-200 hover:bg-rose-50 rounded-xl text-slate-400 hover:text-rose-600 transition-colors flex items-center space-x-1 text-xs font-bold shadow-xs"
title="Report Abuse / Terms violations"
>
{t('report_worker', 'Report Worker')}
{/* Header Card with Clean Premium White BG */}
{worker.photo ? (
) : (
)}
{worker.name}
{worker.verified && (
{t('verified')}
)}
{/* Passport verification status bar & Visa Status */}
{worker.passport_status}
{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')}
•
{worker.category}
{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' && (
{t('mark_hired_action', 'Mark Hired')}
)}
{/* Main Details Grid */}
{/* Left Column: Quick Stats */}
{t('worker_details_title', 'Worker Details')}
{t('name', 'Name')}
{worker.name}
{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('passport_verification', 'Passport Verification')}
{worker.passport_status}
{t('visa_status', 'Visa Status')}
{worker.visa_status}
{t('medical_health_test', 'Medical Health Test')}
{t('passed_certified', 'PASSED CERTIFIED')}
{/* Languages Spoken with visual flags */}
{t('languages_spoken', 'Languages Spoken')}
{worker.languages?.map(lang => (
{getLanguageFlag(lang)}
{lang}
))}
{/* Right Column: Bio & Skills */}
{/* Professional Summary */}
{t('professional_summary', 'Professional Summary')}
"{worker.bio}"
{/* 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 */}
{t('passport_verified', 'Passport (PDPL Compliant)')}
{t('scan_purged', 'Scan Purged')}
{t('uae_pdpl_compliant', 'UAE PDPL compliant')}
{t('document_id', 'Document ID')}
{passportDoc?.number || 'L82739102-UAE'}
{t('issue_date', 'Issue')}
{passportDoc?.issue_date || '12 Jan 2021'}
{t('expiry_date', 'Expiry')}
{passportDoc?.expiry_date || '11 Jan 2031'}
{t('ocr_match', 'OCR Match')}
{passportDoc?.ocr_accuracy || 95}%
{t('physical_scan_storage', 'Physical Scan Storage')}
{t('permanently_purged', 'Permanently Purged')}
{/* Document Card: Visa */}
{t('entry_visa_verified', 'Entry Visa (PDPL Compliant)')}
{worker.visa_status && (worker.visa_status.toLowerCase().includes('tourist') || worker.visa_status.toLowerCase().includes('visit') || worker.visa_status.toLowerCase().includes('cancelled')) ? (
) : (
)}
{t('scan_purged', 'Scan Purged')}
{t('uae_pdpl_compliant', 'UAE PDPL compliant')}
{t('document_id', 'Document ID')}
{visaDoc?.number || 'V2839102-DXB'}
{t('issue_date', 'Issue')}
{visaDoc?.issue_date || '12 Jan 2023'}
{t('expiry_date', 'Expiry')}
{visaDoc?.expiry_date || '11 Jan 2026'}
{t('visa_category', 'Visa Category')}
{worker.visa_status}
{t('verification_status', 'Verification status')}
{worker.visa_status && (worker.visa_status.toLowerCase().includes('tourist') || worker.visa_status.toLowerCase().includes('visit')) ? (
{t('transfer_required', 'Transfer Required')}
) : worker.visa_status && worker.visa_status.toLowerCase().includes('cancelled') ? (
{t('needs_regularization', 'Needs Regularization')}
) : (
<>
{t('clear_records', 'Clear Records')}
>
)}
{/* 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.')}
setShowReviewModal(true)}
className="bg-[#185FA5] hover:bg-[#144f8a] text-white px-5 py-2.5 rounded-xl text-xs font-bold shadow-xs transition-colors"
>
{t('post_trust_review', 'Post a Trust Review')}
{/* Reviews List */}
{workerReviews.map((review) => (
{review.employer_name}
{review.date}
{[...Array(5)].map((_, i) => (
))}
"{review.comment}"
))}
{/* Similar Recommendations Slider */}
{t('similar_recommended_workers', 'Similar Recommended Workers')}
{worker.similar_workers?.map((sim) => (
{sim.name}
{sim.nationality} • {sim.category}
{sim.verified && (
{t('verified', 'Verified')}
)}
{sim.salary} {t('aed', 'AED')}/{t('mo', 'mo')}
{t('view_profile', 'View Profile')}
→
))}
{/* 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)}
{
setShowHiredModal(false);
setShowReviewModal(true);
}}
className="w-full bg-[#185FA5] hover:bg-[#144f8a] text-white py-3 rounded-xl flex items-center justify-center space-x-2"
>
{t('leave_trust_review', 'Leave a Trust Review')}
{t('back_to_worker_directory', 'Back to Worker Directory')}
)}
{/* Report Abuse Modal Overlay */}
{showReportModal && (
)}
{/* Trust Review Modal Overlay */}
{showReviewModal && (
setShowReviewModal(false)}
className="absolute top-4 right-4 text-slate-400 hover:text-slate-600"
>
{t('submit_performance_review', 'Submit a Verified Performance Review')}
{t('feedback_helps_sponsors_desc', 'Your feedback helps other sponsors make secure and direct hiring choices.')}
{t('star_rating', 'Star Rating')}
{[1, 2, 3, 4, 5].map((star) => (
setNewRating(star)}
className="p-1 hover:scale-110 transition-transform"
>
))}
{t('share_your_experience', 'Share Your Experience')}
setNewComment(e.target.value)}
placeholder={t('share_experience_placeholder', 'Tell other sponsors about childcare skills, cleaning, cooking style, driving safety, etc...')}
className="w-full p-2.5 border border-slate-300 rounded-xl text-xs focus:outline-none"
/>
setShowReviewModal(false)}
className="px-4 py-2 border border-slate-200 hover:bg-slate-50 rounded-lg"
>
{t('cancel', 'Cancel')}
{t('post_trust_review_action', 'Post Trust Review')}
)}
);
}