import React, { useState, useMemo } from 'react'; import { Head, Link, router } from '@inertiajs/react'; import EmployerLayout from '@/Layouts/EmployerLayout'; import { Plus, Search, Filter, Download, MoreHorizontal, MapPin, DollarSign, Users, Calendar, Briefcase, CheckCircle2, XCircle, Clock, Eye, Edit2, Trash2, LayoutGrid, List, Shield, Navigation, Layers } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { toast } from 'sonner'; // Helper function to map jobs dynamically to categories and skills based on title const getJobMetadata = (title = '') => { const t = title.toLowerCase(); if (t.includes('electrician') || t.includes('electrical')) { return { category: 'Skilled Worker', skills: ['Electrical Wiring', 'Maintenance', 'Safety Inspection', 'Wiring Diagrams'] }; } if (t.includes('clean') || t.includes('housekeep') || t.includes('maid') || t.includes('laundry')) { return { category: 'General Worker', skills: ['Cleaning', 'Housekeeping', 'Laundry', 'Sanitization'] }; } if (t.includes('plumb')) { return { category: 'Skilled Worker', skills: ['Plumbing', 'Pipe Fitting', 'Leak Repair', 'Blueprint Reading'] }; } if (t.includes('security') || t.includes('guard') || t.includes('watchman')) { return { category: 'Security', skills: ['Security', 'Surveillance', 'Access Control', 'Patrolling'] }; } if (t.includes('driver') || t.includes('chauffeur') || t.includes('delivery')) { return { category: 'Driver', skills: ['Driving', 'Route Knowledge', 'Vehicle Safety', 'Navigation'] }; } if (t.includes('mason') || t.includes('carpenter') || t.includes('woodwork') || t.includes('construction')) { return { category: 'Skilled Worker', skills: ['Carpentry', 'Woodwork', 'Masonry', 'Tool Operation'] }; } if (t.includes('store') || t.includes('warehouse') || t.includes('inventory') || t.includes('keeper')) { return { category: 'Logistics', skills: ['Inventory', 'Stock Management', 'Packaging', 'Labeling'] }; } if (t.includes('helper') || t.includes('labor') || t.includes('assistant')) { return { category: 'General Worker', skills: ['Loading', 'Unloading', 'Physical Labor', 'Material Handling'] }; } // Fallback return { category: 'Skilled Worker', skills: ['General Support', 'Task Execution', 'Operations'] }; }; export default function Index({ initialJobs }) { const [searchTerm, setSearchTerm] = useState(''); const [statusFilter, setStatusFilter] = useState('All'); const [categoryFilter, setCategoryFilter] = useState('All'); const [skillFilter, setSkillFilter] = useState('All'); const [viewMode, setViewMode] = useState('grid'); const [jobs, setJobs] = useState(initialJobs || []); const handleDelete = (jobId) => { if (confirm('Are you sure you want to delete this job posting? This action cannot be undone.')) { router.delete(`/employer/jobs/${jobId}`, { onSuccess: () => { toast.success('Job deleted successfully.'); }, onError: () => { toast.error('Failed to delete job.'); } }); } }; // Derived category list const categories = ['All', 'Skilled Worker', 'General Worker', 'Security', 'Driver', 'Logistics']; // Derived skills list const skills = [ 'All', 'Electrical Wiring', 'Cleaning', 'Housekeeping', 'Plumbing', 'Pipe Fitting', 'Security', 'Surveillance', 'Driving', 'Route Knowledge', 'Carpentry', 'Woodwork', 'Inventory', 'Stock Management', 'Loading', 'Unloading' ]; const filteredJobs = useMemo(() => { return jobs.filter(job => { const meta = getJobMetadata(job.title); const matchesSearch = job.title.toLowerCase().includes(searchTerm.toLowerCase()) || job.location.toLowerCase().includes(searchTerm.toLowerCase()); const matchesStatus = statusFilter === 'All' || job.status.toLowerCase() === statusFilter.toLowerCase(); const matchesCategory = categoryFilter === 'All' || meta.category === categoryFilter; const matchesSkill = skillFilter === 'All' || meta.skills.includes(skillFilter); return matchesSearch && matchesStatus && matchesCategory && matchesSkill; }); }, [jobs, searchTerm, statusFilter, categoryFilter, skillFilter]); return (
{/* Header Actions */}

Active Job Postings

Manage and track your recruitment status

Post a Job
{/* Filters & Search Bar */}
{/* Search */}
setSearchTerm(e.target.value)} />
{/* Select Dropdowns */}
{/* Status Toggle & Views */}
{['All', 'Active', 'Closed', 'Draft'].map(status => ( ))}
{/* Jobs Display */} {filteredJobs.length > 0 ? ( viewMode === 'grid' ? ( /* Grid Layout */
{filteredJobs.map((job) => { const meta = getJobMetadata(job.title); const isFilled = job.hired_count >= job.workers_needed; const percentFilled = Math.min(100, Math.round((job.hired_count / job.workers_needed) * 100)); return (
{/* Header */}
{meta.category === 'Security' ? : meta.category === 'Driver' ? : meta.category === 'Logistics' ? : }

{job.title}

{job.posted_at}
{job.status}
{/* Location & Salary */}
{job.location}
$ {job.salary.toLocaleString()} AED / month
{/* Stats & Progress Bar */}
{job.workers_needed}
Total Req
{job.hired_count}
Hired
{job.applied_count}
Applications
{isFilled ? ( All positions filled ) : ( {job.workers_needed - job.hired_count} more to hire )}
{/* Skills Tags */}
Skills
{meta.skills.slice(0, 2).map((skill, idx) => ( {skill} ))} {meta.skills.length > 2 && ( +{meta.skills.length - 2} )}
{/* Category Row */}
Category {meta.category}
{/* Actions footer */}
View Applicants Quick Actions View Details Edit Posting handleDelete(job.id)}>
Delete Job
); })}
) : ( /* List Layout */
{filteredJobs.map((job) => { const meta = getJobMetadata(job.title); const isFilled = job.hired_count >= job.workers_needed; return (
{meta.category === 'Security' ? : meta.category === 'Driver' ? : meta.category === 'Logistics' ? : }

{job.title}

{job.status}
Posted {job.posted_at} {job.location} $ {job.salary.toLocaleString()} AED | {meta.category}
Hired: {job.hired_count} / {job.workers_needed} ({job.applied_count} applied)
{isFilled ? Filled : {job.workers_needed - job.hired_count} needed}
Applicants Quick Actions View Details Edit Posting handleDelete(job.id)}>
Delete Job
); })}
) ) : ( /* Empty State */

No jobs found

Post your first job
)}
); }