"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("./iPadShowKeyboard.css.js");
const dom = require("../../../../base/browser/dom.js");
const lifecycle = require("../../../../base/common/lifecycle.js");
const editorExtensions = require("../../../browser/editorExtensions.js");
const platform = require("../../../../base/common/platform.js");
class IPadShowKeyboard extends lifecycle.Disposable {
  constructor(editor) {
    super();
    this.editor = editor;
    this.widget = null;
    if (platform.isIOS) {
      this._register(editor.onDidChangeConfiguration(() => this.update()));
      this.update();
    }
  }
  update() {
    const shouldHaveWidget = !this.editor.getOption(
      81
      /* readOnly */
    );
    if (!this.widget && shouldHaveWidget) {
      this.widget = new ShowKeyboardWidget(this.editor);
    } else if (this.widget && !shouldHaveWidget) {
      this.widget.dispose();
      this.widget = null;
    }
  }
  dispose() {
    super.dispose();
    if (this.widget) {
      this.widget.dispose();
      this.widget = null;
    }
  }
}
IPadShowKeyboard.ID = "editor.contrib.iPadShowKeyboard";
class ShowKeyboardWidget extends lifecycle.Disposable {
  constructor(editor) {
    super();
    this.editor = editor;
    this._domNode = document.createElement("textarea");
    this._domNode.className = "iPadShowKeyboard";
    this._register(dom.addDisposableListener(this._domNode, "touchstart", (e) => {
      this.editor.focus();
    }));
    this._register(dom.addDisposableListener(this._domNode, "focus", (e) => {
      this.editor.focus();
    }));
    this.editor.addOverlayWidget(this);
  }
  dispose() {
    this.editor.removeOverlayWidget(this);
    super.dispose();
  }
  // ----- IOverlayWidget API
  getId() {
    return ShowKeyboardWidget.ID;
  }
  getDomNode() {
    return this._domNode;
  }
  getPosition() {
    return {
      preference: 1
      /* BOTTOM_RIGHT_CORNER */
    };
  }
}
ShowKeyboardWidget.ID = "editor.contrib.ShowKeyboardWidget";
editorExtensions.registerEditorContribution(IPadShowKeyboard.ID, IPadShowKeyboard);
exports.IPadShowKeyboard = IPadShowKeyboard;
