import * as i0 from '@angular/core';
import { NgModule, inject, Injector } from '@angular/core';
import { AXP_MODULE_MANIFEST_PROVIDER, provideLazyProvider } from '@acorex/platform/core';
import { AXP_ENTITY_DEFINITION_LOADER, AXPEntityService } from '@acorex/platform/layout/entity';
import { AXP_MENU_PROVIDER } from '@acorex/platform/common';
import { AXP_PERMISSION_DEFINITION_PROVIDER } from '@acorex/platform/auth';
import { AXPCommonMenuKeys } from '@acorex/modules/common';
import { AXTranslationService } from '@acorex/core/translation';

//#region ----   Root Configuration   ----
const config = {
    i18n: 'contact-core',
    module: 'ContactCore',
};
const RootConfig = {
    config,
    module: {
        name: config.module,
        title: `@${config.i18n}:module.title`,
        icon: 'fa-light fa-address-book',
    },
    entities: {
        emergencyService: {
            name: 'EmergencyService',
            source: `${config.module}.EmergencyService`,
            title: `@${config.i18n}:emergency-services.entities.emergency-service.title`,
            titlePlural: `@${config.i18n}:emergency-services.entities.emergency-service.plural`,
            icon: 'fa-light fa-siren',
        },
    },
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Manifest Definition   ----
/**
 * Contact Core Module Manifest.
 * Defines module metadata for shared contact reference data and emergency services.
 */
const ContactCoreManifest = {
    name: RootConfig.module.name,
    version: '1.0.0',
    title: RootConfig.module.title,
    icon: RootConfig.module.icon,
    i18n: RootConfig.config.i18n,
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Module   ----
class AXPContactCoreModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXPContactCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXPContactCoreModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXPContactCoreModule, providers: [
            {
                provide: AXP_MODULE_MANIFEST_PROVIDER,
                useValue: ContactCoreManifest,
                multi: true,
            },
            provideLazyProvider(AXP_PERMISSION_DEFINITION_PROVIDER, () => Promise.resolve().then(function () { return permissionDefinition_provider; }).then((m) => m.AXPContactCorePermissionDefinitionProvider)),
            provideLazyProvider(AXP_MENU_PROVIDER, () => Promise.resolve().then(function () { return menu_provider; }).then((m) => m.AXPContactCoreMenuProvider)),
            provideLazyProvider(AXP_ENTITY_DEFINITION_LOADER, () => Promise.resolve().then(function () { return entity_provider; }).then((m) => m.AXPContactCoreEntityProvider)),
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXPContactCoreModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [],
                    providers: [
                        {
                            provide: AXP_MODULE_MANIFEST_PROVIDER,
                            useValue: ContactCoreManifest,
                            multi: true,
                        },
                        provideLazyProvider(AXP_PERMISSION_DEFINITION_PROVIDER, () => Promise.resolve().then(function () { return permissionDefinition_provider; }).then((m) => m.AXPContactCorePermissionDefinitionProvider)),
                        provideLazyProvider(AXP_MENU_PROVIDER, () => Promise.resolve().then(function () { return menu_provider; }).then((m) => m.AXPContactCoreMenuProvider)),
                        provideLazyProvider(AXP_ENTITY_DEFINITION_LOADER, () => Promise.resolve().then(function () { return entity_provider; }).then((m) => m.AXPContactCoreEntityProvider)),
                    ],
                }]
        }] });

//#region ----   Emergency Service Model   ----
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Provider   ----
class AXPContactCoreEntityProvider {
    constructor() {
        this.injector = inject(Injector);
    }
    async get(moduleName, entityName) {
        if (moduleName !== RootConfig.module.name) {
            return null;
        }
        switch (entityName) {
            case RootConfig.entities.emergencyService.name:
                return (await import('./acorex-modules-contact-core-emergency-service.entity-l8rYNqP1.mjs')).emergencyServiceFactory(this.injector);
        }
        return null;
    }
    async list() {
        const m = RootConfig.module.name;
        return Promise.resolve(Object.values(RootConfig.entities).map((e) => ({ name: e.name, module: m })));
    }
}
//#endregion

var entity_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXPContactCoreEntityProvider: AXPContactCoreEntityProvider
});

const AXPContactCoreMenuKeys = {
    Root: 'ContactCore:Menu',
    EmergencyServices: 'ContactCore:Menu:EmergencyServices',
};

const AXPContactCorePermissionKeys = {
    ContactCore: {
        EmergencyService: {
            Management: 'ContactCore:Permission:EmergencyService.Management',
        },
    },
};

//#region ----   Imports   ----
//#endregion
//#region ----   Menu Provider   ----
class AXPContactCoreMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const module = RootConfig.module;
        // Create Contacts root menu if it doesn't exist
        const contactsMenu = context.find(AXPCommonMenuKeys.Contacts);
        if (!contactsMenu.exists) {
            context.addItems([
                {
                    name: AXPCommonMenuKeys.Contacts,
                    priority: 9000,
                    text: '@general:menus.contacts.title',
                    icon: 'fa-light fa-address-book',
                    type: 'menu',
                    children: [],
                },
            ]);
        }
        // Add Emergency Services under Contacts menu
        context.find(AXPCommonMenuKeys.Contacts).addItems([
            {
                name: AXPContactCoreMenuKeys.EmergencyServices,
                priority: 1,
                text: RootConfig.entities.emergencyService.titlePlural,
                icon: RootConfig.entities.emergencyService.icon,
                path: this.entityService
                    .withEntity(module.name, RootConfig.entities.emergencyService.name)
                    .createPath(),
                policy: {
                    permissions: [AXPContactCorePermissionKeys.ContactCore.EmergencyService.Management],
                },
            },
        ]);
    }
}
//#endregion

var menu_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXPContactCoreMenuProvider: AXPContactCoreMenuProvider
});

//#region ----   Imports   ----
//#endregion
//#region ----   Permission Definition Provider   ----
class AXPContactCorePermissionDefinitionProvider {
    constructor() {
        this.translationService = inject(AXTranslationService);
    }
    async define(context) {
        const emergencyServiceTrans = (action) => this.translationService.translateAsync(`@contact-core:emergency-services.permissions.emergency-service.${action}.title`);
        context
            .addGroup(RootConfig.module.name, await this.translationService.translateAsync('@contact-core:module.title'))
            .addPermission(AXPContactCorePermissionKeys.ContactCore.EmergencyService.Management, await emergencyServiceTrans('manage'))
            .endPermission()
            .endGroup();
    }
}
//#endregion

var permissionDefinition_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXPContactCorePermissionDefinitionProvider: AXPContactCorePermissionDefinitionProvider
});

// Main Module

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

export { AXPContactCoreEntityProvider, AXPContactCoreMenuProvider, AXPContactCoreModule, AXPContactCorePermissionDefinitionProvider, AXPContactCorePermissionKeys, RootConfig };
//# sourceMappingURL=acorex-modules-contact-core.mjs.map
