import * as i1 from '@acorex/components/button';
import { AXButtonModule } from '@acorex/components/button';
import { AXDecoratorModule } from '@acorex/components/decorators';
import * as i4 from '@acorex/core/translation';
import { AXTranslationModule } from '@acorex/core/translation';
import { AXPColumnWidgetComponent } from '@acorex/platform/layout/widget-core';
import { AXPCommandService } from '@acorex/platform/runtime';
import { AsyncPipe } from '@angular/common';
import * as i0 from '@angular/core';
import { inject, signal, computed, Input, 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 AXMAnswersViewerWidgetColumnComponent extends AXPColumnWidgetComponent {
    constructor() {
        super(...arguments);
        //#region ----   Services & Dependencies   ----
        this.commandService = inject(AXPCommandService);
        //#endregion
        //#region ----   Inputs   ----
        this.rawValueSignal = signal(null, ...(ngDevMode ? [{ debugName: "rawValueSignal" }] : []));
        this.rowDataSignal = signal(null, ...(ngDevMode ? [{ debugName: "rowDataSignal" }] : []));
        //#endregion
        //#region ----   Computed Properties   ----
        this.hasAnswers = computed(() => {
            const answers = this.rawValueSignal();
            return Boolean(answers && typeof answers === 'object' && Object.keys(answers).length > 0);
        }, ...(ngDevMode ? [{ debugName: "hasAnswers" }] : []));
        this.disabled = computed(() => {
            return Boolean(this.options['disabled'] ?? false);
        }, ...(ngDevMode ? [{ debugName: "disabled" }] : []));
        this.buttonText = computed(() => {
            return this.hasAnswers()
                ? '@assessment-management:sessions.entities.assessment-session.fields.answers.states.answered'
                : '@assessment-management:sessions.entities.assessment-session.fields.answers.states.not-answered';
        }, ...(ngDevMode ? [{ debugName: "buttonText" }] : []));
    }
    set rawValueInput(value) {
        this.rawValueSignal.set(value);
    }
    set rowDataInput(value) {
        this.rowDataSignal.set(value);
    }
    //#endregion
    //#region ----   Event Handlers   ----
    async handleViewClick() {
        const rowData = this.rowDataSignal();
        if (!rowData || !rowData.id) {
            return;
        }
        const sessionId = rowData.id;
        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: AXMAnswersViewerWidgetColumnComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: AXMAnswersViewerWidgetColumnComponent, isStandalone: true, selector: "axm-answers-viewer-widget-column", inputs: { rawValue: "rawValue", rowData: "rowData", rawValueInput: ["rawValue", "rawValueInput"], rowDataInput: ["rowData", "rowDataInput"] }, usesInheritance: true, ngImport: i0, template: `
        @if (hasAnswers()) {
            <div class="ax-xs">
                <ax-button
                    [disabled]="disabled()"
                    color="success"
                    look="twotone"
                    [text]="buttonText()"
                    (onClick)="handleViewClick()"
                >
                </ax-button>
            </div>
        } @else {
            <span class="ax-text-danger">{{ buttonText() | translate | async }}</span>
        }
    `, isInline: true, dependencies: [{ kind: "ngmodule", type: AXButtonModule }, { kind: "component", type: i1.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: "ngmodule", type: AXTranslationModule }, { kind: "pipe", type: i4.AXTranslatorPipe, name: "translate" }, { kind: "pipe", type: AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMAnswersViewerWidgetColumnComponent, decorators: [{
            type: Component,
            args: [{
                    selector: 'axm-answers-viewer-widget-column',
                    template: `
        @if (hasAnswers()) {
            <div class="ax-xs">
                <ax-button
                    [disabled]="disabled()"
                    color="success"
                    look="twotone"
                    [text]="buttonText()"
                    (onClick)="handleViewClick()"
                >
                </ax-button>
            </div>
        } @else {
            <span class="ax-text-danger">{{ buttonText() | translate | async }}</span>
        }
    `,
                    changeDetection: ChangeDetectionStrategy.OnPush,
                    imports: [AXButtonModule, AXDecoratorModule, AXTranslationModule, AsyncPipe],
                    inputs: ['rawValue', 'rowData'],
                }]
        }], propDecorators: { rawValueInput: [{
                type: Input,
                args: ['rawValue']
            }], rowDataInput: [{
                type: Input,
                args: ['rowData']
            }] } });

export { AXMAnswersViewerWidgetColumnComponent };
//# sourceMappingURL=acorex-modules-assessment-management-answers-viewer-widget-column.component-C9occE-a.mjs.map
