"use client" import { Fragment } from "react" import { AlertTriangleIcon, CircleAlertIcon, CircleHelpIcon, InfoIcon, BugIcon } from "lucide-react" import { Badge } from "@/components/reui/badge" import type { LogLevel } from "@mmapp/contracts" export const LEVEL_LABELS: Record = { critical: "Критическая", error: "Ошибка", warning: "Предупреждение", info: "Информация", debug: "Отладка", unknown: "Не определён" } export const LEVEL_COLORS: Record = { critical: "var(--destructive)", error: "var(--destructive)", warning: "var(--warning)", info: "var(--info)", debug: "var(--muted-foreground)", unknown: "var(--border)" } export function LevelBadge({ level }: { level: LogLevel }) { const Icon = level === "critical" || level === "error" ? CircleAlertIcon : level === "warning" ? AlertTriangleIcon : level === "debug" ? BugIcon : level === "unknown" ? CircleHelpIcon : InfoIcon return } export function HighlightMessage({ text, search }: { text: string; search: string }) { if (!search) return <>{text} const lower = text.toLocaleLowerCase(), needle = search.toLocaleLowerCase(), parts = [] let start = 0, found = lower.indexOf(needle) while (found >= 0) { parts.push({text.slice(start, found)}{text.slice(found, found + search.length)}) start = found + search.length; found = lower.indexOf(needle, start) } return <>{parts}{text.slice(start)} } export function formatLogTime(at: string | null) { return at ? new Date(at).toLocaleString("ru-RU", { day: "2-digit", month: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit" }) : "—" }