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.attendance.name,
        title: RootConfig.entities.attendance.title,
        icon: RootConfig.entities.attendance.icon,
        plugins: [{ name: 'history' }, { name: 'lock' }, { name: 'compare' }],
        formats: {
            individual: RootConfig.entities.attendance.title,
            plural: RootConfig.entities.attendance.titlePlural,
            searchResult: {
                title: '{{ sessionDate | date:"mediumDate" }}',
                description: '{{ status }}',
            },
        },
        groups: [{ id: 'basic-info', title: '@learning-management:enrollments.entities.attendance.groups.basic-info' }],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'enrollmentId',
                title: '@learning-management:enrollments.entities.attendance.fields.enrollment-id.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.enrollment.name}`,
                            expose: [
                                { source: 'id', target: 'enrollment.id' },
                                { source: 'employeeId', target: 'enrollment.employeeId' },
                                { source: 'training.title', target: 'enrollment.trainingTitle' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'sessionDate',
                title: '@learning-management:enrollments.entities.attendance.fields.session-date.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsList.Editors.DateTimeBox,
                        options: {
                            displayFormat: 'date',
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'status',
                title: '@learning-management:enrollments.entities.attendance.fields.status.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    defaultValue: 'Present',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'id',
                            dataSource: [
                                {
                                    id: 'Present',
                                    title: '@learning-management:enrollments.entities.attendance.fields.status.options.present',
                                },
                                {
                                    id: 'Absent',
                                    title: '@learning-management:enrollments.entities.attendance.fields.status.options.absent',
                                },
                                {
                                    id: 'Late',
                                    title: '@learning-management:enrollments.entities.attendance.fields.status.options.late',
                                },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'notes',
                title: '@learning-management:enrollments.entities.attendance.fields.notes.title',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 3,
                            placeholder: '@learning-management:enrollments.entities.attendance.fields.notes.placeholder',
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'sessionDate' },
            { name: 'status' },
            { name: 'enrollmentId', options: { dataPath: 'enrollment.employeeId' } },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } }],
                    properties: [
                        { name: 'enrollmentId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'sessionDate', layout: { positions: { lg: { colSpan: 4, order: 2 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } }],
                    properties: [
                        { name: 'enrollmentId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'sessionDate', layout: { positions: { lg: { colSpan: 4, order: 2 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                    ],
                },
                single: {
                    title: '{{ sessionDate | date:"mediumDate" }}',
                    sections: [{ id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } }],
                    properties: [
                        { name: 'enrollmentId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'sessionDate', layout: { positions: { lg: { colSpan: 4, order: 2 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'sessionDate', dir: 'desc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { factory };
//# sourceMappingURL=acorex-modules-learning-management-attendance.entity-BXm8I4nQ.mjs.map
