module.exports = function(RED) {
  "use strict";

  var router = require('router');

  function SignalLEDNode(n) {
    // Create a RED node
    RED.nodes.createNode(this, n);

    var node = this;

    // Store local copies of the node configuration (as defined in the .html)
    this.led = n.led;
    this.initial = Boolean(Number(n.initial));
    this.inverting = n.inverting;

    node.on("input", (msg) => {
      var newState = (msg.payload ? true : false);
      newState = (node.inverting ? !newState : newState);
      router.usrLED = newState;
    });

    router.LED_USR = this.initial;
  }

  // Register the node by name. This must be called before overriding any of the
  // Node functions.
  RED.nodes.registerType("signal_led", SignalLEDNode);
}
