import { useState, useEffect } from "react"; import type { FileDetail as FileDetailType, FileVersionSummary, FileVersion } from "../../lib/api"; import { BodyRenderer } from "./BodyRenderer"; import { VersionHistoryDropdown } from "./VersionHistoryDropdown"; export interface FocusedElement { index: number; type: string; preview: string; } interface FileDetailProps { file: FileDetailType; loading: boolean; onBack: () => void; onSave: (id: string, name: string, description: string) => void; onDelete: (id: string) => void; onBodyElementUpdate?: (index: number, element: import("../../lib/api").BodyElement) => void; onBodyReorder?: (fromIndex: number, toIndex: number) => void; onBodyElementDelete?: (index: number) => void; onBodyElementDuplicate?: (index: number) => void; onEditingChange?: (isEditing: boolean) => void; hasPendingRemoteUpdate?: boolean; onOverwrite?: () => void; // Focus element props focusedElement?: FocusedElement | null; onFocusElement?: (element: FocusedElement | null) => void; onGenerateFromElement?: (index: number, action: string) => void; onConvertElement?: (index: number, toType: string) => void; onCreateTaskFromElement?: (index: number, selectedText?: string) => void; // Version history props versions?: FileVersionSummary[]; versionsLoading?: boolean; selectedVersion?: FileVersion | null; loadingVersion?: boolean; restoring?: boolean; onSelectVersion?: (version: number) => void; onRestoreVersion?: (version: number) => void; onClearVersionSelection?: () => void; } export function FileDetail({ file, loading, onBack, onSave, onDelete, onBodyElementUpdate, onBodyReorder, onBodyElementDelete, onBodyElementDuplicate, onEditingChange, hasPendingRemoteUpdate, onOverwrite, focusedElement: _focusedElement, onFocusElement, onGenerateFromElement, onConvertElement, onCreateTaskFromElement, versions = [], versionsLoading = false, selectedVersion = null, loadingVersion = false, restoring = false, onSelectVersion, onRestoreVersion, onClearVersionSelection, }: FileDetailProps) { const [isEditing, setIsEditing] = useState(false); const [name, setName] = useState(file.name); const [description, setDescription] = useState(file.description || ""); const [transcriptExpanded, setTranscriptExpanded] = useState(false); // Helper to get element preview text const getElementPreview = (index: number): string => { const element = file.body[index]; if (!element) return ""; switch (element.type) { case "heading": case "paragraph": return element.text.slice(0, 50) + (element.text.length > 50 ? "..." : ""); case "code": return element.content.slice(0, 50) + (element.content.length > 50 ? "..." : ""); case "list": return element.items[0]?.slice(0, 40) + (element.items.length > 1 ? ` (+${element.items.length - 1} more)` : ""); case "chart": return element.title || `${element.chartType} chart`; case "image": return element.alt || element.caption || "Image"; default: return "Element"; } }; // Handler for focus action from context menu const handleFocusElement = (index: number) => { const element = file.body[index]; if (!element || !onFocusElement) return; onFocusElement({ index, type: element.type, preview: getElementPreview(index), }); }; // Update local state when file changes useEffect(() => { setName(file.name); setDescription(file.description || ""); }, [file.name, file.description]); const handleSave = () => { onSave(file.id, name, description); setIsEditing(false); }; const handleCancel = () => { setName(file.name); setDescription(file.description || ""); setIsEditing(false); }; if (loading) { return (
Loading...
); } return (
{/* Header */}
{isEditing ? ( <> {onSelectVersion && onRestoreVersion && onClearVersionSelection && ( )} ) : ( <> )}
{isEditing ? (
setName(e.target.value)} className="w-full px-3 py-2 bg-[#0d1b2d] border border-[#3f6fb3] text-[#dbe7ff] font-mono text-sm focus:outline-none focus:border-[#75aafc]" placeholder="File name" />