"use client" import { useState } from "react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { ScrollArea } from "@/components/ui/scroll-area" import { Eye, EyeOff, Lock, Unlock, Plus, Trash2, ChevronRight, ChevronDown, Folder, Box, Circle, } from "lucide-react" import { usePlannerStore } from "@/lib/store/planner-store" import { cn } from "@/lib/utils" import type { PlacedObject } from "@/lib/types/planner.types" interface TreeNodeProps { obj: PlacedObject level: number onSelect: (id: string) => void isSelected: boolean } function TreeNode({ obj, level, onSelect, isSelected }: TreeNodeProps) { const [isExpanded, setIsExpanded] = useState(true) const { getChildObjects, toggleVisibility, lockObject, removeObject, ungroupObject, selectedElementId, selectElement, selectPart, } = usePlannerStore() const children = getChildObjects(obj.id) const hasChildren = children.length > 0 || obj.elements.length > 0 return (
{/* Object row */}
onSelect(obj.id)} > {/* Expand/collapse */} {hasChildren ? ( ) : (
)} {/* Icon */} {obj.isGroup ? ( ) : ( )} {/* Name */} {obj.name} {/* Layer color indicator */}
{/* Actions */}
{obj.isGroup && ( )}
{/* Children and Elements */} {isExpanded && hasChildren && (
{/* Render elements */} {obj.elements.map((element) => (
{ e.stopPropagation() selectElement(obj.id, element.id) }} >
{element.name} Element
{/* Render parts */} {element.parts.map((part) => (
{ e.stopPropagation() selectPart(obj.id, element.id, part.id) }} >
{part.name} {part.type}
))}
))} {/* Render child objects */} {children.map((child) => ( ))}
)}
) } export function LayersPanel() { const [newLayerName, setNewLayerName] = useState("") const [showNewLayerInput, setShowNewLayerInput] = useState(false) const { placedObjects, layers, activeLayerId, selectedObjectId, selectObject, addLayer, removeLayer, setActiveLayer, toggleLayerVisibility, toggleLayerLock, groupObjects, selectedObjectIds, } = usePlannerStore() // Get root level objects (no parent) const rootObjects = placedObjects.filter((obj) => !obj.parentId) const handleAddLayer = () => { if (newLayerName.trim()) { addLayer(newLayerName.trim()) setNewLayerName("") setShowNewLayerInput(false) } } const handleGroupSelected = () => { if (selectedObjectIds.length >= 2) { groupObjects(selectedObjectIds) } } return (
{/* Layers header */}

Layers

{showNewLayerInput && (
setNewLayerName(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleAddLayer()} className="h-7 text-xs" autoFocus />
)} {selectedObjectIds.length >= 2 && ( )}
{/* Layers list */}
{layers.map((layer) => (
setActiveLayer(layer.id)} >
{layer.name} {layer.objectIds.length} {layer.id !== "default" && ( )}
))}
{/* Objects tree */}
{rootObjects.length === 0 ? (
No objects in scene.
Drag products from the sidebar!
) : ( rootObjects.map((obj) => ( )) )}
) }