/** * @file FileViewer.tsx * @description Read-only file-content modal for the config explorer. Takes * already-fetched data as props (path/data/error) rather than fetching * itself, so it stays tool-agnostic — the orchestrator (Claude or Codex * config page) owns the fetch. * @author Nguyễn Ngọc Trí Vĩ */ import { useEffect } from "react"; import { useTranslation } from "react-i18next"; import { FileText, X, AlertCircle } from "lucide-react"; import type { CcFileResponse } from "../../lib/api"; import { CopyButton } from "./configPrimitives"; export function FileViewer({ state, onClose, }: { state: { path: string; data: CcFileResponse | null; error: string | null }; onClose: () => void; }) { const { t } = useTranslation("ccConfig"); useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [onClose]); return (
e.stopPropagation()} >
{state.path}
{state.error ? (
{state.error}
) : !state.data ? (
…
) : (
              {state.data.text}
              {state.data.truncated && (
                
                  {"\n\n"}
                  {t("common.truncated")}
                
              )}
            
)}
); }