/**
 * Würth Elektronik WL-SMSW 155060GS75300 — SMT mono-colour SIDE VIEW LED.
 *
 * This is the part that makes the nameplate work. A normal 0603 chip LED is a
 * top-view emitter: it fires straight up, away from the board, and the copper
 * you are trying to light up sees nothing. A side-view (right-angle) LED puts
 * the die on its side behind a window in the long face of the package, so the
 * beam leaves PARALLEL to the board surface, ~0.5 mm above the soldermask.
 * Ring the board with them facing inward and the light rakes across the
 * nameplate at a grazing angle instead of escaping to the sky.
 *
 * Package  1.6 × 0.8 × 1.1 mm ("0603 rectangular"), window on a 1.6 × 1.1 face
 * Land     2 pads, 0.6 mm × 0.8 mm, 1.4 mm pitch (2.0 mm overall span)
 * Optical  515 nm peak / 525 nm dominant, 260–560 mcd @ 20 mA, 140° 2θ½
 * Electric VF 3.2 V typ (3.5 max) @ 20 mA, IF 20 mA cont, 30 mA peak
 *
 * Local frame: pads run along X, the emitting window faces local +Y.
 * So pcbRotation aims the beam:  0° → north, 90° → west, 180° → south,
 * 270° → east.
 */

export const SIDE_VIEW_LED_MPN = "155060GS75300"

export const SideViewLed = ({
  name,
  pcbX,
  pcbY,
  pcbRotation = 0,
  schX,
  schY,
  glbUrl,
}: {
  name: string
  pcbX: number
  pcbY: number
  /** Direction the light is thrown, in degrees CCW from north. */
  pcbRotation?: 0 | 90 | 180 | 270
  schX?: number
  schY?: number
  /** Absolute URL of side-view-led.glb for this board. */
  glbUrl: string
}) => (
  <led
    name={name}
    color="green"
    pcbX={pcbX}
    pcbY={pcbY}
    pcbRotation={pcbRotation}
    schX={schX}
    schY={schY}
    manufacturerPartNumber={SIDE_VIEW_LED_MPN}
    // No vendor ships a cadModel for this part, so tscircuit draws nothing
    // on its pads. scripts/gen-models.py builds one: package body plus a
    // translucent cone at the datasheet 140 deg spread, so the 3D view
    // shows WHERE the light actually goes. Model origin is the footprint
    // centre and +Y is the emitting face, matching the footprint below, so
    // pcbRotation carries body and beam together with no positionOffset to
    // drift.
    cadModel={{ glbUrl }}
    footprint={
      <footprint>
        {/* Würth pin 2 = anode. */}
        <smtpad
          portHints={["pin1", "anode", "pos"]}
          shape="rect"
          width="0.6mm"
          height="0.8mm"
          pcbX="0.7mm"
          pcbY="0mm"
        />
        {/* Würth pin 1 = cathode, marked on the package. */}
        <smtpad
          portHints={["pin2", "cathode", "neg"]}
          shape="rect"
          width="0.6mm"
          height="0.8mm"
          pcbX="-0.7mm"
          pcbY="0mm"
        />
        {/* Body outline, with the emitting window on the +Y face. */}
        <silkscreenpath
          route={[
            { x: -0.8, y: -0.4 },
            { x: 0.8, y: -0.4 },
            { x: 0.8, y: 0.4 },
            { x: -0.8, y: 0.4 },
            { x: -0.8, y: -0.4 },
          ]}
        />
        {/* Cathode bar. tscircuit's <led> calls pin1 the anode while Würth
            calls pin 1 the cathode, so the pad-to-package mapping is inverted
            on purpose above. Without a mark on the board an assembler has no
            way to see which end is which — draw it. */}
        <silkscreenpath
          route={[
            { x: -1.05, y: -0.5 },
            { x: -1.05, y: 0.5 },
          ]}
        />
      </footprint>
    }
  />
)
