/**
 * Pro UI slot registry (Phase 7.2 — plan §8.4 "remove stubs as a boundary").
 *
 * Replaces the vite resolve.alias + render-nothing-stub mechanism: the Pro
 * entrypoint registers its admin components (settings tabs, AI drawer,
 * license surface, shortcode generator) into named slots BEFORE the shared
 * app boots; the shared shell renders a slot only when it is filled. The
 * Free entrypoint registers nothing, so the Free bundle contains neither the
 * component code nor the stub indirection.
 *
 * Boot hooks let Pro register extra mount targets (the License page) without
 * the shared boot code referencing them at all.
 */

const slots = new Map();
const bootHooks = [];

export function registerProUi(name, component) {
    slots.set(name, component);
}

/** @param {Record<string, object>} map slot name → component */
export function registerProUiSlots(map) {
    Object.entries(map || {}).forEach(([name, component]) => registerProUi(name, component));
}

/** @returns {object|null} the registered component, or null in Free. */
export function proUi(name) {
    return slots.get(name) || null;
}

/** Runs after the shared boot's own mount attempts (DOMContentLoaded). */
export function registerAdminBootHook(fn) {
    if (typeof fn === "function") {
        bootHooks.push(fn);
    }
}

export function runAdminBootHooks() {
    bootHooks.forEach((fn) => fn());
}
