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

  var HaloItem;
  return {
    setters: [function (_srcComponentsHaloLivelyHaloItemJs) {
      HaloItem = _srcComponentsHaloLivelyHaloItemJs.default;
    }],
    execute: function () {
      _recorder_._src_components_halo_lively_halo_name_item_js = _recorder_._src_components_halo_lively_halo_name_item_js || {};
      _recorder_._src_components_halo_lively_halo_name_item_js.HaloItem = HaloItem;
      class HalloNameItem extends _recorder_._src_components_halo_lively_halo_name_item_js.HaloItem {

        initialize() {
          lively.html.registerKeys(this.get("#name"), "Halo", this);
          this.draggable = true;
          this.addEventListener("dragstart", evt => this.onCustomDragStart(evt));
          this.addEventListener("drag", evt => this.onCustomDrag(evt));
        }

        async onCustomDragStart(evt) {
          // lively.notify("drag2")
          var target = that;
          let url = lively.files.tempfile(),
              name = (target.id || "unnamed") + ".html",
              mimetype = "text/html";
          lively.files.saveFile(url, target.outerHTML
          // there can be a race condition, when the url is faster requested 
          // than it is actually loaded #Hack 
          // This is a #Problem, but we cannot wait after until after we told the server, because the dataTransfer have to be intialized syncronously 
          // so we hope fore the best!
          );evt.dataTransfer.setData("DownloadURL", `${mimetype}:${name}:${url}`);

          evt.dataTransfer.setData("text/html", target.outerHTML);
          evt.dataTransfer.setData("text/plain", target.textContent);
        }

        onCustomDrag(evt) {
          evt.stopPropagation();
        }

        onEnterDown(evt) {
          evt.stopPropagation();
          evt.preventDefault();
          this.target.id = this.get("#name").textContent;
          lively.focusWithoutScroll(document.body);
        }

        onLeftDown(evt) {
          evt.stopPropagation(); // don't move halo, but text cursor
        }

        onRightDown(evt) {
          evt.stopPropagation(); // don't move halo, but text cursor
        }

        updateTarget(target) {
          this.target = target;
          if (target.id) {
            this.get("#name").textContent = target.id;
          } else {
            this.get("#name").textContent = "";
          }

          this.get("#classname").textContent = this.target.tagName.toLowerCase() + (this.target.classList.length > 0 ? "." + Array.from(this.target.classList).join(".") : "");
        }
      }

      _export("default", HalloNameItem);

      _recorder_._src_components_halo_lively_halo_name_item_js.HalloNameItem = HalloNameItem;
    }
  };
});