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,MAAA;AAAA,IACX;AAKA,IAAA,KAAA,MAAW,CAAC,gBAAA,EAAkB,SAAS,CAAA,IAAK,GAAA,CAAI,SAAQ,EAAG;AACvD,MAAA,IAAI,UAAU,SAAS,CAAA,IAAK,MAAA,CAAO,MAAA,CAAO,gBAAgB,CAAA,EAAG;AACzD,QAAA,OAAO,SAAA;AAAA,MACX;AAAA,IACJ;AAIA,IAAA,KAAA,MAAW,CAAC,gBAAA,EAAkB,SAAS,CAAA,IAAK,GAAA,CAAI,SAAQ,EAAG;AACvD,MAAA,IAAI,UAAU,SAAS,CAAA,IAAK,MAAA,CAAO,KAAA,CAAM,gBAAgB,CAAA,EAAG;AACxD,QAAA,OAAO,SAAA;AAAA,MACX;AAAA,IACJ;AAIA,IAAA,KAAA,MAAW,CAAC,gBAAA,EAAkB,SAAS,CAAA,IAAK,GAAA,CAAI,SAAQ,EAAG;AACvD,MAAA,IAAI,UAAU,SAAS,CAAA,IAAK,MAAA,CAAO,QAAA,CAAS,gBAAgB,CAAA,EAAG;AAC3D,QAAA,OAAO,SAAA;AAAA,MACX;AAAA,IACJ;AAEA,IAAA,OAAO,MAAA;AAAA,EACX;AAEJ","file":"AreSignals.meta.mjs","sourcesContent":["import { A_ComponentMeta, A_TYPES__ComponentMeta, A_TYPES__Ctor } from \"@adaas/a-concept\";\nimport type { A_SignalVector } from \"@adaas/a-utils/a-signal\";\nimport type { Are } from \"@adaas/are/component/Are.component\";\n\n\nexport class AreSignalsMeta extends A_ComponentMeta<{\n    vectorToComponent: Map<A_SignalVector, A_TYPES__Ctor<Are>>;\n    componentToVector: Map<A_TYPES__Ctor<Are>, Set<A_SignalVector>>;\n    /**\n     * Conditions scoped to a single root id. The outer key is the root id\n     * (the `id` attribute of an `<are-root>` outlet); the inner map mirrors\n     * the global `vectorToComponent` map but only applies when matching is\n     * performed for that exact root. Conditions registered here are NEVER\n     * considered for any other root, allowing the same component / vector to\n     * resolve differently per outlet in a multi-root application.\n     */\n    rootScopedConditions: Map<string, Map<A_SignalVector, A_TYPES__Ctor<Are>>>;\n} & A_TYPES__ComponentMeta> {\n\n\n    /**\n     * Registers a condition vector for a component.\n     *\n     * @param component The component constructor to render when the condition matches.\n     * @param vector    The signal vector that activates the component.\n     * @param root      Optional root id. When provided, the condition only\n     *                  applies to the outlet with that id (per-root targeting).\n     *                  When omitted, the condition applies to ALL roots — this\n     *                  is the original, root-agnostic behavior.\n     */\n    registerCondition<T extends Are>(\n        component: A_TYPES__Ctor<T>,\n        vector: A_SignalVector,\n        root?: string\n    ) {\n        if (root) {\n            const rootScopedConditions = this.get('rootScopedConditions')\n                || new Map<string, Map<A_SignalVector, A_TYPES__Ctor<Are>>>();\n\n            if (!rootScopedConditions.has(root)) {\n                rootScopedConditions.set(root, new Map<A_SignalVector, A_TYPES__Ctor<Are>>());\n            }\n            rootScopedConditions.get(root)!.set(vector, component);\n\n            this.set('rootScopedConditions', rootScopedConditions);\n            return;\n        }\n\n        const vectorToComponent = this.get('vectorToComponent') || new Map<A_SignalVector, A_TYPES__Ctor<T>>();\n        const componentToVector = this.get('componentToVector') || new Map<A_TYPES__Ctor<T>, Set<A_SignalVector>>();\n\n        vectorToComponent.set(vector, component);\n        if (!componentToVector.has(component)) {\n            componentToVector.set(component, new Set<A_SignalVector>());\n        }\n        componentToVector.get(component)?.add(vector);\n\n        this.set('vectorToComponent', vectorToComponent);\n        this.set('componentToVector', componentToVector);\n    }\n\n\n    /**\n     * Finds the best registered component whose condition vector matches the\n     * provided signal vector.\n     *\n     * An optional `allowed` set restricts the search to specific component\n     * constructors — used by outlets that maintain a pool of admissible\n     * components. This prevents a globally-registered component from another\n     * outlet (whose condition happens to match the same signals) from being\n     * returned and then rejected by the caller, which would otherwise mask a\n     * lower-priority but pool-eligible match.\n     *\n     * @param vector   The incoming signal vector.\n     * @param allowed  Optional set/array of component constructors to consider.\n     *                 When omitted, every registered component is eligible.\n     * @param root     Optional root id. When provided, conditions registered\n     *                 specifically for that root (via `@Are.Condition(vector,\n     *                 { root })`) are considered FIRST and take priority over\n     *                 global, root-agnostic conditions. Conditions scoped to a\n     *                 DIFFERENT root are never returned here.\n     */\n    findComponentByVector(\n        vector: A_SignalVector,\n        allowed?: ReadonlySet<A_TYPES__Ctor<Are>> | ReadonlyArray<A_TYPES__Ctor<Are>>,\n        root?: string\n    ): A_TYPES__Ctor<Are> | undefined {\n        if (!vector) return undefined;\n\n        const allowedSet = allowed\n            ? (allowed instanceof Set\n                ? allowed\n                : new Set<A_TYPES__Ctor<Are>>(allowed as ReadonlyArray<A_TYPES__Ctor<Are>>))\n            : undefined;\n\n        const isAllowed = (component: A_TYPES__Ctor<Are>): boolean =>\n            !allowedSet || allowedSet.has(component);\n\n        /**\n         * 0. Root-scoped conditions take priority. Only consulted when a root\n         *    id is supplied; conditions registered for OTHER roots are never\n         *    visible here, so they cannot leak across outlets.\n         */\n        if (root) {\n            const rootScoped = this.get('rootScopedConditions')?.get(root);\n            if (rootScoped) {\n                const match = this.matchInMap(rootScoped, vector, isAllowed);\n                if (match) return match;\n            }\n        }\n\n        /**\n         * 1+. Global (root-agnostic) conditions — original behavior.\n         */\n        const vectorToComponent = this.get('vectorToComponent');\n        if (vectorToComponent) {\n            return this.matchInMap(vectorToComponent, vector, isAllowed);\n        }\n\n        return undefined;\n    }\n\n\n    /**\n     * Resolves the best component from a vector→component map using the\n     * three-tier priority shared by all condition matching:\n     *   1. Simple identity lookup (same vector instance).\n     *   2. Full equivalence (`vector.equals`).\n     *   3. Logical match (`vector.match`, order-independent).\n     *   4. Inclusion (`vector.includes`, provided vector is a subset).\n     */\n    protected matchInMap(\n        map: Map<A_SignalVector, A_TYPES__Ctor<Are>>,\n        vector: A_SignalVector,\n        isAllowed: (component: A_TYPES__Ctor<Are>) => boolean\n    ): A_TYPES__Ctor<Are> | undefined {\n        /**\n         * 1. try simple lookup\n         */\n        const direct = map.get(vector);\n        if (direct && isAllowed(direct)) {\n            return direct;\n        }\n\n        /**\n         * 2.1 Priority 1: Full Equivalence - find a component whose registered vector is fully equivalent to the provided vector (i.e., all signals match in type and data).\n         */\n        for (const [registeredVector, component] of map.entries()) {\n            if (isAllowed(component) && vector.equals(registeredVector)) {\n                return component;\n            }\n        }\n        /**\n         * 2.2 Priority 2: Logical Match - find a component whose registered vector logically matches the provided vector (i.e., all signals match in type and data, but order may differ).\n         */\n        for (const [registeredVector, component] of map.entries()) {\n            if (isAllowed(component) && vector.match(registeredVector)) {\n                return component;\n            }\n        }\n        /**\n         * 2.3 Priority 3: Inclusion - find a component whose registered vector includes all signals from the provided vector (i.e., the provided vector is a subset of the registered vector).\n         */\n        for (const [registeredVector, component] of map.entries()) {\n            if (isAllowed(component) && vector.includes(registeredVector)) {\n                return component;\n            }\n        }\n\n        return undefined;\n    }\n\n}"]}