import React, { useEffect, useState } from 'react'; import { Link, usePage } from '@inertiajs/react'; import { toast } from 'sonner'; import { LayoutDashboard, Search, Bookmark, MessageSquare, CreditCard, User, LogOut, Bell, CheckCircle, AlertCircle, ArrowRight, UserCheck, Megaphone, Briefcase, Heart, FileText, ChevronDown, ChevronRight, LifeBuoy, Users } from 'lucide-react'; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator } from '@/components/ui/dropdown-menu'; import { useTranslation, languages } from '../lib/LanguageContext'; export default function EmployerLayout({ children, title, fullPage = false }) { const { url, props } = usePage(); const { auth, unread_messages_count, flash } = props; const { locale, setLocale, t } = useTranslation(); useEffect(() => { if (flash?.success) { toast.success(flash.success); } if (flash?.error) { toast.error(flash.error); } if (flash?.first_login) { // Elegant first login celebratory alert toast.success(`🎉 ${t('welcome_title', 'Welcome to Marketplace!')}`, { description: t('welcome_desc', 'Your employer profile is verified and active with 30 days of Premium Access.'), duration: 6000, }); } }, [flash, t]); const user = auth?.user || { name: 'Guest', company_name: '', email: '', subscription_status: 'active', subscription_expires_at: '', enable_job_apply: false, }; const isSubActive = true; const [openGroups, setOpenGroups] = useState({ workers: url.startsWith('/employer/workers') || url.startsWith('/employer/shortlist') || url.startsWith('/employer/candidates'), jobs: url.startsWith('/employer/jobs'), }); useEffect(() => { setOpenGroups({ workers: url.startsWith('/employer/workers') || url.startsWith('/employer/shortlist') || url.startsWith('/employer/candidates'), jobs: url.startsWith('/employer/jobs'), }); }, [url]); const toggleGroup = (groupKey) => { setOpenGroups(prev => ({ ...prev, [groupKey]: !prev[groupKey] })); }; const isChildActive = (childHref) => { let isActive = url.startsWith(childHref); if (url.startsWith('/employer/workers/')) { const isHired = props.worker?.status === 'Hired' || props.worker?.availability_status === 'Hired'; if (isHired) { if (childHref === '/employer/candidates') { isActive = true; } else if (childHref === '/employer/workers') { isActive = false; } } else { if (childHref === '/employer/workers') { isActive = true; } } } return isActive; }; const navItems = [ { name: 'Dashboard', translationKey: 'dashboard', href: '/employer/dashboard', icon: LayoutDashboard }, { name: 'Workers', translationKey: 'workers_group', icon: Users, isGroup: true, groupKey: 'workers', children: [ { name: 'Workers List', translationKey: 'workers_list', href: '/employer/workers' }, { name: 'Saved Workers', translationKey: 'saved_workers', href: '/employer/shortlist' }, { name: 'Hired Workers', translationKey: 'hired_workers', href: '/employer/candidates' }, ] }, ...(user.enable_job_apply ? [{ name: 'Jobs', translationKey: 'jobs_group', icon: Briefcase, isGroup: true, groupKey: 'jobs', children: [ { name: 'My Jobs', translationKey: 'my_jobs', href: '/employer/jobs' }, { name: 'Applicants', translationKey: 'applicants', href: '/employer/jobs/all-applicants' }, { name: 'Shortlisted Workers', translationKey: 'shortlisted_workers', href: '/employer/jobs/shortlisted' }, ] }] : []), { name: 'Messages', translationKey: 'messages', href: '/employer/messages', icon: MessageSquare, badge: unread_messages_count }, { name: 'Charity Events', translationKey: 'charity_events', href: '/employer/events', icon: Heart }, { name: 'Subscription', translationKey: 'subscription', href: '/employer/subscription', icon: CreditCard }, { name: 'Payment History', translationKey: 'payment_history', href: '/employer/payments', icon: FileText }, { name: 'My Profile', translationKey: 'my_profile', href: '/employer/profile', icon: User }, { name: 'Help & Support', translationKey: 'help_support', href: '/employer/support', icon: LifeBuoy }, ]; const mobileTabs = [ { name: 'Search', translationKey: 'search', href: '/employer/workers', icon: Search }, { name: 'Saved Workers', translationKey: 'saved_workers', href: '/employer/shortlist', icon: Bookmark }, { name: 'Hired Workers', translationKey: 'hired_workers', href: '/employer/candidates', icon: UserCheck }, { name: 'Messages', translationKey: 'messages', href: '/employer/messages', icon: MessageSquare, badge: unread_messages_count }, { name: 'Profile', translationKey: 'profile', href: '/employer/profile', icon: User }, ]; return (