import { useState } from "react"; import { BarChart3, Calendar, Building2, FolderOpen, Clock, } from "lucide-react"; import { useStatistics } from "@/hooks/useTimeEntries"; import { useClients } from "@/hooks/useClients"; import { useProjects } from "@/hooks/useProjects"; import { ProjectColorDot } from "@/components/ProjectColorDot"; import { formatDuration, toISOTimezone } from "@/utils/dateUtils"; import type { StatisticsFilters } from "@/types"; export function StatisticsPage() { const [filters, setFilters] = useState({}); const { data: statistics, isLoading } = useStatistics(filters); const { clients } = useClients(); const { projects } = useProjects(); const handleFilterChange = ( key: keyof StatisticsFilters, value: string | undefined, ) => { setFilters((prev) => ({ ...prev, [key]: value || undefined, })); }; const clearFilters = () => { setFilters({}); }; return (
{/* Page Header */}

Statistics

View your working hours with filters

{/* Filters */}

Filters

{/* Date Range */}
handleFilterChange( "startDate", e.target.value ? toISOTimezone(`${e.target.value}T00:00:00`) : undefined, ) } className="input" />
handleFilterChange( "endDate", e.target.value ? toISOTimezone(`${e.target.value}T23:59:59`) : undefined, ) } className="input" />
{/* Client Filter */}
{/* Project Filter */}
{/* Clear Filters Button */} {(filters.startDate || filters.endDate || filters.clientId || filters.projectId) && (
)}
{/* Total Hours Display */}

Total Working Time

{isLoading ? ( Loading... ) : ( formatDuration(statistics?.totalSeconds || 0) )}

{statistics?.entryCount || 0} time entries

{/* Breakdown by Project */} {statistics && statistics.byProject.length > 0 && (

By Project

{statistics.byProject.map((project) => (
{project.projectName} ({project.entryCount} entries)
{formatDuration(project.totalSeconds)}
))}
)} {/* Breakdown by Client */} {statistics && statistics.byClient.length > 0 && (

By Client

{statistics.byClient.map((client) => (
{client.clientName} ({client.entryCount} entries)
{formatDuration(client.totalSeconds)}
))}
)} {/* Empty State */} {!isLoading && statistics && statistics.entryCount === 0 && (

No data available

No time entries found for the selected filters.

)}
); }