import { createAllQueryView, AXPEntityQueryType, AXP_MENU_PROVIDER, AXP_SETTING_DEFINITION_PROVIDER } from '@acorex/platform/common';
import { AXMEntityCrudServiceImpl, entityMasterCrudActions, entityMasterRecordActions, AXPEntityService, AXP_ENTITY_DEFINITION_LOADER } from '@acorex/platform/layout/entity';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import * as i0 from '@angular/core';
import { Injectable, NgModule, inject, Injector } from '@angular/core';

const config = {
    i18n: 'text-template-management',
};
const RootConfig = {
    config,
    module: {
        route: 'template-management',
        name: 'TemplateManagement',
        title: `t('module-name', {scope:"${config.i18n}"})`,
        icon: 'fa-light fa-file-invoice',
    },
    entities: {
        category: {
            name: 'TemplateCategories',
            title: `t("category", { scope: "${config.i18n}" })`,
            icon: 'fa-light fa-list',
        },
        template: {
            name: 'Templates',
            title: `t("template",{scope:"${config.i18n}"})`,
            icon: 'fa-light fa-file-code',
        },
    },
};

class AXMTextTemplateManagementCategoryEntityService extends AXMEntityCrudServiceImpl {
}
class AXMTextTemplateManagementCategoryEntityServiceImpl extends AXMTextTemplateManagementCategoryEntityService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.category.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementCategoryEntityServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementCategoryEntityServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementCategoryEntityServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

