import React, { useState } from 'react'; import { Trash2, Settings, Link as LinkIcon, Move, RotateCw, Power, Download, Upload, Box } from 'lucide-react'; import { SimObject, ObjectType, AxisObject, CylinderObject, LedObject, SwitchObject, AxisData } from '../types'; interface SidebarProps { objects: SimObject[]; selectedId: string | null; isPlaying: boolean; inputNames: string[]; outputNames: string[]; axes: AxisData[]; onAddObject: (type: ObjectType) => void; onDeleteObject: (id: string) => void; onUpdateObject: (id: string, updates: Partial) => void; onUpdateAxis: (index: number, updates: Partial) => void; onSelect: React.Dispatch>; onUpdatePortName: (type: 'input' | 'output', index: number, name: string) => void; } export const Sidebar: React.FC = ({ objects, selectedId, isPlaying, inputNames, outputNames, axes, onAddObject, onDeleteObject, onUpdateObject, onUpdateAxis, onSelect, onUpdatePortName, }) => { const selectedObject = objects.find(o => o.id === selectedId); const renderInput = (label: string, value: any, onChange: (val: any) => void, type = "text", step?: number) => (
{ const val = type === 'number' ? parseFloat(e.target.value) : e.target.value; onChange(val); }} />
); return (
{/* Header */}

Layout Config

{/* Tool Box */}
} label="Lin Axis" onClick={() => onAddObject(ObjectType.AXIS_LINEAR)} /> } label="Rot Axis" onClick={() => onAddObject(ObjectType.AXIS_ROTARY)} /> } label="Cylinder" onClick={() => onAddObject(ObjectType.CYLINDER)} /> } label="Switch" onClick={() => onAddObject(ObjectType.SWITCH)} /> } label="LED" onClick={() => onAddObject(ObjectType.LED)} />
{/* Properties Form */}
{!selectedObject ? (

Select an object
to edit properties

) : (

Component Detail

{renderInput("Object Name", selectedObject.name, (val) => onUpdateObject(selectedObject.id, { name: val }))} {selectedObject.type === ObjectType.SWITCH && ( <>
onUpdateObject(selectedObject.id, { isMomentary: e.target.checked })} /> Momentary Contact
)} {selectedObject.type === ObjectType.LED && ( <>
{renderInput("Light Color", (selectedObject as LedObject).color, (v) => onUpdateObject(selectedObject.id, { color: v }), "color")} )} {(selectedObject.type === ObjectType.AXIS_LINEAR || selectedObject.type === ObjectType.AXIS_ROTARY) && (
{/* Axis Control Slider in Sidebar */}
Manual Jog {axes[(selectedObject as AxisObject).axisIndex]?.value.toFixed(1) || '0.0'}
{ const val = parseFloat(e.target.value); const idx = (selectedObject as AxisObject).axisIndex; if (axes[idx]) { onUpdateAxis(idx, { value: val, target: val }); } }} className="w-full h-2 bg-gray-800 rounded-lg appearance-none cursor-pointer accent-blue-500" />
)}
)}
); }; const ToolBtn: React.FC<{ icon: React.ReactNode, label: string, onClick: () => void }> = ({ icon, label, onClick }) => ( );