class Ai12zManager {
    constructor() {
        this.controls = {};
        this.activeTag = null;
    }
    register(tag, instance) {
        this.controls[tag] = instance;
        if (!this.activeTag)
            this.activeTag = tag;
    }
    unregister(tag) {
        delete this.controls[tag];
        if (this.activeTag === tag) {
            const nextTag = Object.keys(this.controls)[0];
            this.activeTag = nextTag !== null && nextTag !== void 0 ? nextTag : null;
        }
    }
    setActive(tag) {
        if (this.controls[tag]) {
            this.activeTag = tag;
        }
    }
    get active() {
        return this.activeTag ? this.controls[this.activeTag] : null;
    }
    // Fetch any registered instance by its instanceId / registration key
    getById(instanceId) {
        var _a;
        return (_a = this.controls[instanceId]) !== null && _a !== void 0 ? _a : null;
    }
}
// ─── Global singleton guard ───────────────────────────────────────────────────
// WordPress (and any environment that enqueues the CDN bundle more than once)
// evaluates this module multiple times, producing a fresh `new Ai12zManager()`
// each time.  The component registers with one instance while exposeAi12zBridge()
// captured a reference to a different instance, so `ai12zManager.active` is
// always null from the bridge's perspective.
//
// Fix: treat `globalThis.__ai12zManager__` as the authoritative instance.
// The first evaluation creates and stores it; every subsequent evaluation of
// this module reuses the already-stored object instead of creating a new one.
const GLOBAL_MANAGER_KEY = "__ai12zManager__";
if (!globalThis[GLOBAL_MANAGER_KEY]) {
    globalThis[GLOBAL_MANAGER_KEY] = new Ai12zManager();
}
export const ai12zManager = globalThis[GLOBAL_MANAGER_KEY];
export default Ai12zManager;
