import React from 'react'; import { Search, RefreshCw, FileText } from 'lucide-react'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Switch } from '@/components/ui/switch'; export function LogViewer({ files = [], selectedPath, onSelectFile, onRefreshFiles, content, contentLoading = false, contentEmpty, searchPattern = '', onSearchChange, onSearchSubmit, lineCount, onLineCountChange, lineCountOptions = [50, 100, 200, 500, 1000], autoRefresh = false, onAutoRefreshChange, onRefreshContent, onDownload, onClear, formatFileSize = defaultFormatFileSize, getLogIconType = () => 'default', }) { return (

Log Files

{onRefreshFiles && ( )}
{files.length === 0 ? (
No log files found
) : ( files.map((log) => (
onSelectFile?.(log)} >
{log.name} {log.path}
{formatFileSize(log.size)}
)) )}
onSearchChange?.(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && onSearchSubmit?.()} placeholder="Search pattern..." />
{onLineCountChange && ( )}
{onAutoRefreshChange && ( )} {onRefreshContent && ( )} {onDownload && ( )} {onClear && ( )}
{contentLoading ? (
Loading...
) : !content ? (
{contentEmpty ?? 'Select a log file to view its contents.'}
) : (
{content}
)}
); } function defaultFormatFileSize(bytes) { if (bytes == null) return ''; if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`; } export default LogViewer;