import { createAllQueryView, AXPEntityCommandScope } from '@acorex/platform/common';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { RootConfig } from './acorex-modules-human-capital-management.mjs';

//#region ----   Imports   ----
//#endregion
async function factory() {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.leaveRequest.name,
        title: RootConfig.entities.leaveRequest.title,
        icon: RootConfig.entities.leaveRequest.icon,
        plugins: [
            { name: 'history' },
            { name: 'attachments' },
            { name: 'workflow' },
            {
                name: 'status',
                options: {
                    field: 'statusId',
                    definition: 'human-capital-management.status.leave-request',
                },
            },
            {
                name: 'meta-data-form', options: {
                    path: 'leaveTypeId',
                    display: 'popup',
                    // display: {
                    //   // section: {
                    //   //   title: 'Sample Form'
                    //   // },
                    //   popup: {
                    //     enabled: true,
                    //     title: "Sample Form"
                    //   }
                    // }
                }
            },
        ],
        formats: {
            individual: RootConfig.entities.leaveRequest.title,
            plural: RootConfig.entities.leaveRequest.titlePlural,
            searchResult: { title: '{{ employee.person.displayName }}', description: RootConfig.module.title },
        },
        groups: [
            { id: 'basic-info', title: '@human-capital-management:leave-requests.entities.leave-request.groups.basic-info' },
            { id: 'period', title: '@general:terms.datetime.period' },
            { id: 'additional', title: '@general:terms.interface.additional-info' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'employeeId',
                title: '@general:terms.people.employee',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.employee.name}`,
                            textField: 'person.displayName',
                            valueField: 'id',
                            look: 'select',
                            columns: ['person.displayName', 'employeeCode'],
                            expose: [
                                { source: 'id', target: 'employee.id' },
                                { source: 'person.displayName', target: 'employee.person.displayName' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'leaveTypeId',
                title: '@human-capital-management:leave-requests.entities.leave-request.fields.leave-type-id',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.leaveType.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            columns: ['title'],
                            expose: [
                                { source: 'id', target: 'leaveType.id' },
                                { source: 'title', target: 'leaveType.title' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'startDate',
                title: '@general:terms.datetime.start-date',
                groupId: 'period',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'endDate',
                title: '@general:terms.datetime.end-date',
                groupId: 'period',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'durationDays',
                title: '@human-capital-management:leave-requests.entities.leave-request.fields.duration-days',
                groupId: 'period',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: { dataType: 'number', interface: { type: AXPWidgetsCatalog.number } },
            },
            {
                name: 'reason',
                title: '@human-capital-management:leave-requests.entities.leave-request.fields.reason',
                groupId: 'additional',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: true }, inline: { enabled: false } },
                },
                schema: { dataType: 'string', interface: { type: AXPWidgetsCatalog.largeText } },
            },
        ],
        columns: [
            { name: 'employeeId', options: { dataPath: 'employee.person.displayName' } },
            { name: 'leaveTypeId', options: { dataPath: 'leaveType.title' } },
            { name: 'startDate' },
            { name: 'endDate' },
            { name: 'durationDays' },
            { name: 'statusId' },
            { name: 'reason' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info' }, { id: 'period' }, { id: 'additional' }],
                    properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'leaveTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'durationDays', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'reason', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' }, { id: 'period' }, { id: 'additional' }],
                    properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'leaveTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'durationDays', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'reason', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                single: {
                    title: '{{employee.person.displayName}}',
                    sections: [
                        { id: 'basic-info', order: 1 },
                        { id: 'period', order: 2 },
                        { id: 'additional', order: 3 },
                    ],
                    properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'leaveTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'durationDays', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'reason', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    actions: entityMasterRecordActions(),
                },
                list: {
                    actions: [
                        // Override create action to use workflow instead of default Entity:Create
                        {
                            title: '@general:actions.create.title',
                            command: {
                                name: 'WorkflowManagement.WorkflowDefinition:Execute',
                                options: {
                                    workflowId: 'createLeaveRequest',
                                    input: {},
                                },
                            },
                            priority: 'primary',
                            type: 'create',
                            scope: AXPEntityCommandScope.TypeLevel,
                        },
                        // Keep other default actions (delete, view)
                        ...entityMasterCrudActions({ create: false }),
                    ],
                    views: [createAllQueryView({ sorts: [{ name: 'startDate', dir: 'desc' }] })],
                },
            },
        },
    };
    return entityDef;
}

export { factory };
//# sourceMappingURL=acorex-modules-human-capital-management-leave-request.entity-CS3Fr_k2.mjs.map
