import { isFunction } from './utils.js';
var ConditionalHandler = /** @class */ (function () {
    function ConditionalHandler() {
        this.actions = [];
    }
    ConditionalHandler.prototype.add = function (condition, handler) {
        this.actions.push({ condition: condition, handler: handler });
        return this;
    };
    /**
     * @returns {Boolean} found - был ли найден и вызван хоть один обработчик
     */
    ConditionalHandler.prototype.build = function () {
        var _this = this;
        return function (reference) {
            var args = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                args[_i - 1] = arguments[_i];
            }
            var found = false;
            _this.actions.forEach(function (_a) {
                var condition = _a.condition, handler = _a.handler;
                if (isFunction(condition) ? condition(reference) : condition === reference) {
                    handler.apply(void 0, args);
                    found = true;
                }
            });
            return found;
        };
    };
    return ConditionalHandler;
}());
export { ConditionalHandler };
//# sourceMappingURL=ConditionalHandler.js.map