import { useEffect, useState } from 'react' import { Card } from '@/components/ui/Card' import { Skeleton } from '@/components/ui/Skeleton' import { Table, TableHead, TableBody, TableRow, TableHeader, TableCell, } from '@/components/ui/Table' import { Badge } from '@/components/ui/Badge' import { Button } from '@/components/ui/Button' import { formatDate } from '@/lib/utils' import { hrApi } from '@/lib/api' import { Users, Calendar, Plus, Search, Filter, MoreHorizontal, Clock, } from 'lucide-react' import { AgentFAB } from '@/components/agent/AgentFAB' interface Employee { id: string first_name: string last_name: string name?: string email: string department: string position: string role?: string status: string start_date?: string startDate?: string } interface Leave { id: string employeeId: string employeeName: string type: string startDate: string endDate: string status: string days: number } const tabs = ['Employees', 'Leaves'] const departmentColors: Record = { Sales: 'primary', Engineering: 'success', Finance: 'warning', HR: 'primary', Legal: 'default', } export function HRPage() { const [activeTab, setActiveTab] = useState('Employees') const [searchQuery, setSearchQuery] = useState('') const [loading, setLoading] = useState(true) const [error, setError] = useState('') const [employees, setEmployees] = useState([]) const [leaves, setLeaves] = useState([]) useEffect(() => { async function fetchData() { setLoading(true) setError('') try { const [employeesRes, leavesRes] = await Promise.all([ hrApi.employees(), hrApi.leaves(), ]) setEmployees((employeesRes as { employees: Employee[] }).employees || []) setLeaves((leavesRes as { leaves: Leave[] }).leaves || []) } catch (err) { setError(err instanceof Error ? err.message : 'Failed to load HR data') } finally { setLoading(false) } } fetchData() }, []) const activeEmployees = employees.filter((e) => e.status === 'active').length const onLeave = employees.filter((e) => e.status === 'on_leave').length const pendingLeaves = leaves.filter((l) => l.status === 'pending').length const filteredEmployees = employees.filter( (e) => (e.name || `${e.first_name} ${e.last_name}`).toLowerCase().includes(searchQuery.toLowerCase()) || e.department.toLowerCase().includes(searchQuery.toLowerCase()) || (e.role || e.position).toLowerCase().includes(searchQuery.toLowerCase()) ) const filteredLeaves = leaves.filter( (l) => l.employeeName.toLowerCase().includes(searchQuery.toLowerCase()) || l.type.toLowerCase().includes(searchQuery.toLowerCase()) ) if (loading) { return (
) } if (error) { return (

{error}

) } return (
{/* Page Header */}

HR

Employees and leave management

{/* Quick Stats */}

{activeEmployees}

Active Employees

{onLeave}

On Leave

{pendingLeaves}

Pending Requests

{/* Tabs + Search */}
{tabs.map((tab) => ( ))}
setSearchQuery(e.target.value)} className="w-full sm:w-64 h-10 pl-9 pr-4 rounded-[14px] border bg-surface text-sm text-text-primary placeholder:text-text-secondary/50 focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/30" />
{/* Tab Content */} {activeTab === 'Employees' && ( Employee Department Role Status Start Date {filteredEmployees.map((employee) => { const empName = employee.name || `${employee.first_name} ${employee.last_name}` const empRole = employee.role || employee.position const empStartDate = employee.startDate || employee.start_date return (
{empName.split(' ').map((n) => n[0]).join('')}

{empName}

{employee.email}

{employee.department} {empRole} {employee.status.replace('_', ' ')} {formatDate(empStartDate || '')}
)})} {filteredEmployees.length === 0 && ( No employees found )}
)} {activeTab === 'Leaves' && ( Employee Type Period Days Status {filteredLeaves.map((leave) => (
{leave.employeeName.split(' ').map((n) => n[0]).join('')}
{leave.employeeName}
{leave.type} {formatDate(leave.startDate)} — {formatDate(leave.endDate)} {leave.days} {leave.status}
))} {filteredLeaves.length === 0 && ( No leave requests found )}
)} {/* HR Agent */}
) }