import * as i0 from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { AXMProjectManagementJsaService } from './acorex-modules-project-management.mjs';
import { AXPLayoutBuilderService } from '@acorex/platform/layout/builder';
import { AXTranslationService } from '@acorex/core/translation';
import { AXPWidgetsList } from '@acorex/modules/common';

class AXPSignJsaCommand {
    constructor() {
        //#region ----   Services & Dependencies   ----
        this.jsaService = inject(AXMProjectManagementJsaService);
        this.layoutBuilder = inject(AXPLayoutBuilderService);
        this.translationService = inject(AXTranslationService);
    }
    //#endregion
    //#region ----   Command Execution   ----
    async execute(input) {
        // Show dialog to collect signature data
        const dialogResult = await this.showSignDialog();
        if (dialogResult.cancelled) {
            return { success: false };
        }
        // Update JSA with signature data
        await this.jsaService.updateOne(input.id, {
            status: 'Signed',
            // Add signature fields when they exist in the entity
            // signatureNote: dialogResult.note,
            // signature: dialogResult.signature,
            // signedAt: new Date().toISOString(),
        });
        return { success: true };
    }
    //#endregion
    //#region ----   Dialog Logic   ----
    async showSignDialog() {
        const dialogRef = await this.layoutBuilder
            .create()
            .dialog(dialog => {
            dialog
                .setTitle('@project-management:jsa.sign-dialog.title')
                .setMessage('@project-management:jsa.sign-dialog.message')
                .setContext({ note: '', signature: '' })
                .content(flex => {
                flex
                    .setDirection('column')
                    .formField('@project-management:jsa.sign-dialog.note-label', field => {
                    field.path('note');
                    field.largeTextBox({
                        placeholder: '@project-management:jsa.sign-dialog.note-placeholder',
                        maxLength: 1000
                    });
                })
                    .formField('@project-management:jsa.sign-dialog.signature-label', field => {
                    field.path('signature');
                    field.customWidget(AXPWidgetsList.Editors.SignatureBox, {
                        validations: [{ rule: 'required', options: { message: 'Please sign the JSA' } }]
                    });
                });
            })
                .setActions(actions => {
                actions.cancel('@general:actions.cancel.title').submit('@project-management:jsa.sign-dialog.submit-text');
            });
        })
            .show();
        const formData = dialogRef.context();
        const action = dialogRef.action();
        dialogRef.close();
        return {
            note: formData['note'],
            signature: formData['signature'],
            cancelled: action === 'cancel'
        };
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPSignJsaCommand, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPSignJsaCommand, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPSignJsaCommand, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

export { AXPSignJsaCommand };
//# sourceMappingURL=acorex-modules-project-management-sign-jsa.command-DX_d7bYE.mjs.map
