import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import { Colors } from '../colors.js';
import { useRuntimeApi } from '../contexts/RuntimeContext.js';
const METRIC_COL_WIDTH = 35;
const VALUE_COL_WIDTH = 20;
const StatRow = ({ title, value, isSubtle = false, }) => (_jsxs(Box, { children: [_jsx(Box, { width: METRIC_COL_WIDTH, children: _jsx(Text, { color: Colors.LightBlue, children: isSubtle ? `  ↳ ${title}` : title }) }), _jsx(Box, { width: VALUE_COL_WIDTH, justifyContent: "flex-end", children: _jsx(Text, { children: value }) })] }));
export const CacheStatsDisplay = () => {
    const { getCliProviderManager } = useRuntimeApi();
    const providerManager = getCliProviderManager();
    if (!providerManager) {
        return (_jsx(Box, { borderStyle: "round", borderColor: Colors.Gray, paddingY: 1, paddingX: 2, children: _jsx(Text, { children: "Provider manager not available" }) }));
    }
    // Get cache statistics from ProviderManager
    const cacheStats = providerManager.getCacheStatistics?.() ?? null;
    if (!cacheStats) {
        return (_jsx(Box, { borderStyle: "round", borderColor: Colors.Gray, paddingY: 1, paddingX: 2, children: _jsx(Text, { color: Colors.Foreground, children: "Cache statistics are not available for the current provider." }) }));
    }
    const totalCacheReads = cacheStats.totalCacheReads;
    const totalCacheWrites = cacheStats.totalCacheWrites;
    const requestsWithCacheHits = cacheStats.requestsWithCacheHits;
    const cacheHitRate = cacheStats.hitRate;
    // Check if we have any cache data
    // totalCacheWrites can be null (not reported by provider) vs 0 (explicitly reported as zero)
    const hasCacheData = totalCacheReads > 0 || (totalCacheWrites ?? 0) > 0;
    if (!hasCacheData) {
        return (_jsx(Box, { borderStyle: "round", borderColor: Colors.Gray, paddingY: 1, paddingX: 2, children: _jsx(Text, { color: Colors.Foreground, children: "No cache data available. Cache statistics are available for providers with prompt caching support (Anthropic, OpenAI, Groq, Deepseek, Fireworks, OpenRouter, Qwen)." }) }));
    }
    return (_jsxs(Box, { borderStyle: "round", borderColor: Colors.Gray, flexDirection: "column", paddingY: 1, paddingX: 2, children: [_jsx(Text, { bold: true, color: Colors.AccentPurple, children: "Cache Stats" }), _jsx(Box, { height: 1 }), _jsx(StatRow, { title: "Total Cache Reads (tokens)", value: _jsx(Text, { color: Colors.AccentGreen, children: totalCacheReads.toLocaleString() }) }), totalCacheWrites !== null && (_jsx(StatRow, { title: "Total Cache Writes (tokens)", value: _jsx(Text, { color: Colors.Foreground, children: totalCacheWrites.toLocaleString() }) })), _jsx(StatRow, { title: "Cache Hit Rate", value: _jsxs(Text, { color: cacheHitRate > 0 ? Colors.AccentGreen : Colors.Foreground, children: [cacheHitRate.toFixed(1), "%"] }) }), _jsx(StatRow, { title: "Requests with Cache Hits", value: _jsx(Text, { color: Colors.Foreground, children: requestsWithCacheHits.toLocaleString() }) })] }));
};
//# sourceMappingURL=CacheStatsDisplay.js.map