System.register(["reactive-jsx", "src/components/widgets/lively-morph.js", "src/external/moment.js"], function (_export, _context) {
  "use strict";

  var _addSourceLocation, Morph, moment;

  return {
    setters: [function (_reactiveJsx) {
      _addSourceLocation = _reactiveJsx.addSourceLocation;
    }, function (_srcComponentsWidgetsLivelyMorphJs) {
      Morph = _srcComponentsWidgetsLivelyMorphJs.default;
    }, function (_srcExternalMomentJs) {
      moment = _srcExternalMomentJs.default;
    }],
    execute: function () {
      const __SystemJSRewritingHack = {};
      _recorder_._src_components_tools_lively_version_control_js = _recorder_._src_components_tools_lively_version_control_js || {};
      Object.defineProperty(_recorder_._src_components_tools_lively_version_control_js, "Morph", {
        get() {
          return Morph;
        },

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

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_tools_lively_version_control_js, "moment", {
        get() {
          return moment;
        },

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

        enumerable: true,
        configurable: true
      });
      class VersionControl extends Morph {

        initialize() {}

        showVersions(url) {
          this.url = url;
          var listNode = this.shadowRoot.querySelector("#list");
          fetch(url, {
            method: "OPTIONS",
            headers: {
              showversions: true
            }
          }).then(r => r.text()).then(text => {
            try {
              var json = JSON.parse(text);
            } catch (e) {
              lively.notify("[version control] could not parse " + url + "versions:" + e, text.slice(0, 1000), 10, () => {
                lively.openWorkspace(text);
              }, "red");
              return;
            }
            if (!json.versions) {
              lively.notify("[version control] no versions found", text);
              return;
            }
            listNode.innerHTML = "";
            json.versions.forEach(ea => {
              if (!ea) return; // guard for syntax fixing null in server..  
              var item = _addSourceLocation(document.createElement("tr"), {
                file: 'https://lively-kernel.org/lively4/lively4-constraints/src/components/tools/lively-version-control.js',
                end: {
                  column: 47,
                  line: 35
                },
                start: {
                  column: 19,
                  line: 35
                }
              });
              item.innerHTML = "<td class='date'>" + moment(ea.date).format("YYYY-MM-DD hh:mm") + "</td><td>" + ea.author + "</td><td>" + ea.comment + "</td>";
              listNode.appendChild(item);
              ea.toString = function () {
                return JSON.stringify(this);
              }; // generic pretty print
              item.value = ea;
              item.onclick = () => {
                this.selectItem(item);
              };
            });
          });
        }

        selectItem(item) {
          if (this.selectedItem) this.selectedItem.classList.remove("selected");
          if (this.selectedItem !== item) {
            this.selectedItem = item;
            this.selectedItem.classList.add("selected");
            this.selection = item.value;
            fetch(this.url, {
              headers: {
                fileversion: item.value.version
              }
            }).then(r => r.text()).then(text => {
              if (this.editor && this.editor.mergeView) {
                this.editor.mergeView(text);
              }
              // this.get("#preview").editor.setValue(text)
            });
          } else {
            this.selectedItem = null;
            this.selection = null;
          }
        }

        livelyExample() {
          this.showVersions(lively4url + "/README.md");
        }

        livelyMigrate(obj) {
          this.showVersions(obj.url);
        }

      }

      _export("default", VersionControl);

      Object.defineProperty(_recorder_._src_components_tools_lively_version_control_js, "VersionControl", {
        get() {
          return VersionControl;
        },

        set(thisIsVererySecretVariableName) {
          _export("default", VersionControl = thisIsVererySecretVariableName);

          return true;
        },

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