"use client"; import { Eye, Edit3, GitCompare } from "lucide-react"; import { useFileViewerStore, type FileTab, type FileViewMode } from "@/lib/fileViewerStore"; import { cn } from "@/lib/utils"; interface FileInfoBarProps { tab: FileTab; } function formatBytes(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } const LANGUAGE_LABELS: Record = { typescript: "TypeScript", tsx: "TSX", javascript: "JavaScript", jsx: "JSX", python: "Python", rust: "Rust", go: "Go", css: "CSS", scss: "SCSS", html: "HTML", json: "JSON", markdown: "Markdown", bash: "Bash", yaml: "YAML", toml: "TOML", sql: "SQL", graphql: "GraphQL", ruby: "Ruby", java: "Java", c: "C", cpp: "C++", csharp: "C#", php: "PHP", swift: "Swift", kotlin: "Kotlin", dockerfile: "Dockerfile", makefile: "Makefile", text: "Plain Text", }; const VIEW_MODES: { mode: FileViewMode; label: string; icon: React.ComponentType<{ className?: string }> }[] = [ { mode: "view", label: "View", icon: Eye }, { mode: "edit", label: "Edit", icon: Edit3 }, { mode: "diff", label: "Diff", icon: GitCompare }, ]; export function FileInfoBar({ tab }: FileInfoBarProps) { const { setMode } = useFileViewerStore(); const lineCount = tab.content.split("\n").length; const byteSize = new TextEncoder().encode(tab.content).length; const langLabel = LANGUAGE_LABELS[tab.language] ?? tab.language; return (
{/* Left: file stats */}
{langLabel} UTF-8 {lineCount.toLocaleString()} lines {formatBytes(byteSize)} {tab.isDirty && ( ● Unsaved changes )}
{/* Right: mode switcher */} {!tab.isImage && (
{VIEW_MODES.map(({ mode, label, icon: Icon }) => ( ))}
)}
); }