import React, { useState } from 'react';
import { Head, useForm, Link } from '@inertiajs/react';
import EmployerLayout from '../../Layouts/EmployerLayout';
import { useTranslation } from '../../lib/LanguageContext';
import {
User,
Mail,
Phone,
MapPin,
Home,
Camera,
Save,
XCircle,
ArrowLeft,
Compass
} from 'lucide-react';
import { toast } from 'sonner';
export default function ProfileEdit({ employerProfile }) {
const { t } = useTranslation();
const { data, setData, post, processing, errors } = useForm({
name: employerProfile?.name || '',
email: employerProfile?.email || '',
phone: employerProfile?.phone || '',
address: employerProfile?.address || '',
property_type: employerProfile?.property_type || '',
profile_photo: null,
});
const [photoPreview, setPhotoPreview] = useState(employerProfile?.profile_photo_url || null);
const handlePhotoChange = (e) => {
const file = e.target.files[0];
if (file) {
setData('profile_photo', file);
setPhotoPreview(URL.createObjectURL(file));
}
};
const handleSubmit = (e) => {
e.preventDefault();
post('/employer/profile/update', {
preserveScroll: true,
onSuccess: () => {
toast.success(t('profile_updated_successfully', 'Profile updated successfully!'));
},
onError: (errs) => {
toast.error(t('profile_update_failed', 'Failed to update profile'), {
description: Object.values(errs)[0] || t('check_form_fields', 'Please check the form fields.')
});
}
});
};
return (