// The agents page's picks for select mode. Plain functions with no imports, so // `npm test` runs them; `useAgentSelection` holds the state. /** `picked` without the agents the roster no longer has (one destroyed meanwhile). */ export function stillThere(picked: string[], roster: string[]): string[] { const known = new Set(roster); return picked.filter((name) => known.has(name)); } /** Starting select mode on `name`: it is picked, and any earlier picks stay. */ export function startedOn(picked: string[], name: string | null): string[] { if (name === null || picked.includes(name)) return picked; return [...picked, name]; } /** `picked` with `name` flipped. */ export function toggled(picked: string[], name: string): string[] { return picked.includes(name) ? picked.filter((n) => n !== name) : [...picked, name]; } /** `picked` plus every shown agent, without repeating a name. */ export function pickedAll(picked: string[], shown: string[]): string[] { const out = [...picked]; for (const name of shown) { if (!out.includes(name)) out.push(name); } return out; }