import React, { useState } from 'react';
import { Head, Link, router } from '@inertiajs/react';
import EmployerLayout from '../../Layouts/EmployerLayout';
import { useTranslation } from '../../lib/LanguageContext';
import {
User,
ShieldCheck,
Mail,
Phone,
Globe,
MapPin,
Home,
Edit3,
Calendar,
Briefcase,
Building,
FileText,
MessageSquare,
AlertCircle,
CheckCircle2,
Lock,
ExternalLink,
Compass,
FileSpreadsheet,
Eye,
Bell,
Camera,
Save,
XCircle
} from 'lucide-react';
import { toast } from 'sonner';
import { compressImage } from '../../lib/utils';
export default function Profile({ employerProfile }) {
const { t } = useTranslation();
const [showConfirmPopup, setShowConfirmPopup] = useState(false);
const handleEditClick = () => {
setShowConfirmPopup(true);
};
const handleConfirmEdit = () => {
setShowConfirmPopup(false);
router.get('/employer/profile/edit');
};
const handleCancelEdit = () => {
setShowConfirmPopup(false);
};
const [showRenewModal, setShowRenewModal] = useState(false);
const [frontFile, setFrontFile] = useState(null);
const [backFile, setBackFile] = useState(null);
const [frontPreview, setFrontPreview] = useState(null);
const [backPreview, setBackPreview] = useState(null);
const [isSubmitting, setIsSubmitting] = useState(false);
const expiryDateStr = employerProfile?.emirates_id?.expiry_date;
const isExpired = expiryDateStr ? new Date(expiryDateStr) <= new Date() : false;
const handleRenewalSubmit = (e) => {
e.preventDefault();
if (!frontFile || !backFile) {
toast.error(t('upload_both_sides', 'Please upload both front and back sides of your Emirates ID.'));
return;
}
setIsSubmitting(true);
router.post('/employer/profile/update', {
name: employerProfile.name,
email: employerProfile.email,
phone: employerProfile.phone,
emirates_id_front: frontFile,
emirates_id_back: backFile,
}, {
forceFormData: true,
onSuccess: () => {
toast.success(t('document_renewed', 'Emirates ID renewed successfully!'));
setShowRenewModal(false);
setFrontFile(null);
setBackFile(null);
setFrontPreview(null);
setBackPreview(null);
setIsSubmitting(false);
},
onError: (errs) => {
toast.error(Object.values(errs)[0] || t('renewal_failed', 'Failed to renew Emirates ID.'));
setIsSubmitting(false);
}
});
};
const toggleNotification = (type, currentVal) => {
router.post('/employer/profile/update', {
name: employerProfile.name,
email: employerProfile.email,
phone: employerProfile.phone,
email_notifications: type === 'email' ? !currentVal : employerProfile.email_notifications,
push_notifications: type === 'push' ? !currentVal : employerProfile.push_notifications,
}, {
preserveScroll: true,
onSuccess: () => {
toast.success(t('preferences_updated', 'Preferences updated successfully'));
}
});
};
const profilePhoto = employerProfile?.profile_photo_url;
return (
Your Emirates ID card expired on {employerProfile?.emirates_id?.expiry_date}. Please upload a renewed document to maintain compliance and system access.
{employerProfile?.email}
{t('manage_contact_desc', 'Contact and notification channels')}
{t('email_alerts_sub', 'Invoices, updates & announcements')}
{t('push_alerts_sub', 'Live updates & mobile alerts')}
{t('vetted_details_badge', 'Vetted MOHRE identity credentials')}
{t('edit_profile_confirm_body', 'Are you sure you want to edit your profile details?')}
Upload both sides of your new document