import { useMemo, useState } from "react"; import { ChevronDown, FolderGit2, FolderRoot } from "lucide-react"; import type { WorkspaceInfo } from "../hooks/useWorkspaces"; import "./WorkspaceSelector.css"; interface WorkspaceSelectorProps { currentWorkspace: string; projectName: string; workspaces: WorkspaceInfo[]; onSelect: (workspace: string) => void; } function truncateTitle(title?: string, maxLength = 44): string | undefined { if (!title) return undefined; if (title.length <= maxLength) return title; return `${title.slice(0, maxLength - 1)}…`; } export function WorkspaceSelector({ currentWorkspace, projectName, workspaces, onSelect, }: WorkspaceSelectorProps) { const [open, setOpen] = useState(false); const safeWorkspace = typeof currentWorkspace === "string" ? currentWorkspace : "project"; const currentLabel = useMemo(() => { if (safeWorkspace === "project") { return projectName || "Project Root"; } const match = workspaces.find((workspace) => workspace.id === safeWorkspace); return match?.label ?? safeWorkspace; }, [safeWorkspace, projectName, workspaces]); return (