import { useEffect, useRef, useState } from 'react'; import type { GridSpec } from '../types'; // Miniature preview of a cols×rows grid, drawn as filled cells. export function GridIcon({ cols, rows }: GridSpec) { const w = 12 / cols; const h = 12 / rows; const cells = []; for (let r = 0; r < rows; r++) { for (let c = 0; c < cols; c++) { cells.push(); } } return {cells}; } /** * Pane-arrangement picker for a group: the button shows the current grid, * clicking reveals the nine cols×rows presets plus Auto (grow with agents). */ export default function LayoutPicker({ grid, isAuto, onPick }: { grid: GridSpec; isAuto: boolean; onPick: (l: GridSpec | null) => void; }) { const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { if (!open) return; const close = (e: MouseEvent) => { if (!ref.current?.contains(e.target as Node)) setOpen(false); }; document.addEventListener('mousedown', close); return () => document.removeEventListener('mousedown', close); }, [open]); return ( setOpen((o) => !o)}> {grid.cols}×{grid.rows}{isAuto ? ' auto' : ''} {open && ( { onPick(null); setOpen(false); }}> Auto — grow with agents {[1, 2, 3].flatMap((rows) => [1, 2, 3].map((cols) => ( { onPick({ cols, rows }); setOpen(false); }} > )))} )} ); }