import { createAllQueryView, createQueryView, AXPEntityCommandScope, AXPEntityQueryType } from '@acorex/platform/common';
import { AXPWidgetsList } from '@acorex/modules/common';
import { a as AXMFormTemplateManagementTemplateEntityService, R as RootConfig, b as AXMFormTemplateTypes } from './acorex-modules-form-template-management-acorex-modules-form-template-management-DCKQMU5_.mjs';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';

async function factory(injector) {
    const dataService = injector.get(AXMFormTemplateManagementTemplateEntityService);
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        plugins: [
            { name: 'identifier', options: { field: 'code', rule: 'form-template' } },
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            // { name: 'comments' },
            { name: 'category' },
            { name: 'clone' },
            { name: 'archive' },
            { name: 'extra-properties' },
        ],
        module: RootConfig.module.name,
        name: RootConfig.entities.template.name,
        title: RootConfig.entities.template.title,
        icon: RootConfig.entities.template.icon,
        formats: {
            individual: '@form-template-management:template.title',
            plural: '@form-template-management:templates',
            displayName: '@form-template-management:template.title',
            searchResult: {
                title: '{{ title }}',
                description: RootConfig.module.title,
            },
        },
        relatedEntities: [],
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
            {
                id: 'template-content',
                title: `@${i18n}:designer`,
            },
        ],
        properties: [
            {
                name: 'code',
                title: `@general:terms.common.code`,
                groupId: 'basic-info',
                options: {
                    filter: {
                        inline: { enabled: true },
                        advance: { enabled: true }
                    },
                    sort: {
                        enabled: true,
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'title',
                title: '@general:terms.common.title',
                groupId: 'basic-info',
                options: {
                    filter: {
                        inline: { enabled: true },
                        advance: { enabled: true }
                    },
                    sort: {
                        enabled: true,
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                    {
                        rule: 'minLength',
                        options: {
                            value: 3,
                        },
                    },
                    {
                        rule: 'maxLength',
                        options: {
                            value: 50,
                        },
                    },
                ],
            },
            {
                name: 'type',
                title: '@general:terms.common.type',
                groupId: 'basic-info',
                options: {
                    filter: {
                        inline: { enabled: true },
                        advance: { enabled: true }
                    },
                    sort: {
                        enabled: true,
                    },
                },
                schema: {
                    dataType: 'string',
                    defaultValue: AXMFormTemplateTypes.Form,
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'id',
                            textField: 'title',
                            dataSource: [AXMFormTemplateTypes.Form, AXMFormTemplateTypes.Widget],
                            multiple: false,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'template',
                title: `@${i18n}:edit-template`,
                groupId: 'template-content',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Templates.Designer,
                    },
                },
            },
        ],
        columns: [
            { name: 'code' },
            { name: '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 await dataService.getOne(id);
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    console.log('e: ', e);
                    const res = await dataService.query(e);
                    console.log('res: ', res);
                    return res;
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'template-content',
                        },
                    ],
                    properties: [
                        {
                            name: 'code',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'type',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'template',
                            layout: {
                                label: {
                                    visible: false,
                                },
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 4,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'template-content',
                        },
                    ],
                    properties: [
                        {
                            name: 'code',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'type',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'template',
                            layout: {
                                label: {
                                    visible: false,
                                },
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 4,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        {
                            id: 'basic-info',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            id: 'template-content',
                            layout: {
                                label: {
                                    visible: false,
                                },
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'code',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'type',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'template',
                            layout: {
                                label: {
                                    visible: false,
                                },
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 4,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [
                        ...entityMasterRecordActions()
                    ],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions(),
                        {
                            title: '@general:actions.configuration.design.title',
                            command: 'design-form-template',
                            priority: 'primary',
                            type: 'design',
                            scope: AXPEntityCommandScope.Individual,
                        },
                        {
                            title: '@general:actions.utility.open.title',
                            command: {
                                name: 'open-form-template',
                                metadata: {
                                    preview: true,
                                },
                            },
                            priority: 'primary',
                            type: 'view',
                            scope: AXPEntityCommandScope.Individual,
                        },
                    ],
                    views: [
                        createAllQueryView({ sorts: [{ name: 'title', dir: 'asc' }] }),
                        createQueryView('forms', `@${i18n}:forms`, true, {
                            conditions: [
                                {
                                    name: 'type.id',
                                    operator: {
                                        type: 'equal',
                                    },
                                    value: 10,
                                    hidden: true,
                                },
                            ],
                        }),
                        createQueryView('widgets', `@${i18n}:widgets`, true, {
                            conditions: [
                                {
                                    name: 'type.id',
                                    operator: {
                                        type: 'equal',
                                    },
                                    value: 20,
                                    hidden: true,
                                },
                            ],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

export { factory };
//# sourceMappingURL=acorex-modules-form-template-management-template.entity-CqEvewsA.mjs.map
