import { action, makeObservable, observable } from 'mobx';
import { EventEmitter } from 'events';
export class AutoCompleteReadonlyState {
    constructor() {
        this.disableEditing = true;
        this.isFocused = false;
        this.events = new EventEmitter();
        this.focusInput = action(() => {
            this.disableEditing = false;
            setTimeout(() => {
                this.autoCompleteRef?.current?.focus();
            }, 0);
        });
        this.onFocus = action(() => {
            this.isFocused = true;
            this.disableEditing = false;
        });
        this.onBlur = 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(action(() => {
                if (!this.isFocused) {
                    this.disableEditing = true;
                    this.clearInput?.();
                }
            }), 300);
        });
        this.onItemClick = action(() => {
            this.disableEditing = true;
        });
        this.onClickOutside = action(() => {
            this.disableEditing = true;
            this.clearInput?.();
        });
        this.onInputClearButtonClick = action(() => {
            this.clearInput?.();
        });
        this.onTabKeyDown = action(() => {
            this.disableEditing = true;
            this.clearInput?.();
        });
        this.onSelect = action(() => {
            this.disableEditing = true;
        });
        this.onOptionsShow = action(() => {
            this.disableEditing = false;
        });
        makeObservable(this, {
            disableEditing: observable.ref,
        });
    }
}
//# sourceMappingURL=AutoCompleteReadonlyState.js.map