import { __exports as basicInput } from '../../../../_virtual/basicInput.js';
import require$$0 from '../../../../_virtual/_monaco-editor.js';

var hasRequiredBasicInput;

function requireBasicInput () {
	if (hasRequiredBasicInput) return basicInput;
	hasRequiredBasicInput = 1;
	Object.defineProperty(basicInput, "__esModule", { value: true });
	basicInput.BasicInputWidget = void 0;
	var monaco = require$$0;
	var BASE_CLASS = 'ext-emacs-basic-input';
	function generateCss() {
	    return "\n  .".concat(BASE_CLASS, " {\n    color: #d4d4d4;\n    transition: top 200ms linear;\n    visibility: hidden;\n    width: 200px;\n    display: flex;\n    align-items: center;\n    padding: 5px;\n  }\n\n  .").concat(BASE_CLASS, ".").concat(BASE_CLASS, "-visible {\n    visibility: visible;\n  }\n\n  .").concat(BASE_CLASS, " input {\n    color: rgb(97, 97, 97);\n    background-color: transparent;\n    display: inline-block;\n    box-sizing: border-box;\n    height: 100%;\n    line-height: inherit;\n    border: none;\n    font-family: inherit;\n    font-size: inherit;\n    resize: none;\n    padding-top: 2px;\n    padding-bottom: 2px;\n    margin-left: 5px;\n    max-width: 50px;\n  }\n\n  .").concat(BASE_CLASS, " input:focus {\n    outline: none;\n  }\n\n  .vs .").concat(BASE_CLASS, " {\n    color: rgb(97, 97, 97);\n    background-color: #efeff2;\n    box-shadow: 0 2px 8px #a8a8a8;\n  }\n\n  .vs-dark .").concat(BASE_CLASS, " {\n    background-color: #2d2d30;\n    box-shadow: 0 2px 8px #000000;\n  }\n\n  .vs-dark .").concat(BASE_CLASS, " input {\n    color: rgb(204, 204, 204);\n  }\n\n  .hc-black .").concat(BASE_CLASS, " {\n    border: 2px solid #6fc3df;\n    background-color: #0c141f;\n    color: #ffffff;\n  }\n\n  .hc-black .").concat(BASE_CLASS, " input {\n    color: #ffffff;\n  }\n");
	}
	var BasicInputWidget = (function () {
	    function BasicInputWidget() {
	        var _this = this;
	        this._pendingPromise = null;
	        this.onKeyDown = function (ev) {
	            if (ev.altKey || ev.ctrlKey || ev.metaKey) {
	                ev.preventDefault();
	                ev.stopPropagation();
	            }
	            if (ev.which === 13) {
	                if (_this._pendingPromise) {
	                    ev.preventDefault();
	                    _this._pendingPromise.resolve(ev.target.value);
	                    _this._pendingPromise = null;
	                }
	            }
	            else if (ev.which === 27) {
	                if (_this._pendingPromise) {
	                    _this._pendingPromise.reject();
	                    _this._pendingPromise = null;
	                }
	            }
	        };
	        this.onBlur = function () {
	            if (_this._pendingPromise) {
	                _this._pendingPromise.reject();
	                _this._pendingPromise = null;
	            }
	        };
	        this._dom = document.createElement('div');
	        this._messageDom = document.createElement('div');
	        var medDom = document.createElement('div');
	        this._dom.setAttribute('class', BASE_CLASS);
	        this._dom.setAttribute('aria-hidden', 'true');
	        this._input = document.createElement('input');
	        this._dom.appendChild(this._messageDom);
	        medDom.appendChild(this._input);
	        this._dom.appendChild(medDom);
	        this.addListeners();
	        this._style = document.createElement('style');
	        this._style.type = 'text/css';
	        this._style.textContent = generateCss();
	        (document.head || document.body).appendChild(this._style);
	    }
	    BasicInputWidget.prototype.getDomNode = function () {
	        return this._dom;
	    };
	    BasicInputWidget.prototype.getId = function () {
	        return 'extension.emacs.basicinput';
	    };
	    BasicInputWidget.prototype.getPosition = function () {
	        return {
	            preference: monaco.editor.OverlayWidgetPositionPreference.TOP_RIGHT_CORNER,
	        };
	    };
	    BasicInputWidget.prototype.addListeners = function () {
	        this._input.addEventListener('keydown', this.onKeyDown);
	        this._input.addEventListener('blur', this.onBlur);
	    };
	    BasicInputWidget.prototype.showWidgetAndFocus = function (message) {
	        this._dom.classList.add("".concat(BASE_CLASS, "-visible"));
	        this._dom.setAttribute('aria-hidden', 'false');
	        this._messageDom.textContent = message;
	        this._input.focus();
	    };
	    BasicInputWidget.prototype.cleanup = function () {
	        this._dom.classList.remove("".concat(BASE_CLASS, "-visible"));
	        this._dom.setAttribute('aria-hidden', 'true');
	        this._messageDom.textContent = '';
	        this._input.placeholder = '';
	        this._input.value = '';
	    };
	    BasicInputWidget.prototype.getInput = function (message) {
	        var _this = this;
	        if (this._pendingPromise) {
	            this._pendingPromise.reject();
	            this._pendingPromise = null;
	        }
	        return new Promise(function (resolve, reject) {
	            _this._pendingPromise = {
	                resolve: function (val) {
	                    resolve(val);
	                    _this.cleanup();
	                },
	                reject: function () {
	                    reject();
	                    _this.cleanup();
	                },
	            };
	            _this.showWidgetAndFocus(message);
	        });
	    };
	    BasicInputWidget.prototype.dispose = function () {
	        this.cleanup();
	        this._input.removeEventListener('keydown', this.onKeyDown);
	        this._input.removeEventListener('blur', this.onBlur);
	        (document.head || document.body).removeChild(this._style);
	    };
	    return BasicInputWidget;
	}());
	basicInput.BasicInputWidget = BasicInputWidget;
	return basicInput;
}

export { requireBasicInput as __require };
