"use client"; import React from "react"; import { useTranslations } from "next-intl"; import { Card } from "@/shared/components"; interface CachePerformanceProps { hits?: number; misses?: number; hitRate?: string; avgLatencyMs?: number; p95LatencyMs?: number; totalRequests?: number; loading?: boolean; error?: string | null; onRetry?: () => void; } function HitRateBar({ hitRate, label }: { hitRate: number; label: string }) { const colorClass = hitRate >= 70 ? "bg-green-500" : hitRate >= 40 ? "bg-amber-400" : "bg-red-500"; const textClass = hitRate >= 70 ? "text-green-500" : hitRate >= 40 ? "text-amber-400" : "text-red-500"; return (
{label} {hitRate.toFixed(1)}%
); } // ─── Skeleton ───────────────────────────────────────────────────────────────── function Skeleton({ className }: { className?: string }) { return (
); } // ─── CachePerformance ───────────────────────────────────────────────────────── export default function CachePerformance({ hits = 0, misses = 0, hitRate, avgLatencyMs, p95LatencyMs, totalRequests = 0, loading = false, error = null, onRetry, stats, }: CachePerformanceProps) { const t = useTranslations("cache"); // Parse hitRate string (e.g. "85.0%") to number for the bar const hitRateNum = hitRate ? parseFloat(hitRate) : 0; return (
{/* Header */}

{t("performanceTitle")}

{/* Error state */} {error && (

{error}

{onRetry && ( )}
)} {/* Loading state */} {loading && !error && (
{(avgLatencyMs !== undefined || p95LatencyMs !== undefined) && (
)}
)} {/* Data state — hidden while loading */} {!loading && !error && stats !== null && ( <> {/* Hit rate bar */} {hitRate !== undefined && ( )} {/* Hit / Miss / Total breakdown */}
{hits}
{t("hits")}
{misses}
{t("misses")}
{totalRequests}
{t("total")}
{/* Latency metrics */} {(avgLatencyMs !== undefined || p95LatencyMs !== undefined) && (
{avgLatencyMs !== undefined && (
{avgLatencyMs}
{t("cachePerformanceAvgLatency")}
)} {p95LatencyMs !== undefined && (
{p95LatencyMs}
{t("cachePerformanceP95Latency")}
)}
)} {/* hitRate as text for test assertions */} {hitRate !== undefined && (
{hitRate}
)} )}
); }