import * as i0 from '@angular/core';
import { NgModule, inject, Injector } from '@angular/core';
import { AXP_MODULE_MANIFEST_PROVIDER, AXP_DATASOURCE_DEFINITION_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 { AXDataSource } from '@acorex/cdk/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { AXPCommonMenuKeys } from '@acorex/modules/common';
import { AXTranslationService } from '@acorex/core/translation';

const config = {
    i18n: 'person-core',
    module: 'PersonCore',
};
const RootConfig = {
    config,
    module: {
        name: config.module,
        title: `@${config.i18n}:module.title`,
        icon: 'fa-light fa-user',
    },
    entities: {
        educationLevel: {
            name: 'EducationLevel',
            title: `@${config.i18n}:education-levels.entities.education-level.title`,
            titlePlural: `@${config.i18n}:education-levels.entities.education-level.plural`,
            icon: 'fa-light fa-graduation-cap',
        },
        maritalStatus: {
            name: 'MaritalStatus',
            title: `@${config.i18n}:marital-statuses.entities.marital-status.title`,
            titlePlural: `@${config.i18n}:marital-statuses.entities.marital-status.plural`,
            icon: 'fa-light fa-heart',
        },
        personIdentifierType: {
            name: 'PersonIdentifierType',
            title: `@${config.i18n}:person-identifier-types.entities.person-identifier-type.title`,
            titlePlural: `@${config.i18n}:person-identifier-types.entities.person-identifier-type.plural`,
            icon: 'fa-light fa-id-card',
        },
        personRelationshipType: {
            name: 'PersonRelationshipType',
            title: `@${config.i18n}:person-relationship-types.entities.person-relationship-type.title`,
            titlePlural: `@${config.i18n}:person-relationship-types.entities.person-relationship-type.plural`,
            icon: 'fa-light fa-diagram-project',
        },
        religion: {
            name: 'Religion',
            title: `@${config.i18n}:religions.entities.religion.title`,
            titlePlural: `@${config.i18n}:religions.entities.religion.plural`,
            icon: 'fa-light fa-place-of-worship',
        },
    },
};

//#region ----   Imports   ----
//#endregion
//#region ----   Manifest Definition   ----
/**
 * Person Core Module Manifest.
 * Defines module metadata for shared person/demographic reference data.
 */
const PersonCoreManifest = {
    name: RootConfig.module.name,
    version: '1.0.0',
    title: RootConfig.module.title,
    icon: RootConfig.module.icon,
    i18n: RootConfig.config.i18n,
};
//#endregion

/**
 * Gender options datasource for person/demographic forms (Male, Female, Non-binary, etc.).
 */
class AXMGenderOptionsDataSourceDefinition {
    constructor() {
        this.definition = {
            name: 'gender-options',
            title: '@person-core:datasources.gender-options.title',
            columns: [
                {
                    name: 'value',
                    title: '@person-core:datasources.gender-options.columns.value.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
                {
                    name: 'title',
                    title: '@person-core:datasources.gender-options.columns.title.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
            ],
            filters: [],
            textField: { name: 'title', title: '@person-core:datasources.gender-options.columns.title.title' },
            valueField: { name: 'value', title: '@person-core:datasources.gender-options.columns.value.title' },
            samples: [
                { value: 'male', title: '@person-core:datasources.gender-options.samples.male' },
                { value: 'female', title: '@person-core:datasources.gender-options.samples.female' },
                { value: 'non-binary', title: '@person-core:datasources.gender-options.samples.non-binary' },
                { value: 'other', title: '@person-core:datasources.gender-options.samples.other' },
                { value: 'prefer-not-to-say', title: '@person-core:datasources.gender-options.samples.prefer-not-to-say' },
            ],
            source: () => {
                const items = [
                    { value: 'male', title: '@person-core:datasources.gender-options.samples.male' },
                    { value: 'female', title: '@person-core:datasources.gender-options.samples.female' },
                    { value: 'non-binary', title: '@person-core:datasources.gender-options.samples.non-binary' },
                    { value: 'other', title: '@person-core:datasources.gender-options.samples.other' },
                    { value: 'prefer-not-to-say', title: '@person-core:datasources.gender-options.samples.prefer-not-to-say' },
                ];
                return new AXDataSource({
                    pageSize: 10,
                    key: 'value',
                    load: async () => ({ items, total: items.length }),
                    byKey: async (key) => items.find((item) => item.value === key),
                });
            },
        };
    }
    async items() {
        return [this.definition];
    }
}

/**
 * Person title (salutation) options datasource for forms (Mr, Mrs, Ms, Dr, etc.).
 */
class AXMPersonTitleOptionsDataSourceDefinition {
    constructor() {
        this.definition = {
            name: 'person-title-options',
            title: '@person-core:datasources.person-title-options.title',
            columns: [
                {
                    name: 'value',
                    title: '@person-core:datasources.person-title-options.columns.value.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
                {
                    name: 'title',
                    title: '@person-core:datasources.person-title-options.columns.title.title',
                    type: AXPWidgetsCatalog.text,
                    datatype: 'string',
                },
            ],
            filters: [],
            textField: { name: 'title', title: '@person-core:datasources.person-title-options.columns.title.title' },
            valueField: { name: 'value', title: '@person-core:datasources.person-title-options.columns.value.title' },
            samples: [
                { value: 'mr', title: '@person-core:datasources.person-title-options.samples.mr' },
                { value: 'mrs', title: '@person-core:datasources.person-title-options.samples.mrs' },
                { value: 'ms', title: '@person-core:datasources.person-title-options.samples.ms' },
                { value: 'miss', title: '@person-core:datasources.person-title-options.samples.miss' },
                { value: 'dr', title: '@person-core:datasources.person-title-options.samples.dr' },
                { value: 'prof', title: '@person-core:datasources.person-title-options.samples.prof' },
                { value: 'other', title: '@person-core:datasources.person-title-options.samples.other' },
            ],
            source: () => {
                const items = [
                    { value: 'mr', title: '@person-core:datasources.person-title-options.samples.mr' },
                    { value: 'mrs', title: '@person-core:datasources.person-title-options.samples.mrs' },
                    { value: 'ms', title: '@person-core:datasources.person-title-options.samples.ms' },
                    { value: 'miss', title: '@person-core:datasources.person-title-options.samples.miss' },
                    { value: 'dr', title: '@person-core:datasources.person-title-options.samples.dr' },
                    { value: 'prof', title: '@person-core:datasources.person-title-options.samples.prof' },
                    { value: 'other', title: '@person-core:datasources.person-title-options.samples.other' },
                ];
                return new AXDataSource({
                    pageSize: 10,
                    key: 'value',
                    load: async () => ({ items, total: items.length }),
                    byKey: async (key) => items.find((item) => item.value === key),
                });
            },
        };
    }
    async items() {
        return [this.definition];
    }
}

//#region ----   Imports   ----
//#endregion
//#region ----   Data Source Provider   ----
/**
 * Person Core Data Source Provider.
 * Provides demographic choice datasources (gender, person title).
 */
class AXMPersonCoreDataSourceProvider {
    constructor() {
        this.genderOptions = new AXMGenderOptionsDataSourceDefinition();
        this.personTitleOptions = new AXMPersonTitleOptionsDataSourceDefinition();
    }
    async items() {
        const items = await Promise.all([
            this.genderOptions.items(),
            this.personTitleOptions.items(),
        ]);
        return items.flat();
    }
}
//#endregion

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

//#region ----   Education Level Model   ----
//#endregion

//#region ----   Marital Status Model   ----
//#endregion

//#region ----   Person Identifier Type Model   ----
//#endregion

//#region ----   Person Relationship Type Model   ----
//#endregion

//#region ----   Religion Model   ----
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Provider   ----
class AXMPersonCoreEntityProvider {
    constructor() {
        this.injector = inject(Injector);
    }
    async get(moduleName, entityName) {
        if (moduleName !== RootConfig.module.name) {
            return null;
        }
        switch (entityName) {
            case RootConfig.entities.educationLevel.name:
                return (await import('./acorex-modules-person-core-education-level.entity-BiXdPA-Z.mjs')).educationLevelFactory(this.injector);
            case RootConfig.entities.maritalStatus.name:
                return (await import('./acorex-modules-person-core-marital-status.entity-j6sMTtTS.mjs')).maritalStatusFactory(this.injector);
            case RootConfig.entities.personIdentifierType.name:
                return (await import('./acorex-modules-person-core-person-identifier-type.entity-BIFiRZ2d.mjs')).personIdentifierTypeFactory(this.injector);
            case RootConfig.entities.personRelationshipType.name:
                return (await import('./acorex-modules-person-core-person-relationship-type.entity-2qysKjU5.mjs')).personRelationshipTypeFactory(this.injector);
            case RootConfig.entities.religion.name:
                return (await import('./acorex-modules-person-core-religion.entity-Czb5aHb6.mjs')).religionFactory(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,
    AXMPersonCoreEntityProvider: AXMPersonCoreEntityProvider
});

const AXMPersonCoreMenuKeys = {
    Root: 'person-core',
    EducationLevels: 'person-core.education-levels',
    MaritalStatuses: 'person-core.marital-statuses',
    PersonIdentifierTypes: 'person-core.person-identifier-types',
    PersonRelationshipTypes: 'person-core.person-relationship-types',
    Religions: 'person-core.religions',
};

const AXMPersonCorePermissionKeys = {
    PersonCore: {
        EducationLevel: {
            Management: 'PersonCore:Permission:EducationLevel.Management',
        },
        MaritalStatus: {
            Management: 'PersonCore:Permission:MaritalStatus.Management',
        },
        PersonIdentifierType: {
            Management: 'PersonCore:Permission:PersonIdentifierType.Management',
        },
        PersonRelationshipType: {
            Management: 'PersonCore:Permission:PersonRelationshipType.Management',
        },
        Religion: {
            Management: 'PersonCore:Permission:Religion.Management',
        },
    },
};

//#region ----   Imports   ----
//#endregion
//#region ----   Menu Provider   ----
class AXMPersonCoreMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const module = RootConfig.module;
        context.find(AXPCommonMenuKeys.Configuration).addItems([
            {
                name: AXMPersonCoreMenuKeys.Root,
                priority: 8450,
                text: '@person-core:module.menus.root.title',
                icon: module.icon,
                policy: {
                    features: [RootConfig.module.name],
                },
                children: [
                    {
                        name: AXMPersonCoreMenuKeys.EducationLevels,
                        text: RootConfig.entities.educationLevel.titlePlural,
                        icon: RootConfig.entities.educationLevel.icon,
                        priority: 1,
                        path: this.entityService
                            .withEntity(module.name, RootConfig.entities.educationLevel.name)
                            .createPath(),
                        policy: {
                            permissions: [AXMPersonCorePermissionKeys.PersonCore.EducationLevel.Management],
                        },
                    },
                    {
                        name: AXMPersonCoreMenuKeys.MaritalStatuses,
                        text: RootConfig.entities.maritalStatus.titlePlural,
                        icon: RootConfig.entities.maritalStatus.icon,
                        priority: 2,
                        path: this.entityService
                            .withEntity(module.name, RootConfig.entities.maritalStatus.name)
                            .createPath(),
                        policy: {
                            permissions: [AXMPersonCorePermissionKeys.PersonCore.MaritalStatus.Management],
                        },
                    },
                    {
                        name: AXMPersonCoreMenuKeys.PersonIdentifierTypes,
                        text: RootConfig.entities.personIdentifierType.titlePlural,
                        icon: RootConfig.entities.personIdentifierType.icon,
                        priority: 3,
                        path: this.entityService
                            .withEntity(module.name, RootConfig.entities.personIdentifierType.name)
                            .createPath(),
                        policy: {
                            permissions: [AXMPersonCorePermissionKeys.PersonCore.PersonIdentifierType.Management],
                        },
                    },
                    {
                        name: AXMPersonCoreMenuKeys.PersonRelationshipTypes,
                        text: RootConfig.entities.personRelationshipType.titlePlural,
                        icon: RootConfig.entities.personRelationshipType.icon,
                        priority: 4,
                        path: this.entityService
                            .withEntity(module.name, RootConfig.entities.personRelationshipType.name)
                            .createPath(),
                        policy: {
                            permissions: [AXMPersonCorePermissionKeys.PersonCore.PersonRelationshipType.Management],
                        },
                    },
                    {
                        name: AXMPersonCoreMenuKeys.Religions,
                        text: RootConfig.entities.religion.titlePlural,
                        icon: RootConfig.entities.religion.icon,
                        priority: 5,
                        path: this.entityService
                            .withEntity(module.name, RootConfig.entities.religion.name)
                            .createPath(),
                        policy: {
                            permissions: [AXMPersonCorePermissionKeys.PersonCore.Religion.Management],
                        },
                    },
                ],
            },
        ]);
    }
}
//#endregion

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

//#region ----   Imports   ----
//#endregion
//#region ----   Permission Definition Provider   ----
class AXMPersonCorePermissionDefinitionProvider {
    constructor() {
        this.translationService = inject(AXTranslationService);
    }
    async define(context) {
        const keys = AXMPersonCorePermissionKeys.PersonCore;
        const educationLevelTrans = (action) => this.translationService.translateAsync(`@person-core:education-levels.permissions.education-level.${action}.title`);
        const maritalStatusTrans = (action) => this.translationService.translateAsync(`@person-core:marital-statuses.permissions.marital-status.${action}.title`);
        const personIdentifierTypeTrans = (action) => this.translationService.translateAsync(`@person-core:person-identifier-types.permissions.person-identifier-type.${action}.title`);
        const personRelationshipTypeTrans = (action) => this.translationService.translateAsync(`@person-core:person-relationship-types.permissions.person-relationship-type.${action}.title`);
        const religionTrans = (action) => this.translationService.translateAsync(`@person-core:religions.permissions.religion.${action}.title`);
        context
            .addGroup(RootConfig.module.name, await this.translationService.translateAsync('@person-core:module.title'))
            .addPermission(keys.EducationLevel.Management, await educationLevelTrans('manage'))
            .endPermission()
            .addPermission(keys.MaritalStatus.Management, await maritalStatusTrans('manage'))
            .endPermission()
            .addPermission(keys.PersonIdentifierType.Management, await personIdentifierTypeTrans('manage'))
            .endPermission()
            .addPermission(keys.PersonRelationshipType.Management, await personRelationshipTypeTrans('manage'))
            .endPermission()
            .addPermission(keys.Religion.Management, await religionTrans('manage'))
            .endPermission()
            .endGroup();
    }
}
//#endregion

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

// Main Module

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

export { AXMPersonCoreEntityProvider, AXMPersonCoreMenuProvider, AXMPersonCoreModule, AXMPersonCorePermissionDefinitionProvider, AXMPersonCorePermissionKeys, RootConfig };
//# sourceMappingURL=acorex-modules-person-core.mjs.map
