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

async function factory(injector) {
    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' },
        ],
        module: RootConfig.module.name,
        name: RootConfig.entities.template.name,
        title: RootConfig.entities.template.title,
        icon: RootConfig.entities.template.icon,
        formats: {
            individual: '@form-template-management:templates.entities.template.title',
            plural: '@form-template-management:templates.terms.templates',
            displayName: '@form-template-management:templates.entities.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.terms.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}:templates.entities.template.fields.template.title`,
                groupId: 'template-content',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Templates.Designer,
                    },
                },
            },
        ],
        columns: [
            { name: 'code' },
            { name: 'title' },
            { name: 'type' },
        ],
        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}:templates.menus.forms.title`, true, {
                            conditions: [
                                {
                                    name: 'type.id',
                                    operator: {
                                        type: 'equal',
                                    },
                                    value: 10,
                                    visible: false,
                                },
                            ],
                        }),
                        createQueryView('widgets', `@${i18n}:templates.menus.widgets.title`, true, {
                            conditions: [
                                {
                                    name: 'type.id',
                                    operator: {
                                        type: 'equal',
                                    },
                                    value: 20,
                                    visible: false,
                                },
                            ],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

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