/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { Base, delegateCombine, delegateRemove, runOn, markType } from "igniteui-react-core/ES5/type";
import { Message_Spark } from "./Message_Spark";
import { Queue$1 } from "igniteui-react-core/ES5/Queue$1";
/**
 * @hidden
 */
var MessageChannel_Spark = /** @class */ (function (_super) {
    tslib_1.__extends(MessageChannel_Spark, _super);
    function MessageChannel_Spark() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.c = new Queue$1(Message_Spark.$);
        _this.messageSent = null;
        _this.a = null;
        return _this;
    }
    MessageChannel_Spark.prototype.sendMessage = function (a) {
        if (this.messageSent != null) {
            this.messageSent(a);
        }
        else {
            this.c.g(a);
        }
    };
    MessageChannel_Spark.prototype.attachTarget = function (a) {
        this.messageSent = delegateCombine(this.messageSent, a);
        while (this.c.count > 0) {
            var b = this.c.b();
            this.messageSent(b);
        }
    };
    MessageChannel_Spark.prototype.detachTarget = function (a) {
        this.messageSent = delegateRemove(this.messageSent, a);
    };
    MessageChannel_Spark.prototype.connectTo = function (a) {
        this.a = a;
        this.attachTarget(runOn(this, this.sendToNext));
    };
    MessageChannel_Spark.prototype.detachFromNext = function () {
        if (this.a == null) {
            return;
        }
        this.detachTarget(runOn(this, this.sendToNext));
        this.a = null;
    };
    MessageChannel_Spark.prototype.sendToNext = function (a) {
        if (this.a != null) {
            this.a.sendMessage(a);
        }
    };
    MessageChannel_Spark.prototype.toString = function () {
        return "MessageQueue";
    };
    MessageChannel_Spark.$t = markType(MessageChannel_Spark, 'MessageChannel_Spark');
    return MessageChannel_Spark;
}(Base));
export { MessageChannel_Spark };
