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

  var _addSourceLocation, Morph, moment, VersionControl, __SystemJSRewritingHack;
  _export("default", void 0);
  return {
    setters: [function (_reactiveJsx) {
      _addSourceLocation = _reactiveJsx.addSourceLocation;
    }, function (_srcComponentsWidgetsLivelyMorphJs) {
      Morph = _srcComponentsWidgetsLivelyMorphJs.default;
    }, function (_srcExternalMomentJs) {
      moment = _srcExternalMomentJs.default;
    }],
    execute: function () {
      __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() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          return Morph;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          Morph = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_tools_lively_version_control_js, "moment", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          return moment;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          moment = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      _export("default", VersionControl = class VersionControl extends Morph {
        initialize() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
        }
        showVersions(url) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          this.url = url;
          var listNode = this.shadowRoot.querySelector("#list");
          fetch(url, {
            method: "OPTIONS",
            headers: {
              showversions: true
            }
          }).then(r => r.text()).then(text => {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
            try {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
              var json = JSON.parse(text);
            } catch (e) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
              lively.notify("[version control] could not parse " + url + "versions:" + e, text.slice(0, 1000), 10, () => {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
                lively.openWorkspace(text);
              }, "red");
              return;
            }
            if (!json.versions) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
              lively.notify("[version control] no versions found", text);
              return;
            }
            listNode.innerHTML = "";
            json.versions.forEach(ea => {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
              if (!ea) return; // guard for syntax fixing null in server..  
              var item = _addSourceLocation(document.createElement("tr"), {
                file: 'https://lively-kernel.org/lively4/lively4-ansgar/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 () {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
                return JSON.stringify(this);
              }; // generic pretty print
              item.value = ea;
              item.onclick = () => {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
                this.selectItem(item);
              };
            });
          });
        }
        selectItem(item) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          if (this.selectedItem) this.selectedItem.classList.remove("selected");
          if (this.selectedItem !== item) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
            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 => {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
              if (this.editor && this.editor.mergeView) {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
                this.editor.mergeView(text);
              }
              // this.get("#preview").editor.setValue(text)
            });
          } else {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
            this.selectedItem = null;
            this.selection = null;
          }
        }
        livelyExample() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          this.showVersions(lively4url + "/README.md");
        }
        livelyMigrate(obj) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          this.showVersions(obj.url);
        }
      });
      Object.defineProperty(_recorder_._src_components_tools_lively_version_control_js, "VersionControl", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          return VersionControl;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/tools/lively-version-control.js"]++;
          _export("default", VersionControl = thisIsVererySecretVariableName);
          return true;
        },
        enumerable: true,
        configurable: true
      });
    }
  };
});