'use client' import { useState, useEffect } from 'react' import { portalAPI, type Attendance } from '@/lib/api/portal' import LoadingSpinner from '@/components/LoadingSpinner' import { Clock } from 'lucide-react' export default function PortalAttendancePage() { const [attendance, setAttendance] = useState([]) const [loading, setLoading] = useState(true) const [month, setMonth] = useState(new Date().getMonth() + 1) const [year, setYear] = useState(new Date().getFullYear()) useEffect(() => { setLoading(true) portalAPI.getAttendance(month, year) .then(setAttendance) .catch(() => setAttendance([])) .finally(() => setLoading(false)) }, [month, year]) const months = Array.from({ length: 12 }, (_, i) => ({ value: i + 1, label: new Date(2000, i).toLocaleDateString('ar-SA', { month: 'long' }) })) const years = Array.from({ length: 5 }, (_, i) => new Date().getFullYear() - i) if (loading) return return (

حضوري

{attendance.length === 0 ? (

لا توجد سجلات حضور لهذا الشهر

) : (
{attendance.map((a) => ( ))}
التاريخ دخول خروج ساعات العمل الحالة
{new Date(a.date).toLocaleDateString('ar-SA')} {a.checkIn ? new Date(a.checkIn).toLocaleTimeString('ar-SA', { hour: '2-digit', minute: '2-digit' }) : '-'} {a.checkOut ? new Date(a.checkOut).toLocaleTimeString('ar-SA', { hour: '2-digit', minute: '2-digit' }) : '-'} {a.workHours != null ? Number(a.workHours).toFixed(1) : '-'} {a.status === 'PRESENT' ? 'حاضر' : a.status === 'ABSENT' ? 'غائب' : a.status === 'LATE' ? 'متأخر' : a.status}
)}
) }