'use client' import { type AnyNode, type RoofNode, useScene } from '@pascal-app/core' import { useViewer } from '@pascal-app/viewer' import { useCallback } from 'react' import { PanelWrapper } from './panel-wrapper' import { PanelSection } from '../controls/panel-section' import { SliderControl } from '../controls/slider-control' import { MetricControl } from '../controls/metric-control' import { ActionButton } from '../controls/action-button' export function RoofPanel() { const selectedIds = useViewer((s) => s.selection.selectedIds) const setSelection = useViewer((s) => s.setSelection) const nodes = useScene((s) => s.nodes) const updateNode = useScene((s) => s.updateNode) const selectedId = selectedIds[0] const node = selectedId ? (nodes[selectedId as AnyNode['id']] as RoofNode | undefined) : undefined const handleUpdate = useCallback( (updates: Partial) => { if (!selectedId) return updateNode(selectedId as AnyNode['id'], updates) }, [selectedId, updateNode], ) const handleClose = useCallback(() => { setSelection({ selectedIds: [] }) }, [setSelection]) if (!node || node.type !== 'roof' || selectedIds.length !== 1) return null const totalWidth = node.leftWidth + node.rightWidth return ( handleUpdate({ length: v })} min={0.5} max={20} precision={2} step={0.5} unit="m" /> handleUpdate({ height: v })} min={0.1} max={10} precision={2} step={0.1} unit="m" />
Widths Total: {totalWidth.toFixed(1)}m
handleUpdate({ leftWidth: v })} min={0.1} max={10} precision={2} step={0.1} unit="m" /> handleUpdate({ rightWidth: v })} min={0.1} max={10} precision={2} step={0.1} unit="m" />
Rrot} value={Math.round((node.rotation * 180) / Math.PI)} onChange={(degrees) => { const radians = (degrees * Math.PI) / 180 handleUpdate({ rotation: radians }) }} min={-180} max={180} precision={0} step={1} unit="°" />
handleUpdate({ rotation: node.rotation - Math.PI / 2 })} /> handleUpdate({ rotation: node.rotation + Math.PI / 2 })} />
Xpos} value={Math.round(node.position[0] * 100) / 100} onChange={(v) => { const pos = [...node.position] as [number, number, number] pos[0] = v handleUpdate({ position: pos }) }} min={-50} max={50} precision={2} step={0.1} unit="m" /> Ypos} value={Math.round(node.position[1] * 100) / 100} onChange={(v) => { const pos = [...node.position] as [number, number, number] pos[1] = v handleUpdate({ position: pos }) }} min={-50} max={50} precision={2} step={0.1} unit="m" /> Zpos} value={Math.round(node.position[2] * 100) / 100} onChange={(v) => { const pos = [...node.position] as [number, number, number] pos[2] = v handleUpdate({ position: pos }) }} min={-50} max={50} precision={2} step={0.1} unit="m" />
) }