import { useState } from "react"; import type { ToolsetMeta, ToolProfile } from "../types"; import { modalOverlayStyle, modalPanelStyle } from "./modalStyles"; interface Props { toolsets: ToolsetMeta[]; profiles: ToolProfile[]; // built-ins first, then custom selectedId: string; onSelect: (id: string) => void; onSaveProfile: (p: ToolProfile) => void; onDeleteProfile: (id: string) => void; } const selStyle: React.CSSProperties = { background: "rgba(255,255,255,0.04)", border: "1px solid var(--card-border)", borderRadius: 6, color: "var(--text)", fontSize: 11, padding: "3px 6px", cursor: "pointer", outline: "none", maxWidth: 130, }; export function ToolsMenu({ toolsets, profiles, selectedId, onSelect, onSaveProfile, onDeleteProfile }: Props) { const [manageOpen, setManageOpen] = useState(false); const builtins = profiles.filter((p) => p.builtin); const custom = profiles.filter((p) => !p.builtin); // Modal draft state — seeded from the currently selected profile when opened. const selected = profiles.find((p) => p.id === selectedId); const [draftName, setDraftName] = useState(""); const [draftEnabled, setDraftEnabled] = useState>(new Set()); function openManage() { setDraftName(""); setDraftEnabled(new Set(selected?.enabled ?? [])); setManageOpen(true); } function toggle(name: string) { setDraftEnabled((prev) => { const next = new Set(prev); next.has(name) ? next.delete(name) : next.add(name); return next; }); } function save() { const name = draftName.trim(); if (!name) return; const id = `custom-${name.toLowerCase().replace(/[^a-z0-9]+/g, "-")}-${Date.now().toString(36)}`; const profile: ToolProfile = { id, name, enabled: toolsets.map((t) => t.name).filter((n) => draftEnabled.has(n)) }; onSaveProfile(profile); onSelect(id); setManageOpen(false); } return (
Tools {manageOpen && (
setManageOpen(false)} style={{ ...modalOverlayStyle, zIndex: 1000 }} >
e.stopPropagation()} style={{ ...modalPanelStyle, padding: 20, width: 420, maxHeight: "80vh", overflowY: "auto", }} >
Tool profiles
Pick the toolsets a new desk should load. Fewer tools → faster first response.
{/* Toolset checklist. Hermes filters by toolset, not individual tool, so each row is a group; the count + tooltip show what it contains. */}
{toolsets.reduce((n, t) => n + (t.tools?.length ?? 1), 0)} tools across {toolsets.length} toolsets — toggle whole toolsets:
{toolsets.map((t) => ( ))}
{/* Save as new profile */}
setDraftName(e.target.value)} placeholder="New profile name…" style={{ flex: 1, background: "rgba(255,255,255,0.06)", border: "1px solid var(--card-border)", borderRadius: 6, padding: "6px 10px", color: "var(--text)", fontSize: 12, outline: "none", }} />
{/* Existing custom profiles */} {custom.length > 0 && (
Saved profiles
{custom.map((p) => (
{p.name} {p.enabled.length} tools
))}
)}
)}
); }