"use client"; import { useState, useRef, useEffect } from "react"; import type { Terminal } from "@/hooks/domains/session/use-terminals"; /** * Compact dropdown that lists every parked (hidden but PTY-alive) terminal * for the active task. Click an item to resume — the tab reappears in the * main strip with its sequence number and PTY status preserved. * * Right-click an item to destroy (kill PTY + remove the DB row). * * Renders nothing when the parked list is empty; the parent decides * whether to mount it. */ export function ParkedTerminalsMenu({ parkedTerminals, onResume, onDestroy, }: { parkedTerminals: Terminal[]; onResume: (id: string) => Promise | void; onDestroy: (id: string) => Promise | void; }) { const [open, setOpen] = useState(false); const wrapperRef = useRef(null); useEffect(() => { if (!open) return; const onDocumentClick = (event: globalThis.MouseEvent) => { if (!wrapperRef.current) return; if (!wrapperRef.current.contains(event.target as Node)) setOpen(false); }; document.addEventListener("mousedown", onDocumentClick); return () => document.removeEventListener("mousedown", onDocumentClick); }, [open]); if (parkedTerminals.length === 0) return null; return (
{open && (
{parkedTerminals.map((t) => ( ))}
)}
); }