// (C) 2025-2026 GoodData Corporation
/**
 * Lightweight in-memory arbiter to prevent multiple {@link KdaDialogController} instances from opening at once.
 *
 * @remarks
 * This is an internal short-term mitigation. Ideal solution is a single host.
 */
export class KdaDialogArbiter {
    static instance;
    static getInstance() {
        if (!KdaDialogArbiter.instance) {
            KdaDialogArbiter.instance = new KdaDialogArbiter();
        }
        return KdaDialogArbiter.instance;
    }
    activeOwnerId = null;
    openRequestListeners = new Map();
    constructor() { }
    registerOwner(ownerId, onOpenRequested) {
        this.openRequestListeners.set(ownerId, onOpenRequested);
        return () => {
            this.openRequestListeners.delete(ownerId);
            this.release(ownerId);
        };
    }
    tryAcquire(ownerId) {
        if (this.activeOwnerId === null || this.activeOwnerId === ownerId) {
            this.activeOwnerId = ownerId;
            return true;
        }
        return false;
    }
    requestOpen(ownerId, definition) {
        if (this.tryAcquire(ownerId)) {
            return true;
        }
        const activeOwnerId = this.activeOwnerId;
        if (!activeOwnerId) {
            return false;
        }
        this.openRequestListeners.get(activeOwnerId)?.(definition);
        return false;
    }
    release(ownerId) {
        if (this.activeOwnerId === ownerId) {
            this.activeOwnerId = null;
        }
    }
}
//# sourceMappingURL=KdaDialogArbiter.js.map