/**
* RecentFileTabs.tsx — S613: tab strip file recenti sopra il code editor
*
* Mostra gli ultimi MAX_RECENT file aperti come tab cliccabili (pattern VS Code).
* Integrato nella riga sopra FileEditor nel top Panel del PanelGroup S612.
*
* - Click tab → apre il file (setOpenFile + setRequestOpenPath)
* - × → chiude il tab (closeRecentFile; se era il file attivo, apre il precedente)
* - Tab attivo evidenziato in blu
* - Overflow orizzontale (no wrap) con scroll invisibile
*
* S614: import type { CSSProperties, RefObject } — import diretto da "react", non prefissato
* data-path su FileTab per useActiveTabScroll
* auto-scroll del tab attivo nella viewport
*
* S616: badge arancione "●" sui tab modificati dall'agente mentre erano in background.
* onVfsChanged → markDirty(path) per file in recentFiles che non sono aperti.
* Apertura tab → clearDirty(path) automatica via setOpenFile.
*/
import { useRef, useEffect, memo } from "react";
import type { CSSProperties, RefObject } from "react";
import { X } from "lucide-react";
import { useWorkspaceStore } from "@/store/workspaceStore";
import { onVfsFileChanged } from "@/lib/vfsDb"; // S619: usa onVfsFileChanged per dirty badge preciso
import type { VFSFile } from "@/lib/vfsDb";
// ─── Icon helpers ─────────────────────────────────────────────────────────────
function fileIcon(name: string): string {
if (name.endsWith(".py")) return "🐍";
if (name.endsWith(".ts") || name.endsWith(".tsx")) return "📘";
if (name.endsWith(".js") || name.endsWith(".jsx")) return "📜";
if (name.endsWith(".json")) return "📋";
if (name.endsWith(".html")) return "🌐";
if (name.endsWith(".css") || name.endsWith(".scss")) return "🎨";
if (name.endsWith(".md")) return "📝";
if (name.endsWith(".sh")) return "⚙️";
return "📄";
}
// ─── Single tab ───────────────────────────────────────────────────────────────
function FileTab({
file,
isActive,
isDirty,
onOpen,
onClose,
}: {
file: VFSFile;
isActive: boolean;
isDirty: boolean;
onOpen: (f: VFSFile) => void;
onClose: (path: string) => void;
}) {
return (