"use client"; import React, { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import SidebarLayout from "@/components/SidebarLayout"; import { fetchApi, getLocalDateString } from "@/app/utils/api"; import { FileText, Calendar, Download, Loader2, CheckCircle2, FileSpreadsheet, FileDown, CalendarDays, User, Layers, ChevronDown, Check } from "lucide-react"; const REPORT_TYPES = [ { value: "daily", label: "Daily Punch Summary", desc: "Per-day punch logs for all staff", icon: FileText }, { value: "weekly", label: "Weekly Timesheets", desc: "Weekly hours and punch history", icon: Calendar }, { value: "monthly", label: "Monthly Salary Ledger", desc: "Monthly attendance & late statistics", icon: CalendarDays }, { value: "employee", label: "Staff Profile Report", desc: "Detailed record for a specific employee", icon: User }, ]; const FORMATS = [ { value: "xlsx", label: "Excel Sheet", desc: ".xlsx Workbook" }, { value: "pdf", label: "PDF Report", desc: ".pdf Format" }, { value: "csv", label: "CSV Flatfile", desc: ".csv Flat data" }, ]; export default function ReportsPage() { const [reportType, setReportType] = useState("daily"); const [format, setFormat] = useState("xlsx"); const [startDate, setStartDate] = useState(() => { const d = new Date(Date.now() - 30 * 86400000); return getLocalDateString(d); }); const [endDate, setEndDate] = useState(() => getLocalDateString()); const [employeeId, setEmployeeId] = useState(""); const [departmentId, setDepartmentId] = useState(""); const [exporting, setExporting] = useState(false); const [success, setSuccess] = useState(false); const { data: departments } = useQuery({ queryKey: ["departments"], queryFn: () => fetchApi("/departments/") }); const { data: employees } = useQuery({ queryKey: ["employees-list"], queryFn: () => fetchApi("/employees/") }); const handleExport = async (e: React.FormEvent) => { e.preventDefault(); setExporting(true); setSuccess(false); try { const params = [`report_type=${reportType}`, `format=${format}`, `start_date=${startDate}`, `end_date=${endDate}`]; if (employeeId) params.push(`employee_id=${employeeId}`); if (departmentId) params.push(`department_id=${departmentId}`); const blob: Blob = await fetchApi(`/reports/export?${params.join("&")}`); const url = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = `netraid_${reportType}_${startDate}_${endDate}.${format}`; document.body.appendChild(a); a.click(); a.remove(); window.URL.revokeObjectURL(url); setSuccess(true); setTimeout(() => setSuccess(false), 5000); } catch (err: any) { alert(err.message || "Failed to generate report."); } finally { setExporting(false); } }; const inputCls = "input-field h-9.5 text-[12.5px] bg-white border-slate-200 focus:border-slate-800 text-slate-900 rounded-xl transition-all w-full"; const selectCls = "input-field h-9.5 text-[12.5px] bg-white border-slate-200 focus:border-slate-800 text-slate-900 rounded-xl transition-all appearance-none cursor-pointer w-full pr-8"; return (
{/* Header */}

Reports & Export

Compile and generate compliance-ready corporate records in PDF, Excel, or CSV format.

{/* Form */}

Export Parameters

Specify report criteria and format

{/* Report Type */}
{REPORT_TYPES.map(rt => { const Icon = rt.icon; const isActive = reportType === rt.value; return ( ); })}
{/* Output Format */}
{FORMATS.map(f => { const isActive = format === f.value; return ( ); })}
{/* Date range */}
setStartDate(e.target.value)} className={`${inputCls} !pl-10 h-10`} />
setEndDate(e.target.value)} className={`${inputCls} !pl-10 h-10`} />
{/* Optional filters */}
{/* Submit */}
{/* Sidebar info */}

Audit Protocols

{[ "Reports compile directly from the master SQL presence ledgers.", "Cosine similarity confidence scores are detailed for raw logs.", "Grace periods and overtime values recalculate dynamically.", "Failed anti-spoof events are highlighted in transaction files.", ].map((note, i) => (
{note}
))}
{success && (

Report Generated

The requested file was generated and saved to your device. Check your downloads directory.

)}
); }