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 } from '../types'; interface SidebarProps { objects: SimObject[]; selectedId: string | null; isPlaying: boolean; inputNames: string[]; outputNames: string[]; onAddObject: (type: ObjectType) => void; onDeleteObject: (id: string) => void; onUpdateObject: (id: string, updates: Partial) => void; onSelect: (id: string | null) => void; onUpdatePortName: (type: 'input' | 'output', index: number, name: string) => void; } export const Sidebar: React.FC = ({ objects, selectedId, isPlaying, inputNames, outputNames, onAddObject, onDeleteObject, onUpdateObject, onUpdatePortName }) => { const [activeTab, setActiveTab] = useState<'properties' | 'system'>('properties'); 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 (
{/* Sub-navigation */}

Layout Config

{activeTab === 'properties' && ( <> {/* 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) && (
onUpdateObject(selectedObject.id, { currentValue: parseFloat(e.target.value), targetValue: parseFloat(e.target.value) })} className="w-full h-1.5 bg-gray-800 rounded-lg appearance-none cursor-pointer accent-blue-500" />
)}
)}
)} {activeTab === 'system' && (

Hardware Mapping

Inputs (X0 - X15)

{inputNames.map((name, i) => (
X{i.toString().padStart(2, '0')} onUpdatePortName('input', i, e.target.value)} />
))}

Outputs (Y0 - Y15)

{outputNames.map((name, i) => (
Y{i.toString().padStart(2, '0')} onUpdatePortName('output', i, e.target.value)} />
))}
)}
); }; const ToolBtn: React.FC<{ icon: React.ReactNode, label: string, onClick: () => void }> = ({ icon, label, onClick }) => ( );