import { Clock, Gauge, Globe, Tags } from 'lucide-react' import { KpiStatGrid, type KpiStatItem } from '@/components/kpi-stat-grid' import { Badge } from '@/components/reui/badge' import { KpiStatGridSkeleton } from '@/components/skeletons' import { formatDateTime, moduleIntervalLabel } from '@/lib/modules/display' import { communityLabel, moduleDohProfileIds } from '@/lib/modules/helpers' import { dohPolicyRu } from '@/lib/ui-labels' import type { AsEntry, BgpCommunity, ModuleRow } from '@/types/api' interface ModuleKpiCardsProps { mod: ModuleRow | null communities: BgpCommunity[] asEntries: AsEntry[] entriesCount?: number loading?: boolean } export function ModuleKpiCards({ mod, communities, asEntries, entriesCount = 0, loading = false, }: ModuleKpiCardsProps) { if (loading || !mod) { return } const asPrefixTotal = asEntries.reduce((acc, entry) => acc + (entry.prefix_count ?? 0), 0) const dohIds = moduleDohProfileIds(mod) const isDomains = mod.type === 'DOMAINS' const isAsPrefixes = mod.type === 'AS_PREFIXES' const community = communityLabel(mod.default_community_id, communities) const entriesFooter = isAsPrefixes ? ( {asEntries.length} AS · в модуле ) : isDomains ? ( {mod.default_community_id ? community : 'без community'} ) : ( {entriesCount} · в модуле ) const policyItem: KpiStatItem = isDomains ? { id: 'doh', icon: , iconClassName: 'text-primary', value: dohIds.length > 0 ? String(dohIds.length) : '—', label: 'DoH', footer: ( 0 ? 'info-light' : 'outline'} size="sm"> {dohIds.length > 0 ? dohPolicyRu(mod.doh_resolver_policy) : 'без DoH'} ), } : { id: 'community', icon: , iconClassName: 'text-primary', value: community, label: 'Community', footer: ( по умолчанию ), } const items: KpiStatItem[] = [ { id: 'priority', icon: , iconClassName: 'text-info', value: String(mod.priority ?? 0), label: 'Приоритет', footer: ( {mod.enabled !== false ? 'активен' : 'выключен'} · {mod.type} ), }, { id: 'interval', icon: , iconClassName: 'text-warning', value: moduleIntervalLabel(mod), label: 'Интервал обновления', footer: ( {formatDateTime(mod.last_refreshed_at) || 'никогда'} ), }, { id: 'prefixes', icon: , iconClassName: 'text-success', value: isAsPrefixes ? String(asPrefixTotal) : String(entriesCount), label: isAsPrefixes ? 'Префиксы AS' : 'Записи модуля', footer: entriesFooter, }, policyItem, ] return }