System.register(['src/client/lively.js', 'src/components/widgets/lively-morph.js', 'src/components/halo/lively-halo.js'], function (_export, _context) {
  "use strict";

  var lively, Morph, Halo;
  return {
    setters: [function (_srcClientLivelyJs) {
      lively = _srcClientLivelyJs.default;
    }, function (_srcComponentsWidgetsLivelyMorphJs) {
      Morph = _srcComponentsWidgetsLivelyMorphJs.default;
    }, function (_srcComponentsHaloLivelyHaloJs) {
      Halo = _srcComponentsHaloLivelyHaloJs.default;
    }],
    execute: function () {
      const __SystemJSRewritingHack = {};
      _recorder_._src_components_halo_lively_halo_item_js = _recorder_._src_components_halo_lively_halo_item_js || {};
      Object.defineProperty(_recorder_._src_components_halo_lively_halo_item_js, 'lively', {
        get() {
          return lively;
        },

        set(thisIsVererySecretVariableName) {
          lively = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_halo_lively_halo_item_js, 'Morph', {
        get() {
          return Morph;
        },

        set(thisIsVererySecretVariableName) {
          Morph = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_halo_lively_halo_item_js, 'Halo', {
        get() {
          return Halo;
        },

        set(thisIsVererySecretVariableName) {
          Halo = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });


      /*
       * HaloItem are buttons layouted in from o halo around the object 
       */

      class HaloItem extends Morph {

        get isHaloItem() {
          return true;
        }

        get isMetaNode() {
          return true;
        }

        initialize() {
          // super.initialize()
          this.registerMouseEvents();
        }

        hideHalo() {
          Halo.hideHalos();
        }

        registerMouseEvents() {
          this.registerEvent('click', 'onClick');
          this.registerEvent('pointerdown', 'onMouseDown');
          this.registerEvent('pointerup', 'onMouseUp');
        }

        registerEvent(eventName, methodName) {
          if (this[methodName]) {
            lively.removeEventListener('Morphic', this, eventName);
            lively.addEventListener('Morphic', this, eventName, e => this[methodName](e));
          }
        }

        startCustomDragging() {
          lively.removeEventListener("Drag", this, 'mousedown');
          lively.addEventListener("Drag", this, 'mousedown', e => this.startCustomDrag(e));
        }

        startCustomDrag(evt) {
          HaloService.isDragging = true;
          lively.removeEventListener("Drag", document, 'mouseup');
          lively.addEventListener("Drag", document, 'mouseup', e => this.stopCustomDrag(e));

          this.start(evt);

          // attach mousemove handler to body only after mousedown occured
          lively.removeEventListener("Drag", document.body.parentElement, 'mousemove');
          lively.addEventListener("Drag", document.body.parentElement, 'mousemove', dragEvt => {
            this.move(dragEvt);
            // update position of halos on mousemove
            HaloService.showHalos(window.that);
          });
        }

        stopCustomDrag(evt) {
          lively.removeEventListener("Drag", document, 'mouseup');
          // save this as dragging.stop will overwrite the current value
          var wasDragging = this.isDragging;
          this.stop(evt);
          // detach mousemove handler from body
          lively.removeEventListener("Drag", document.body.parentElement, 'mousemove');

          if (wasDragging) {
            HaloService.showHalos(window.that);
            evt.stopPropagation();
          }
          HaloService.isDragging = false;
        }

      }

      _export('default', HaloItem);

      Object.defineProperty(_recorder_._src_components_halo_lively_halo_item_js, 'HaloItem', {
        get() {
          return HaloItem;
        },

        set(thisIsVererySecretVariableName) {
          _export('default', HaloItem = thisIsVererySecretVariableName);

          return true;
        },

        enumerable: true,
        configurable: true
      });
    }
  };
});