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

  var HaloItem, nodes, events, pt, Preferences, Snapping, Grid;
  return {
    setters: [function (_srcComponentsHaloLivelyHaloItemJs) {
      HaloItem = _srcComponentsHaloLivelyHaloItemJs.default;
    }, function (_srcClientMorphicNodeHelpersJs) {
      nodes = _srcClientMorphicNodeHelpersJs;
    }, function (_srcClientMorphicEventHelpersJs) {
      events = _srcClientMorphicEventHelpersJs;
    }, function (_srcClientGraphicsJs) {
      pt = _srcClientGraphicsJs.pt;
    }, function (_srcClientPreferencesJs) {
      Preferences = _srcClientPreferencesJs.default;
    }, function (_srcClientMorphicSnappingJs) {
      Snapping = _srcClientMorphicSnappingJs.default;
      Grid = _srcClientMorphicSnappingJs.Grid;
    }],
    execute: function () {
      const __SystemJSRewritingHack = {};
      _recorder_._src_components_halo_lively_halo_resize_item_js = _recorder_._src_components_halo_lively_halo_resize_item_js || {};
      Object.defineProperty(_recorder_._src_components_halo_lively_halo_resize_item_js, 'HaloItem', {
        get() {
          return HaloItem;
        },

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

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

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

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

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

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

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

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

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

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

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

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

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

        enumerable: true,
        configurable: true
      });
      class HaloResizeItem extends HaloItem {
        initialize() {
          lively.addEventListener("Morphic", this, 'mousedown', e => this.onMouseDown(e));
        }

        onMouseDown(evt) {
          this.start(evt);

          // attach mousemove handler to body only after mousedown occured
          lively.addEventListener("HaloResize", document.body.parentElement, 'pointermove', evt => {
            this.move(evt);
          });
          // and capture the following mouse up anywere 
          lively.addEventListener("HaloResize", document.body.parentElement, 'pointerup', e => this.onPointerUp(e));
        }

        onPointerUp(evt) {
          lively.removeEventListener("HaloResize", document.body.parentElement, 'pointerup');
          lively.removeEventListener("HaloResize", document.body.parentElement, 'pointermove');

          this.stop(evt);
        }

        start(evt) {
          evt.preventDefault();
          this.target = window.that;
          this.snapping = new Snapping(this.target);

          if (!this.halo) {
            console.error("this.halo dont defined....");
            return;
          }

          if (this.halo.info) this.halo.info.stop();
          this.halo.info = lively.showInfoBox(this.target);
          this.halo.info.update();

          if (this.target.haloResizeStart) {
            this.target.haloResizeStart(evt, this);
          } else {
            this.initialExtent = lively.getExtent(this.target);
            this.eventOffset = events.globalPosition(evt);
            this.removeRestrictions(this.target);
          }
        }

        move(evt) {

          evt.preventDefault();
          if (this.target.haloResizeMove) {
            this.target.haloResizeMove(evt, this);
          } else {
            var delta = pt(evt.clientX, evt.clientY).subPt(this.eventOffset
            // console.log("this.initialExtent " + this.initialExtent)

            );var newextent = this.initialExtent.addPt(delta);
            newextent = newextent.rounded();

            lively.setExtent(this.target, Grid.optSnapPosition(newextent, evt));
            if (!evt.altKey && that.style.position == "absolute") {
              this.snapping.snapBounds("bottomRight");
            }
            newextent = lively.getExtent(this.target);
            this.halo.info.innerHTML = "resize w=" + newextent.x + " h=" + newextent.y;

            HaloService.showHalos(window.that);
          }
        }

        stop(evt) {
          this.halo.info.stop();
          evt.preventDefault();
          if (this.target.haloResizeStop) {
            this.target.haloResizeStop(evt, this);
          } else {
            // do nothing... anymore
          }
        }

        removeRestrictions(node) {
          node.style.minWidth = null;
          node.style.minHeight = null;
          node.style.maxWidth = null;
          node.style.maxHeight = null;
        }

      }

      _export('default', HaloResizeItem);

      Object.defineProperty(_recorder_._src_components_halo_lively_halo_resize_item_js, 'HaloResizeItem', {
        get() {
          return HaloResizeItem;
        },

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

          return true;
        },

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