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

  var _addSourceLocation, Morph, pt;

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

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

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

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

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

        initialize() {
          this.registerButtons();
          this.get("#prompt").addEventListener("keyup", evt => {
            if (evt.keyCode == 13) {
              // ENTER
              this.onPromptEntered(evt);
            }
          });
        }

        onClose() {
          this.onCancel();
        }
        onOk() {
          this.resolve && this.resolve(true);
          this.remove();
        }

        onCancel() {
          this.resolve && this.resolve(false);
          this.remove();
        }

        onPromptEntered(evt) {
          this.resolve && this.resolve(true);
          this.remove();
        }

        async confirm(msgOrElement) {
          if (msgOrElement instanceof HTMLElement) {
            this.get("#message").innerHTML = "";
            this.get("#message").appendChild(msgOrElement);
          } else {
            this.get("#message").innerHTML = msgOrElement;
          }
          return new Promise((resolve, reject) => {
            this.resolve = resolve;
          });
        }

        static async dialog(customizeCB) {
          var w = lively.findWindow(document.activeElement);
          if (w && !w.getAddOnRoot) w = null; // we did not find a window...

          var dialog = _addSourceLocation(document.createElement("lively-dialog"), {
            file: 'https://lively-kernel.org/lively4/lively4-leo/src/components/widgets/lively-dialog.js',
            end: {
              column: 56,
              line: 50
            },
            start: {
              column: 17,
              line: 50
            }
          });

          var scope = w ? w.getAddOnRoot() : document.body;
          await lively.components.openIn(scope, dialog);

          var bounds = dialog.getBoundingClientRect();
          if (!w) {
            // center in fixed 
            lively.setPosition(dialog, pt(window.innerWidth / 2 - bounds.width / 2, window.innerHeight / 2 - bounds.height / 2));
            dialog.style.position = "fixed";
          } else {
            var ext = lively.getExtent(w);
            w.getAddOnRoot().appendChild(dialog);
            lively.setPosition(dialog, pt(ext.x / 2 - bounds.width / 2, ext.y / 2 - bounds.height / 2));
          }
          if (customizeCB) customizeCB(dialog);

          return dialog;
        }

        static async prompt(msg, value, customizeCB) {
          var dialog = await this.dialog(customizeCB);
          if (value !== undefined) dialog.get("#prompt").value = value;

          dialog.get("#prompt").focus();
          var result = await dialog.confirm(msg);
          if (result == false) return undefined;
          return dialog.get("#prompt").value;
        }

        static async confirm(msg, customizeCB) {
          var dialog = await this.dialog(customizeCB);
          dialog.get("#prompt").style.display = "none";
          dialog.get("#ok").focus();
          return dialog.confirm(msg);
        }
      }

      _export("default", Dialog);

      Object.defineProperty(_recorder_._src_components_widgets_lively_dialog_js, "Dialog", {
        get() {
          return Dialog;
        },

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

          return true;
        },

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