import { useState } from "preact/hooks"; import { useT } from "../../../shared/i18n/context"; import { useUsageSummary, useUsageHistory, type Granularity } from "../../../shared/hooks/use-usage-stats"; import { UsageChart, formatNumber } from "../components/UsageChart"; import type { TranslationKey } from "../../../shared/i18n/translations"; const granularityOptions: Array<{ value: Granularity; label: TranslationKey }> = [ { value: "hourly", label: "granularityHourly" }, { value: "daily", label: "granularityDaily" }, ]; const rangeOptions: Array<{ hours: number; label: TranslationKey }> = [ { hours: 24, label: "last24h" }, { hours: 72, label: "last3d" }, { hours: 168, label: "last7d" }, ]; export function UsageStats() { const t = useT(); const { summary, loading: summaryLoading } = useUsageSummary(); const [granularity, setGranularity] = useState("hourly"); const [hours, setHours] = useState(24); const { dataPoints, loading: historyLoading } = useUsageHistory(granularity, hours); return (
{/* Header */}
{/* Summary cards */}
{/* Controls */}
{granularityOptions.map(({ value, label }) => ( ))}
{rangeOptions.map(({ hours: h, label }) => ( ))}
{/* Chart */}
{historyLoading ? (
Loading...
) : ( )}
); } function SummaryCard({ label, value }: { label: string; value: string }) { return (
{label}
{value}
); }