System.register(['src/client/lively.js', 'src/client/morphic/node-helpers.js', 'src/client/morphic/event-helpers.js', 'src/client/graphics.js', 'src/components/halo/lively-halo-item.js', 'src/client/preferences.js', 'src/client/morphic/snapping.js'], function (_export, _context) {
  "use strict";

  var lively, nodes, events, pt, HaloItem, Preferences, Snapping, Grid;
  return {
    setters: [function (_srcClientLivelyJs) {
      lively = _srcClientLivelyJs.default;
    }, function (_srcClientMorphicNodeHelpersJs) {
      nodes = _srcClientMorphicNodeHelpersJs;
    }, function (_srcClientMorphicEventHelpersJs) {
      events = _srcClientMorphicEventHelpersJs;
    }, function (_srcClientGraphicsJs) {
      pt = _srcClientGraphicsJs.pt;
    }, function (_srcComponentsHaloLivelyHaloItemJs) {
      HaloItem = _srcComponentsHaloLivelyHaloItemJs.default;
    }, function (_srcClientPreferencesJs) {
      Preferences = _srcClientPreferencesJs.default;
    }, function (_srcClientMorphicSnappingJs) {
      Snapping = _srcClientMorphicSnappingJs.default;
      Grid = _srcClientMorphicSnappingJs.Grid;
    }],
    execute: function () {
      _recorder_._src_components_halo_lively_halo_drag_item_js = _recorder_._src_components_halo_lively_halo_drag_item_js || {};
      _recorder_._src_components_halo_lively_halo_drag_item_js.lively = lively;
      _recorder_._src_components_halo_lively_halo_drag_item_js.nodes = nodes;
      _recorder_._src_components_halo_lively_halo_drag_item_js.events = events;
      _recorder_._src_components_halo_lively_halo_drag_item_js.pt = pt;
      _recorder_._src_components_halo_lively_halo_drag_item_js.HaloItem = HaloItem;
      _recorder_._src_components_halo_lively_halo_drag_item_js.Preferences = Preferences;
      _recorder_._src_components_halo_lively_halo_drag_item_js.Snapping = Snapping;
      _recorder_._src_components_halo_lively_halo_drag_item_js.Grid = Grid;
      class HaloDragItem extends _recorder_._src_components_halo_lively_halo_drag_item_js.HaloItem {

        initialize() {
          this.startCustomDragging();
        }

        // Drag API
        start(evt) {
          this.dragTarget = window.that;
          if (this.dragTarget) {
            this.dragStartNodePosition = _recorder_._src_components_halo_lively_halo_drag_item_js.lively.getPosition(this.dragTarget);
            this.dragStartEventPosition = _recorder_._src_components_halo_lively_halo_drag_item_js.events.globalPosition(evt);
            evt.preventDefault();

            this.snapping = new _recorder_._src_components_halo_lively_halo_drag_item_js.Snapping(this.dragTarget);
            this.halo.info = _recorder_._src_components_halo_lively_halo_drag_item_js.lively.showInfoBox(this.dragTarget);

            if (this.dragTarget.haloDragStart) {
              this.dragTarget.haloDragStart(this.dragStartEventPosition);
            }
          }
        }

        move(evt) {
          if (this.dragTarget && !this.isDragging && _recorder_._src_components_halo_lively_halo_drag_item_js.events.noticableDistanceTo(evt, this.dragStartEventPosition)) {
            // this.dragTarget.style.position = 'absolute';
            this.isDragging = true;
          }
          if (this.isDragging) {
            this.dragTo(evt);
          }
        }

        stop(evt) {
          this.halo.info.stop
          //  STOP DRAGGING
          ();if (this.isDragging) {
            this.isDragging = false;
            evt.preventDefault();
          }
          this.dragTarget = null;
          this.dragStartEventPosition = null;
          this.dragStartNodePosition = null;
          this.snapping.clearHelpers();
          this.snapping = null;
        }

        dragTo(evt) {
          if (this.dragTarget.haloDragTo) {
            this.dragTarget.haloDragTo(_recorder_._src_components_halo_lively_halo_drag_item_js.events.globalPosition(evt), this.dragStartEventPosition);
          } else {
            var eventPos = _recorder_._src_components_halo_lively_halo_drag_item_js.events.globalPosition(evt);
            var newPosition = eventPos.subPt(this.dragStartEventPosition).addPt(this.dragStartNodePosition);

            newPosition = newPosition.rounded();
            if (this.dragTarget.style.position == "absolute") {
              _recorder_._src_components_halo_lively_halo_drag_item_js.lively.setPosition(this.dragTarget, _recorder_._src_components_halo_lively_halo_drag_item_js.Grid.optSnapPosition(newPosition, evt));
              if (!evt.altKey) {
                this.snapping.snap();
              }
            } else {
              _recorder_._src_components_halo_lively_halo_drag_item_js.lively.setPosition(this.dragTarget, newPosition, "relative");
            }
            this.halo.info.innerHTML = "drag " + _recorder_._src_components_halo_lively_halo_drag_item_js.lively.getPosition(this.dragTarget);
          }
          evt.preventDefault();
        }
      }

      _export('default', HaloDragItem);

      _recorder_._src_components_halo_lively_halo_drag_item_js.HaloDragItem = HaloDragItem;
    }
  };
});