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

async function factory() {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.employee.name,
        title: RootConfig.entities.employee.title,
        icon: 'fa-light fa-building',
        formats: {
            individual: RootConfig.entities.employee.title,
            plural: RootConfig.entities.employee.titlePlural,
            displayName: 'Employment Information',
            searchResult: { title: '{{ person.displayName }}', description: RootConfig.module.title },
        },
        plugins: [
            { name: 'identifier', options: { field: 'employeeCode', rule: 'employee-code' } },
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            {
                name: 'attachments',
                options: { field: 'imageId', accept: '.jpg,.jpeg,.png,.pdf', multiple: true, fileEditable: true },
            },
            { name: 'archive' },
            {
                name: 'computed-property',
                options: {
                    fields: [
                        {
                            name: 'manager',
                            title: '@human-capital-management:employees.entities.employee.fields.manager',
                            value: "{{ context.eval('manager') ? context.eval('manager.person.displayName') : '' }}",
                            group: { id: 'organizationalStructure' },
                            showAs: { type: AXPWidgetsCatalog.text },
                        },
                        {
                            name: 'activePosition',
                            title: '@human-capital-management:employees.entities.employee.fields.active-position',
                            value: '',
                            group: { id: 'organizationalStructure' },
                            showAs: { type: AXPWidgetsCatalog.text },
                        },
                        {
                            name: 'jobDefinitionId',
                            title: '@human-capital-management:employees.entities.employee.fields.job-definition',
                            value: "{{ context.eval('jobDefinition') ? context.eval('jobDefinition.title') : '' }}",
                            group: { id: 'organizationalStructure' },
                            showAs: { type: AXPWidgetsCatalog.text },
                        },
                    ],
                },
            },
        ],
        relatedEntities: [
            {
                entity: `PersonManagement.Person`,
                title: 'Personal Information',
                conditions: [{ name: 'id', operator: { type: 'equal' }, value: '{{ context.eval("personId") }}' }],
                layout: { type: 'merge-detail' },
                persistence: {
                    dataPath: 'person',
                    strategy: 'referenced',
                    idField: 'personId',
                },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.leaveRequest.name}`,
                title: RootConfig.entities.leaveRequest.titlePlural,
                columns: ['leaveTypeId', 'startDate', 'endDate', 'durationDays', 'status', 'reason'],
                conditions: [entityDetailsSimpleCondition('employeeId')],
                actions: [...entityDetailsCrudActions('employeeId')],
                layout: { type: 'page-list', position: 'after', order: 4 },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.positionAssignment.name}`,
                title: RootConfig.entities.positionAssignment.titlePlural,
                columns: ['positionId', 'businessUnitId', 'startDate', 'endDate', 'isPrimary'],
                conditions: [entityDetailsSimpleCondition('employeeId')],
                actions: [...entityDetailsCrudActions('employeeId')],
                layout: { type: 'page-list', position: 'after', order: 3 },
            },
            {
                entity: `SecurityManagement.User`,
                title: 'Security Information',
                icon: 'fa-light fa-lock',
                conditions: [{ name: 'id', operator: { type: 'equal' }, value: '{{ context.eval("userId") }}' }],
                layout: { type: 'page-detail', position: 'after', order: 1 },
                persistence: {
                    dataPath: 'user',
                    strategy: 'referenced',
                    idField: 'userId',
                    hydrate: 'eager',
                    map: {
                        displayName: '$parent.person.displayName',
                    },
                },
            },
        ],
        groups: [
            {
                id: 'organizationalStructure',
                title: '@human-capital-management:employees.entities.employee.groups.organizational-structure',
            },
            {
                id: 'employmentProfile',
                title: '@human-capital-management:employees.entities.employee.groups.employment-profile',
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'personalInformation',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'employeeCode',
                title: '@human-capital-management:employees.entities.employee.fields.employee-code',
                groupId: 'employmentProfile',
                schema: { dataType: 'string', interface: { type: AXPWidgetsCatalog.text } },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'employmentTypeId',
                title: '@human-capital-management:employees.entities.employee.fields.employment-type-id',
                groupId: 'employmentProfile',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.employmentType.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'employmentType.id' },
                                { source: 'title', target: 'employmentType.title' },
                            ],
                        },
                    },
                },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'hireDate',
                title: '@human-capital-management:employees.entities.employee.fields.hire-date',
                groupId: 'employmentProfile',
                schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'managerId',
                title: '@human-capital-management:employees.entities.employee.fields.manager-id',
                groupId: 'organizationalStructure',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.employee.name}`,
                            textField: 'person.displayName',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'manager.id' },
                                { source: 'person.displayName', target: 'manager.person.displayName' },
                            ],
                        },
                    },
                },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
            },
        ],
        columns: [
            {
                name: 'person.displayName',
                title: '@general:terms.common.display-name',
                showAs: { type: AXPWidgetsCatalog.text },
            },
            {
                name: 'person.primaryContact',
                title: '@general:terms.communication.email',
                options: { width: '350px' },
                showAs: { type: AXPWidgetsCatalog.contact, options: { type: 'email' } },
            },
            // { name: 'person.mobile', title: '@general:terms.communication.mobile', options: { width: '250px' }, showAs: { type: AXPWidgetsCatalog.contact, options: { type: 'phone' } } },
            { name: 'user.username', title: '@general:terms.contact.username', showAs: { type: AXPWidgetsCatalog.text } },
            { name: 'employeeCode' },
            { name: 'jobDefinitionId', options: { dataPath: 'jobDefinition.title' } },
            { name: 'employmentTypeId', options: { dataPath: 'employmentType.title' } },
            { name: 'hireDate' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'personalInformation' }, { id: 'organizationalStructure' }, { id: 'employmentProfile' }],
                    properties: [
                        { name: 'employeeCode', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'employmentTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'hireDate', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'personalInformation' }, { id: 'organizationalStructure' }, { id: 'employmentProfile' }],
                    properties: [
                        { name: 'employeeCode', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'employmentTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'hireDate', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                single: {
                    // title: '{{context.eval("employeeCode") + " - " + context.eval("person.displayName")}}',
                    title: '{{person.displayName}}',
                    sections: [
                        { id: 'personalInformation', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'employmentProfile', order: 3, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'organizationalStructure', order: 4, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'employeeCode', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'employmentTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'hireDate', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'person.displayName', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}

export { factory };
//# sourceMappingURL=acorex-modules-human-capital-management-employee.entity-Dcv5nfxA.mjs.map
