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 () {
      _recorder_._src_components_widgets_lively_dialog_js = _recorder_._src_components_widgets_lively_dialog_js || {};
      _recorder_._src_components_widgets_lively_dialog_js.Morph = Morph;
      _recorder_._src_components_widgets_lively_dialog_js.pt = pt;
      class Dialog extends _recorder_._src_components_widgets_lively_dialog_js.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(msg) {
          this.get("#message").innerHTML = msg;
          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-RP19-4/src/components/widgets/lively-dialog.js',
            end: {
              column: 56,
              line: 45
            },
            start: {
              column: 17,
              line: 45
            }
          });

          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, _recorder_._src_components_widgets_lively_dialog_js.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, _recorder_._src_components_widgets_lively_dialog_js.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) {
          var dialog = await this.dialog();
          dialog.get("#prompt").style.display = "none";
          dialog.get("#ok").focus();
          return dialog.confirm(msg);
        }
      }

      _export("default", Dialog);

      _recorder_._src_components_widgets_lively_dialog_js.Dialog = Dialog;
    }
  };
});