import React from 'react'; import { useSimulatorStore } from '../../store/useSimulatorStore'; import { WireRenderer } from './WireRenderer'; import { WireInProgressRenderer } from './WireInProgressRenderer'; import { useIsCoarsePointer } from '../../utils/useTouchDevice'; export interface SegmentHandle { segIndex: number; axis: 'horizontal' | 'vertical'; mx: number; // midpoint X my: number; // midpoint Y } export interface WaypointHandle { /** Index of this waypoint in the wire's waypoints[] array */ index: number; x: number; y: number; } export interface AlignmentGuide { axis: 'x' | 'y'; /** World coordinate of the guide line (x for vertical, y for horizontal) */ value: number; } interface WireLayerProps { hoveredWireId: string | null; /** Segment drag preview: overrides the path of a specific wire */ segmentDragPreview: { wireId: string; overridePath: string } | null; /** Handles to render for the selected wire */ segmentHandles: SegmentHandle[]; /** Bend-point handles to render for the selected wire */ waypointHandles: WaypointHandle[]; /** Alignment guides shown while dragging */ alignmentGuides?: AlignmentGuide[]; /** Called when user starts dragging a segment handle (passes segIndex) */ onHandleMouseDown: (e: React.MouseEvent, segIndex: number) => void; /** Called when user starts dragging a segment handle via touch (passes segIndex) */ onHandleTouchStart?: (e: React.TouchEvent, segIndex: number) => void; /** Called when user starts dragging a waypoint handle */ onWaypointMouseDown: (e: React.MouseEvent, waypointIndex: number) => void; /** Called when user starts dragging a waypoint handle via touch */ onWaypointTouchStart?: (e: React.TouchEvent, waypointIndex: number) => void; } export const WireLayer: React.FC = ({ hoveredWireId, segmentDragPreview, segmentHandles, waypointHandles, alignmentGuides, onHandleMouseDown, onHandleTouchStart, onWaypointMouseDown, onWaypointTouchStart, }) => { const wires = useSimulatorStore((s) => s.wires); const wireInProgress = useSimulatorStore((s) => s.wireInProgress); const selectedWireId = useSimulatorStore((s) => s.selectedWireId); const isTouchDevice = useIsCoarsePointer(); return ( {wires.map((wire) => ( ))} {/* Alignment guides — full-canvas dashed lines snap-targets while dragging */} {alignmentGuides?.map((g, i) => g.axis === 'x' ? ( ) : ( ), )} {/* Segment handles for the selected wire */} {segmentHandles.map((handle) => ( onHandleMouseDown(e, handle.segIndex)} onTouchStart={(e) => onHandleTouchStart?.(e, handle.segIndex)} /> ))} {/* Waypoint handles — bend points that drag freely in any direction */} {waypointHandles.map((handle) => ( onWaypointMouseDown(e, handle.index)} onTouchStart={(e) => onWaypointTouchStart?.(e, handle.index)} /> ))} {wireInProgress && } ); };