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

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function factory(injector) {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.learningPath.name,
        title: RootConfig.entities.learningPath.title,
        icon: RootConfig.entities.learningPath.icon,
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            { name: 'clone' },
            { name: 'tags' },
            { name: 'attachments' },
        ],
        formats: {
            individual: RootConfig.entities.learningPath.title,
            plural: RootConfig.entities.learningPath.titlePlural,
            searchResult: {
                title: '{{ name }}',
                description: '{{ isActive ? "@general:states.active" : "@general:states.inactive" }}',
            },
        },
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.learningPathCourse.name}`,
                title: RootConfig.entities.learningPathCourse.titlePlural,
                columns: ['orderIndex', 'courseId'],
                conditions: [
                    {
                        name: 'learningPathId',
                        operator: { type: 'equal' },
                        value: '{{ id }}',
                    },
                ],
            },
        ],
        groups: [
            { id: 'basic-info', title: '@learning-management:learning-paths.entities.learning-path.groups.basic-info' },
            { id: 'settings', title: '@learning-management:learning-paths.entities.learning-path.groups.settings' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'name',
                title: '@learning-management:learning-paths.entities.learning-path.fields.name.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: '@learning-management:learning-paths.entities.learning-path.fields.name.placeholder',
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'description',
                title: '@learning-management:learning-paths.entities.learning-path.fields.description.title',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 4,
                            placeholder: '@learning-management:learning-paths.entities.learning-path.fields.description.placeholder',
                        },
                    },
                },
            },
            {
                name: 'isActive',
                title: '@learning-management:learning-paths.entities.learning-path.fields.is-active.title',
                groupId: 'settings',
                schema: {
                    dataType: 'boolean',
                    defaultValue: true,
                    interface: {
                        type: AXPWidgetsList.Editors.ToggleSwitch,
                    },
                },
            },
        ],
        columns: [{ name: 'name' }, { name: 'isActive' }, { name: 'description' }],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'settings', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 8, order: 1 } } } },
                        { name: 'isActive', layout: { positions: { lg: { colSpan: 4, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'settings', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 8, order: 1 } } } },
                        { name: 'isActive', layout: { positions: { lg: { colSpan: 4, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                    ],
                },
                single: {
                    title: '{{ name }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'settings', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 8, order: 1 } } } },
                        { name: 'isActive', layout: { positions: { lg: { colSpan: 4, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'name', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { factory };
//# sourceMappingURL=acorex-modules-learning-management-learning-path.entity-8QlM3R4B.mjs.map
