import { AXTranslationService } from '@acorex/core/translation';
import * as i0 from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { A as AXMQuestionnaireViewerService } from './acorex-modules-assessment-management-questionnaire-viewer.service-BwxkdgXr.mjs';
import { a as AXMAssessmentSessionService, b as AXMAssessmentCaseService, A as AXMQuestionnaireService } from './acorex-modules-assessment-management-acorex-modules-assessment-management-W8hHssaa.mjs';

//#endregion
//#region ----   View Session Answers Command   ----
/**
 * Command that opens a readonly view of assessment session answers in a dialog.
 */
class ViewSessionAnswersCommand {
    constructor() {
        //#region ----   Services & Dependencies   ----
        this.sessionService = inject(AXMAssessmentSessionService);
        this.caseService = inject(AXMAssessmentCaseService);
        this.questionnaireService = inject(AXMQuestionnaireService);
        this.questionnaireViewerService = inject(AXMQuestionnaireViewerService);
        this.translationService = inject(AXTranslationService);
    }
    //#endregion
    //#region ----   Command Implementation   ----
    async execute(input) {
        try {
            // Get session data
            const session = await this.sessionService.getOne(input.sessionId);
            if (!session) {
                return {
                    success: false,
                    message: {
                        text: `Assessment session with ID ${input.sessionId} not found`,
                    },
                };
            }
            // Get case data
            const assessmentCase = await this.caseService.getOne(session.caseId);
            if (!assessmentCase) {
                return {
                    success: false,
                    message: {
                        text: `Assessment case with ID ${session.caseId} not found`,
                    },
                };
            }
            // Get questionnaire data
            const questionnaire = await this.questionnaireService.getOne(assessmentCase.questionnaireId);
            if (!questionnaire) {
                return {
                    success: false,
                    message: {
                        text: `Questionnaire with ID ${assessmentCase.questionnaireId} not found`,
                    },
                };
            }
            // Check if questionnaire has structure
            if (!questionnaire.structure || !questionnaire.structure.sections || questionnaire.structure.sections.length === 0) {
                return {
                    success: false,
                    message: {
                        text: 'Questionnaire has no structure to display',
                    },
                };
            }
            // Get view title - translate the base title and append responder name
            const viewTitleKey = '@assessment-management:sessions.actions.view-answers.title';
            const viewTitleBase = await this.translationService.translateAsync(viewTitleKey);
            const responderName = session.responder?.displayName || session.responderId;
            const viewTitle = viewTitleBase && responderName
                ? `${viewTitleBase}: ${responderName}`
                : viewTitleBase || 'View Answers';
            // Open questionnaire viewer with answers in readonly mode
            await this.questionnaireViewerService.open({
                title: viewTitle,
                structure: questionnaire.structure,
                size: 'lg',
                config: {
                    readonly: true, // Readonly mode - answers cannot be edited
                },
                initialAnswers: session.answers || {}, // Pre-fill with session answers
            });
            return {
                success: true,
            };
        }
        catch (error) {
            return {
                success: false,
                message: {
                    text: `Error viewing session answers: ${error.message || 'Unknown error'}`,
                },
            };
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: ViewSessionAnswersCommand, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: ViewSessionAnswersCommand }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: ViewSessionAnswersCommand, decorators: [{
            type: Injectable
        }] });

export { ViewSessionAnswersCommand };
//# sourceMappingURL=acorex-modules-assessment-management-view-session-answers.command-CwR0yKS8.mjs.map
