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

  var HaloGrabItem, nodes, events, pt, scriptManager, persistence, copyBlacklist;
  return {
    setters: [function (_livelyHaloGrabItemJs) {
      HaloGrabItem = _livelyHaloGrabItemJs.default;
    }, function (_srcClientMorphicNodeHelpersJs) {
      nodes = _srcClientMorphicNodeHelpersJs;
    }, function (_srcClientMorphicEventHelpersJs) {
      events = _srcClientMorphicEventHelpersJs;
    }, function (_srcClientGraphicsJs) {
      pt = _srcClientGraphicsJs.pt;
    }, function (_srcClientScriptManagerJs) {
      scriptManager = _srcClientScriptManagerJs.default;
    }, function (_srcClientPersistenceJs) {
      persistence = _srcClientPersistenceJs.default;
    }],
    execute: function () {
      _recorder_._src_components_halo_lively_halo_copy_item_js = _recorder_._src_components_halo_lively_halo_copy_item_js || {};
      _recorder_._src_components_halo_lively_halo_copy_item_js.HaloGrabItem = HaloGrabItem;
      _recorder_._src_components_halo_lively_halo_copy_item_js.nodes = nodes;
      _recorder_._src_components_halo_lively_halo_copy_item_js.events = events;
      _recorder_._src_components_halo_lively_halo_copy_item_js.pt = pt;
      _recorder_._src_components_halo_lively_halo_copy_item_js.scriptManager = scriptManager;
      _recorder_._src_components_halo_lively_halo_copy_item_js.persistence = persistence;
      copyBlacklist = ["body", "html"];
      _recorder_._src_components_halo_lively_halo_copy_item_js.copyBlacklist = copyBlacklist;
      class HaloCopyItem extends _recorder_._src_components_halo_lively_halo_copy_item_js.HaloGrabItem {

        get isCopyItem() {
          return true;
        }

        onClick() {
          if (!this.copiedObject) {
            this.copyObject(window.that);
            this.copiedObject.style.position = 'absolute';
            _recorder_._src_components_halo_lively_halo_copy_item_js.nodes.setPosition(this.copiedObject, _recorder_._src_components_halo_lively_halo_copy_item_js.nodes.getPosition(this.copyTarget).addPt(_recorder_._src_components_halo_lively_halo_copy_item_js.pt(10, 10)));
            window.that = this.copiedObject;
            window.HaloService.showHalos(that);
          }
          this.copiedObject = null;
        }

        cloneObject(obj) {
          var html = lively.clipboard.nodesToHTML([obj]);
          lively.clipboard.lastClickPos = lively.getGlobalPosition(obj // used in pasted as offset
          );var result = lively.clipboard.pasteHTMLDataInto(html, obj.parentElement, true);
          return result[0];
        }

        copyObject(el) {
          this.copyTarget = el;
          if (el.haloCopyObject) {
            this.copiedObject = el.haloCopyObject(this); // copy selection etc...
          } else {
            if (this.isAllowedToBeCopied(this.copyTarget)) {
              this.copiedObject = this.cloneObject(this.copyTarget);
              this.copyTarget.parentNode.appendChild(this.copiedObject);
            } else {
              lively.notify("Could not copy " + sourceObj);
            }
          }
          return this.copiedObject;
        }

        isAllowedToBeCopied(element) {
          return _recorder_._src_components_halo_lively_halo_copy_item_js.copyBlacklist.indexOf(element.tagName.toLowerCase()) < 0;
        }

        // DRAG API
        prepareGrabTarget() {
          this.grabTarget = this.copyObject(this.grabTarget);
          window.that = this.grabTarget;
          HaloService.showHalos(this.grabTarget);

          super.prepareGrabTarget();
        }
      }

      _export('default', HaloCopyItem);

      _recorder_._src_components_halo_lively_halo_copy_item_js.HaloCopyItem = HaloCopyItem;
    }
  };
});