import { displayAuthors } from '../../shared/names.ts'; import type { SearchResult } from '../../shared/types.ts'; /** Next highlighted index for an arrow key; -1 means nothing is highlighted. */ export function moveActive(key: string, active: number, count: number): number { if (count === 0) return -1; if (key === 'ArrowDown') return active < count - 1 ? active + 1 : 0; if (key === 'ArrowUp') return active > 0 ? active - 1 : count - 1; return active; } export interface Footer { label: string; onPick: () => void } /** Search results as a listbox. The input that owns it keeps focus and points at the highlighted option. */ export function ResultList({ id, label, results, active, onPick, onHover, footer }: { id: string; label: string; results: SearchResult[]; active: number; onPick: (r: SearchResult) => void; onHover: (i: number) => void; footer?: Footer; }) { const keep = (e: Event) => e.preventDefault(); // a click must not take focus from the input return ( ); }