import * as i1 from '@acorex/components/badge';
import { AXBadgeModule } from '@acorex/components/badge';
import * as i1$1 from '@acorex/components/button';
import { AXButtonModule } from '@acorex/components/button';
import * as i2 from '@acorex/components/decorators';
import { AXDecoratorModule } from '@acorex/components/decorators';
import { AXTranslationModule } from '@acorex/core/translation';
import { AXPLayoutBaseWidgetComponent } from '@acorex/platform/layout/widget-core';
import { AXPCommandService } from '@acorex/platform/runtime';
import * as i0 from '@angular/core';
import { inject, computed, ChangeDetectionStrategy, Component } from '@angular/core';
import { R as RootConfig } from './acorex-modules-assessment-management-acorex-modules-assessment-management-W8hHssaa.mjs';

//#region ----   Imports   ----
//#endregion
//#region ----   Component   ----
class AXMAnswersViewerWidgetViewComponent extends AXPLayoutBaseWidgetComponent {
    constructor() {
        super(...arguments);
        //#region ----   Services & Dependencies   ----
        this.commandService = inject(AXPCommandService);
        //#endregion
        //#region ----   Computed Properties   ----
        this.hasAnswers = computed(() => {
            const path = this.node.path;
            if (!path)
                return false;
            const answers = this.contextService.getValue(path);
            return answers && typeof answers === 'object' && Object.keys(answers).length > 0;
        }, ...(ngDevMode ? [{ debugName: "hasAnswers" }] : []));
        this.disabled = computed(() => {
            return this.options()['disabled'] ?? false;
        }, ...(ngDevMode ? [{ debugName: "disabled" }] : []));
        this.answeredText = computed(() => {
            return '@assessment-management:sessions.entities.assessment-session.fields.answers.states.answered';
        }, ...(ngDevMode ? [{ debugName: "answeredText" }] : []));
        this.notAnsweredText = computed(() => {
            return '@assessment-management:sessions.entities.assessment-session.fields.answers.states.not-answered';
        }, ...(ngDevMode ? [{ debugName: "notAnsweredText" }] : []));
        this.viewText = computed(() => {
            return '@assessment-management:sessions.actions.view-answers.title';
        }, ...(ngDevMode ? [{ debugName: "viewText" }] : []));
    }
    //#endregion
    //#region ----   Event Handlers   ----
    async handleViewClick() {
        // Get session ID from context - it should be in the parent context
        const context = this.contextService.data();
        const sessionId = context?.id || context?.sessionId;
        if (!sessionId) {
            console.error('[AnswersViewerWidget] Session ID not found in context');
            return;
        }
        const commandKey = `${RootConfig.module.name}.${RootConfig.entities.assessmentSession.name}:ViewAnswers`;
        try {
            await this.commandService.execute(commandKey, { sessionId });
        }
        catch (error) {
            console.error('[AnswersViewerWidget] Error executing view command:', error);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMAnswersViewerWidgetViewComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: AXMAnswersViewerWidgetViewComponent, isStandalone: true, selector: "axm-answers-viewer-widget-view", usesInheritance: true, ngImport: i0, template: `
        <div class="ax-flex ax-items-center ax-gap-2">
            @if (hasAnswers()) {
                <ax-badge [color]="'success'" [look]="'twotone'" [text]="answeredText()"></ax-badge>
            } @else {
                <ax-badge [color]="'danger'" [look]="'twotone'" [text]="notAnsweredText()"></ax-badge>
            }
            <ax-button
                [disabled]="disabled()"
                [color]="hasAnswers() ? 'primary' : 'default'"
                look="solid"
                [text]="viewText()"
                (onClick)="handleViewClick()"
            >
                <ax-prefix>
                    <i class="fa-light fa-eye"></i>
                </ax-prefix>
            </ax-button>
        </div>
    `, isInline: true, dependencies: [{ kind: "ngmodule", type: AXBadgeModule }, { kind: "component", type: i1.AXBadgeComponent, selector: "ax-badge", inputs: ["color", "look", "text"] }, { kind: "ngmodule", type: AXButtonModule }, { kind: "component", type: i1$1.AXButtonComponent, selector: "ax-button", inputs: ["disabled", "size", "tabIndex", "color", "look", "text", "toggleable", "selected", "iconOnly", "type", "loadingText"], outputs: ["onBlur", "onFocus", "onClick", "selectedChange", "toggleableChange", "lookChange", "colorChange", "disabledChange", "loadingTextChange"] }, { kind: "ngmodule", type: AXDecoratorModule }, { kind: "component", type: i2.AXDecoratorGenericComponent, selector: "ax-footer, ax-header, ax-content, ax-divider, ax-form-hint, ax-prefix, ax-suffix, ax-text, ax-title, ax-subtitle, ax-placeholder, ax-overlay" }, { kind: "ngmodule", type: AXTranslationModule }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMAnswersViewerWidgetViewComponent, decorators: [{
            type: Component,
            args: [{
                    selector: 'axm-answers-viewer-widget-view',
                    template: `
        <div class="ax-flex ax-items-center ax-gap-2">
            @if (hasAnswers()) {
                <ax-badge [color]="'success'" [look]="'twotone'" [text]="answeredText()"></ax-badge>
            } @else {
                <ax-badge [color]="'danger'" [look]="'twotone'" [text]="notAnsweredText()"></ax-badge>
            }
            <ax-button
                [disabled]="disabled()"
                [color]="hasAnswers() ? 'primary' : 'default'"
                look="solid"
                [text]="viewText()"
                (onClick)="handleViewClick()"
            >
                <ax-prefix>
                    <i class="fa-light fa-eye"></i>
                </ax-prefix>
            </ax-button>
        </div>
    `,
                    changeDetection: ChangeDetectionStrategy.OnPush,
                    imports: [AXBadgeModule, AXButtonModule, AXDecoratorModule, AXTranslationModule],
                }]
        }] });

export { AXMAnswersViewerWidgetViewComponent };
//# sourceMappingURL=acorex-modules-assessment-management-answers-viewer-widget-view.component-Dx1v9ySF.mjs.map
