import { HttpHeaders } from '@angular/common/http';
import { Component, Inject, Input, Optional } from '@angular/core';
import { HttpClientService } from '@aztrix/helpers';
import { BASE_URL, DocumentRepresentation } from '@aztrix/sdk';
import * as i0 from "@angular/core";
import * as i1 from "@aztrix/helpers";
import * as i2 from "@angular/common";
import * as i3 from "@aztrix/icons";
import * as i4 from "../document-template-preview/document-template-preview.component";
export class DocumentLinkComponent {
    constructor(_http, baseUrl) {
        this._http = _http;
        this.baseUrl = baseUrl;
        this.isProposalDocument = true;
        this.demo = false;
    }
    getPath() {
        switch (this.documentType) {
            case 'SIGNING-ORDER':
                return '/staticFiles/signingOrderDocuments/' + this.document?.value;
            case 'AGREEMENT':
                return this.isAgreementDocument
                    ? '/staticFiles/agreementDocuments/' + this.agreementDocument?.value
                    : this.demo
                        ? '/staticFiles/proposalDocuments/' + this.document.value
                        : '/staticFiles/intermediateAgreementDocuments/' + this.agreementDocument?.value;
            case 'PROPOSAL':
                return '/staticFiles/proposalDocuments/' + this.document.value;
            default:
                return null;
        }
    }
    downloadPdf() {
        if (this.demo && this.document.type === DocumentRepresentation.TypeEnum.TEMPLATE) {
            this._http
                .post(`r/utils/generatePdfFromHtml`, this.template, {
                params: { _noAuth: 'true' },
                headers: new HttpHeaders({ 'Content-Type': 'text/html' }),
                responseType: 'blob',
            })
                .subscribe((pdf) => {
                const blob = new Blob([pdf], { type: 'application/pdf' });
                window.open(window.URL.createObjectURL(blob));
            });
        }
        else {
            window.open(this.baseUrl + this.getPath(), '_blank');
        }
    }
}
DocumentLinkComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: DocumentLinkComponent, deps: [{ token: i1.HttpClientService }, { token: BASE_URL, optional: true }], target: i0.ɵɵFactoryTarget.Component });
DocumentLinkComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.5", type: DocumentLinkComponent, selector: "ax-document-link", inputs: { document: "document", documentType: "documentType", agreementDocument: "agreementDocument", isAgreementDocument: "isAgreementDocument", isProposalDocument: "isProposalDocument", proposal: "proposal", proposalLanguage: "proposalLanguage", agreementProperties: "agreementProperties", demo: "demo" }, ngImport: i0, template: "<ng-container *ngIf=\"document?.type === 'TEMPLATE' && demo; else normalLink\">\n  <a class=\"link\" (click)=\"downloadPdf(); $event.preventDefault()\">\n    <span class=\"legal-text\" [attr.title]=\"('label.download' | translate) + ' ' + document.name\"\n      >{{ document?.name }}<ax-icon class=\"icon\" name=\"open-in-new\"></ax-icon\n    ></span>\n  </a>\n\n  <ax-document-template-preview\n    class=\"template-value-view\"\n    *ngIf=\"document?.type === 'TEMPLATE'\"\n    [document]=\"document\"\n    [proposal]=\"proposal\"\n    [proposalLanguage]=\"proposalLanguage\"\n    [agreementProperties]=\"agreementProperties\"\n    [(template)]=\"template\"\n  ></ax-document-template-preview>\n</ng-container>\n\n<ng-template #normalLink>\n  <ng-container *ngIf=\"document\">\n    <a\n      class=\"link\"\n      *ngIf=\"document?.type !== 'LINK'\"\n      [attr.href]=\"getPath()\"\n      [attr.download]=\"document?.filename\"\n      (click)=\"downloadPdf(); $event.preventDefault()\"\n      target=\"_blank\"\n    >\n      <span class=\"legal-text\" [attr.title]=\"document.filename\"\n        >{{ document?.name }}<ax-icon class=\"icon\" name=\"open-in-new\"></ax-icon\n      ></span>\n    </a>\n\n    <a class=\"link\" *ngIf=\"document?.type === 'LINK'\" [attr.href]=\"document?.value\" target=\"_blank\">\n      <span class=\"legal-text\" [attr.title]=\"document.value\"\n        >{{ document?.name }} <ax-icon class=\"icon\" name=\"open-in-new\"></ax-icon\n      ></span>\n    </a>\n  </ng-container>\n</ng-template>\n", styles: [":host{display:inline}.link .icon{width:1em;height:1em;vertical-align:middle}.link,.link:visited,.link:hover{color:var(--primary-color-500)}.link:active,.link:focus{color:var(--primary-color-500)}.link:hover{cursor:pointer}.template-value-view{display:none}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.IconComponent, selector: "ax-icon", inputs: ["name", "inline"] }, { kind: "component", type: i4.DocumentTemplatePreviewComponent, selector: "ax-document-template-preview", inputs: ["document", "proposalLanguage", "proposal", "template", "agreementProperties"], outputs: ["templateChange"] }, { kind: "pipe", type: i1.TranslatePipe, name: "translate" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: DocumentLinkComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-document-link', template: "<ng-container *ngIf=\"document?.type === 'TEMPLATE' && demo; else normalLink\">\n  <a class=\"link\" (click)=\"downloadPdf(); $event.preventDefault()\">\n    <span class=\"legal-text\" [attr.title]=\"('label.download' | translate) + ' ' + document.name\"\n      >{{ document?.name }}<ax-icon class=\"icon\" name=\"open-in-new\"></ax-icon\n    ></span>\n  </a>\n\n  <ax-document-template-preview\n    class=\"template-value-view\"\n    *ngIf=\"document?.type === 'TEMPLATE'\"\n    [document]=\"document\"\n    [proposal]=\"proposal\"\n    [proposalLanguage]=\"proposalLanguage\"\n    [agreementProperties]=\"agreementProperties\"\n    [(template)]=\"template\"\n  ></ax-document-template-preview>\n</ng-container>\n\n<ng-template #normalLink>\n  <ng-container *ngIf=\"document\">\n    <a\n      class=\"link\"\n      *ngIf=\"document?.type !== 'LINK'\"\n      [attr.href]=\"getPath()\"\n      [attr.download]=\"document?.filename\"\n      (click)=\"downloadPdf(); $event.preventDefault()\"\n      target=\"_blank\"\n    >\n      <span class=\"legal-text\" [attr.title]=\"document.filename\"\n        >{{ document?.name }}<ax-icon class=\"icon\" name=\"open-in-new\"></ax-icon\n      ></span>\n    </a>\n\n    <a class=\"link\" *ngIf=\"document?.type === 'LINK'\" [attr.href]=\"document?.value\" target=\"_blank\">\n      <span class=\"legal-text\" [attr.title]=\"document.value\"\n        >{{ document?.name }} <ax-icon class=\"icon\" name=\"open-in-new\"></ax-icon\n      ></span>\n    </a>\n  </ng-container>\n</ng-template>\n", styles: [":host{display:inline}.link .icon{width:1em;height:1em;vertical-align:middle}.link,.link:visited,.link:hover{color:var(--primary-color-500)}.link:active,.link:focus{color:var(--primary-color-500)}.link:hover{cursor:pointer}.template-value-view{display:none}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.HttpClientService }, { type: undefined, decorators: [{
                    type: Optional
                }, {
                    type: Inject,
                    args: [BASE_URL]
                }] }]; }, propDecorators: { document: [{
                type: Input
            }], documentType: [{
                type: Input
            }], agreementDocument: [{
                type: Input
            }], isAgreementDocument: [{
                type: Input
            }], isProposalDocument: [{
                type: Input
            }], proposal: [{
                type: Input
            }], proposalLanguage: [{
                type: Input
            }], agreementProperties: [{
                type: Input
            }], demo: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 