import { useEffect, useRef, useState } from 'react'; import { CheckIcon, CopyIcon, CornersInIcon, CornersOutIcon, EyeIcon, EyeSlashIcon, MagnifyingGlassIcon, } from '@phosphor-icons/react'; import type { HealthResponse, LensId, SearchHit, SizeMetric } from '../api/types.ts'; import { fetchSearch } from '../api/client.ts'; import { formatBytes, formatDisplayPath, formatSignedBytes } from '../lib/format.ts'; import { LENS_DEFINITIONS } from '../lib/lenses.ts'; import { AstrolabeMark } from './Bezel.tsx'; export interface SessionMover { path: string; deltaBytes: number; updatedAt: number; } interface CommandRailProps { activePath: string; onNavigate: (path: string) => void; activeLens: LensId; onSelectLens: (lens: LensId) => void; metric: SizeMetric; onToggleMetric: () => void; includeHidden: boolean; onToggleHidden: () => void; fseventsActive: boolean; movers: SessionMover[]; searchOpen: boolean; onOpenSearch: () => void; onCloseSearch: () => void; activeBytes?: number | null; platform?: HealthResponse['platform']; homeDisplay?: string; isWindows?: boolean; maximized?: boolean; onToggleMaximized?: () => void; } export function CommandRail({ activePath, onNavigate, activeLens, onSelectLens, metric, onToggleMetric, includeHidden, onToggleHidden, fseventsActive, movers, searchOpen, onOpenSearch, onCloseSearch, activeBytes = null, platform, homeDisplay = '~', isWindows = false, maximized = false, onToggleMaximized, }: CommandRailProps) { const [copied, setCopied] = useState(false); const copyTimerRef = useRef(null); const [moversOpen, setMoversOpen] = useState(false); const [query, setQuery] = useState(''); const [hits, setHits] = useState([]); const [searchScoped, setSearchScoped] = useState(false); const [selectedIndex, setSelectedIndex] = useState(0); const segments = activePath ? activePath.split('/') : []; useEffect(() => { return () => { if (copyTimerRef.current !== null) { window.clearTimeout(copyTimerRef.current); } }; }, []); useEffect(() => { if (!searchOpen) { setQuery(''); setHits([]); setSelectedIndex(0); return; } if (!query.trim()) { setHits([]); setSelectedIndex(0); return; } const ctrl = new AbortController(); const scope = searchScoped ? activePath : ''; const timer = window.setTimeout(() => { void fetchSearch(query, scope, 30, ctrl.signal) .then((res) => { if (!ctrl.signal.aborted) { setHits(res.hits); setSelectedIndex(0); } }) .catch(() => { // Ignore aborted requests }); }, 120); return () => { ctrl.abort(); window.clearTimeout(timer); }; }, [query, searchOpen, activePath, searchScoped]); const handleCopyPath = () => { void navigator.clipboard .writeText(formatDisplayPath(activePath, homeDisplay, isWindows)) .then(() => { setCopied(true); if (copyTimerRef.current !== null) window.clearTimeout(copyTimerRef.current); copyTimerRef.current = window.setTimeout(() => { setCopied(false); copyTimerRef.current = null; }, 1500); }) .catch(() => {}); }; const navigateToHit = (h: SearchHit) => { const target = h.kind === 'directory' ? h.path : h.path.includes('/') ? h.path.slice(0, h.path.lastIndexOf('/')) : ''; onNavigate(target); onCloseSearch(); }; const netMoverBytes = movers.reduce((s, m) => s + m.deltaBytes, 0); const railContent = ( <> {/* Breadcrumb Trail (with inline Brand + Active Dir Size when maximised) */}
{maximized ? ( <>

Getǣl

{/* Lens Switcher Tabs */}
{LENS_DEFINITIONS.map((lens) => { const active = activeLens === lens.id; return ( ); })}
{/* Controls Cluster */}
{/* Live Watcher Pulse + Session Movers */}
{moversOpen ? (
Session Movers ({movers.length})
{movers.length === 0 ? (

Watching filesystem. Live directory deltas will appear here.

) : (
    {movers.slice(0, 12).map((m) => (
  • = 0 ? 'text-[var(--accent)]' : 'text-[var(--status-ok)]'} > {formatSignedBytes(m.deltaBytes)}
  • ))}
)}
) : null}
); return ( <> {maximized ? (
{railContent}
) : (
{railContent}
)} {/* Quick Jump Command Palette */} {searchOpen ? (
{ e.stopPropagation(); }} >
{ setQuery(e.target.value); }} onKeyDown={(e) => { if (e.key === 'ArrowDown' && hits.length > 0) { e.preventDefault(); setSelectedIndex((i) => Math.min(hits.length - 1, i + 1)); } else if (e.key === 'ArrowUp' && hits.length > 0) { e.preventDefault(); setSelectedIndex((i) => Math.max(0, i - 1)); } else if (e.key === 'Enter' && hits.length > 0) { e.preventDefault(); const chosen = hits[selectedIndex]; if (chosen) navigateToHit(chosen); } }} placeholder="Jump to cached folder or large file…" className="w-full bg-transparent text-sm text-[var(--text-primary)] placeholder:text-[var(--text-muted)] focus:outline-none font-mono-tabular" /> {activePath !== '' ? ( ) : null}
{hits.length === 0 ? (
{query.trim() ? 'No matching directories or indexed top files.' : 'Type to search cached paths…'}
) : ( hits.map((h, idx) => ( )) )}
) : null} ); }