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 () {
      _recorder_._src_components_halo_lively_halo_item_js = _recorder_._src_components_halo_lively_halo_item_js || {};
      _recorder_._src_components_halo_lively_halo_item_js.lively = lively;
      _recorder_._src_components_halo_lively_halo_item_js.Morph = Morph;
      _recorder_._src_components_halo_lively_halo_item_js.Halo = Halo;


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

      class HaloItem extends _recorder_._src_components_halo_lively_halo_item_js.Morph {

        get isHaloItem() {
          return true;
        }

        get isMetaNode() {
          return true;
        }

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

        hideHalo() {
          _recorder_._src_components_halo_lively_halo_item_js.Halo.hideHalos();
        }

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

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

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

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

          this.start(evt);

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

        stopCustomDrag(evt) {
          _recorder_._src_components_halo_lively_halo_item_js.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
          _recorder_._src_components_halo_lively_halo_item_js.lively.removeEventListener("Drag", document.body.parentElement, 'mousemove');

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

      }

      _export('default', HaloItem);

      _recorder_._src_components_halo_lively_halo_item_js.HaloItem = HaloItem;
    }
  };
});