"use client"; import { useRef, useState, type KeyboardEvent, type ReactNode } from "react"; import styles from "./pixel.module.css"; export type MenuItem = { label: ReactNode; href?: string; onSelect?: () => void; hint?: ReactNode }; /** A game menu: one tab stop, arrow keys move the blinking ▶ cursor, Enter picks. */ export function Menu({ items, label, orientation }: { items: MenuItem[]; label: string; orientation: "vertical" | "horizontal"; }) { const [active, setActive] = useState(0); const refs = useRef<(HTMLElement | null)[]>([]); const moveTo = (index: number) => { const next = (index + items.length) % items.length; setActive(next); refs.current[next]?.focus(); }; const onKeyDown = (event: KeyboardEvent) => { const vertical = orientation === "vertical"; if (event.key === (vertical ? "ArrowDown" : "ArrowRight")) moveTo(active + 1); else if (event.key === (vertical ? "ArrowUp" : "ArrowLeft")) moveTo(active - 1); else if (event.key === "Home") moveTo(0); else if (event.key === "End") moveTo(items.length - 1); else return; event.preventDefault(); }; return (