"use client"; import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog"; import { Save, X } from "@/components/icons/platform-icons"; import type { FileReadResponse } from "@/lib/shared/contracts/files"; import { PreviewBody } from "@/modules/files/components/content/file-manager-open-file-preview"; import { FILES_BADGE_SURFACE, FILES_PANEL_INSET, } from "@/modules/files/components/file-manager-surface"; import { getFileIcon, type FileEntry } from "@/modules/files/components/file-manager-presenters"; import React, { useState } from "react"; import type { SetStateAction } from "react"; type OpenFileDialogProps = { canSaveOpenFile: boolean; editorNotice: string | null; fileContentErrorMessage: string; fileContentIsError: boolean; fileContentIsLoading: boolean; hasUnsavedChanges: boolean; onChangeOpenFileDraft: (value: SetStateAction) => void; onClose: () => void; onSave: () => void; openFile: { entry: FileEntry }; openFileAssetUrl: string; openFileBadgeLabel: string; openFileContent: string; openFileKey: string | null; openFileLanguage: string; openFileViewer: FileReadResponse | null; showSaveOpenFile: boolean; }; export function OpenFileDialog({ canSaveOpenFile, editorNotice, fileContentErrorMessage, fileContentIsError, fileContentIsLoading, hasUnsavedChanges, onChangeOpenFileDraft, onClose, onSave, openFile, openFileAssetUrl, openFileBadgeLabel, openFileContent, openFileKey, openFileLanguage, openFileViewer, showSaveOpenFile, }: OpenFileDialogProps) { const [showDiscardConfirm, setShowDiscardConfirm] = useState(false); const headerEntry = openFileViewer && openFile.entry.type === "file" ? { ...openFile.entry, ext: openFileViewer.ext ?? openFile.entry.ext } : openFile.entry; function handleCloseRequest() { if (hasUnsavedChanges) { setShowDiscardConfirm(true); } else { onClose(); } } return ( <> { if (!open) handleCloseRequest(); }}> {/* Accessible title/description (visually hidden) */} {openFile.entry.name} File editor — {openFileBadgeLabel} {/* Window chrome title bar */}
{/* Traffic lights */}
{/* Centered file tab */}
{getFileIcon(headerEntry)} {openFile.entry.name} {hasUnsavedChanges ? ( ) : null} {openFileBadgeLabel}
{/* Right gutter — balances traffic lights */}
{hasUnsavedChanges ? ( ⌘S ) : null}
{/* Editor body */}
{/* Floating save button */} {showSaveOpenFile && !showDiscardConfirm ? (
) : null} {/* Inline discard confirmation strip */} {showDiscardConfirm ? (

Discard changes to{" "} {openFile.entry.name}?

) : null}
{/* Status bar */} {editorNotice && !showDiscardConfirm ? (
{editorNotice}
) : null}
); }