import * as i0 from '@angular/core';
import { Injectable, InjectionToken, inject, EnvironmentInjector, runInInjectionContext, makeEnvironmentProviders, input, ElementRef, effect, Directive, isDevMode, NgModule } from '@angular/core';
import { AXPBroadcastEventService, AXPDistributedEventListenerService } from '@acorex/platform/core';
import { castArray } from 'lodash-es';

//#endregion
//#region ----   Middleware Composition   ----
/**
 * Creates a composed handler by chaining the provided command middlewares.
 */
function composeCommandMiddlewares(middlewares) {
    return (handler) => {
        let composed = handler;
        for (let i = middlewares.length - 1; i >= 0; i--) {
            const mw = middlewares[i];
            const next = composed;
            composed = (input) => mw(input, next);
        }
        return composed;
    };
}
//#endregion

class AXPCommandRegistry {
    constructor() {
        this.registry = new Map();
        this.middlewares = [];
    }
    register(key, loader) {
        this.registry.set(key, loader);
    }
    unregister(key) {
        return this.registry.delete(key);
    }
    use(middleware) {
        this.middlewares.push(middleware);
    }
    exists(key) {
        return this.registry.has(key);
    }
    getLoader(key) {
        return this.registry.get(key);
    }
    getMiddlewares() {
        return [...this.middlewares];
    }
    getRegisteredKeys() {
        return Array.from(this.registry.keys());
    }
    clear() {
        this.registry.clear();
        this.middlewares.length = 0;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandRegistry, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandRegistry, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

// plugins/command.extension.token.ts
const AXP_COMMAND_EXTENSION = new InjectionToken('AXP_COMMAND_EXTENSION');

//#region ----   Imports   ----
//#endregion
const COMMAND_EXECUTION_EVENT_KEY = '@commands:execution';
class AXPCommandEventsService {
    constructor() {
        //#region ----   Services & Dependencies   ----
        this.broadcast = inject(AXPBroadcastEventService);
        this.distributedEvents = inject(AXPDistributedEventListenerService, { optional: true });
    }
    //#endregion
    //#region ----   Public API   ----
    listen(handler) {
        const subscription = this.broadcast
            .listen(COMMAND_EXECUTION_EVENT_KEY)
            .subscribe(({ data }) => handler(data));
        return () => subscription.unsubscribe();
    }
    async emit(event) {
        this.broadcast.publish(COMMAND_EXECUTION_EVENT_KEY, event);
        await this.distributedEvents?.dispatch(COMMAND_EXECUTION_EVENT_KEY, event);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandEventsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandEventsService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandEventsService, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

class AXPCommandExecutor {
    constructor() {
        this.injector = inject(EnvironmentInjector);
        this.registry = inject(AXPCommandRegistry);
        this.extensions = inject(AXP_COMMAND_EXTENSION, { optional: true });
        this.commandEvents = inject(AXPCommandEventsService);
    }
    async execute(key, input) {
        const loader = this.registry.getLoader(key);
        if (!loader) {
            throw new Error(`Command '${key}' is not registered`);
        }
        const command = await loader();
        const handler = (i) => command.execute(i);
        const pluginMiddlewares = this.getPluginMiddlewares(key);
        const globalMiddlewares = this.registry.getMiddlewares();
        const wrappedMiddlewares = [
            ...globalMiddlewares,
            ...pluginMiddlewares,
        ].map(middleware => {
            return (input, next) => runInInjectionContext(this.injector, () => middleware(input, next));
        });
        const composed = composeCommandMiddlewares(wrappedMiddlewares)(handler);
        const beforeEvent = {
            stage: 'before',
            key,
            input,
        };
        await this.commandEvents.emit(beforeEvent);
        try {
            const result = await composed(input);
            const afterEvent = {
                stage: 'after',
                key,
                input,
                success: true,
                result,
            };
            await this.commandEvents.emit(afterEvent);
            return result;
        }
        catch (error) {
            const afterEvent = {
                stage: 'after',
                key,
                input,
                success: false,
                error,
            };
            await this.commandEvents.emit(afterEvent);
            throw error;
        }
    }
    getPluginMiddlewares(key) {
        return this.extensions
            ?.filter(ext => ext.target instanceof RegExp ? ext.target.test(key) : ext.target === key)
            .map(ext => ext.middleware) ?? [];
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandExecutor, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandExecutor, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandExecutor, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

class AXPCommandService {
    constructor() {
        this.registry = inject(AXPCommandRegistry);
        this.executor = inject(AXPCommandExecutor);
    }
    // Registry methods
    register(key, loader) {
        this.registry.register(key, loader);
    }
    unregister(key) {
        return this.registry.unregister(key);
    }
    use(middleware) {
        this.registry.use(middleware);
    }
    exists(key) {
        return this.registry.exists(key);
    }
    getRegisteredKeys() {
        return this.registry.getRegisteredKeys();
    }
    clear() {
        this.registry.clear();
    }
    // Executor methods
    async execute(key, input) {
        return this.executor.execute(key, input);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPCommandService, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

const AXP_COMMAND_SETUP = new InjectionToken('AXP_COMMAND_SETUP');
function provideCommandSetups(entries) {
    return makeEnvironmentProviders([
        {
            provide: AXP_COMMAND_SETUP,
            useFactory: () => {
                const registry = inject(AXPCommandRegistry);
                const injector = inject(EnvironmentInjector);
                for (const entry of entries) {
                    registry.register(entry.key, async () => {
                        const CommandType = await entry.command();
                        // Try to get from DI first, if fails create new instance
                        try {
                            return injector.get(CommandType);
                        }
                        catch (e) {
                            // If not in DI (e.g., for activities), create new instance
                            return runInInjectionContext(injector, () => new CommandType());
                        }
                    });
                }
                return true;
            },
            multi: true
        }
    ]);
}
function provideCommand(key, loader) {
    return provideCommandSetups([
        {
            key,
            command: loader
        }
    ]);
}

const AXP_COMMAND_MIDDLEWARE_SETUP = new InjectionToken('AXP_COMMAND_MIDDLEWARE_SETUP');
function provideCommandMiddleware(entries) {
    const global = [];
    const extensions = [];
    for (const entry of entries) {
        if (typeof entry === 'function') {
            global.push(entry);
        }
        else {
            extensions.push(entry);
        }
    }
    return makeEnvironmentProviders([
        // Plugin middleware entries
        ...extensions.map(ext => ({
            provide: AXP_COMMAND_EXTENSION,
            useValue: ext,
            multi: true
        })),
        // Global middleware setup (triggered via this token)
        {
            provide: AXP_COMMAND_MIDDLEWARE_SETUP,
            useFactory: () => {
                const registry = inject(AXPCommandRegistry);
                for (const mw of global) {
                    registry.use(mw);
                }
                return true;
            }
        }
    ]);
}

function composeQueryMiddlewares(middlewares) {
    return (handler) => {
        let composed = handler;
        for (let i = middlewares.length - 1; i >= 0; i--) {
            const mw = middlewares[i];
            const next = composed;
            composed = (input) => mw(input, next);
        }
        return composed;
    };
}

// queries/query.registry.ts
class AXPQueryRegistry {
    constructor() {
        this.registry = new Map();
        this.middlewares = [];
    }
    register(key, loader) {
        this.registry.set(key, loader);
    }
    unregister(key) {
        return this.registry.delete(key);
    }
    use(middleware) {
        this.middlewares.push(middleware);
    }
    exists(key) {
        return this.registry.has(key);
    }
    getLoader(key) {
        return this.registry.get(key);
    }
    getMiddlewares() {
        return [...this.middlewares];
    }
    getRegisteredKeys() {
        return Array.from(this.registry.keys());
    }
    clear() {
        this.registry.clear();
        this.middlewares.length = 0;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPQueryRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPQueryRegistry, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPQueryRegistry, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

// plugins/query.extension.token.ts
const AXP_QUERY_EXTENSION = new InjectionToken('AXP_QUERY_EXTENSION');

class AXPQueryExecutor {
    constructor() {
        this.injector = inject(EnvironmentInjector);
        this.registry = inject(AXPQueryRegistry);
        this.extensions = inject(AXP_QUERY_EXTENSION, { optional: true });
    }
    async fetch(key, input) {
        const loader = this.registry.getLoader(key);
        if (!loader) {
            return null;
        }
        const query = await loader();
        const handler = (i) => query.fetch(i);
        const pluginMiddlewares = this.getPluginMiddlewares(key);
        const globalMiddlewares = this.registry.getMiddlewares();
        const wrappedMiddlewares = [...globalMiddlewares, ...pluginMiddlewares].map(middleware => {
            return (input, next) => runInInjectionContext(this.injector, () => middleware(input, next));
        });
        const composed = composeQueryMiddlewares(wrappedMiddlewares)(handler);
        return composed(input);
    }
    getPluginMiddlewares(key) {
        return this.extensions
            ?.filter(ext => ext.target instanceof RegExp ? ext.target.test(key) : ext.target === key)
            .map(ext => ext.middleware) ?? [];
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPQueryExecutor, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPQueryExecutor, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPQueryExecutor, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

class AXPQueryService {
    constructor() {
        this.registry = inject(AXPQueryRegistry);
        this.executor = inject(AXPQueryExecutor);
    }
    // Registry methods
    register(key, loader) {
        this.registry.register(key, loader);
    }
    unregister(key) {
        return this.registry.unregister(key);
    }
    use(middleware) {
        this.registry.use(middleware);
    }
    exists(key) {
        return this.registry.exists(key);
    }
    getRegisteredKeys() {
        return this.registry.getRegisteredKeys();
    }
    clear() {
        this.registry.clear();
    }
    // Executor methods
    async fetch(key, input) {
        return this.executor.fetch(key, input);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPQueryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPQueryService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPQueryService, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

const AXP_QUERY_SETUP = new InjectionToken('AXP_QUERY_SETUP');
function provideQuerySetups(entries) {
    return makeEnvironmentProviders([
        {
            provide: AXP_QUERY_SETUP,
            useFactory: () => {
                const registry = inject(AXPQueryRegistry);
                const injector = inject(EnvironmentInjector);
                for (const entry of entries) {
                    registry.register(entry.key, async () => {
                        const CommandType = await entry.loader();
                        return injector.get(CommandType);
                    });
                }
                return true;
            },
            multi: true
        }
    ]);
}

const AXP_QUERY_MIDDLEWARE_SETUP = new InjectionToken('AXP_QUERY_MIDDLEWARE_SETUP');
function provideQueryMiddleware(entries) {
    const global = [];
    const extensions = [];
    for (const entry of entries) {
        if (typeof entry === 'function') {
            global.push(entry);
        }
        else {
            extensions.push(entry);
        }
    }
    return makeEnvironmentProviders([
        // Plugin middleware entries
        ...extensions.map(ext => ({
            provide: AXP_QUERY_EXTENSION,
            useValue: ext,
            multi: true
        })),
        // Global middleware setup (triggered via this token)
        {
            provide: AXP_QUERY_MIDDLEWARE_SETUP,
            useFactory: () => {
                const registry = inject(AXPQueryRegistry);
                for (const mw of global) {
                    registry.use(mw);
                }
                return true;
            }
        }
    ]);
}

function composeViewMiddlewares(middlewares) {
    return (handler) => {
        let composed = handler;
        for (let i = middlewares.length - 1; i >= 0; i--) {
            const mw = middlewares[i];
            const next = composed;
            composed = (input) => mw(input, next);
        }
        return composed;
    };
}

class AXPViewRegistry {
    constructor() {
        this.registry = new Map();
        this.middlewares = [];
    }
    register(key, loader) {
        this.registry.set(key, loader);
    }
    unregister(key) {
        return this.registry.delete(key);
    }
    use(middleware) {
        this.middlewares.push(middleware);
    }
    exists(key) {
        return this.registry.has(key);
    }
    getLoader(key) {
        return this.registry.get(key);
    }
    getMiddlewares() {
        return [...this.middlewares];
    }
    getRegisteredKeys() {
        return Array.from(this.registry.keys());
    }
    clear() {
        this.registry.clear();
        this.middlewares.length = 0;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPViewRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPViewRegistry, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPViewRegistry, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

const AXP_VIEW_EXTENSION = new InjectionToken('AXP_VIEW_EXTENSION');

class AXPViewExecutor {
    constructor() {
        this.injector = inject(EnvironmentInjector);
        this.registry = inject(AXPViewRegistry);
        this.extensions = inject(AXP_VIEW_EXTENSION, { optional: true });
    }
    async provide(key, input) {
        const loader = this.registry.getLoader(key);
        if (!loader) {
            return null;
        }
        const provider = await loader();
        const handler = (i) => provider.provide(i);
        const pluginMiddlewares = this.getPluginMiddlewares(key);
        const globalMiddlewares = this.registry.getMiddlewares();
        const wrappedMiddlewares = [...globalMiddlewares, ...pluginMiddlewares].map(middleware => {
            return (input, next) => runInInjectionContext(this.injector, () => middleware(input, next));
        });
        const composed = composeViewMiddlewares(wrappedMiddlewares)(handler);
        return composed(input);
    }
    getPluginMiddlewares(key) {
        return this.extensions
            ?.filter(ext => ext.target instanceof RegExp ? ext.target.test(key) : ext.target === key)
            .map(ext => ext.middleware) ?? [];
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPViewExecutor, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPViewExecutor, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPViewExecutor, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

class AXPViewService {
    constructor() {
        this.registry = inject(AXPViewRegistry);
        this.executor = inject(AXPViewExecutor);
    }
    //#region ----   Registry Methods   ----
    register(key, loader) {
        this.registry.register(key, loader);
    }
    unregister(key) {
        return this.registry.unregister(key);
    }
    use(middleware) {
        this.registry.use(middleware);
    }
    exists(key) {
        return this.registry.exists(key);
    }
    getRegisteredKeys() {
        return this.registry.getRegisteredKeys();
    }
    clear() {
        this.registry.clear();
    }
    //#endregion
    //#region ----   Executor Methods   ----
    async provide(key, input) {
        return this.executor.provide(key, input);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPViewService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPViewService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPViewService, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

const AXP_VIEW_SETUP = new InjectionToken('AXP_VIEW_SETUP');
function provideViewSetups(providers) {
    return makeEnvironmentProviders([
        ...providers,
        {
            provide: AXP_VIEW_SETUP,
            useFactory: () => {
                const registry = inject(AXPViewRegistry);
                // Setup will be handled by the provided registration functions
                return;
            },
            multi: true
        }
    ]);
}
function provideViewSetup(key, loader) {
    return {
        provide: AXP_VIEW_SETUP,
        useFactory: () => {
            const registry = inject(AXPViewRegistry);
            registry.register(key, loader);
            return;
        },
        multi: true
    };
}

function composePolicyEngineMiddlewares(middlewares) {
    return (handler) => {
        let composed = handler;
        for (let i = middlewares.length - 1; i >= 0; i--) {
            const mw = middlewares[i];
            const next = composed;
            composed = (context) => mw(context, next);
        }
        return composed;
    };
}

class AXPPolicyEngineContext {
    constructor(options) {
        this._visible = true;
        this._enabled = true;
        this._id = options.id;
        this._sender = options.sender;
    }
    get sender() {
        return this._sender;
    }
    get id() {
        return this._id;
    }
    get visible() {
        return this._visible;
    }
    get enabled() {
        return this._enabled;
    }
    setVisible(visible) {
        this._visible = visible;
        return this;
    }
    setEnabled(enabled) {
        this._enabled = enabled;
        return this;
    }
}

// plugins/command.extension.token.ts
const AXP_POLICY_EXTENSION = new InjectionToken('AXP_POLICY_EXTENSION');

class AXPPolicyEngineRegistry {
    constructor() {
        this.registry = new Map();
        this.middlewares = [];
        this.extensions = inject(AXP_POLICY_EXTENSION, { optional: true });
        this.injector = inject(EnvironmentInjector);
    }
    use(mw) {
        this.middlewares.push(mw);
    }
    exists(key) {
        return this.registry.has(key);
    }
    getPolicies() {
        return Array.from(this.registry.keys());
    }
    register(key, loader) {
        this.registry.set(key, loader);
    }
    getPluginMiddlewares(key) {
        return this.extensions
            ?.filter(ext => ext.key === key)
            .map(ext => ext.middleware) ?? [];
    }
    async execute(policy, instance) {
        const loader = this.registry.get(policy);
        if (!loader) {
            throw new Error(`${policy} not implemented`);
        }
        const context = new AXPPolicyEngineContext(instance);
        const applier = await loader();
        const handler = (i) => applier.apply(i);
        const pluginMws = this.getPluginMiddlewares(policy);
        const wrappedMws = [...this.middlewares, ...pluginMws].map(mw => {
            return (input, next) => runInInjectionContext(this.injector, () => mw(input, next));
        });
        const composed = composePolicyEngineMiddlewares(wrappedMws)(handler);
        await composed(context);
        return context;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPPolicyEngineRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPPolicyEngineRegistry, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPPolicyEngineRegistry, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

class AXPPolicyEngineService {
    constructor() {
        this.registry = inject(AXPPolicyEngineRegistry);
    }
    async apply(options) {
        const allPolicies = this.registry.getPolicies().filter(p => (options.policies?.length ?? 0) == 0 || options.policies?.includes(p));
        await Promise.all(allPolicies.map(async (policy) => {
            const context = await this.registry.execute(policy, options);
            return context;
        }));
        //
        // if (instance instanceof HTMLElement) {
        //     if (context.visible === false) {
        //         instance.style.display = 'none';
        //     } else {
        //         instance.style.display = '';
        //     }
        // }
        // //
        // if (instance instanceof MXBaseComponent) {
        //     if (context.visible === false) {
        //         instance.getHostElement().style.display = 'none';
        //     } else {
        //         instance.getHostElement().style.display = '';
        //     }
        // }
        // // Handle disabled state for interactive components
        // if (instance instanceof MXInteractiveComponent) {
        //     if (context.enabled === false) {
        //         instance.disabled = true;
        //     } else {
        //         instance.disabled = false;
        //     }
        // }
        // // TODO: Handle object properties   
        // if (instance instanceof Object) {
        //     if (context.visible === false) {
        //         set(instance, 'visible', false);
        //     }
        //     if (context.enabled === false) {
        //         set(instance, 'disabled', true);
        //     }
        // }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPPolicyEngineService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPPolicyEngineService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPPolicyEngineService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

class AXPPolicyEngineDirective {
    constructor() {
        this.policy = input.required(...(ngDevMode ? [{ debugName: "policy", alias: 'axp-apply-policy' }] : [{ alias: 'axp-apply-policy' }]));
        this.service = inject(AXPPolicyEngineService);
        this.elementRef = inject((ElementRef));
        this.#eff = effect(async () => {
            const policy = this.policy();
            if (!policy) {
                return;
            }
            await this.service.apply({
                id: this.elementRef.nativeElement.id,
                policies: castArray(policy),
                sender: this.elementRef.nativeElement
            });
        }, ...(ngDevMode ? [{ debugName: "#eff" }] : []));
    }
    #eff;
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPPolicyEngineDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.16", type: AXPPolicyEngineDirective, isStandalone: true, selector: "[axp-apply-policy]", inputs: { policy: { classPropertyName: "policy", publicName: "axp-apply-policy", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPPolicyEngineDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[axp-apply-policy]',
                    standalone: true
                }]
        }], propDecorators: { policy: [{ type: i0.Input, args: [{ isSignal: true, alias: "axp-apply-policy", required: true }] }] } });

const AXP_POLICY_ENGINE_MIDDLEWARE_SETUP = new InjectionToken('AXP_POLICY_ENGINE_MIDDLEWARE_SETUP');
function providePolicySetups(entries) {
    return makeEnvironmentProviders([
        {
            provide: AXP_POLICY_ENGINE_MIDDLEWARE_SETUP,
            useFactory: () => {
                const registry = inject(AXPPolicyEngineRegistry);
                const injector = inject(EnvironmentInjector);
                for (const entry of entries) {
                    registry.register(entry.key, async () => {
                        const PolicyType = await entry.policy();
                        return injector.get(PolicyType);
                    });
                }
                return true;
            }
        }
    ]);
}

const AXP_VIEW_MIDDLEWARE_SETUP = new InjectionToken('AXP_VIEW_MIDDLEWARE_SETUP');
function provideViewMiddleware(middlewares) {
    return makeEnvironmentProviders([
        {
            provide: AXP_VIEW_MIDDLEWARE_SETUP,
            useFactory: () => {
                const registry = inject(AXPViewRegistry);
                middlewares.forEach(middleware => registry.use(middleware));
                return;
            },
            multi: true
        }
    ]);
}
function provideViewMiddlewareSetup(middleware) {
    return {
        provide: AXP_VIEW_MIDDLEWARE_SETUP,
        useFactory: () => {
            const registry = inject(AXPViewRegistry);
            registry.use(middleware);
            return;
        },
        multi: true
    };
}

class AXPRuntimeModule {
    constructor() {
        this._commandSetup = inject(AXP_COMMAND_SETUP, { optional: true });
        this._commandMiddlewareSetup = inject(AXP_COMMAND_MIDDLEWARE_SETUP, { optional: true });
        this._querySetup = inject(AXP_QUERY_SETUP, { optional: true });
        this._queryMiddlewareSetup = inject(AXP_QUERY_MIDDLEWARE_SETUP, { optional: true });
        this._viewSetup = inject(AXP_VIEW_SETUP, { optional: true });
        this._viewMiddlewareSetup = inject(AXP_VIEW_MIDDLEWARE_SETUP, { optional: true });
        this._policyEngineSetup = inject(AXP_POLICY_ENGINE_MIDDLEWARE_SETUP, { optional: true });
        if (isDevMode() && false) {
            console.log('[AXPRuntimeModule] Command Setup:', this._commandSetup);
            console.log('[AXPRuntimeModule] Command Middleware Setup:', this._commandMiddlewareSetup);
            console.log('[AXPRuntimeModule] Query Setup:', this._querySetup);
            console.log('[AXPRuntimeModule] Query Middleware Setup:', this._queryMiddlewareSetup);
            console.log('[AXPRuntimeModule] View Setup:', this._viewSetup);
            console.log('[AXPRuntimeModule] View Middleware Setup:', this._viewMiddlewareSetup);
            console.log('[AXPRuntimeModule] Policy Engine Setup:', this._policyEngineSetup);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPRuntimeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.16", ngImport: i0, type: AXPRuntimeModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPRuntimeModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: AXPRuntimeModule, decorators: [{
            type: NgModule
        }], ctorParameters: () => [] });

// Commands

/**
 * Generated bundle index. Do not edit.
 */

export { AXPCommandEventsService, AXPCommandExecutor, AXPCommandRegistry, AXPCommandService, AXPPolicyEngineContext, AXPPolicyEngineDirective, AXPPolicyEngineRegistry, AXPPolicyEngineService, AXPQueryExecutor, AXPQueryRegistry, AXPQueryService, AXPRuntimeModule, AXPViewExecutor, AXPViewRegistry, AXPViewService, AXP_COMMAND_EXTENSION, AXP_COMMAND_MIDDLEWARE_SETUP, AXP_COMMAND_SETUP, AXP_POLICY_ENGINE_MIDDLEWARE_SETUP, AXP_POLICY_EXTENSION, AXP_QUERY_EXTENSION, AXP_QUERY_MIDDLEWARE_SETUP, AXP_QUERY_SETUP, AXP_VIEW_EXTENSION, AXP_VIEW_SETUP, composeCommandMiddlewares, composePolicyEngineMiddlewares, composeQueryMiddlewares, composeViewMiddlewares, provideCommand, provideCommandMiddleware, provideCommandSetups, providePolicySetups, provideQueryMiddleware, provideQuerySetups, provideViewSetup, provideViewSetups };
//# sourceMappingURL=acorex-platform-runtime.mjs.map
