'use client' import NextImage from 'next/image' import { useContextualTools } from '../../../hooks/use-contextual-tools' import { cn } from '../../../lib/utils' import useEditor, { type CatalogCategory, type StructureTool, type Tool, } from '../../../store/use-editor' import { ActionButton } from './action-button' export type ToolConfig = { id: StructureTool iconSrc: string label: string catalogCategory?: CatalogCategory } export const tools: ToolConfig[] = [ { id: 'wall', iconSrc: '/icons/wall.png', label: 'Wall' }, { id: 'door', iconSrc: '/icons/door.png', label: 'Door' }, { id: 'window', iconSrc: '/icons/window.png', label: 'Window' }, { id: 'stair', iconSrc: '/icons/stairs.png', label: 'Stairs' }, { id: 'roof', iconSrc: '/icons/roof.png', label: 'Gable Roof' }, { id: 'fence', iconSrc: '/icons/fence.png', label: 'Fence' }, { id: 'column', iconSrc: '/icons/column.png', label: 'Column' }, { id: 'elevator', iconSrc: '/icons/elevator.png', label: 'Elevator' }, // { id: 'room', iconSrc: '/icons/room.png', label: 'Room' }, // { id: 'custom-room', iconSrc: '/icons/custom-room.png', label: 'Custom Room' }, { id: 'slab', iconSrc: '/icons/floor.png', label: 'Slab' }, { id: 'ceiling', iconSrc: '/icons/ceiling.png', label: 'Ceiling' }, { id: 'zone', iconSrc: '/icons/zone.png', label: 'Zone' }, { id: 'spawn', iconSrc: '/icons/site.png', label: 'Spawn Point' }, { id: 'shelf', iconSrc: '/icons/shelf.png', label: 'Shelf' }, // Roof-mounted accessories (box-vent / ridge-vent / chimney / // solar-panel / skylight / dormer) are intentionally NOT in the top // palette — they only make sense in the context of a selected roof. // The roof inspector's "Add element" section is the entry point // (`packages/nodes/src/roof/panel.tsx`), which activates the same // registry-driven placement tools via `setTool(kind)`. ] export function StructureTools() { const activeTool = useEditor((state) => state.tool) const catalogCategory = useEditor((state) => state.catalogCategory) const structureLayer = useEditor((state) => state.structureLayer) const setTool = useEditor((state) => state.setTool) const setCatalogCategory = useEditor((state) => state.setCatalogCategory) const contextualTools = useContextualTools() // Filter tools based on structureLayer const visibleTools = structureLayer === 'zones' ? tools.filter((t) => t.id === 'zone') : tools.filter((t) => t.id !== 'zone') const hasActiveTool = visibleTools.some( (t) => activeTool === t.id && (t.catalogCategory ? catalogCategory === t.catalogCategory : true), ) return (
{visibleTools.map((tool, index) => { // For item tools with catalog category, check both tool and category match const isActive = activeTool === tool.id && (tool.catalogCategory ? catalogCategory === tool.catalogCategory : true) const isContextual = contextualTools.includes(tool.id) return ( { if (!isActive) { setTool(tool.id) setCatalogCategory(tool.catalogCategory ?? null) // Automatically switch to build mode if we select a tool if (useEditor.getState().mode !== 'build') { useEditor.getState().setMode('build') } } }} size="icon" variant="ghost" > ) })}
) }