/*
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 { Base, delegateCombine, delegateRemove, runOn, markType } from "igniteui-react-core/ES2015/type";
import { Message_Spark } from "./Message_Spark";
import { Queue$1 } from "igniteui-react-core/ES2015/Queue$1";
/**
 * @hidden
 */
export class MessageChannel_Spark extends Base {
    constructor() {
        super(...arguments);
        this.c = new Queue$1(Message_Spark.$);
        this.messageSent = null;
        this.a = null;
    }
    sendMessage(a) {
        if (this.messageSent != null) {
            this.messageSent(a);
        }
        else {
            this.c.g(a);
        }
    }
    attachTarget(a) {
        this.messageSent = delegateCombine(this.messageSent, a);
        while (this.c.count > 0) {
            let b = this.c.b();
            this.messageSent(b);
        }
    }
    detachTarget(a) {
        this.messageSent = delegateRemove(this.messageSent, a);
    }
    connectTo(a) {
        this.a = a;
        this.attachTarget(runOn(this, this.sendToNext));
    }
    detachFromNext() {
        if (this.a == null) {
            return;
        }
        this.detachTarget(runOn(this, this.sendToNext));
        this.a = null;
    }
    sendToNext(a) {
        if (this.a != null) {
            this.a.sendMessage(a);
        }
    }
    toString() {
        return "MessageQueue";
    }
}
MessageChannel_Spark.$t = markType(MessageChannel_Spark, 'MessageChannel_Spark');
