"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.AutoCompleteReadonlyState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
var _events = require("events");
class AutoCompleteReadonlyState {
  constructor() {
    (0, _defineProperty2.default)(this, "disableEditing", true);
    (0, _defineProperty2.default)(this, "isFocused", false);
    (0, _defineProperty2.default)(this, "clearInput", void 0);
    (0, _defineProperty2.default)(this, "autoCompleteRef", void 0);
    (0, _defineProperty2.default)(this, "events", new _events.EventEmitter());
    (0, _defineProperty2.default)(this, "focusInput", (0, _mobx.action)(() => {
      this.disableEditing = false;
      setTimeout(() => {
        var _this$autoCompleteRef;
        (_this$autoCompleteRef = this.autoCompleteRef) == null || (_this$autoCompleteRef = _this$autoCompleteRef.current) == null || _this$autoCompleteRef.focus();
      }, 0);
    }));
    (0, _defineProperty2.default)(this, "onFocus", (0, _mobx.action)(() => {
      this.isFocused = true;
      this.disableEditing = false;
    }));
    (0, _defineProperty2.default)(this, "onBlur", (0, _mobx.action)(() => {
      this.isFocused = false;
      this.events.emit('blur');
      // verify that eventually disableEditing=true if isFocused=false
      // not doing this immediately not to hide `inputClearButton` too soon when it's clicked
      window.setTimeout((0, _mobx.action)(() => {
        if (!this.isFocused) {
          var _this$clearInput;
          this.disableEditing = true;
          (_this$clearInput = this.clearInput) == null || _this$clearInput.call(this);
        }
      }), 300);
    }));
    (0, _defineProperty2.default)(this, "onItemClick", (0, _mobx.action)(() => {
      this.disableEditing = true;
    }));
    (0, _defineProperty2.default)(this, "onClickOutside", (0, _mobx.action)(() => {
      var _this$clearInput2;
      this.disableEditing = true;
      (_this$clearInput2 = this.clearInput) == null || _this$clearInput2.call(this);
    }));
    (0, _defineProperty2.default)(this, "onInputClearButtonClick", (0, _mobx.action)(() => {
      var _this$clearInput3;
      (_this$clearInput3 = this.clearInput) == null || _this$clearInput3.call(this);
    }));
    (0, _defineProperty2.default)(this, "onTabKeyDown", (0, _mobx.action)(() => {
      var _this$clearInput4;
      this.disableEditing = true;
      (_this$clearInput4 = this.clearInput) == null || _this$clearInput4.call(this);
    }));
    (0, _defineProperty2.default)(this, "onSelect", (0, _mobx.action)(() => {
      this.disableEditing = true;
    }));
    (0, _defineProperty2.default)(this, "onOptionsShow", (0, _mobx.action)(() => {
      this.disableEditing = false;
    }));
    (0, _mobx.makeObservable)(this, {
      disableEditing: _mobx.observable.ref
    });
  }
}
exports.AutoCompleteReadonlyState = AutoCompleteReadonlyState;
//# sourceMappingURL=AutoCompleteReadonlyState.js.map