"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "InputController", {
    enumerable: true,
    get: function() {
        return InputController;
    }
});
const _object = require("../../../helpers/object");
const _localHooks = /*#__PURE__*/ _interop_require_default(require("../../../mixins/localHooks"));
function _check_private_redeclaration(obj, privateCollection) {
    if (privateCollection.has(obj)) {
        throw new TypeError("Cannot initialize the same private elements twice on an object");
    }
}
function _class_private_method_get(receiver, privateSet, fn) {
    if (!privateSet.has(receiver)) {
        throw new TypeError("attempted to get private field on non-instance");
    }
    return fn;
}
function _class_private_method_init(obj, privateSet) {
    _check_private_redeclaration(obj, privateSet);
    privateSet.add(obj);
}
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
var /**
   * Triggers the filtering.
   *
   * @param {string} value The value of the input.
   */ _triggerFilter = /*#__PURE__*/ new WeakSet();
class InputController {
    /**
   * Gets the input element.
   *
   * @returns {HTMLInputElement} The input element.
   */ getInputElement() {
        return this.input;
    }
    /**
   * Sets the value of the input.
   *
   * @param {string} value The value to set.
   */ setValue(value) {
        this.input.value = value;
    }
    /**
   * Toggles the input.
   *
   * @param {boolean} enabled If true, the input will be enabled.
   */ toggle(enabled) {
        this.enabled = enabled;
        if (this.input) {
            if (enabled) {
                this.listen();
            } else {
                this.unlisten();
            }
        }
    }
    /**
   * Listens to the input keyup event.
   */ listen() {
        this.eventManager.addEventListener(this.input, 'input', this.onInput);
    }
    /**
   * Unlistens to the input keyup event.
   */ unlisten() {
        this.eventManager.removeEventListener(this.input, 'input', this.onInput);
    }
    /**
   * OnInput listener.
   */ onInput() {
        _class_private_method_get(this, _triggerFilter, triggerFilter).call(this, this.input.value);
    }
    /**
   * Creates a new InputController.
   *
   * @param {object} options Options object.
   * @param {HTMLInputElement} options.input Input element.
   * @param {EventManager} options.eventManager Event manager.
   */ constructor({ input, eventManager }){
        _class_private_method_init(this, _triggerFilter);
        this.input = input;
        this.eventManager = eventManager;
        this.enabled = true;
        this.onInput = this.onInput.bind(this);
    }
}
function triggerFilter(value) {
    this.runLocalHooks('triggerFilter', value);
}
(0, _object.mixin)(InputController, _localHooks.default);
