"use client"; import { useTranslations } from "next-intl"; export interface CacheTrendPoint { timestamp: string; requests: number; cachedRequests: number; inputTokens: number; cachedTokens: number; cacheCreationTokens: number; } interface CacheTrendsProps { data?: CacheTrendPoint[] | null; loading?: boolean; error?: string | null; onRetry?: () => void; } export default function CacheTrends({ data, loading = false, error = null, onRetry, }: CacheTrendsProps) { const t = useTranslations("cache"); const trendData: CacheTrendPoint[] = data ?? []; const maxRequests = trendData.length > 0 ? Math.max(...trendData.map((p) => p.requests), 1) : 1; const maxCachedRequests = trendData.length > 0 ? Math.max(...trendData.map((p) => p.cachedRequests), 0) : 0; return (

{t("trend24h")}

{loading ? (
) : error ? (
{error} {onRetry && ( )}
) : trendData.length === 0 ? (
No data available — no cache activity in the last 24h
) : ( <> {maxCachedRequests > 0 && (
{t("peakCached")}:{" "} {maxCachedRequests} / {maxRequests}
)}
{trendData.map((point) => { const height = Math.max(4, (point.requests / maxRequests) * 100); const cachedHeight = point.requests > 0 ? Math.max(2, (point.cachedRequests / point.requests) * height) : 0; const hour = new Date(point.timestamp).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hour12: false, }); return (
{hour}: {point.requests} {t("requests").toLowerCase()}, {point.cachedRequests}{" "} {t("cached").toLowerCase()}
{hour.split(":")[0]}
); })}
{t("total")}
{t("cached")}
)}
); }