import { AXPWidgetsList } from '@acorex/modules/common';
import { createAllQueryView, createQueryView, AXPEntityCommandScope } from '@acorex/platform/common';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { R as RootConfig } from './acorex-modules-assessment-management-acorex-modules-assessment-management-W8hHssaa.mjs';

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function factory(injector) {
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.questionnaire.name,
        title: RootConfig.entities.questionnaire.title,
        icon: RootConfig.entities.questionnaire.icon,
        plugins: [
            { name: 'history' },
            { name: 'audit-info' },
            { name: 'attachments' },
            { name: 'category' },
            { name: 'lock' },
            { name: 'archive' },
            { name: 'clone' },
        ],
        formats: {
            individual: RootConfig.entities.questionnaire.title,
            plural: RootConfig.entities.questionnaire.titlePlural,
            searchResult: {
                title: '{{ title }}',
                description: '{{ type }}',
            },
        },
        groups: [
            { id: 'basic-info', title: '@general:terms.interface.basic-info' },
            { id: 'structure', title: '@assessment-management:questionnaires.entities.questionnaire.groups.structure' },
            { id: 'pre-questionnaire', title: '@assessment-management:questionnaires.entities.questionnaire.groups.pre-questionnaire' },
            { id: 'post-questionnaire', title: '@assessment-management:questionnaires.entities.questionnaire.groups.post-questionnaire' },
            { id: 'scoring', title: '@assessment-management:questionnaires.entities.questionnaire.groups.scoring' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'title',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.title.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: 'Questionnaire title...' } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'type',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.type.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    defaultValue: 'questionnaire',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'id',
                            dataSource: [
                                {
                                    id: 'questionnaire',
                                    title: '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.questionnaire',
                                },
                                {
                                    id: 'survey',
                                    title: '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.survey',
                                },
                                {
                                    id: 'checklist',
                                    title: '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.checklist',
                                },
                                {
                                    id: 'test',
                                    title: '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.test',
                                },
                                {
                                    id: 'evaluation',
                                    title: '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.evaluation',
                                },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'description',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.description.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: true }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'string',
                    interface: { type: AXPWidgetsList.Editors.LargeTextBox, options: { rows: 3 } },
                },
            },
            // Pre-questionnaire: Welcome / intro screen before questions
            {
                name: 'preEnabled',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.pre-enabled.title',
                groupId: 'pre-questionnaire',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'boolean',
                    defaultValue: false,
                    interface: {
                        type: AXPWidgetsList.Editors.ToggleSwitch,
                        options: {
                            description: '@assessment-management:questionnaires.entities.questionnaire.fields.pre-enabled.description',
                        },
                    },
                },
            },
            {
                name: 'preContent',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.pre-content.title',
                groupId: 'pre-questionnaire',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.RichText,
                        options: {
                            multiLanguage: true,
                            placeholder: '@assessment-management:questionnaires.entities.questionnaire.fields.pre-content.placeholder',
                            visibility: `{{ context.eval('preEnabled') === true }}`,
                        },
                    },
                },
            },
            // Post-questionnaire: Review before submit, summary after submit
            {
                name: 'postReviewEnabled',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.post-review-enabled.title',
                groupId: 'post-questionnaire',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'boolean',
                    defaultValue: false,
                    interface: {
                        type: AXPWidgetsList.Editors.ToggleSwitch,
                        options: {
                            description: '@assessment-management:questionnaires.entities.questionnaire.fields.post-review-enabled.description',
                        },
                    },
                },
            },
            {
                name: 'postSummaryEnabled',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.post-summary-enabled.title',
                groupId: 'post-questionnaire',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'boolean',
                    defaultValue: false,
                    interface: {
                        type: AXPWidgetsList.Editors.ToggleSwitch,
                        options: {
                            description: '@assessment-management:questionnaires.entities.questionnaire.fields.post-summary-enabled.description',
                        },
                    },
                },
            },
            {
                name: 'postSummaryContent',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.post-summary-content.title',
                groupId: 'post-questionnaire',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.RichText,
                        options: {
                            multiLanguage: true,
                            placeholder: '@assessment-management:questionnaires.entities.questionnaire.fields.post-summary-content.placeholder',
                            visibility: `{{ context.eval('postSummaryEnabled') === true }}`,
                        },
                    },
                },
            },
            // STRUCTURE: Merged sections and items using questionnaire-builder widget
            {
                name: 'structure',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.structure.title',
                groupId: 'structure',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'object',
                    defaultValue: { sections: [] },
                    interface: {
                        type: 'questionnaire-builder-editor',
                    },
                },
            },
            // Scoring Configuration
            {
                name: 'scoringType',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.scoring-type.title',
                groupId: 'scoring',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    defaultValue: 'none',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'id',
                            dataSource: [
                                {
                                    id: 'none',
                                    title: '@assessment-management:questionnaires.entities.questionnaire.fields.scoring-type.options.none',
                                },
                                {
                                    id: 'cumulative',
                                    title: '@assessment-management:questionnaires.entities.questionnaire.fields.scoring-type.options.cumulative',
                                },
                                {
                                    id: 'weighted',
                                    title: '@assessment-management:questionnaires.entities.questionnaire.fields.scoring-type.options.weighted',
                                },
                                {
                                    id: 'formula',
                                    title: '@assessment-management:questionnaires.entities.questionnaire.fields.scoring-type.options.formula',
                                },
                            ],
                        },
                    },
                },
            },
            {
                name: 'passingScore',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.passing-score.title',
                groupId: 'scoring',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: {
                            minValue: 0,
                            maxValue: 100,
                            placeholder: 'Percentage (0-100)',
                            visibility: `{{ context.eval('scoringType') !== 'none' }}`,
                        },
                    },
                },
            },
            {
                name: 'scoringFormula',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.scoring-formula.title',
                groupId: 'scoring',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: '(section1 * 0.3) + (section2 * 0.7)',
                            visibility: `{{ context.eval('scoringType') === 'formula' }}`,
                        },
                    },
                },
            },
            {
                name: 'gradingScale',
                title: '@assessment-management:questionnaires.entities.questionnaire.fields.grading-scale.title',
                groupId: 'scoring',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 4,
                            placeholder: '{ "A": { "min": 90, "max": 100 }, "B": { "min": 80, "max": 89 } }',
                            visibility: `{{ context.eval('scoringType') !== 'none' }}`,
                        },
                    },
                },
            },
        ],
        columns: [{ name: 'title' }, { name: 'type' }, { name: 'scoringType' }],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'type', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'structure', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'pre-questionnaire', order: 3, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'post-questionnaire', order: 4, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'scoring', order: 5, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'type', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'structure', layout: { label: { visible: false }, positions: { lg: { colSpan: 12 } } } },
                        { name: 'preEnabled', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'preContent', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'postReviewEnabled', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'postSummaryEnabled', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'postSummaryContent', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'scoringType', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'passingScore', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'scoringFormula', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'gradingScale', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'structure', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'pre-questionnaire', order: 3, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'post-questionnaire', order: 4, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'scoring', order: 5, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'type', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'structure', layout: { label: { visible: false }, positions: { lg: { colSpan: 12 } } } },
                        { name: 'preEnabled', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'preContent', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'postReviewEnabled', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'postSummaryEnabled', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'postSummaryContent', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'scoringType', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'passingScore', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'scoringFormula', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'gradingScale', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    actions: [
                        ...entityMasterRecordActions(),
                        {
                            title: '@assessment-management:questionnaires.entities.questionnaire.actions.preview.title',
                            command: {
                                name: `${RootConfig.module.name}.${RootConfig.entities.questionnaire.name}:Preview`,
                                options: {
                                    questionnaireId: '{{ context.eval("id") }}',
                                    questionnaireTitle: '{{ context.eval("title") }}',
                                },
                            },
                            priority: 'primary',
                            type: 'action',
                            icon: 'fa-light fa-eye',
                            scope: AXPEntityCommandScope.Individual,
                        },
                    ],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions(),
                        {
                            title: '@assessment-management:questionnaires.entities.questionnaire.actions.preview.title',
                            command: {
                                name: `${RootConfig.module.name}.${RootConfig.entities.questionnaire.name}:Preview`,
                                options: {
                                    questionnaireId: '{{ context.eval("id") }}',
                                    questionnaireTitle: '{{ context.eval("title") }}',
                                },
                            },
                            priority: 'primary',
                            type: 'action',
                            icon: 'fa-light fa-eye',
                            scope: AXPEntityCommandScope.Individual,
                        },
                    ],
                    views: [
                        createAllQueryView({ sorts: [{ name: 'title', dir: 'asc' }] }),
                        createQueryView('questionnaire', '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.questionnaire', true, {
                            conditions: [{ name: 'type', operator: { type: 'equal' }, value: 'questionnaire' }],
                        }),
                        createQueryView('survey', '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.survey', true, {
                            conditions: [{ name: 'type', operator: { type: 'equal' }, value: 'survey' }],
                        }),
                        createQueryView('checklist', '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.checklist', true, {
                            conditions: [{ name: 'type', operator: { type: 'equal' }, value: 'checklist' }],
                        }),
                        createQueryView('test', '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.test', true, {
                            conditions: [{ name: 'type', operator: { type: 'equal' }, value: 'test' }],
                        }),
                        createQueryView('evaluation', '@assessment-management:questionnaires.entities.questionnaire.fields.type.options.evaluation', true, {
                            conditions: [{ name: 'type', operator: { type: 'equal' }, value: 'evaluation' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { factory };
//# sourceMappingURL=acorex-modules-assessment-management-questionnaire.entity-B8eP0kxN.mjs.map
