import * as i2 from '@acorex/components/button';
import { AXButtonModule } from '@acorex/components/button';
import * as i1$1 from '@acorex/components/decorators';
import { AXDecoratorModule } from '@acorex/components/decorators';
import * as i3 from '@acorex/components/form';
import { AXFormModule } from '@acorex/components/form';
import { AXBasePageComponent } from '@acorex/components/page';
import * as i3$1 from '@acorex/core/translation';
import { AXTranslationModule } from '@acorex/core/translation';
import { AXPFileStorageService } from '@acorex/platform/common';
import * as i1 from '@acorex/platform/layout/widget-core';
import { AXPWidgetCoreModule } from '@acorex/platform/layout/widget-core';
import * as i1$2 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { signal, inject, Component } from '@angular/core';
import { c as AXMDistributionInteractionService } from './acorex-modules-document-management-acorex-modules-document-management-BsfSETMk.mjs';

class AXMDocumentSignaturePopupComponent extends AXBasePageComponent {
    constructor() {
        super(...arguments);
        this.context = signal({}, ...(ngDevMode ? [{ debugName: "context" }] : []));
        this.signatureInstructions = 'document-signature.instructions';
        this.fileService = inject(AXPFileStorageService);
        this.documentInteractionService = inject(AXMDistributionInteractionService);
        this.fileView = {
            name: 'fileView',
            path: 'fileView',
            type: 'file-uploader',
            options: {
                readonly: true,
            },
        };
        this.signatureNode = {
            name: 'signature',
            path: 'signature',
            type: 'signature',
            options: {
                placeholder: 'Please sign here',
            },
        };
    }
    ngOnInit() {
        this.isLoading = true;
        this.fileService.getInfo(this.removeFilePrefix(this.fileId)).then(x => {
            this.context.set({
                fileView: [x],
            });
            this.isLoading = false;
        });
        //save interaction
        this.documentInteractionService.insertOne({
            documentDistributionId: this.documentId,
            action: 'Viewed',
            actionTime: new Date(),
        });
    }
    removeFilePrefix(fileId) {
        return fileId.startsWith('file:') ? fileId.substring(5) : fileId;
    }
    handleContextChanged($event) {
        this.context.set($event.data);
    }
    async handleSubmit(form) {
        const validation = await form.validate();
        if (validation.result && this.context()?.signature) {
            this.isLoading = true;
            await this.documentInteractionService.insertOne({
                documentDistributionId: this.documentId,
                action: 'Signed',
                actionTime: new Date(),
                signatureData: this.context()?.signature,
            });
            this.isLoading = false;
            this.close({
                signature: this.context()?.signature,
                confirmed: true,
            });
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMDocumentSignaturePopupComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.4", type: AXMDocumentSignaturePopupComponent, isStandalone: true, selector: "ng-component", usesInheritance: true, ngImport: i0, template: `
    <div class="ax-p-4 ax-min-h-64">
      <ax-form #form>
        <axp-widgets-container [context]="context()" (onContextChanged)="handleContextChanged($event)">
          <div class="ax-flex ax-flex-col ax-gap-4">
            <ng-container axp-widget-renderer [node]="fileView" [mode]="'view'"></ng-container>
            <ng-container axp-widget-renderer [node]="signatureNode" [mode]="'edit'"></ng-container>
            <div class="ax-text-sm ax-text-gray-600">
              {{ signatureInstructions | translate : { scope: 'document-management' } | async }}
            </div>
          </div>
        </axp-widgets-container>
      </ax-form>
    </div>
    <ax-footer *translate="let t">
      <ax-suffix>
        <ax-button [text]="'@general:actions.cancel.title' | translate | async" (onClick)="this.close()"></ax-button>
        <ax-button
          color="primary"
          [text]="'@document-management:workflows.documentSignature.submit.title' | translate | async"
          [disabled]="!context()?.signature"
          (onClick)="handleSubmit(form)"
        >
        </ax-button>
      </ax-suffix>
    </ax-footer>
  `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: AXPWidgetCoreModule }, { kind: "component", type: i1.AXPWidgetContainerComponent, selector: "axp-widgets-container", inputs: ["context", "functions"], outputs: ["onContextChanged"] }, { kind: "directive", type: i1.AXPWidgetRendererDirective, selector: "[axp-widget-renderer]", inputs: ["parentNode", "index", "mode", "node"], outputs: ["onOptionsChanged", "onValueChanged"], exportAs: ["widgetRenderer"] }, { kind: "ngmodule", type: AXDecoratorModule }, { kind: "component", type: i1$1.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: AXButtonModule }, { kind: "component", type: i2.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: AXFormModule }, { kind: "component", type: i3.AXFormComponent, selector: "ax-form", inputs: ["labelMode", "look", "messageStyle", "updateOn"], outputs: ["onValidate", "updateOnChange"] }, { kind: "ngmodule", type: AXTranslationModule }, { kind: "directive", type: i3$1.AXTranslatorDirective, selector: "[translate]" }, { kind: "pipe", type: i1$2.AsyncPipe, name: "async" }, { kind: "pipe", type: i3$1.AXTranslatorPipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMDocumentSignaturePopupComponent, decorators: [{
            type: Component,
            args: [{
                    template: `
    <div class="ax-p-4 ax-min-h-64">
      <ax-form #form>
        <axp-widgets-container [context]="context()" (onContextChanged)="handleContextChanged($event)">
          <div class="ax-flex ax-flex-col ax-gap-4">
            <ng-container axp-widget-renderer [node]="fileView" [mode]="'view'"></ng-container>
            <ng-container axp-widget-renderer [node]="signatureNode" [mode]="'edit'"></ng-container>
            <div class="ax-text-sm ax-text-gray-600">
              {{ signatureInstructions | translate : { scope: 'document-management' } | async }}
            </div>
          </div>
        </axp-widgets-container>
      </ax-form>
    </div>
    <ax-footer *translate="let t">
      <ax-suffix>
        <ax-button [text]="'@general:actions.cancel.title' | translate | async" (onClick)="this.close()"></ax-button>
        <ax-button
          color="primary"
          [text]="'@document-management:workflows.documentSignature.submit.title' | translate | async"
          [disabled]="!context()?.signature"
          (onClick)="handleSubmit(form)"
        >
        </ax-button>
      </ax-suffix>
    </ax-footer>
  `,
                    imports: [CommonModule, AXPWidgetCoreModule, AXDecoratorModule, AXButtonModule, AXFormModule, AXTranslationModule],
                }]
        }] });

export { AXMDocumentSignaturePopupComponent };
//# sourceMappingURL=acorex-modules-document-management-document-signature-popup.component-DMFqz5jZ.mjs.map