async function categoryFactory(injector) {
    const dataService = injector.get(AXMTextTemplateManagementCategoryEntityService);
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.category.name,
        title: RootConfig.entities.category.title,
        formats: {
            individual: '@text-template-management:category.title',
            plural: '@general:terms.classification.categories',
        },
        relatedEntities: [],
        groups: [
            {
                id: 'category',
                title: '@general:terms.classification.category',
            },
        ],
        properties: [
            {
                name: 'name',
                title: '@general:terms.common.name',
                groupId: 'category',
                options: {
                    sort: {
                        enabled: true,
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'title',
                title: '@general:terms.common.title',
                groupId: 'category',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        inline: {
                            enabled: true,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
        ],
        columns: [{ name: 'name' }, { name: 'title' }],
        commands: {
            create: {
                execute: async (data) => {
                    const res = await dataService.insertOne(data);
                    return { id: res };
                },
            },
            delete: {
                execute: async (id) => {
                    return await dataService.deleteOne(id);
                },
            },
            update: {
                execute: async (data) => {
                    return await dataService.updateOne(data.id, data);
                },
            },
        },
        queries: {
            byKey: {
                execute: async (id) => {
                    return await dataService.getOne(id);
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    return await dataService.query(e);
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'category',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'category',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        {
                            id: 'category',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'title', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

class AXMTextTemplateManagementCategoryEntityModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementCategoryEntityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementCategoryEntityModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementCategoryEntityModule, providers: [
            {
                provide: AXMTextTemplateManagementCategoryEntityService,
                useClass: AXMTextTemplateManagementCategoryEntityServiceImpl,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementCategoryEntityModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [],
                    exports: [],
                    declarations: [],
                    providers: [
                        {
                            provide: AXMTextTemplateManagementCategoryEntityService,
                            useClass: AXMTextTemplateManagementCategoryEntityServiceImpl,
                        },
                    ],
                }]
        }] });

class AXMTextTemplateManagementTemplateEntityService extends AXMEntityCrudServiceImpl {
}
class AXMTextTemplateManagementTemplateEntityServiceImpl extends AXMTextTemplateManagementTemplateEntityService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.template.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementTemplateEntityServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementTemplateEntityServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementTemplateEntityServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

async function templateFactory(injector) {
    const dataService = injector.get(AXMTextTemplateManagementTemplateEntityService);
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.template.name,
        title: RootConfig.entities.template.title,
        icon: RootConfig.entities.template.icon,
        formats: {
            individual: `t("template", { scope: "${i18n}" })`,
            plural: `t("templates", { scope: "${i18n}" })`,
        },
        relatedEntities: [],
        groups: [
            {
                id: 'template',
                title: '@text-template-management:template.title',
            },
        ],
        properties: [
            {
                name: 'name',
                title: '@general:terms.common.name',
                groupId: 'template',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'title',
                title: '@general:terms.common.title',
                groupId: 'template',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'content',
                title: `t("content", { scope: "${i18n}" })`,
                groupId: 'template',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.richText,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'categoryId',
                title: `t("categoryId", { scope: "${i18n}" })`,
                groupId: 'template',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.category.name}`,
                            expose: [
                                { source: 'id', target: 'categoryId' },
                                { source: 'title', target: 'category.title' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'type',
                title: `t("type", { scope: "${i18n}" })`,
                groupId: 'template',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            valueField: 'name',
                            textField: 'title',
                            dataSource: [
                                { title: 'Layout', name: 'layout' },
                                { title: 'Template', name: 'template' },
                            ],
                            direction: 'horizontal',
                            multiple: false,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
        ],
        columns: [
            { name: 'name' },
            { name: 'title' },
            { name: 'categoryId', options: { dataPath: 'category.title' } },
            { name: 'type' },
        ],
        commands: {
            create: {
                execute: async (data) => {
                    const res = await dataService.insertOne(data);
                    return { id: res };
                },
            },
            delete: {
                execute: async (id) => {
                    return await dataService.deleteOne(id);
                },
            },
            update: {
                execute: async (data) => {
                    return await dataService.updateOne(data.id, data);
                },
            },
        },
        queries: {
            byKey: {
                execute: async (id) => {
                    return new Promise((resolve) => {
                        setTimeout(async () => {
                            const entity = await dataService.getOne(id);
                            resolve(entity);
                        }, 500);
                    });
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    return await dataService.query(e);
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'template',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'content',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'categoryId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'type',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'tags',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'template',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'content',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'categoryId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'type',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'tags',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        {
                            id: 'template',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'content',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'type',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'categoryId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'tags',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView()],
                },
            },
        },
    };
    return entityDef;
}

class AXMTextTemplateManagementTemplateEntityModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementTemplateEntityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementTemplateEntityModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementTemplateEntityModule, providers: [
            {
                provide: AXMTextTemplateManagementTemplateEntityService,
                useClass: AXMTextTemplateManagementTemplateEntityServiceImpl,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementTemplateEntityModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [],
                    exports: [],
                    declarations: [],
                    providers: [
                        {
                            provide: AXMTextTemplateManagementTemplateEntityService,
                            useClass: AXMTextTemplateManagementTemplateEntityServiceImpl,
                        },
                    ],
                }]
        }] });

var index = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMTextTemplateManagementCategoryEntityModule: AXMTextTemplateManagementCategoryEntityModule,
    AXMTextTemplateManagementCategoryEntityService: AXMTextTemplateManagementCategoryEntityService,
    AXMTextTemplateManagementCategoryEntityServiceImpl: AXMTextTemplateManagementCategoryEntityServiceImpl,
    AXMTextTemplateManagementTemplateEntityModule: AXMTextTemplateManagementTemplateEntityModule,
    AXMTextTemplateManagementTemplateEntityService: AXMTextTemplateManagementTemplateEntityService,
    AXMTextTemplateManagementTemplateEntityServiceImpl: AXMTextTemplateManagementTemplateEntityServiceImpl,
    categoryFactory: categoryFactory,
    templateFactory: templateFactory
});

class AXMEntityProvider {
    constructor() {
        this.injector = inject(Injector);
    }
    preload() {
        const module = RootConfig.module.name;
        return Array.from(Object.values(RootConfig.entities)).map((entity) => ({
            module: module,
            entity: entity.name,
        }));
    }
    async get(moduleName, entityName) {
        if (moduleName == RootConfig.module.name) {
            switch (entityName) {
                case RootConfig.entities.template.name: {
                    const entity = (await Promise.resolve().then(function () { return index; })).templateFactory;
                    return entity(this.injector);
                }
                case RootConfig.entities.category.name: {
                    const entity = (await Promise.resolve().then(function () { return index; })).categoryFactory;
                    return entity(this.injector);
                }
            }
        }
        return null;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMEntityProvider, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMEntityProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMEntityProvider, decorators: [{
            type: Injectable
        }] });

class AXMMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const scope = RootConfig.config.i18n;
        const moduleName = RootConfig.module.name;
        context.addItems([
            {
                priority: 9001,
                text: `t('root-menu', {scope: "${scope}"})`,
                icon: RootConfig.module.icon,
                data: {
                // requiredPermission: 'demo.admin.settings',
                },
                children: [
                    {
                        text: `t('templates', {scope: "${scope}"})`,
                        path: this.entityService.createPath(moduleName, RootConfig.entities.template.name),
                        icon: RootConfig.entities.template.icon,
                        priority: 1,
                    },
                    {
                        text: `t('category', {scope: "${scope}"})`,
                        path: this.entityService.createPath(moduleName, RootConfig.entities.category.name),
                        icon: RootConfig.entities.category.icon,
                        priority: 2,
                    },
                ],
            },
        ]);
    }
}

class AXMTextTemplateManagementModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementModule, imports: [AXMTextTemplateManagementTemplateEntityModule, AXMTextTemplateManagementCategoryEntityModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementModule, providers: [
            {
                provide: AXP_MENU_PROVIDER,
                useClass: AXMMenuProvider,
                multi: true,
            },
            {
                provide: AXP_SETTING_DEFINITION_PROVIDER,
                useFactory: async () => {
                    const provider = (await import('./acorex-modules-text-template-management-settings.provider-fX0dhWUL.mjs')).AXMSettingProvider;
                    return new provider();
                },
                multi: true,
            },
            {
                provide: AXP_ENTITY_DEFINITION_LOADER,
                useClass: AXMEntityProvider,
                multi: true,
            },
        ], imports: [AXMTextTemplateManagementTemplateEntityModule, AXMTextTemplateManagementCategoryEntityModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMTextTemplateManagementModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [AXMTextTemplateManagementTemplateEntityModule, AXMTextTemplateManagementCategoryEntityModule],
                    exports: [],
                    declarations: [],
                    providers: [
                        {
                            provide: AXP_MENU_PROVIDER,
                            useClass: AXMMenuProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_SETTING_DEFINITION_PROVIDER,
                            useFactory: async () => {
                                const provider = (await import('./acorex-modules-text-template-management-settings.provider-fX0dhWUL.mjs')).AXMSettingProvider;
                                return new provider();
                            },
                            multi: true,
                        },
                        {
                            provide: AXP_ENTITY_DEFINITION_LOADER,
                            useClass: AXMEntityProvider,
                            multi: true,
                        },
                    ],
                }]
        }] });

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

export { AXMEntityProvider, AXMMenuProvider, AXMTextTemplateManagementCategoryEntityModule, AXMTextTemplateManagementCategoryEntityService, AXMTextTemplateManagementCategoryEntityServiceImpl, AXMTextTemplateManagementModule, AXMTextTemplateManagementTemplateEntityModule, AXMTextTemplateManagementTemplateEntityService, AXMTextTemplateManagementTemplateEntityServiceImpl, RootConfig, categoryFactory, templateFactory };
//# sourceMappingURL=acorex-modules-text-template-management.mjs.map
