import { Lock, LockOpen, RotateCcw, RotateCw, Search } from 'lucide-react' import { useMemo, useState } from 'react' import type { Component, Design } from '../types/pcb' import { Badge, EmptyNote, NumberField } from './ui' interface Props { design: Design selectedRef: string | null disabled: boolean onSelect: (ref: string) => void onHighlightNet: (net: string) => void onPatch: (ref: string, patch: { x?: number; y?: number; rotation?: number; locked?: boolean }) => void } const CAT_TONE: Record = { mcu: 'accent', sensor: 'ok', power: 'warn', connector: 'neutral', ui: 'neutral', passive: 'neutral', antenna: 'warn', } export function ComponentPanel({ design, selectedRef, disabled, onSelect, onHighlightNet, onPatch }: Props) { const [q, setQ] = useState('') const list = useMemo(() => { const t = q.trim().toLowerCase() const items = design.components.filter((c) => !t || `${c.ref} ${c.value} ${c.name} ${c.package} ${c.role}`.toLowerCase().includes(t)) return items.sort((a, b) => refKey(a.ref).localeCompare(refKey(b.ref))) }, [design.components, q]) const sel = design.components.find((c) => c.ref === selectedRef) ?? null return (
setQ(e.target.value)} aria-label="Search components" />
{sel && }
    {list.map((c) => (
  • ))} {!list.length && }
) } function Inspector({ comp: c, disabled, onPatch, onHighlightNet }: { comp: Component disabled: boolean onPatch: Props['onPatch'] onHighlightNet: (n: string) => void }) { const pins = c.pads.filter((p) => !p.number.startsWith('~cu')) // footprint copper shapes are not pins const connected = pins.filter((p) => p.net) return (
{c.ref} {c.category} {c.edge && edge: {c.edge}} {c.side === 'bottom' && bottom}
{c.name}
{c.value}{c.mpn ? ` · ${c.mpn}` : ''}
{c.fp_lib_id ?? c.package}
{c.role &&
{c.role}
}
v !== null && Math.abs(v - c.x) > 1e-6 && onPatch(c.ref, { x: v })} /> v !== null && Math.abs(v - c.y) > 1e-6 && onPatch(c.ref, { y: v })} />
Rotation {Number.isInteger(c.rotation) ? c.rotation : c.rotation.toFixed(1)}°
Pins ({connected.length}/{pins.length} connected) {pins.map((p) => ( ))}
{p.number} {p.name || '—'} {p.net ? ( ) : ( {p.pin_type === 'nc' ? 'NC' : 'unused'} )}
) } const design_step = 0.25 const round = (v: number) => Math.round(v * 1000) / 1000 function refKey(ref: string) { const m = /^([A-Za-z]+)(\d+)$/.exec(ref) return m ? `${m[1]}${m[2].padStart(4, '0')}` : ref } function shortPkg(p: string) { return p.replace(/_\d+(\.\d+)?x\d+(\.\d+)?mm/, '').replace(/_P\d.*$/, '').slice(0, 18) }