import { Activity, HardDrive, Loader2, RefreshCw, Trash2 } from "lucide-react" import { useTranslation } from "react-i18next" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Progress } from "@/components/ui/progress" import { Separator } from "@/components/ui/separator" import { cn } from "@/lib/utils" import { formatCacheRatio, useCacheStats } from "../hooks/use-cache-stats" /** * Модальное окно статистики кэша */ export function CacheStatisticsModal() { const { t } = useTranslation() const { stats, isLoading, error, refreshStats, clearPreviewCache, clearAllCache } = useCacheStats() const handleClearPreviewCache = async () => { const confirmed = window.confirm(t("videoCompiler.cache.confirmClearPreview")) if (confirmed) { await clearPreviewCache() } } const handleClearAllCache = async () => { const confirmed = window.confirm(t("videoCompiler.cache.confirmClearAll")) if (confirmed) { await clearAllCache() } } if (isLoading && !stats) { return (
) } if (error) { return (

{error}

) } if (!stats) { return (

{t("videoCompiler.cache.noData")}

) } return (
{/* Общая статистика */} {t("videoCompiler.cache.overallEfficiency")}
{t("videoCompiler.cache.hitRate")}: 0.7 ? "default" : "secondary"}> {formatCacheRatio(stats.hit_ratio)}
{/* Детальная статистика */}
{/* Превью */} {t("videoCompiler.cache.preview")} {t("videoCompiler.cache.previewDescription")}
{t("videoCompiler.cache.hits")}: {stats.preview_hits}
{t("videoCompiler.cache.misses")}: {stats.preview_misses}
{t("videoCompiler.cache.efficiency")}: 0.7 && "border-green-600 text-green-600", stats.preview_hit_ratio <= 0.7 && stats.preview_hit_ratio > 0.4 && "border-yellow-600 text-yellow-600", stats.preview_hit_ratio <= 0.4 && "border-red-600 text-red-600", )} > {formatCacheRatio(stats.preview_hit_ratio)}
{/* Метаданные */} {t("videoCompiler.cache.metadata")} {t("videoCompiler.cache.metadataDescription")}
{t("videoCompiler.cache.hits")}: {stats.metadata_hits}
{t("videoCompiler.cache.misses")}: {stats.metadata_misses}
{stats.memory_usage && (
{t("videoCompiler.cache.memory")}: {stats.memory_usage.total_bytes ? `${(stats.memory_usage.total_bytes / (1024 * 1024)).toFixed(1)} MB` : "0 MB"}
)}
{/* Действия */} {t("videoCompiler.cache.cacheManagement")} {t("videoCompiler.cache.cacheManagementDescription")}
) }