([])
const note = (line: string) => setLog(lines => [...lines.slice(-5), line])
return {
categoryId, activeToolId, aux, layouts, space, history, log,
onCategoryChange: (id: string) => { setCategoryId(id); setActiveToolId(null); note(`category:${id}`) },
onToolSelect: (id: string) => {
setActiveToolId(current => (current === id ? null : id))
setHistory(lines => [...lines, `Command: ${id.toUpperCase()}`])
note(`tool:${id}`)
},
onSlotAdd: (index: number, category: string) => note(`slotAdd:${category}#${index}`),
onCategoryAdd: () => note("categoryAdd"),
onAuxPressedChange: (id: string, pressed: boolean) => { setAux(items => items.map(item => (item.id === id ? { ...item, pressed } : item))); note(`aux:${id}=${pressed}`) },
onSpaceChange: (value: string) => { setSpace(value); note(`space:${value}`) },
onLayoutAdd: () => {
setLayouts(items => {
const next = Math.max(0, ...items.map(item => Number(item.id.replace("layout", "")) || 0)) + 1
return [{ id: `layout${next}`, label: `Layout ${String(next).padStart(2, "0")}` }, ...items]
})
note("layoutAdd")
},
onLayoutRemove: (id: string) => { setLayouts(items => items.filter(item => item.id !== id)); setSpace(value => (value === id ? "model" : value)); note(`layoutRemove:${id}`) },
onLayoutRename: (id: string, label: string) => { setLayouts(items => items.map(item => (item.id === id ? { ...item, label } : item))); note(`layoutRename:${id}=${label}`) },
onCommand: (command: string) => { if (command.trim()) setHistory(lines => [...lines, `Command: ${command}`]); note(`command:${command}`) },
onSide: (name: string) => () => note(name),
}
}
export function Log({ lines }: { lines: string[] }) {
return Callback: {lines.length ? lines.join(" → ") : "없음"}
}