UNPKG

@hmcts/annotation-ui-lib

Version:

PDF Viewer and ability to highlight text with and comment tracking

3,342 lines 116 kB
import { v4 } from 'uuid';
import { isPlatformServer, CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { WINDOW, NgtUniversalModule } from '@ng-toolkit/universal';
import { __values, __awaiter, __generator } from 'tslib';
import { Injectable, Inject, PLATFORM_ID, Component, ViewChildren, Input, Output, EventEmitter, ViewChild, ChangeDetectorRef, Renderer2, ComponentFactoryResolver, Injector, ApplicationRef, Directive, ViewContainerRef, NgModule, defineInjectable, inject } from '@angular/core';
import { HttpClient, HttpErrorResponse, HttpClientModule } from '@angular/common/http';
import { BehaviorSubject, Subject, of, throwError } from 'rxjs';
import { TransferState, makeStateKey } from '@angular/platform-browser';
import { tap, catchError, map } from 'rxjs/operators';

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var Comment = /** @class */ (function () {
    function Comment(id, annotationId, createdBy, createdByDetails, createdDate, lastModifiedBy, lastModifiedByDetails, lastModifiedDate, content) {
        this.id = id;
        this.annotationId = annotationId;
        this.createdBy = createdBy;
        this.createdByDetails = createdByDetails;
        this.createdDate = createdDate;
        this.lastModifiedBy = lastModifiedBy;
        this.lastModifiedByDetails = lastModifiedByDetails;
        this.lastModifiedDate = lastModifiedDate;
        this.content = content;
    }
    return Comment;
}());
var Annotation = /** @class */ (function () {
    function Annotation(id, annotationSetId, createdBy, createdDate, createdByDetails, lastModifiedBy, lastModifiedByDetails, lastModifiedDate, documentId, page, color, comments, rectangles, type) {
        this.id = id;
        this.annotationSetId = annotationSetId;
        this.createdBy = createdBy;
        this.createdDate = createdDate;
        this.createdByDetails = createdByDetails;
        this.lastModifiedBy = lastModifiedBy;
        this.lastModifiedByDetails = lastModifiedByDetails;
        this.lastModifiedDate = lastModifiedDate;
        this.documentId = documentId;
        this.page = page;
        this.color = color;
        this.comments = comments;
        this.rectangles = rectangles;
        this.type = type;
    }
    return Annotation;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var PdfAnnotateWrapper = /** @class */ (function () {
    function PdfAnnotateWrapper() {
    }
    /**
     * @param {?} pageNumber
     * @return {?}
     */
    PdfAnnotateWrapper.prototype.createPage = /**
     * @param {?} pageNumber
     * @return {?}
     */
    function (pageNumber) {
        return PDFAnnotate.UI.createPage(pageNumber);
    };
    /**
     * @param {?} pageNumber
     * @param {?} RENDER_OPTIONS
     * @return {?}
     */
    PdfAnnotateWrapper.prototype.renderPage = /**
     * @param {?} pageNumber
     * @param {?} RENDER_OPTIONS
     * @return {?}
     */
    function (pageNumber, RENDER_OPTIONS) {
        return PDFAnnotate.UI.renderPage(pageNumber, RENDER_OPTIONS);
    };
    /**
     * @param {?} type
     * @return {?}
     */
    PdfAnnotateWrapper.prototype.enableRect = /**
     * @param {?} type
     * @return {?}
     */
    function (type) {
        PDFAnnotate.UI.enableRect(type);
    };
    /**
     * @return {?}
     */
    PdfAnnotateWrapper.prototype.disableRect = /**
     * @return {?}
     */
    function () {
        PDFAnnotate.UI.disableRect();
    };
    /**
     * @param {?=} storeAdapter
     * @return {?}
     */
    PdfAnnotateWrapper.prototype.setStoreAdapter = /**
     * @param {?=} storeAdapter
     * @return {?}
     */
    function (storeAdapter) {
        if (storeAdapter) {
            PDFAnnotate.setStoreAdapter(storeAdapter);
        }
        else {
            PDFAnnotate.setStoreAdapter(new PDFAnnotate.LocalStoreAdapter());
        }
    };
    /**
     * @return {?}
     */
    PdfAnnotateWrapper.prototype.getStoreAdapter = /**
     * @return {?}
     */
    function () {
        return PDFAnnotate.getStoreAdapter();
    };
    /**
     * @return {?}
     */
    PdfAnnotateWrapper.prototype.getUi = /**
     * @return {?}
     */
    function () {
        return PDFAnnotate.UI;
    };
    return PdfAnnotateWrapper;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var EmLoggerService = /** @class */ (function () {
    function EmLoggerService() {
    }
    /**
     * @param {?} loggingClass
     * @return {?}
     */
    EmLoggerService.prototype.setClass = /**
     * @param {?} loggingClass
     * @return {?}
     */
    function (loggingClass) {
        this.loggingClass = loggingClass;
    };
    /**
     * @param {?} message
     * @return {?}
     */
    EmLoggerService.prototype.error = /**
     * @param {?} message
     * @return {?}
     */
    function (message) {
        this.buildLog('error-' + JSON.stringify(message));
    };
    /**
     * @param {?} message
     * @return {?}
     */
    EmLoggerService.prototype.info = /**
     * @param {?} message
     * @return {?}
     */
    function (message) {
        this.buildLog('info-' + JSON.stringify(message));
    };
    /**
     * @param {?} message
     * @return {?}
     */
    EmLoggerService.prototype.buildLog = /**
     * @param {?} message
     * @return {?}
     */
    function (message) {
        console.log(this.loggingClass + "-" + message);
    };
    EmLoggerService.decorators = [
        { type: Injectable }
    ];
    return EmLoggerService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var PdfService = /** @class */ (function () {
    function PdfService(log, pdfAnnotateWrapper) {
        this.log = log;
        this.pdfAnnotateWrapper = pdfAnnotateWrapper;
        log.setClass('PdfService');
    }
    /**
     * @return {?}
     */
    PdfService.prototype.preRun = /**
     * @return {?}
     */
    function () {
        this.pageNumber = new BehaviorSubject(1);
    };
    /**
     * @return {?}
     */
    PdfService.prototype.getAnnotationWrapper = /**
     * @return {?}
     */
    function () {
        return this.annotationWrapper;
    };
    /**
     * @param {?} annotationWrapper
     * @return {?}
     */
    PdfService.prototype.setAnnotationWrapper = /**
     * @param {?} annotationWrapper
     * @return {?}
     */
    function (annotationWrapper) {
        this.annotationWrapper = annotationWrapper;
    };
    /**
     * @return {?}
     */
    PdfService.prototype.getPageNumber = /**
     * @return {?}
     */
    function () {
        return this.pageNumber;
    };
    /**
     * @param {?} pageNumber
     * @return {?}
     */
    PdfService.prototype.setPageNumber = /**
     * @param {?} pageNumber
     * @return {?}
     */
    function (pageNumber) {
        this.pageNumber.next(pageNumber);
    };
    /**
     * @return {?}
     */
    PdfService.prototype.setHighlightTool = /**
     * @return {?}
     */
    function () {
        this.log.info('Highlight cursor is enabled');
        this.pdfAnnotateWrapper.enableRect('highlight');
    };
    /**
     * @return {?}
     */
    PdfService.prototype.setCursorTool = /**
     * @return {?}
     */
    function () {
        this.pdfAnnotateWrapper.disableRect();
    };
    PdfService.decorators = [
        { type: Injectable }
    ];
    PdfService.ctorParameters = function () { return [
        { type: EmLoggerService },
        { type: PdfAnnotateWrapper }
    ]; };
    return PdfService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var Utils = /** @class */ (function () {
    function Utils() {
    }
    /**
     * @param {?} rectangles
     * @return {?}
     */
    Utils.prototype.buildLineRectangle = /**
     * @param {?} rectangles
     * @return {?}
     */
    function (rectangles) {
        this.sortByY(rectangles);
        /** @type {?} */
        var lowestY = rectangles[0].y;
        /** @type {?} */
        var lineHeight = rectangles[0].height;
        this.sortByX(rectangles);
        /** @type {?} */
        var lowestX = rectangles[0].x;
        /** @type {?} */
        var upperX = rectangles[rectangles.length - 1].x;
        /** @type {?} */
        var width = rectangles[rectangles.length - 1].width;
        /** @type {?} */
        var rectangle = {
            y: lowestY,
            x: lowestX,
            width: (upperX - lowestX) + width,
            height: lineHeight
        };
        return rectangle;
    };
    /**
     * @param {?} annotationRectangles
     * @param {?} generatedRectangles
     * @return {?}
     */
    Utils.prototype.generateRectanglePerLine = /**
     * @param {?} annotationRectangles
     * @param {?} generatedRectangles
     * @return {?}
     */
    function (annotationRectangles, generatedRectangles) {
        this.sortByY(annotationRectangles);
        /** @type {?} */
        var highestY = annotationRectangles[annotationRectangles.length - 1].y;
        /** @type {?} */
        var lowestY = annotationRectangles[0].y;
        /** @type {?} */
        var lineHeight = this.getAnnotationLineHeight(annotationRectangles);
        if (this.difference(highestY, lowestY) > lineHeight) {
            /** @type {?} */
            var currentLineRectangles = annotationRectangles.filter(function (rectangle) { return rectangle.y <= (lowestY + lineHeight); });
            /** @type {?} */
            var nextLineRectangles = annotationRectangles.filter(function (rectangle) { return rectangle.y > (lowestY + lineHeight); });
            generatedRectangles.push(this.buildLineRectangle(currentLineRectangles));
            this.generateRectanglePerLine(nextLineRectangles, generatedRectangles);
        }
        else {
            generatedRectangles.push(this.buildLineRectangle(annotationRectangles));
        }
    };
    /**
     * @param {?} rectangles
     * @return {?}
     */
    Utils.prototype.getAnnotationLineHeight = /**
     * @param {?} rectangles
     * @return {?}
     */
    function (rectangles) {
        return rectangles[0].height;
    };
    /**
     * @param {?} rectangles
     * @param {?=} lowest
     * @return {?}
     */
    Utils.prototype.sortByY = /**
     * @param {?} rectangles
     * @param {?=} lowest
     * @return {?}
     */
    function (rectangles, lowest) {
        if (lowest === void 0) { lowest = true; }
        rectangles.sort(function (a, b) {
            /** @type {?} */
            var keyA = a.y;
            /** @type {?} */
            var keyB = b.y;
            if (keyA < keyB) {
                return lowest ? -1 : 1;
            }
            if (keyA > keyB) {
                return lowest ? 1 : -1;
            }
            return 0;
        });
    };
    /**
     * @param {?} rectangles
     * @param {?=} lowest
     * @return {?}
     */
    Utils.prototype.sortByX = /**
     * @param {?} rectangles
     * @param {?=} lowest
     * @return {?}
     */
    function (rectangles, lowest) {
        if (lowest === void 0) { lowest = true; }
        rectangles.sort(function (a, b) {
            /** @type {?} */
            var keyA = a.x;
            /** @type {?} */
            var keyB = b.x;
            if (keyA < keyB) {
                return lowest ? -1 : 1;
            }
            if (keyA > keyB) {
                return lowest ? 1 : -1;
            }
            return 0;
        });
    };
    /**
     * @param {?} a
     * @param {?} b
     * @return {?}
     */
    Utils.prototype.sortByLinePosition = /**
     * @param {?} a
     * @param {?} b
     * @return {?}
     */
    function (a, b) {
        this.sortByX(a);
        this.sortByX(b);
        return (a[0].x > b[0].x) ? 1 : -1;
    };
    /**
     * @param {?} a
     * @param {?} b
     * @return {?}
     */
    Utils.prototype.difference = /**
     * @param {?} a
     * @param {?} b
     * @return {?}
     */
    function (a, b) { return Math.abs(a - b); };
    /**
     * @param {?} event
     * @return {?}
     */
    Utils.prototype.clickIsHighlight = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        /** @type {?} */
        var target = (/** @type {?} */ (event.target));
        /** @type {?} */
        var isHighlight = target.firstElementChild;
        if (isHighlight == null) {
            return false;
        }
        else if (isHighlight.id.includes('pdf-annotate-screenreader')) {
            return true;
        }
        else {
            return false;
        }
    };
    /**
     * @param {?} event
     * @return {?}
     */
    Utils.prototype.getClickedPage = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        /** @type {?} */
        var currentParent = event.target;
        for (var step = 0; step < 5; step++) {
            if (currentParent.parentNode != null) {
                /** @type {?} */
                var pageNumber = currentParent.parentNode.getAttribute('data-page-number');
                if (pageNumber != null) {
                    return parseInt(pageNumber, null);
                }
                currentParent = currentParent.parentNode;
            }
        }
    };
    return Utils;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var PdfAdapter = /** @class */ (function () {
    function PdfAdapter(log, utils, window) {
        this.log = log;
        this.utils = utils;
        this.window = window;
        this.annotationChangeSubject = new Subject();
        log.setClass('PdfAdapter');
    }
    /**
     * @return {?}
     */
    PdfAdapter.prototype.getAnnotationChangeSubject = /**
     * @return {?}
     */
    function () {
        return this.annotationChangeSubject;
    };
    /**
     * @param {?} annotationSet
     * @return {?}
     */
    PdfAdapter.prototype.setStoreData = /**
     * @param {?} annotationSet
     * @return {?}
     */
    function (annotationSet) {
        var _this = this;
        this.annotationSet = annotationSet;
        this.annotations = annotationSet.annotations;
        this.commentData = [];
        this.annotations.forEach(function (annotation) {
            annotation.comments.forEach(function (comment) {
                _this.commentData.push(comment);
            });
        });
        this.annotationSetId = annotationSet.id;
    };
    /**
     * @param {?} comment
     * @return {?}
     */
    PdfAdapter.prototype.editComment = /**
     * @param {?} comment
     * @return {?}
     */
    function (comment) {
        var _this = this;
        this.annotations.forEach(function (annotation) {
            annotation.comments
                .filter(function (storeComment) { return storeComment.id === comment.id; })
                .map(function (storeComment) {
                _this.log.info('Editing comment:' + comment.id);
                storeComment.content = comment.content;
                _this.annotationChangeSubject.next({ 'type': 'editComment', 'annotation': annotation });
            });
        });
    };
    /**
     * @param {?} documentId
     * @param {?} comment
     * @return {?}
     */
    PdfAdapter.prototype.updateComments = /**
     * @param {?} documentId
     * @param {?} comment
     * @return {?}
     */
    function (documentId, comment) {
        this.commentData.push(comment);
    };
    /**
     * @param {?} documentId
     * @return {?}
     */
    PdfAdapter.prototype._getAnnotations = /**
     * @param {?} documentId
     * @return {?}
     */
    function (documentId) {
        return this.annotations || [];
    };
    /**
     * @param {?} documentId
     * @return {?}
     */
    PdfAdapter.prototype._getComments = /**
     * @param {?} documentId
     * @return {?}
     */
    function (documentId) {
        return this.commentData || [];
    };
    /**
     * @return {?}
     */
    PdfAdapter.prototype.clearSelection = /**
     * @return {?}
     */
    function () {
        /** @type {?} */
        var sel = this.window.getSelection();
        if (sel) {
            if (sel.removeAllRanges) {
                sel.removeAllRanges();
            }
            else if (sel.empty) {
                sel.empty();
            }
        }
    };
    /**
     * @param {?} comment
     * @return {?}
     */
    PdfAdapter.prototype.isDraftComment = /**
     * @param {?} comment
     * @return {?}
     */
    function (comment) {
        return (comment.content === null || comment.content === '');
    };
    /**
     * @return {?}
     */
    PdfAdapter.prototype.getStoreAdapter = /**
     * @return {?}
     */
    function () {
        var _this = this;
        /** @type {?} */
        var getAnnotations = function (documentId, pageNumber) {
            return new Promise(function (resolve, reject) {
                /** @type {?} */
                var annotations = _this._getAnnotations(documentId).filter(function (i) {
                    return i.page === pageNumber;
                });
                resolve({
                    documentId: documentId,
                    pageNumber: pageNumber,
                    annotations: annotations
                });
            });
        };
        /** @type {?} */
        var getComments = function (documentId, annotationId) {
            return new Promise(function (resolve, reject) {
                resolve(_this._getComments(documentId).filter(function (i) {
                    return i.annotationId === annotationId;
                }));
            });
        };
        /** @type {?} */
        var getAnnotation = function (documentId, annotationId) {
            return new Promise(function (resolve, reject) {
                /** @type {?} */
                var annotation = _this._getAnnotations(documentId).find(function (i) {
                    return i.id === annotationId;
                });
                resolve(annotation);
            });
        };
        /** @type {?} */
        var addAnnotation = function (documentId, pageNumber, annotation) {
            return new Promise(function (resolve, reject) {
                _this.clearSelection();
                /** @type {?} */
                var persistAnnotation = new Annotation();
                persistAnnotation.id = v4();
                persistAnnotation.page = pageNumber;
                persistAnnotation.color = annotation.color;
                persistAnnotation.type = annotation.type;
                persistAnnotation.comments = [];
                persistAnnotation.annotationSetId = _this.annotationSetId;
                /** @type {?} */
                var rectangles = [];
                _this.log.info('Generating efficient rectangles for new annotation:' + persistAnnotation.id);
                _this.utils.generateRectanglePerLine(annotation.rectangles, rectangles);
                rectangles.forEach(function (rectangle) {
                    rectangle.id = v4();
                });
                persistAnnotation.rectangles = rectangles;
                /** @type {?} */
                var annotations = _this._getAnnotations(documentId);
                annotations.push(persistAnnotation);
                _this.log.info('Added annotation:' + annotation.id);
                _this.annotationChangeSubject.next({ 'type': 'addAnnotation', 'annotation': persistAnnotation });
                resolve(persistAnnotation);
            });
        };
        /** @type {?} */
        var deleteAnnotation = function (documentId, annotationId) {
            return new Promise(function (resolve, reject) {
                /** @type {?} */
                var annotation = _this.findById(_this.annotations, annotationId);
                _this.remove(_this.annotations, annotationId);
                _this.log.info('Deleted annotation:' + annotationId);
                _this.annotationChangeSubject.next({ 'type': 'deleteAnnotation', 'annotation': annotation });
                resolve(_this.annotations);
            });
        };
        /** @type {?} */
        var addComment = function (documentId, annotationId, content) {
            return new Promise(function (resolve, reject) {
                /** @type {?} */
                var comment = new Comment(v4(), annotationId, null, null, new Date(), null, null, null, content);
                _this.updateComments(documentId, comment);
                /** @type {?} */
                var annotation = _this.findById(_this.annotations, annotationId);
                _this.log.info('Comment:' + comment.id + ' has been added to annotation:' + annotationId);
                annotation.comments.push(comment);
                if (_this.isDraftComment(comment)) {
                    _this.log.info('Removing comment box because no content exists');
                    resolve(comment);
                }
                else {
                    _this.log.info('Add comment:' + comment.id + '-' + 'annotationId:' + annotation.id);
                    _this.annotationChangeSubject.next({ 'type': 'addComment', 'annotation': annotation });
                    resolve(comment);
                }
            });
        };
        /** @type {?} */
        var deleteComment = function (documentId, commentId) {
            return new Promise(function (resolve, reject) {
                /** @type {?} */
                var comment = _this.findById(_this.commentData, commentId);
                /** @type {?} */
                var annotation = _this.findById(_this.annotations, comment.annotationId);
                _this.remove(_this.commentData, commentId);
                _this.remove(annotation.comments, commentId);
                if (_this.isDraftComment(comment)) {
                    _this.log.info('Removing comment box because no content exists');
                    resolve(comment);
                }
                else {
                    _this.log.info('Deleted comment:' + commentId + '-' + 'annotationId:' + annotation.id);
                    _this.annotationChangeSubject.next({ 'type': 'deleteComment', 'annotation': annotation });
                    resolve(_this.annotations);
                }
            });
        };
        // Unused
        /** @type {?} */
        var editAnnotation = function (documentId, pageNumber, annotation) {
            return new Promise(function (resolve, reject) {
                _this.annotationChangeSubject.next({ 'type': 'editAnnotation', 'annotation': annotation });
                resolve(_this.commentData);
            });
        };
        return {
            getAnnotations: getAnnotations,
            getComments: getComments,
            getAnnotation: getAnnotation,
            addAnnotation: addAnnotation,
            editAnnotation: editAnnotation,
            deleteAnnotation: deleteAnnotation,
            addComment: addComment,
            deleteComment: deleteComment
        };
    };
    /**
     * @param {?} array
     * @param {?} id
     * @return {?}
     */
    PdfAdapter.prototype.findById = /**
     * @param {?} array
     * @param {?} id
     * @return {?}
     */
    function (array, id) {
        return array.find(function (e) { return e.id === id; });
    };
    /**
     * @param {?} array
     * @param {?} id
     * @return {?}
     */
    PdfAdapter.prototype.remove = /**
     * @param {?} array
     * @param {?} id
     * @return {?}
     */
    function (array, id) {
        return array.splice(array.findIndex(function (e) { return e.id === id; }), 1);
    };
    PdfAdapter.decorators = [
        { type: Injectable }
    ];
    PdfAdapter.ctorParameters = function () { return [
        { type: EmLoggerService },
        { type: Utils },
        { type: undefined, decorators: [{ type: Inject, args: [WINDOW,] }] }
    ]; };
    return PdfAdapter;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var ApiHttpService = /** @class */ (function () {
    function ApiHttpService(log, httpClient, platformId, transferState) {
        this.log = log;
        this.httpClient = httpClient;
        this.platformId = platformId;
        this.transferState = transferState;
        log.setClass('ApiHttpService');
    }
    /**
     * @param {?} baseUrl
     * @return {?}
     */
    ApiHttpService.prototype.setBaseUrl = /**
     * @param {?} baseUrl
     * @return {?}
     */
    function (baseUrl) {
        this.baseUrl = baseUrl;
    };
    /**
     * @return {?}
     */
    ApiHttpService.prototype.getBaseUrl = /**
     * @return {?}
     */
    function () {
        return this.baseUrl;
    };
    /**
     * @param {?} baseUrl
     * @param {?} body
     * @return {?}
     */
    ApiHttpService.prototype.createAnnotationSet = /**
     * @param {?} baseUrl
     * @param {?} body
     * @return {?}
     */
    function (baseUrl, body) {
        return this.httpClient.post(baseUrl + "/em-anno/annotation-sets", body, { observe: 'response' });
    };
    /**
     * @param {?} baseUrl
     * @param {?} dmDocumentId
     * @return {?}
     */
    ApiHttpService.prototype.fetch = /**
     * @param {?} baseUrl
     * @param {?} dmDocumentId
     * @return {?}
     */
    function (baseUrl, dmDocumentId) {
        var _this = this;
        /** @type {?} */
        var STATE_KEY = makeStateKey('annotationSet-' + dmDocumentId);
        if (this.transferState.hasKey(STATE_KEY)) {
            /** @type {?} */
            var annotationSet = this.transferState.get(STATE_KEY, null);
            this.transferState.remove(STATE_KEY);
            return of(annotationSet);
        }
        else {
            /** @type {?} */
            var url = baseUrl + "/em-anno/annotation-sets/" + dmDocumentId;
            return this.httpClient.get(url, { observe: 'response' })
                .pipe(tap(function (annotationSet) {
                if (isPlatformServer(_this.platformId)) {
                    _this.transferState.set(STATE_KEY, annotationSet);
                }
            }));
        }
    };
    /**
     * @param {?} dmDocumentId
     * @param {?} outputDmDocumentId
     * @param {?} baseUrl
     * @return {?}
     */
    ApiHttpService.prototype.documentTask = /**
     * @param {?} dmDocumentId
     * @param {?} outputDmDocumentId
     * @param {?} baseUrl
     * @return {?}
     */
    function (dmDocumentId, outputDmDocumentId, baseUrl) {
        /** @type {?} */
        var url = baseUrl + "/api/em-npa/document-tasks";
        /** @type {?} */
        var documentTasks = {
            inputDocumentId: dmDocumentId,
            outputDocumentId: outputDmDocumentId
        };
        this.log.info('Calling NPA service-' + dmDocumentId);
        return this.httpClient.post(url, documentTasks, { observe: 'response' });
    };
    /**
     * @param {?} annotation
     * @return {?}
     */
    ApiHttpService.prototype.deleteAnnotation = /**
     * @param {?} annotation
     * @return {?}
     */
    function (annotation) {
        /** @type {?} */
        var url = this.baseUrl + "/em-anno/annotations/" + annotation.id;
        return this.httpClient.delete(url, { observe: 'response' });
    };
    /**
     * @param {?} annotation
     * @return {?}
     */
    ApiHttpService.prototype.saveAnnotation = /**
     * @param {?} annotation
     * @return {?}
     */
    function (annotation) {
        /** @type {?} */
        var url = this.baseUrl + "/em-anno/annotations";
        return this.httpClient.post(url, annotation, { observe: 'response' });
    };
    ApiHttpService.decorators = [
        { type: Injectable }
    ];
    ApiHttpService.ctorParameters = function () { return [
        { type: EmLoggerService },
        { type: HttpClient },
        { type: undefined, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] },
        { type: TransferState }
    ]; };
    return ApiHttpService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var PdfWrapper = /** @class */ (function () {
    function PdfWrapper() {
    }
    /**
     * @param {?} documentId
     * @return {?}
     */
    PdfWrapper.prototype.getDocument = /**
     * @param {?} documentId
     * @return {?}
     */
    function (documentId) {
        return PDFJS.getDocument(documentId);
    };
    return PdfWrapper;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var RotationModel = /** @class */ (function () {
    function RotationModel(pageNumber, pageDom) {
        this.pageNumber = pageNumber;
        this.pageDom = pageDom;
    }
    return RotationModel;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var PdfRenderService = /** @class */ (function () {
    function PdfRenderService(pdfWrapper, log, pdfAnnotateWrapper) {
        this.pdfWrapper = pdfWrapper;
        this.log = log;
        this.pdfAnnotateWrapper = pdfAnnotateWrapper;
        this.listPages = [];
        this.log.setClass('PdfRenderService');
        this.dataLoadedSubject = new BehaviorSubject(false);
        this.listPagesSubject = new Subject();
    }
    /**
     * @return {?}
     */
    PdfRenderService.prototype.getDataLoadedSub = /**
     * @return {?}
     */
    function () {
        return this.dataLoadedSubject;
    };
    /**
     * @param {?} isLoaded
     * @return {?}
     */
    PdfRenderService.prototype.dataLoadedUpdate = /**
     * @param {?} isLoaded
     * @return {?}
     */
    function (isLoaded) {
        this.dataLoadedSubject.next(isLoaded);
    };
    /**
     * @return {?}
     */
    PdfRenderService.prototype.getRenderOptions = /**
     * @return {?}
     */
    function () {
        return Object.assign({}, this.RENDER_OPTIONS);
    };
    /**
     * @param {?} RENDER_OPTIONS
     * @return {?}
     */
    PdfRenderService.prototype.setRenderOptions = /**
     * @param {?} RENDER_OPTIONS
     * @return {?}
     */
    function (RENDER_OPTIONS) {
        this.RENDER_OPTIONS = RENDER_OPTIONS;
    };
    /**
     * @return {?}
     */
    PdfRenderService.prototype.getViewerElementRef = /**
     * @return {?}
     */
    function () {
        return this.viewerElementRef;
    };
    /**
     * @return {?}
     */
    PdfRenderService.prototype.getPdfPages = /**
     * @return {?}
     */
    function () {
        return this.pdfPages;
    };
    /**
     * @param {?=} viewerElementRef
     * @return {?}
     */
    PdfRenderService.prototype.render = /**
     * @param {?=} viewerElementRef
     * @return {?}
     */
    function (viewerElementRef) {
        var _this = this;
        if (viewerElementRef != null) {
            this.viewerElementRef = viewerElementRef;
        }
        /** @type {?} */
        var renderOptions = this.getRenderOptions();
        this.pdfWrapper.getDocument(renderOptions.documentId)
            .then(function (pdf) {
            renderOptions.pdfDocument = pdf;
            /** @type {?} */
            var viewer = _this.viewerElementRef.nativeElement;
            viewer.innerHTML = '';
            _this.pdfPages = pdf.pdfInfo.numPages;
            _this.listPages = [];
            var _loop_1 = function (i) {
                /** @type {?} */
                var pageDom = _this.pdfAnnotateWrapper.createPage(i);
                // Create a copy of the render options for each page.
                /** @type {?} */
                var pageOptions = Object.assign({}, renderOptions);
                viewer.appendChild(pageDom);
                _this.addDomPage(pageDom, i);
                pdf.getPage(i).then(function (pdfPage) {
                    // Get current page rotation from page rotation objects
                    pageOptions.rotate = _this.addPageRotation(renderOptions, pageOptions, pdfPage);
                    setTimeout(function () {
                        _this.pdfAnnotateWrapper.renderPage(i, pageOptions).then(function () {
                            if (i === _this.pdfPages) {
                                _this.setRenderOptions(renderOptions);
                                _this.dataLoadedUpdate(true);
                                _this.listPagesSubject.next(_this.listPages);
                            }
                        });
                    });
                });
            };
            for (var i = 1; i < _this.pdfPages + 1; i++) {
                _loop_1(i);
            }
        }).catch(function (error) {
            /** @type {?} */
            var errorMessage = new Error('Unable to render your supplied PDF. ' +
                renderOptions.documentId + '. Error is: ' + error);
            _this.log.error('Encountered error while rendering the PDF:' + errorMessage);
        });
    };
    /**
     * @param {?} pageDom
     * @param {?} pageNumber
     * @return {?}
     */
    PdfRenderService.prototype.addDomPage = /**
     * @param {?} pageDom
     * @param {?} pageNumber
     * @return {?}
     */
    function (pageDom, pageNumber) {
        /** @type {?} */
        var pagedetails = new RotationModel(pageNumber, pageDom);
        /** @type {?} */
        var index = this.listPages.findIndex(function (pageElement) { return pageElement.pageNumber === pageNumber; });
        if (index > 0) {
            this.listPages[index] = pagedetails;
        }
        else {
            this.listPages.push(pagedetails);
        }
    };
    /**
     * @param {?} renderOptions
     * @param {?} pageOptions
     * @param {?} pdfPage
     * @return {?}
     */
    PdfRenderService.prototype.addPageRotation = /**
     * @param {?} renderOptions
     * @param {?} pageOptions
     * @param {?} pdfPage
     * @return {?}
     */
    function (renderOptions, pageOptions, pdfPage) {
        /** @type {?} */
        var rotation = this.getPageRotation(pageOptions, pdfPage);
        if (!rotation) {
            renderOptions.rotationPages.push({ page: pdfPage.pageNumber, rotate: pdfPage.rotate });
            rotation = pdfPage.rotate;
        }
        return rotation;
    };
    /**
     * @param {?} pageOptions
     * @param {?} pdfPage
     * @return {?}
     */
    PdfRenderService.prototype.getPageRotation = /**
     * @param {?} pageOptions
     * @param {?} pdfPage
     * @return {?}
     */
    function (pageOptions, pdfPage) {
        return pageOptions.rotationPages
            .filter(function (rotateObj) { return rotateObj.page === pdfPage.pageNumber; })
            .map(function (rotateObj) { return rotateObj.rotate; })[0];
    };
    PdfRenderService.decorators = [
        { type: Injectable }
    ];
    PdfRenderService.ctorParameters = function () { return [
        { type: PdfWrapper },
        { type: EmLoggerService },
        { type: PdfAnnotateWrapper }
    ]; };
    return PdfRenderService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var AnnotationStoreService = /** @class */ (function () {
    function AnnotationStoreService(log, pdfAdapter, apiHttpService, pdfService, pdfAnnotateWrapper, pdfRenderService) {
        var _this = this;
        this.log = log;
        this.pdfAdapter = pdfAdapter;
        this.apiHttpService = apiHttpService;
        this.pdfService = pdfService;
        this.pdfAnnotateWrapper = pdfAnnotateWrapper;
        this.pdfRenderService = pdfRenderService;
        log.setClass('AnnotationStoreService');
        this.commentBtnSubject = new Subject();
        this.commentFocusSubject = new BehaviorSubject({ annotation: new Annotation(null, null, null, null, null, null, null, null, null, null, null, null) });
        this.contextualToolBarOptions = new Subject();
        this.annotationFocusSubject = new Subject();
        this.annotationChangeSubscription = this.pdfAdapter.getAnnotationChangeSubject().subscribe(function (e) { return _this.handleAnnotationEvent(e); });
    }
    /**
     * @return {?}
     */
    AnnotationStoreService.prototype.getAnnotationFocusSubject = /**
     * @return {?}
     */
    function () {
        return this.annotationFocusSubject;
    };
    /**
     * @param {?} annotation
     * @return {?}
     */
    AnnotationStoreService.prototype.setAnnotationFocusSubject = /**
     * @param {?} annotation
     * @return {?}
     */
    function (annotation) {
        this.annotationFocusSubject.next(annotation);
    };
    /**
     * @return {?}
     */
    AnnotationStoreService.prototype.getCommentFocusSubject = /**
     * @return {?}
     */
    function () {
        return this.commentFocusSubject;
    };
    /**
     * @param {?} annotation
     * @param {?=} showButton
     * @return {?}
     */
    AnnotationStoreService.prototype.setCommentFocusSubject = /**
     * @param {?} annotation
     * @param {?=} showButton
     * @return {?}
     */
    function (annotation, showButton) {
        this.commentFocusSubject.next({ annotation: annotation, showButton: showButton });
    };
    /**
     * @return {?}
     */
    AnnotationStoreService.prototype.getCommentBtnSubject = /**
     * @return {?}
     */
    function () {
        return this.commentBtnSubject;
    };
    /**
     * @param {?} commentId
     * @return {?}
     */
    AnnotationStoreService.prototype.setCommentBtnSubject = /**
     * @param {?} commentId
     * @return {?}
     */
    function (commentId) {
        this.commentBtnSubject.next(commentId);
    };
    /**
     * @param {?} annotation
     * @param {?=} showDelete
     * @return {?}
     */
    AnnotationStoreService.prototype.setToolBarUpdate = /**
     * @param {?} annotation
     * @param {?=} showDelete
     * @return {?}
     */
    function (annotation, showDelete) {
        /** @type {?} */
        var contextualOptions = {
            annotation: annotation,
            showDelete: showDelete
        };
        this.contextualToolBarOptions.next(contextualOptions);
    };
    /**
     * @return {?}
     */
    AnnotationStoreService.prototype.getToolbarUpdate = /**
     * @return {?}
     */
    function () {
        return this.contextualToolBarOptions;
    };
    /**
     * @param {?} annotationData
     * @return {?}
     */
    AnnotationStoreService.prototype.preLoad = /**
     * @param {?} annotationData
     * @return {?}
     */
    function (annotationData) {
        if (annotationData != null) {
            this.pdfAdapter.setStoreData(annotationData);
            this.pdfAnnotateWrapper.setStoreAdapter(this.pdfAdapter.getStoreAdapter());
            this.pdfService.setHighlightTool();
        }
        else {
            this.pdfService.setCursorTool();
            this.pdfAnnotateWrapper.setStoreAdapter();
        }
    };
    /**
     * @param {?} e
     * @return {?}
     */
    AnnotationStoreService.prototype.handleAnnotationEvent = /**
     * @param {?} e
     * @return {?}
     */
    function (e) {
        switch (e.type) {
            case 'addAnnotation': {
                this.saveAnnotation(e.annotation);
                break;
            }
            case 'addComment': {
                this.saveAnnotation(e.annotation, e.type);
                break;
            }
            case 'editComment': {
                this.saveAnnotation(e.annotation, e.type);
                break;
            }
            case 'deleteComment': {
                this.saveAnnotation(e.annotation);
                break;
            }
            case 'editAnnotation': {
                this.saveAnnotation(e.annotation);
                break;
            }
            case 'deleteAnnotation': {
                this.deleteAnnotation(e.annotation);
                break;
            }
        }
    };
    /**
     * @param {?} baseUrl
     * @param {?} dmDocumentId
     * @return {?}
     */
    AnnotationStoreService.prototype.getAnnotationSet = /**
     * @param {?} baseUrl
     * @param {?} dmDocumentId
     * @return {?}
     */
    function (baseUrl, dmDocumentId) {
        var _this = this;
        return this.apiHttpService.fetch(baseUrl, dmDocumentId).pipe(catchError(function (err) {
            if (err instanceof HttpErrorResponse) {
                switch (err.status) {
                    case 400: {
                        _this.log.error('Bad request: ' + err.error);
                        return throwError(err.error);
                    }
                    case 404: {
                        /** @type {?} */
                        var body = {
                            documentId: dmDocumentId,
                            id: v4()
                        };
                        _this.log.info('Creating new annotation set for document id:' + dmDocumentId);
                        return _this.apiHttpService.createAnnotationSet(baseUrl, body);
                    }
                    case 500: {
                        _this.log.error('Internal server error: ' + err);
                        return throwError('Internal server error: ' + err);
                    }
                }
            }
        }));
    };
    /**
     * @return {?}
     */
    AnnotationStoreService.prototype.saveData = /**
     * @return {?}
     */
    function () {
        var _this = this;
        /** @type {?} */
        var loadedData;
        /** @type {?} */
        var toKeepAnnotations;
        /** @type {?} */
        var toRemoveAnnotations;
        loadedData = this.pdfAdapter.annotationSet;
        toKeepAnnotations = this.pdfAdapter.annotations;
        toRemoveAnnotations = this.pdfAdapter.annotationSet.annotations
            .filter(function (annotation) { return !_this.pdfAdapter.annotations.map(function (a) { return a.id; }).includes(annotation.id); });
        toKeepAnnotations.forEach(function (annotation) {
            _this.apiHttpService.saveAnnotation(annotation).subscribe(function (response) { return _this.log.info('Successfully saved annotation:' + response); }, function (error) { return _this.log.error('There has been a problem saving the annotation:' + annotation.id + '-' + error); });
        });
        toRemoveAnnotations.forEach(function (annotation) {
            _this.apiHttpService.deleteAnnotation(annotation).subscribe(function (response) { return _this.log.info('Successfully deleted annotation:' + response); }, function (error) { return _this.log.error('There has been a problem deleting annotation:' + annotation.id + '-' + error); });
        });
        loadedData.annotations.splice(0, loadedData.annotations.length);
        loadedData.annotations.concat(toKeepAnnotations);
        this.pdfAdapter.annotationSet = loadedData;
    };
    /**
     * @param {?} annotation
     * @param {?=} type
     * @return {?}
     */
    AnnotationStoreService.prototype.saveAnnotation = /**
     * @param {?} annotation
     * @param {?=} type
     * @return {?}
     */
    function (annotation, type) {
        var _this = this;
        this.apiHttpService.saveAnnotation(annotation).subscribe(function (response) {
            if (type === 'addComment' || type === 'editComment') {
                _this.pdfAdapter.annotationSet.annotations[_this.pdfAdapter.annotationSet.annotations
                    .findIndex(function (x) { return x.id === annotation.id; })] = response.body;
            }
            _this.log.info('Successfully saved annotation:' + response);
        }, function (error) { return _this.log.error('There has been a problem saving the annotation:' + annotation.id + '-' + error); });
    };
    /**
     * @param {?} annotation
     * @return {?}
     */
    AnnotationStoreService.prototype.deleteAnnotation = /**
     * @param {?} annotation
     * @return {?}
     */
    function (annotation) {
        var _this = this;
        this.apiHttpService.deleteAnnotation(annotation).subscribe(function (response) {
            _this.log.info('Successfully deleted annotation:' + annotation.id + '-' + response);
        }, function (error) { return _this.log.error('There has been a problem deleting annotation:' + annotation.id + '-' + error); });
    };
    /**
     * @param {?} comment
     * @return {?}
     */
    AnnotationStoreService.prototype.editComment = /**
     * @param {?} comment
     * @return {?}
     */
    function (comment) {
        this.pdfAdapter.editComment(comment);
    };
    /**
     * @param {?} annotationId
     * @return {?}
     */
    AnnotationStoreService.prototype.getAnnotationById = /**
     * @param {?} annotationId
     * @return {?}
     */
    function (annotationId) {
        var _this = this;
        return new Promise(function (resolve) {
            _this.getAnnotation(annotationId, function (annotation) {
                resolve(annotation);
            });
        });
    };
    /**
     * @param {?} pageNumber
     * @return {?}
     */
    AnnotationStoreService.prototype.getAnnotationsForPage = /**
     * @param {?} pageNumber
     * @return {?}
     */
    function (pageNumber) {
        var _this = this;
        return new Promise(function (resolve) {
            _this.getAnnotations(pageNumber, function (pageData) {
                resolve(pageData);
            });
        });
    };
    /**
     * @param {?} annotationId
     * @return {?}
     */
    AnnotationStoreService.prototype.getCommentsForAnnotation = /**
     * @param {?} annotationId
     * @return {?}
     */
    function (annotationId) {
        var _this = this;
        return new Promise(function (resolve) {
            _this.getComments(annotationId, function (comments) {
                resolve(comments);
            });
        });
    };
    /**
     * @param {?} annotationId
     * @param {?} callback
     * @return {?}
     */
    AnnotationStoreService.prototype.getAnnotation = /**
     * @param {?} annotationId
     * @param {?} callback
     * @return {?}
     */
    function (annotationId, callback) {
        this.pdfAnnotateWrapper.getStoreAdapter()
            .getAnnotation(this.pdfRenderService.getRenderOptions().documentId, annotationId)
            .then(callback);
    };
    /**
     * @param {?} annotationId
     * @param {?} callback
     * @return {?}
     */
    AnnotationStoreService.prototype.getComments = /**
     * @param {?} annotationId
     * @param {?} callback
     * @return {?}
     */
    function (annotationId, callback) {
        this.pdfAnnotateWrapper.getStoreAdapter()
            .getComments(this.pdfRenderService.getRenderOptions().documentId, annotationId)
            .then(callback);
    };
    /**
     * @param {?} comment
     * @return {?}
     */
    AnnotationStoreService.prototype.addComment = /**
     * @param {?} comment
     * @return {?}
     */
    function (comment) {
        this.pdfAnnotateWrapper.getStoreAdapter()
            .addComment(this.pdfRenderService.getRenderOptions().documentId, comment.annotationId, comment.content)
            .then();
    };
    /**
     * @param {?} pageNumber
     * @param {?} callback
     * @return {?}
     */
    AnnotationStoreService.prototype.getAnnotations = /**
     * @param {?} pageNumber
     * @param {?} callback
     * @return {?}
     */
    function (pageNumber, callback) {
        this.pdfAnnotateWrapper.getStoreAdapter()
            .getAnnotations(this.pdfRenderService.getRenderOptions().documentId, pageNumber)
            .then(callback);
    };
    /**
     * @param {?} commentId
     * @return {?}
     */
    AnnotationStoreService.prototype.deleteComment = /**
     * @param {?} commentId
     * @return {?}
     */
    function (commentId) {
        this.pdfAnnotateWrapper.getStoreAdapter()
            .deleteComment(this.pdfRenderService.getRenderOptions().documentId, commentId)
            .then();
    };
    /**
     * @param {?} annotationId
     * @param {?} pageNumber
     * @return {?}
     */
    AnnotationStoreService.prototype.deleteAnnotationById = /**
     * @param {?} annotationId
     * @param {?} pageNumber
     * @return {?}
     */
    function (annotationId, pageNumber) {
        return __awaiter(this, void 0, void 0, function () {
            var renderOptions;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        renderOptions = this.pdfRenderService.getRenderOptions();
                        return [4 /*yield*/, this.pdfAnnotateWrapper.getStoreAdapter()
                                .deleteAnnotation(renderOptions.documentId, annotationId)];
                    case 1:
                        _a.sent();
                        this.renderPage(renderOptions, pageNumber);
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * @param {?} renderOptions
     * @param {?} pageNumber
     * @return {?}
     */
    AnnotationStoreService.prototype.renderPage = /**
     * @param {?} renderOptions
     * @param {?} pageNumber
     * @return {?}
     */
    function (renderOptions, pageNumber) {
        renderOptions.rotate = this.pdfRenderService.getPageRotation(renderOptions, { pageNumber: pageNumber });
        this.pdfAnnotateWrapper.renderPage(pageNumber, renderOptions);
    };
    /**
     * @return {?}
     */
    AnnotationStoreService.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        if (this.annotationChangeSubscription) {
            this.annotationChangeSubscription.unsubscribe();
        }
    };
    AnnotationStoreService.decorators = [
        { type: Injectable }
    ];
    AnnotationStoreService.ctorParameters = function () { return [
        { type: EmLoggerService },
        { type: PdfAdapter },
        { type: ApiHttpService },
        { type: PdfService },
        { type: PdfAnnotateWrapper },
        { type: PdfRenderService }
    ]; };
    return AnnotationStoreService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var CommentsComponent = /** @class */ (function () {
    function CommentsComponent(annotationStoreService, pdfService, utils, pdfRenderService, log) {
        this.annotationStoreService = annotationStoreService;
        this.pdfService = pdfService;
        this.utils = utils;
        this.pdfRenderService = pdfRenderService;
        this.log = log;
        this.log.setClass('CommentsComponent');
    }
    /**
     * @return {?}
     */
    CommentsComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.dataLoadedSub = this.pdfRenderService.getDataLoadedSub()
            .subscribe(function (isDataLoaded) {
            if (isDataLoaded) {
                _this.showAllComments();
                _this.preRun();
            }
        });
    };
    /**
     * @return {?}
     */
    CommentsComponent.prototype.redrawCommentItemComponents = /**
     * @return {?}
     */
    function () {
        var _this = this;
        setTimeout(function () {
            /** @type {?} */
            var previousCommentItem;
            _this.sortCommentItemComponents().forEach(function (commentItem) {
                previousCommentItem = _this.isOverlapping(commentItem, previousCommentItem);
            });
        });
    };
    /**
     * @return {?}
     */
    CommentsComponent.prototype.sortCommentItemComponents = /**
     * @return {?}
     */
    function () {
        var _this = this;
        return this.commentItems.map(function (commentItem) { return commentItem; })
            .sort(function (a, b) {
            return _this.processSort(a, b);
        });
    };
    /**
     * @param {?} a
     * @param {?} b
     * @return {?}
     */
    CommentsComponent.prototype.processSort = /**
     * @param {?} a
     * @param {?} b
     * @return {?}
     */
    function (a, b) {
        if (this.isAnnotationOnSameLine(a, b)) {
            if (a.annotationLeftPos < b.annotationLeftPos) {
                return -1;
            }
            if (a.annotationLeftPos >= b.annotationLeftPos) {
                return 1;
            }
        }
        if (a.annotationTopPos < b.annotationTopPos) {
            return -1;
        }
        if (a.annotationTopPos >= b.annotationTopPos) {
            return 1;
        }
        return 0;
    };
    /**
     * @param {?} a
     * @param {?} b
     * @return {?}
     */
    CommentsComponent.prototype.isAnnotationOnSameLine = /**
     * @param {?} a
     * @param {?} b
     * @return {?}
     */
    function (a, b) {
        /** @type {?} */
        var delta = (a.annotationHeight >= b.annotationHeight) ? a.annotationHeight : b.annotationHeight;
        if (this.utils.difference(a.annotationTopPos, b.annotationTopPos) > delta) {
            return false;
        }
        return true;
    };
    /**
     * @param {?} commentItem
     * @param {?} previousCommentItem
     * @return {?}
     */
    CommentsComponent.prototype.isOverlapping = /**
     * @param {?} commentItem
     * @param {?} previousCommentItem
     * @return {?}
     */
    function (commentItem, previousCommentItem) {
        commentItem.commentTopPos = commentItem.annotationTopPos;
        if (previousCommentItem) {
            /** @type {?} */
            var endOfPreviousCommentItem = (previousCommentItem.commentTopPos + previousCommentItem.commentHeight);
            if (commentItem.commentTopPos <= endOfPreviousCommentItem) {
                commentItem.commentTopPos = endOfPreviousCommentItem;
            }
        }
        return commentItem;
    };
    /**
     * @return {?}
     */
    CommentsComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        if (this.pageNumSub) {
            this.pageNumSub.unsubscribe();
        }
        if (this.dataLoadedSub) {
            this.dataLoadedSub.unsubscribe();
        }
    };
    /**
     * @return {?}
     */
    CommentsComponent.prototype.preRun = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.pageNumSub = this.pdfService.getPageNumber().subscribe(function (pageNumber) {
            _this.pageNumber = pageNumber;
        });
    };
    /**
     * @return {?}
     */
    CommentsComponent.prototype.showAllComments = /**
     * @return {?}
     */
    function () {
        var _this = this;
        // todo - refactor this out of component
        this.annotations = [];
        for (var i = 0; i < this.pdfRenderService.getPdfPages() + 1; i++) {
            this.annotationStoreService.getAnnotationsForPage(i)
                .then(function (pageData) {
                _this.annotations = _this.annotations.concat(pageData.annotations.slice());
            });
        }
    };
    /**
     * @return {?}
     */
    CommentsComponent.prototype.handleAnnotationBlur = /**
     * @return {?}
     */
    function () {
        this.showAllComments();
    };
    /**
     * @param {?} event
     * @return {?}
     */
    CommentsComponent.prototype.handleAnnotationClick = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        var _this = this;
        /** @type {?} */
        var annotationId = event.getAttribute('data-pdf-annotate-id');
        this.annotationStoreService.getAnnotationById(annotationId)
            .then(function (annotation) {
            _this.annotationStoreService.setAnnotationFocusSubject(annotation);
            _this.annotationStoreService.setCommentFocusSubject(annotation);
            _this.annotationStoreService.setToolBarUpdate(annotation, true);
        });
    };
    CommentsComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app-comments',
                    template: "<div *ngIf=\"pageNumber\" id=\"comment-wrapper\">\n  <div class=\"comment-list-container\">\n\n    <div *ngFor=\"let annotation of annotations\" class=\"highlight-group\">\n      <app-comment-item #commentItem\n                        *ngFor=\"let comment of annotation.comments\"\n                        [annotation]=\"annotation\"\n                        [comment]=\"comment\"\n                        (commentSubmitted)='showAllComments()'\n                        (commentRendered)='redrawCommentItemComponents()'\n      ></app-comment-item>\n    </div>\n  </div>\n</div>\n",
                    styles: ["#comment-wrapper{position:absolute;height:100%;width:380px;right:0;overflow:hidden;z-index:0;font-family:nta,Arial,sans-serif;-webkit-font-smoothing:antialiased;font-size:12px}#comment-wrapper .comment-list{font-size:12px;position:absolute;top:38px;left:0;right:0;bottom:0}#comment-wrapper .comment-list-container{position:absolute;top:0;left:0;right:0;bottom:47px;overflow-x:hidden;overflow-y:auto}"]
                }] }
    ];
    CommentsComponent.ctorParameters = function () { return [
        { type: AnnotationStoreService },
        { type: PdfService },
        { type: Utils },
        { type: PdfRenderService },
        { type: EmLoggerService }
    ]; };
    CommentsComponent.propDecorators = {
        commentItems: [{ type: ViewChildren, args: ['commentItem',] }]
    };
    return CommentsComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var CommentItemComponent = /** @class */ (function () {
    function CommentItemComponent(annotationStoreService, pdfService, pdfRenderService, ref, renderer, utils, log) {
        this.annotationStoreService = annotationStoreService;
        this.pdfService = pdfService;
        this.pdfRenderService = pdfRenderService;
        this.ref = ref;
        this.renderer = renderer;
        this.utils = utils;
        this.log = log;
        this.commentSubmitted = new EventEmitter();
        this.commentRendered = new EventEmitter();
        this.model = new Comment(null, null, null, null, null, null, null, null, null);
        this.log.setClass('CommentItemComponent');
    }
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.hideButton = true;
        this.focused = false;
        this.sliceComment = this.comment.content;
        this.commentFocusSub = this.annotationStoreService.getCommentFocusSubject()
            .subscribe(function (options) {
            if (options.annotation.id === _this.comment.annotationId) {
                if (options.showButton) {
                    _this.onEdit();
                }
                else {
                    _this.handleShowBtn();
                }
                _this.ref.detectChanges();
            }
            else {
                _this.onBlur();
            }
        });
        this.commentBtnSub = this.annotationStoreService.getCommentBtnSubject()
            .subscribe(function (commentId) {
            (commentId === _this.comment.id) ? _this.handleShowBtn() : _this.handleHideBtn();
        });
        this.dataLoadedSub = this.pdfRenderService.getDataLoadedSub()
            .subscribe(function (dataLoaded) {
            if (dataLoaded) {
                _this.annotationTopPos = _this.getRelativePosition(_this.comment.annotationId);
                _this.commentTopPos = _this.annotationTopPos;
                _this.utils.sortByX(_this.annotation.rectangles, true);
                _this.annotationHeight = _this.utils.getAnnotationLineHeight(_this.annotation.rectangles);
                _this.annotationLeftPos = _this.annotation.rectangles[0].x;
                _this.commentRendered.emit(true);
                _this.collapseComment();
            }
        });
        this.commentItem.statusChanges.subscribe(function () {
            if (_this.focused) {
                _this.expandComment();
            }
        });
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.setHeight = /**
     * @return {?}
     */
    function () {
        this.renderer.setStyle(this.commentArea.nativeElement, 'height', 'fit-content');
        this.renderer.setStyle(this.commentArea.nativeElement, 'height', (this.commentArea.nativeElement.scrollHeight) + 'px');
        this.commentHeight = this.commentSelector.nativeElement.getBoundingClientRect().height;
        this.commentRendered.emit(true);
        if (!this.ref['destroyed']) {
            this.ref.detectChanges();
        }
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        if (this.commentFocusSub) {
            this.commentFocusSub.unsubscribe();
        }
        if (this.commentBtnSub) {
            this.commentBtnSub.unsubscribe();
        }
        if (this.dataLoadedSub) {
            this.dataLoadedSub.unsubscribe();
        }
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.onSubmit = /**
     * @return {?}
     */
    function () {
        /** @type {?} */
        var comment = this.convertFormToComment(this.commentItem);
        this.annotationStoreService.editComment(comment);
        this.commentSubmitted.emit(this.annotation);
        this.viewOnly();
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.onEdit = /**
     * @return {?}
     */
    function () {
        this.editOnly();
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.onCancel = /**
     * @return {?}
     */
    function () {
        this.renderer.setProperty(this.commentArea.nativeElement, 'value', this.comment.content);
        this.viewOnly();
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.viewOnly = /**
     * @return {?}
     */
    function () {
        this.renderer.addClass(this.commentArea.nativeElement, 'view-mode');
        this.focused = false;
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.editOnly = /**
     * @return {?}
     */
    function () {
        this.focused = true;
        this.renderer.removeClass(this.commentArea.nativeElement, 'view-mode');
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.isModified = /**
     * @return {?}
     */
    function () {
        if (this.comment.createdDate === null) {
            return false;
        }
        else if (this.comment.lastModifiedBy === null) {
            return false;
        }
        else if (this.comment.createdDate === this.comment.lastModifiedDate) {
            return false;
        }
        else {
            return true;
        }
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.onBlur = /**
     * @return {?}
     */
    function () {
        if (!this.ref['destroyed']) {
            this.ref.detectChanges();
        }
    };
    /**
     * @param {?} commentForm
     * @return {?}
     */
    CommentItemComponent.prototype.convertFormToComment = /**
     * @param {?} commentForm
     * @return {?}
     */
    function (commentForm) {
        return new Comment(this.comment.id, this.comment.annotationId, null, null, new Date(), null, null, null, commentForm.value.content);
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.handleDeleteComment = /**
     * @return {?}
     */
    function () {
        this.annotationStoreService.deleteComment(this.comment.id);
    };
    /**
     * @param {?} event
     * @return {?}
     */
    CommentItemComponent.prototype.handleCommentClick = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        event.stopPropagation();
        this.annotationStoreService.setCommentBtnSubject(this.comment.id);
        this.annotationStoreService.setAnnotationFocusSubject(this.annotation);
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.handleShowBtn = /**
     * @return {?}
     */
    function () {
        var _this = this;
        new Promise(function (resolve) {
            _this.hideButton = false;
            _this.expandComment();
            resolve('Success');
        }).then(function () {
            _this.setHeight();
            setTimeout(function () {
                _this.commentArea.nativeElement.focus();
            });
        });
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.handleHideBtn = /**
     * @return {?}
     */
    function () {
        var _this = this;
        new Promise(function (resolve) {
            if (!_this.commentItem.value.content) {
                _this.annotationStoreService.deleteComment(_this.comment.id);
            }
            _this.focused = false;
            _this.hideButton = true;
            _this.collapseComment();
            resolve('Success');
        }).then(function () {
            _this.setHeight();
        });
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.collapseComment = /**
     * @return {?}
     */
    function () {
        var _this = this;
        new Promise(function (resolve) {
            _this.expandComment();
            resolve('Success');
        }).then(function () {
            if (!_this.isCommentEmpty()) {
                _this.shrinkComment();
            }
            _this.renderer.addClass(_this.commentArea.nativeElement, 'collapsed');
            _this.renderer.removeClass(_this.commentArea.nativeElement, 'expanded');
            _this.renderer.addClass(_this.detailsWrapper.nativeElement, 'collapsed');
            _this.renderer.addClass(_this.commentArea.nativeElement, 'view-mode');
            _this.setHeight();
        });
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.isCommentEmpty = /**
     * @return {?}
     */
    function () {
        return this.comment.content === null;
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.isShrinkable = /**
     * @return {?}
     */
    function () {
        return this.commentArea.nativeElement.scrollHeight > 31;
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.shrinkComment = /**
     * @return {?}
     */
    function () {
        if (this.isShrinkable()) {
            this.sliceComment = this.removeMultipleLines().slice(0, 20) + '...';
        }
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.removeMultipleLines = /**
     * @return {?}
     */
    function () {
        return this.comment.content.split('\n').join(' ');
    };
    /**
     * @return {?}
     */
    CommentItemComponent.prototype.expandComment = /**
     * @return {?}
     */
    function () {
        this.renderer.addClass(this.commentArea.nativeElement, 'expanded');
        this.renderer.removeClass(this.commentArea.nativeElement, 'collapsed');
        this.renderer.removeClass(this.detailsWrapper.nativeElement, 'collapsed');
        this.renderer.addClass(this.detailsWrapper.nativeElement, 'expanded');
        this.sliceComment = this.comment.content;
        this.setHeight();
    };
    /**
     * @param {?} annotationId
     * @return {?}
     */
    CommentItemComponent.prototype.getRelativePosition = /**
     * @param {?} annotationId
     * @return {?}
     */
    function (annotationId) {
        /** @type {?} */
        var svgSelector = this.pdfRenderService.getViewerElementRef().nativeElement
            .querySelector("g[data-pdf-annotate-id=\"" + annotationId + "\"]");
        if (svgSelector === null) {
            return null;
        }
        else {
            /** @type {?} */
            var highlightRect = (/** @type {?} */ (svgSelector.getBoundingClientRect()));
            /** @type {?} */
            var wrapperRect = (/** @type {?} */ (this.pdfService.getAnnotationWrapper().nativeElement.getBoundingClientRect()));
            return (highlightRect.y - wrapperRect.top);
        }
    };
    CommentItemComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app-comment-item',
                    template: "<form class=\"aui-comment comment-list-item\"\n      (ngSubmit)=\"onSubmit()\"\n      #commentSelector\n      #commentItem=\"ngForm\"\n      (click)=\"handleCommentClick($event)\"\n      [style.top.px]=\"commentTopPos\">\n  <div #detailsWrapper id=\"detailsWrapper\" class=\"aui-comment__header\">\n    <span *ngIf=\"comment.createdByDetails\" class=\"aui-comment__author\">{{comment.createdByDetails.forename}} {{comment.createdByDetails.surname}}</span>\n    <time #commentDate class=\"aui-comment__meta\" ng-controller=\"datCtrl\">{{ comment.createdDate | date: 'd MMMM y h:mm a' }}</time>\n    <div *ngIf=\"false\">\n      <span>modified By: {{comment.lastModifiedByDetails.forename}} {{comment.lastModifiedByDetails.surname}}</span>\n      <time class=\"aui-comment__meta\" ng-controller=\"datCtrl\"><br>{{ comment.lastModifiedDate | date: 'd MMMM y h:mm a' }}</time>\n    </div>\n  </div>\n\n  <textarea\n    #commentArea\n    (blur)=\"onBlur()\"\n    type=\"text\"\n    [class.mimic-focus]=\"focused\"\n    class=\"aui-comment__content form-control mimic-focus view-mode\"\n    required\n    [ngModel]=\"sliceComment\" name=\"content\"\n    value=\"comment.content\"\n    [readonly]=\"!focused\"></textarea>\n\n  <div [hidden]=\"hideButton\" class=\"aui-comment__footer commentBtns\">\n    <button *ngIf=\"focused\" type=\"submit\" class=\"govuk-button\" role=\"button\">Save</button>\n    <button *ngIf=\"!focused\" (click)=\"onEdit()\" class=\"govuk-button\" role=\"button\">Edit</button>\n    <button\n      *ngIf=\"!focused\"\n      class=\"govuk-button hmcts hmcts-button--secondary\"\n      role=\"button\"\n      (click)=\"handleDeleteComment()\">Delete</button>\n    <button\n      *ngIf=\"focused\"\n      class=\"govuk-button hmcts hmcts-button--secondary\"\n      role=\"button\"\n      (click)=\"onCancel()\">Cancel</button>\n  </div>\n</form>\n",
                    styles: ["form{width:95%;margin-bottom:5px;position:absolute;background-color:#fff;padding:20px 20px 0}form textarea{width:95%;padding:2px;border:none;font-size:17px;font-family:nta,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-weight:400;overflow:hidden;resize:none}.mimic-focus{outline-offset:-2px;outline:#0b0c0c auto 5px}textarea.view-mode:focus{outline:0}#detailsWrapper{padding:0}#detailsWrapper.expanded{margin-bottom:15px}.commentBtns{height:50px}.expanded{margin-top:0}.collapsed{height:30px}textarea.expanded{margin-bottom:10px}textarea.collapsed{margin-top:-25px;max-height:20px}.collapsed>time{display:none}"]
                }] }
    ];
    CommentItemComponent.ctorParameters = function () { return [
        { type: AnnotationStoreService },
        { type: PdfService },
        { type: PdfRenderService },
        { type: ChangeDetectorRef },
        { type: Renderer2 },
        { type: Utils },
        { type: EmLoggerService }
    ]; };
    CommentItemComponent.propDecorators = {
        comment: [{ type: Input }],
        annotation: [{ type: Input }],
        commentSubmitted: [{ type: Output }],
        commentRendered: [{ type: Output }],
        commentSelector: [{ type: ViewChild, args: ['commentSelector',] }],
        commentArea: [{ type: ViewChild, args: ['commentArea',] }],
        commentItem: [{ type: ViewChild, args: ['commentItem',] }],
        detailsWrapper: [{ type: ViewChild, args: ['detailsWrapper',] }],
        commentDate: [{ type: ViewChild, args: ['commentDate',] }]
    };
    return CommentItemComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var NpaService = /** @class */ (function () {
    function NpaService(log, apiHttpService) {
        this.log = log;
        this.apiHttpService = apiHttpService;
        log.setClass('NpaService');
        this.outputDmDocumentId = new Subject();
        this.documentTask = new Subject();
    }
    /**
     * @param {?} dmDocumentId
     * @param {?} outputDmDocumentId
     * @param {?} baseUrl
     * @return {?}
     */
    NpaService.prototype.exportPdf = /**
     * @param {?} dmDocumentId
     * @param {?} outputDmDocumentId
     * @param {?} baseUrl
     * @return {?}
     */
    function (dmDocumentId, outputDmDocumentId, baseUrl) {
        this.log.info('Calling HTTP service for NPA');
        return this.apiHttpService.documentTask(dmDocumentId, outputDmDocumentId, baseUrl);
    };
    NpaService.decorators = [
        { type: Injectable }
    ];
    NpaService.ctorParameters = function () { return [
        { type: EmLoggerService },
        { type: ApiHttpService }
    ]; };
    return NpaService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var ContextualToolbarComponent = /** @class */ (function () {
    function ContextualToolbarComponent(annotationStoreService, ref, pdfRenderService, pdfService, log) {
        this.annotationStoreService = annotationStoreService;
        this.ref = ref;
        this.pdfRenderService = pdfRenderService;
        this.pdfService = pdfService;
        this.log = log;
        this.deletedAnnotation = new EventEmitter();
        this.log.setClass('ContextualToolbarComponent');
        this.toolPos = {
            left: 0,
            top: 0
        };
    }
    /**
     * @return {?}
     */
    ContextualToolbarComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.contextualToolBarOptions = this.annotationStoreService.getToolbarUpdate()
            .subscribe(function (contextualOptions) {
            if (contextualOptions.annotation != null) {
                _this.showToolBar(contextualOptions.annotation, contextualOptions.showDelete);
            }
            else {
                _this.hideToolBar();
            }
        });
        this.isShowToolbar = false;
    };
    /**
     * @return {?}
     */
    ContextualToolbarComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        this.ref.detach();
        if (this.contextualToolBarOptions) {
            this.contextualToolBarOptions.unsubscribe();
        }
    };
    /**
     * @param {?} annotation
     * @param {?=} showDelete
     * @return {?}
     */
    ContextualToolbarComponent.prototype.showToolBar = /**
     * @param {?} annotation
     * @param {?=} showDelete
     * @return {?}
     */
    function (annotation, showDelete) {
        this.annotation = annotation;
        this.showDelete = showDelete;
        this.toolPos = this.getRelativePosition(annotation.id);
        this.isShowToolbar = true;
        if (!this.ref['destroyed']) {
            this.ref.detectChanges();
        }
    };
    /**
     * @param {?} annotationId
     * @return {?}
     */
    ContextualToolbarComponent.prototype.getRelativePosition = /**
     * @param {?} annotationId
     * @return {?}
     */
    function (annotationId) {
        /** @type {?} */
        var svgSelector = this.pdfRenderService.getViewerElementRef().nativeElement
            .querySelector("g[data-pdf-annotate-id=\"" + annotationId + "\"]");
        /** @type {?} */
        var highlightRect = (/** @type {?} */ (svgSelector.getBoundingClientRect()));
        /** @type {?} */
        var wrapper = this.pdfService.getAnnotationWrapper().nativeElement;
        /** @type {?} */
        var wrapperRect = (/** @type {?} */ (wrapper.getBoundingClientRect()));
        /** @type {?} */
        var left = ((highlightRect.x - wrapperRect.left)
            - 175) + highlightRect.width / 2;
        // Minus half the toolbar width + half the length of the highlight
        /** @type {?} */
        var top = ((highlightRect.y - wrapperRect.top)
            - 59) - 5;
        return {
            left: left,
            top: top
        };
    };
    /**
     * @return {?}
     */
    ContextualToolbarComponent.prototype.hideToolBar = /**
     * @return {?}
     */
    function () {
        this.annotation = null;
        this.isShowToolbar = false;
        this.showDelete = false;
        if (!this.ref['destroyed']) {
            this.ref.detectChanges();
        }
    };
    /**
     * @return {?}
     */
    ContextualToolbarComponent.prototype.handleCommentBtnClick = /**
     * @return {?}
     */
    function () {
        var _this = this;
        if (this.annotation.comments.length === 0) {
            this.annotationStoreService.addComment(new Comment(null, this.annotation.id, null, null, null, null, null, null, null));
        }
        setTimeout(function () {
            /** @type {?} */
            var tempAnnotation = _this.annotation;
            _this.hideToolBar();
            _this.annotationStoreService.setCommentFocusSubject(tempAnnotation, true);
        }, 10);
    };
    /**
     * @return {?}
     */
    ContextualToolbarComponent.prototype.handleHighlightBtnClick = /**
     * @return {?}
     */
    function () {
        this.hideToolBar();
    };
    /**
     * @return {?}
     */
    ContextualToolbarComponent.prototype.handleDeleteBtnClick = /**
     * @return {?}
     */
    function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.annotationStoreService.deleteAnnotationById(this.annotation.id, this.annotation.page)];
                    case 1:
                        _a.sent();
                        this.hideToolBar();
                        this.deletedAnnotation.emit('deleted annotation');
                        return [2 /*return*/];
                }
            });
        });
    };
    ContextualToolbarComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app-contextual-toolbar',
                    template: "<div [hidden]=\"!isShowToolbar\" class=\"toolbar\"\n     [style.left.px]=\"toolPos.left\"\n     [style.top.px]=\"toolPos.top\">\n\n  <button\n    [hidden]=\"showDelete\"\n    type=\"button\" class=\"aui__toolbar-button aui__toolbar-button--comments contextual-btn leftButton\"\n    title=\"Highlight\"\n    (click)=\"handleHighlightBtnClick()\"\n  ><span>Add Highlight</span></button>\n\n  <button\n    [hidden]=\"!showDelete\"\n    type=\"button\"\n    title=\"Delete\" class=\"aui__toolbar-button aui__toolbar-button--comments contextual-btn leftButton\"\n    (click)=\"handleDeleteBtnClick()\"\n  ><span>Remove Highlight</span></button>\n\n  <button type=\"button\" title=\"Comment\" class=\"aui__toolbar-button aui__toolbar-button--comments contextual-btn rightButton\"\n          (click)=\"handleCommentBtnClick()\"\n  ><span>Comment</span></button>\n\n\n  <div class=\"arrow-down\">\n    <div class=\"inner-triangle\"></div>\n  </div>\n\n</div>\n",
                    styles: [".toolbar{position:absolute;background-color:#fff;height:52px;width:350px;margin:0 auto;text-shadow:1px 1px 0 #fff;z-index:1;border:1px solid #c1c1c1;box-shadow:0 2px #c1c1c1}.toolbar .spacer{display:inline-block;border-left:1px solid #c1c1c1;height:34px;margin:0 5px -11px}.toolbar button span{margin-left:20px}.toolbar button{padding:0;margin-left:2.5%;margin-right:2.5%;margin-top:6px;height:40px;border:0}.toolbar button:hover{border:1px solid #000}.contextual-btn{font-size:16px;background:5px 50%/20px 20px no-repeat #fff}.rightButton{width:124px;background-image:url(/assets/images/icon-document-comments.svg)}.leftButton{background-image:url(/assets/images/annotate-highlight.svg);width:190px}.arrow-down{margin:53px auto 0;width:0;height:0;border-left:12px solid transparent;border-right:12px solid transparent;border-top:12px solid #c1c1c1}.inner-triangle{position:relative;top:-13px;left:-10px;width:0;height:0;border-left:10px solid transparent;border-right:10px solid transparent;border-top:10px solid #fff}"]
                }] }
    ];
    ContextualToolbarComponent.ctorParameters = function () { return [
        { type: AnnotationStoreService },
        { type: ChangeDetectorRef },
        { type: PdfRenderService },
        { type: PdfService },
        { type: EmLoggerService }
    ]; };
    ContextualToolbarComponent.propDecorators = {
        deletedAnnotation: [{ type: Output }]
    };
    return ContextualToolbarComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var RenderOptions = /** @class */ (function () {
    function RenderOptions(documentId, pdfDocument, scale, rotate, rotationPages) {
        this.documentId = documentId;
        this.pdfDocument = pdfDocument;
        this.scale = scale;
        this.rotate = rotate;
        this.rotationPages = rotationPages;
    }
    return RenderOptions;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var RotationComponent = /** @class */ (function () {
    function RotationComponent(pdfRenderService, log) {
        this.pdfRenderService = pdfRenderService;
        this.log = log;
        this.rotationStyle = {};
        this.viewerStyle = {};
        this.log.setClass('RotationComponent');
    }
    /**
     * @return {?}
     */
    RotationComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        /** @type {?} */
        var height = "" + ((/** @type {?} */ (document.getElementById('pageContainer' + this.pageNumber).querySelector('.textLayer')))).style.height;
        this.rotationStyle = {
            'margin-top': "-" + height
        };
        this.viewerStyle = {
            'top': "" + height
        };
    };
    /**
     * @param {?} rotateVal
     * @return {?}
     */
    RotationComponent.prototype.calculateRotation = /**
     * @param {?} rotateVal
     * @return {?}
     */
    function (rotateVal) {
        /** @type {?} */
        var circleDegrees = 360;
        return (rotateVal % circleDegrees + circleDegrees) % circleDegrees;
    };
    /**
     * @return {?}
     */
    RotationComponent.prototype.onRotateClockwise = /**
     * @return {?}
     */
    function () {
        var _this = this;
        /** @type {?} */
        var RENDER_OPTIONS = this.pdfRenderService.getRenderOptions();
        /** @type {?} */
        var rotation = RENDER_OPTIONS.rotationPages
            .find(function (rotatePage) { return rotatePage.page === _this.pageNumber; }).rotate;
        RENDER_OPTIONS.rotationPages
            .find(function (rotatePage) { return rotatePage.page === _this.pageNumber; }).rotate = this.calculateRotation(rotation + 90);
        this.pdfRenderService.setRenderOptions(RENDER_OPTIONS);
        this.pdfRenderService.render();
    };
    RotationComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app-rotation-toolbar',
                    template: "<div class=\"viewer-menu\" [ngStyle]=\"viewerStyle\">\n  <button\n    [ngStyle]=\"rotationStyle\"\n    class=\"govuk-button hmcts hmcts-button--secondary rotate\"\n    title=\"Clockwise\"\n    role=\"button\"\n    (click)=\"onRotateClockwise()\">Rotate</button>\n</div>\n",
                    styles: [".viewer-menu{width:100%;position:-webkit-sticky;position:sticky;left:0}.rotate{background-repeat:no-repeat;background-size:14px 14px;background-position:3px 50%;background-image:url(/assets/images/viewer-rotate.svg);padding-left:25px;float:right}"]
                }] }
    ];
    RotationComponent.ctorParameters = function () { return [
        { type: PdfRenderService },
        { type: EmLoggerService }
    ]; };
    RotationComponent.propDecorators = {
        pageNumber: [{ type: Input }]
    };
    return RotationComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var RotationFactoryService = /** @class */ (function () {
    function RotationFactoryService(componentFactoryResolver, log, injector, appRef) {
        this.componentFactoryResolver = componentFactoryResolver;
        this.log = log;
        this.injector = injector;
        this.appRef = appRef;
        this.log.setClass('RotationFactoryService');
    }
    /**
     * @param {?} rotationModel
     * @return {?}
     */
    RotationFactoryService.prototype.addToDom = /**
     * @param {?} rotationModel
     * @return {?}
     */
    function (rotationModel) {
        this.log.info('Adding rotate button to PDF page ' + rotationModel.pageNumber);
        /** @type {?} */
        var componentRef = this.componentFactoryResolver
            .resolveComponentFactory(RotationComponent)
            .create(this.injector);
        componentRef.instance.pageNumber = rotationModel.pageNumber;
        this.appRef.attachView(componentRef.hostView);
        /** @type {?} */
        var domElem = (/** @type {?} */ (((/** @type {?} */ (componentRef.hostView)))
            .rootNodes[0]));
        rotationModel.pageDom.appendChild(domElem);
        return componentRef;
    };
    RotationFactoryService.decorators = [
        { type: Injectable }
    ];
    RotationFactoryService.ctorParameters = function () { return [
        { type: ComponentFactoryResolver },
        { type: EmLoggerService },
        { type: Injector },
        { type: ApplicationRef }
    ]; };
    return RotationFactoryService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var AnnotationPdfViewerComponent = /** @class */ (function () {
    function AnnotationPdfViewerComponent(pdfService, npaService, apiHttpService, annotationStoreService, utils, ref, renderer, pdfAnnotateWrapper, pdfRenderService, rotationFactoryService, log) {
        this.pdfService = pdfService;
        this.npaService = npaService;
        this.apiHttpService = apiHttpService;
        this.annotationStoreService = annotationStoreService;
        this.utils = utils;
        this.ref = ref;
        this.renderer = renderer;
        this.pdfAnnotateWrapper = pdfAnnotateWrapper;
        this.pdfRenderService = pdfRenderService;
        this.rotationFactoryService = rotationFactoryService;
        this.log = log;
        this.rotationComponents = [];
    }
    /**
     * @return {?}
     */
    AnnotationPdfViewerComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.loadAnnotations(this.annotate);
        this.pdfService.preRun();
        this.pdfRenderService.setRenderOptions(new RenderOptions(this.url, null, parseFloat('1.33'), 0, []));
        if (this.rotate) {
            this.pdfPageSubscription = this.pdfRenderService.listPagesSubject
                .subscribe(function (listPages) {
                _this.rotationComponents.forEach(function (rc) { return rc.destroy(); });
                listPages.forEach(function (pageDetails) {
                    _this.rotationComponents.push(_this.rotationFactoryService.addToDom(pageDetails));
                });
            });
        }
        this.pdfRenderService.render(this.viewerElementRef);
        this.pdfService.setAnnotationWrapper(this.annotationWrapper);
        this.pageNumberSubscription = this.pdfService.getPageNumber()
            .subscribe(function (page) { return _this.page = page; });
        this.focusedAnnotationSubscription = this.annotationStoreService.getAnnotationFocusSubject()
            .subscribe(function (focusedAnnotation) { return _this.focusHighlightStyle(focusedAnnotation); });
    };
    /**
     * @return {?}
     */
    AnnotationPdfViewerComponent.prototype.ngAfterViewInit = /**
     * @return {?}
     */
    function () {
        this.pdfAnnotateWrapper.getUi().addEventListener('annotation:click', this.handleAnnotationClick.bind(this));
    };
    /**
     * @return {?}
     */
    AnnotationPdfViewerComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        if (this.pageNumberSubscription) {
            this.pageNumberSubscription.unsubscribe();
        }
        if (this.focusedAnnotationSubscription) {
            this.focusedAnnotationSubscription.unsubscribe();
        }
        if (this.pdfPageSubscription) {
            this.pdfPageSubscription.unsubscribe();
        }
    };
    /**
     * @param {?} annotate
     * @return {?}
     */
    AnnotationPdfViewerComponent.prototype.loadAnnotations = /**
     * @param {?} annotate
     * @return {?}
     */
    function (annotate) {
        if (annotate) {
            this.log.info('annotations are enabled');
            this.apiHttpService.setBaseUrl(this.baseUrl);
            this.annotationStoreService.preLoad(this.annotationSet);
            this.npaService.outputDmDocumentId.next(this.outputDmDocumentId);
        }
        else {
            this.log.info('annotations are disabled');
            this.annotationStoreService.preLoad(null);
        }
    };
    /**
     * @param {?} event
     * @param {?=} isPage
     * @return {?}
     */
    AnnotationPdfViewerComponent.prototype.handleClick = /**
     * @param {?} event
     * @param {?=} isPage
     * @return {?}
     */
    function (event, isPage) {
        if (this.annotate) {
            if (!this.utils.clickIsHighlight(event)) {
                this.unfocusAnnotation();
                this.annotationStoreService.setToolBarUpdate(null, null);
            }
            this.commentsComponent.handleAnnotationBlur();
            if (isPage) {
                this.pdfService.setPageNumber(this.utils.getClickedPage(event));
            }
        }
    };
    /**
     * @return {?}
     */
    AnnotationPdfViewerComponent.prototype.renderComments = /**
     * @return {?}
     */
    function () {
        this.unfocusAnnotation();
        this.commentsComponent.showAllComments();
    };
    /**
     * @return {?}
     */
    AnnotationPdfViewerComponent.prototype.unfocusAnnotation = /**
     * @return {?}
     */
    function () {
        this.annotationStoreService.setAnnotationFocusSubject(new Annotation());
        this.annotationStoreService.setCommentBtnSubject(null);
        this.annotationStoreService.setCommentFocusSubject(new Annotation(), null);
    };
    /**
     * @param {?} event
     * @return {?}
     */
    AnnotationPdfViewerComponent.prototype.handleAnnotationClick = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        var _this = this;
        if (!this.contextualToolbar.isShowToolbar) {
            /** @type {?} */
            var annotationId = event.getAttribute('data-pdf-annotate-id');
            this.annotationStoreService.getAnnotationById(annotationId)
                .then(function (annotation) {
                _this.annotationStoreService.setAnnotationFocusSubject(annotation);
                _this.annotationStoreService.setCommentFocusSubject(annotation);
                _this.annotationStoreService.setToolBarUpdate(annotation, true);
            });
        }
    };
    /**
     * @param {?} focusedAnnotation
     * @return {?}
     */
    AnnotationPdfViewerComponent.prototype.focusHighlightStyle = /**
     * @param {?} focusedAnnotation
     * @return {?}
     */
    function (focusedAnnotation) {
        var _this = this;
        Array.from(this.viewerElementRef.nativeElement.querySelector("#pageContainer" + this.page + " .annotationLayer").childNodes)
            .forEach(function (annotationDom) {
            if (annotationDom.dataset.pdfAnnotateId === focusedAnnotation.id) {
                _this.renderer.addClass(annotationDom, 'comment-selected');
            }
            else {
                _this.renderer.removeClass(annotationDom, 'comment-selected');
            }
        });
        if (!this.ref['destroyed']) {
            this.ref.detectChanges();
        }
    };
    AnnotationPdfViewerComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app-annotation-pdf-viewer',
                    template: "\n<app-comments (click)=\"handleClick($event, false)\" #commentsComponent\n              *ngIf=\"annotate\"></app-comments>\n\n<div id=\"annotation-wrapper\" #annotationWrapper>\n  <app-contextual-toolbar (deletedAnnotation)=\"renderComments()\" #contextualToolbar></app-contextual-toolbar>\n\n  <div id=\"content-wrapper\"\n       #contentWrapper\n       (click)=\"handleClick($event, true)\">\n    <div id=\"viewer\" #viewer class=\"pdfViewer\"></div>\n  </div>\n</div>\n",
                    styles: ["#annotation-wrapper{position:relative;width:100%}#content-wrapper{overflow:hidden}"]
                }] }
    ];
    AnnotationPdfViewerComponent.ctorParameters = function () { return [
        { type: PdfService },
        { type: NpaService },
        { type: ApiHttpService },
        { type: AnnotationStoreService },
        { type: Utils },
        { type: ChangeDetectorRef },
        { type: Renderer2 },
        { type: PdfAnnotateWrapper },
        { type: PdfRenderService },
        { type: RotationFactoryService },
        { type: EmLoggerService }
    ]; };
    AnnotationPdfViewerComponent.propDecorators = {
        annotate: [{ type: Input }],
        dmDocumentId: [{ type: Input }],
        outputDmDocumentId: [{ type: Input }],
        url: [{ type: Input }],
        annotationSet: [{ type: Input }],
        baseUrl: [{ type: Input }],
        rotate: [{ type: Input }],
        contentWrapper: [{ type: ViewChild, args: ['contentWrapper',] }],
        viewerElementRef: [{ type: ViewChild, args: ['viewer',] }],
        annotationWrapper: [{ type: ViewChild, args: ['annotationWrapper',] }],
        commentsComponent: [{ type: ViewChild, args: ['commentsComponent',] }],
        contextualToolbar: [{ type: ViewChild, args: ['contextualToolbar',] }]
    };
    return AnnotationPdfViewerComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var ImageViewerComponent = /** @class */ (function () {
    function ImageViewerComponent(renderer, log) {
        this.renderer = renderer;
        this.log = log;
        this.log.setClass('ImageViewerComponent');
    }
    /**
     * @return {?}
     */
    ImageViewerComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        this.rotation = 0;
    };
    /**
     * @return {?}
     */
    ImageViewerComponent.prototype.onRotateClockwise = /**
     * @return {?}
     */
    function () {
        this.rotation = this.rotation + 90;
        this.rotateImage();
    };
    /**
     * @return {?}
     */
    ImageViewerComponent.prototype.rotateImage = /**
     * @return {?}
     */
    function () {
        this.log.info('rotating to-' + this.rotation + 'degrees');
        /** @type {?} */
        var styles = ['transform', '-ms-transform', '-o-transform', '-moz-transform', '-webkit-transform'];
        try {
            for (var styles_1 = __values(styles), styles_1_1 = styles_1.next(); !styles_1_1.done; styles_1_1 = styles_1.next()) {
                var style = styles_1_1.value;
                this.renderer.setStyle(this.img.nativeElement, style, "rotate(" + this.rotation + "deg)");
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (styles_1_1 && !styles_1_1.done && (_a = styles_1.return)) _a.call(styles_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
        var e_1, _a;
    };
    ImageViewerComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app-image-viewer',
                    template: "\n    <div id=\"viewer-wrapper\">\n        <button\n          *ngIf=\"rotate\"\n          class=\"govuk-button hmcts hmcts-button--secondary rotate\"\n          title=\"Clockwise\"\n          role=\"button\"\n          (click)=\"onRotateClockwise()\">Rotate</button>\n\n        <img #img *ngIf=\"url\" data-hook=\"dm.viewer.img\" [src]=\"url\"  />\n    </div>",
                    styles: ["#viewer-wrapper{position:relative;width:100%}.rotate{z-index:1;position:absolute;right:0;background-repeat:no-repeat;background-size:14px 14px;background-position:3px 50%;padding-left:25px;background-image:url(/assets/images/viewer-rotate.svg)}.anti{right:24px;-webkit-transform:scaleX(-1);transform:scaleX(-1)}img{width:100%}"]
                }] }
    ];
    ImageViewerComponent.ctorParameters = function () { return [
        { type: Renderer2 },
        { type: EmLoggerService }
    ]; };
    ImageViewerComponent.propDecorators = {
        url: [{ type: Input }],
        originalUrl: [{ type: Input }],
        rotate: [{ type: Input }],
        img: [{ type: ViewChild, args: ['img',] }]
    };
    return ImageViewerComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var UnsupportedViewerComponent = /** @class */ (function () {
    function UnsupportedViewerComponent() {
    }
    /**
     * @return {?}
     */
    UnsupportedViewerComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
    };
    UnsupportedViewerComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app-unsupported-viewer',
                    template: "<p data-hook=\"dm.viewer.unsupported\">\n  This file type is not supported. Please <a href=\"{{url}}\">click here to download</a>.\n</p>\n",
                    styles: [""]
                }] }
    ];
    UnsupportedViewerComponent.ctorParameters = function () { return []; };
    UnsupportedViewerComponent.propDecorators = {
        url: [{ type: Input }],
        originalUrl: [{ type: Input }]
    };
    return UnsupportedViewerComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var UrlFixerService = /** @class */ (function () {
    function UrlFixerService() {
    }
    /**
     * @param {?} url
     * @param {?} baseUrl
     * @return {?}
     */
    UrlFixerService.prototype.fixDm = /**
     * @param {?} url
     * @param {?} baseUrl
     * @return {?}
     */
    function (url, baseUrl) {
        return url.replace(/http.*\/documents\//, baseUrl + "/documents/");
    };
    UrlFixerService.decorators = [
        { type: Injectable }
    ];
    return UrlFixerService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var ViewerFactoryService = /** @class */ (function () {
    function ViewerFactoryService(componentFactoryResolver, annotationStoreService, urlFixer, log) {
        this.componentFactoryResolver = componentFactoryResolver;
        this.annotationStoreService = annotationStoreService;
        this.urlFixer = urlFixer;
        this.log = log;
        this.log.setClass('ViewerFactoryService');
    }
    /**
     * @private
     * @param {?} mimeType
     * @return {?}
     */
    ViewerFactoryService.determineComponent = /**
     * @private
     * @param {?} mimeType
     * @return {?}
     */
    function (mimeType) {
        if (ViewerFactoryService.isImage(mimeType)) {
            return ImageViewerComponent;
        }
        return UnsupportedViewerComponent;
    };
    /**
     * @private
     * @param {?} mimeType
     * @return {?}
     */
    ViewerFactoryService.isImage = /**
     * @private
     * @param {?} mimeType
     * @return {?}
     */
    function (mimeType) {
        return mimeType.startsWith('image/') || mimeType === 'image';
    };
    /**
     * @private
     * @param {?} mimeType
     * @return {?}
     */
    ViewerFactoryService.isPdf = /**
     * @private
     * @param {?} mimeType
     * @return {?}
     */
    function (mimeType) {
        return mimeType === 'application/pdf' || mimeType === 'pdf';
    };
    /**
     * @param {?} documentMetaData
     * @return {?}
     */
    ViewerFactoryService.prototype.getDocumentId = /**
     * @param {?} documentMetaData
     * @return {?}
     */
    function (documentMetaData) {
        /** @type {?} */
        var docArray = documentMetaData._links.self.href.split('/');
        return docArray[docArray.length - 1];
    };
    /**
     * @param {?} viewContainerRef
     * @param {?} contentType
     * @param {?} url
     * @param {?} baseUrl
     * @param {?} originalUrl
     * @param {?} annotate
     * @param {?} annotationSet
     * @param {?} rotate
     * @return {?}
     */
    ViewerFactoryService.prototype.buildComponent = /**
     * @param {?} viewContainerRef
     * @param {?} contentType
     * @param {?} url
     * @param {?} baseUrl
     * @param {?} originalUrl
     * @param {?} annotate
     * @param {?} annotationSet
     * @param {?} rotate
     * @return {?}
     */
    function (viewContainerRef, contentType, url, baseUrl, originalUrl, annotate, annotationSet, rotate) {
        if (ViewerFactoryService.isPdf(contentType) && annotate) {
            this.log.info('Selected pdf viewer with annotations enabled');
            return this.buildAnnotateUi(url, viewContainerRef, baseUrl, annotate, annotationSet, rotate);
        }
        else if (ViewerFactoryService.isPdf(contentType) && !annotate) {
            this.log.info('Selected pdf viewer with annotations disabled');
            return this.buildAnnotateUi(url, viewContainerRef, baseUrl, annotate, null, rotate);
        }
        else if (ViewerFactoryService.isImage(contentType)) {
            this.log.info('Selected image viewer');
            return this.createComponent(ImageViewerComponent, viewContainerRef, originalUrl, url, rotate);
        }
        else {
            this.log.info('Unsupported type for viewer');
            return this.createComponent(UnsupportedViewerComponent, viewContainerRef, originalUrl, url);
        }
    };
    /**
     * @param {?} url
     * @param {?} viewContainerRef
     * @param {?} baseUrl
     * @param {?} annotate
     * @param {?} annotationSet
     * @param {?} rotate
     * @return {?}
     */
    ViewerFactoryService.prototype.buildAnnotateUi = /**
     * @param {?} url
     * @param {?} viewContainerRef
     * @param {?} baseUrl
     * @param {?} annotate
     * @param {?} annotationSet
     * @param {?} rotate
     * @return {?}
     */
    function (url, viewContainerRef, baseUrl, annotate, annotationSet, rotate) {
        viewContainerRef.clear();
        /** @type {?} */
        var componentFactory = this.componentFactoryResolver.resolveComponentFactory(AnnotationPdfViewerComponent);
        /** @type {?} */
        var componentRef = viewContainerRef.createComponent(componentFactory);
        componentRef.instance.annotate = annotate;
        componentRef.instance.annotationSet = annotationSet;
        componentRef.instance.outputDmDocumentId = null; // '4fbdde23-e9a7-4843-b6c0-24d5bf2140ab';
        componentRef.instance.baseUrl = baseUrl;
        componentRef.instance.url = url;
        componentRef.instance.rotate = rotate;
        return componentRef.instance;
    };
    /**
     * @param {?} component
     * @param {?} viewContainerRef
     * @param {?} originalUrl
     * @param {?} url
     * @param {?=} rotate
     * @return {?}
     */
    ViewerFactoryService.prototype.createComponent = /**
     * @param {?} component
     * @param {?} viewContainerRef
     * @param {?} originalUrl
     * @param {?} url
     * @param {?=} rotate
     * @return {?}
     */
    function (component, viewContainerRef, originalUrl, url, rotate) {
        /** @type {?} */
        var componentFactory = this.componentFactoryResolver.resolveComponentFactory(component);
        viewContainerRef.clear();
        /** @type {?} */
        var componentRef = viewContainerRef.createComponent(componentFactory);
        componentRef.instance.originalUrl = originalUrl;
        componentRef.instance.url = url;
        componentRef.instance.rotate = rotate;
        return componentRef.instance;
    };
    ViewerFactoryService.decorators = [
        { type: Injectable }
    ];
    ViewerFactoryService.ctorParameters = function () { return [
        { type: ComponentFactoryResolver },
        { type: AnnotationStoreService },
        { type: UrlFixerService },
        { type: EmLoggerService }
    ]; };
    return ViewerFactoryService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var ViewerAnchorDirective = /** @class */ (function () {
    function ViewerAnchorDirective(viewContainerRef) {
        this.viewContainerRef = viewContainerRef;
    }
    ViewerAnchorDirective.decorators = [
        { type: Directive, args: [{
                    selector: '[appViewerAnchor]',
                },] }
    ];
    ViewerAnchorDirective.ctorParameters = function () { return [
        { type: ViewContainerRef }
    ]; };
    return ViewerAnchorDirective;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var DocumentViewerService = /** @class */ (function () {
    function DocumentViewerService(log, httpClient, state) {
        this.log = log;
        this.httpClient = httpClient;
        this.state = state;
        log.setClass('DocumentViewerService');
    }
    /**
     * @param {?} documentUri
     * @return {?}
     */
    DocumentViewerService.prototype.getDocumentMetadata = /**
     * @param {?} documentUri
     * @return {?}
     */
    function (documentUri) {
        var _this = this;
        /** @type {?} */
        var key = makeStateKey(documentUri);
        /** @type {?} */
        var cache = this.state.get(key, (/** @type {?} */ (null)));
        if (cache) {
            return of(cache);
        }
        return this.httpClient
            .get(documentUri)
            .pipe(map(function (data) {
            _this.state.set(key, data);
            return data;
        }))
            .pipe(catchError(function (error) {
            /** @type {?} */
            var value = { error: error };
            _this.state.set(key, value);
            _this.log.error('Encountered error while downloading document:' + documentUri + '-' + error);
            return of(value);
        }));
    };
    DocumentViewerService.decorators = [
        { type: Injectable, args: [{
                    providedIn: 'root'
                },] }
    ];
    DocumentViewerService.ctorParameters = function () { return [
        { type: EmLoggerService },
        { type: HttpClient },
        { type: TransferState }
    ]; };
    /** @nocollapse */ DocumentViewerService.ngInjectableDef = defineInjectable({ factory: function DocumentViewerService_Factory() { return new DocumentViewerService(inject(EmLoggerService), inject(HttpClient), inject(TransferState)); }, token: DocumentViewerService, providedIn: "root" });
    return DocumentViewerService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var DocumentViewerComponent = /** @class */ (function () {
    function DocumentViewerComponent(log, viewerFactoryService, annotationStoreService, urlFixer, documentViewerService) {
        this.log = log;
        this.viewerFactoryService = viewerFactoryService;
        this.annotationStoreService = annotationStoreService;
        this.urlFixer = urlFixer;
        this.documentViewerService = documentViewerService;
        this.url = '';
        this.rotate = false;
        log.setClass('DocumentViewerComponent');
    }
    /**
     * @return {?}
     */
    DocumentViewerComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
    };
    /**
     * @param {?} changes
     * @return {?}
     */
    DocumentViewerComponent.prototype.ngOnChanges = /**
     * @param {?} changes
     * @return {?}
     */
    function (changes) {
        if (changes.url || changes.annotate) {
            this.buildViewer();
        }
    };
    /**
     * @return {?}
     */
    DocumentViewerComponent.prototype.buildViewer = /**
     * @return {?}
     */
    function () {
        var _this = this;
        if (!this.url) {
            this.log.error('url is required argument');
            throw new Error('url is required argument');
        }
        if (this.isDM) {
            this.documentViewerService.getDocumentMetadata("" + this.urlFixer.fixDm(this.url, this.baseUrl)).subscribe(function (metadata) {
                _this.log.info(metadata);
                if (metadata && metadata._links) {
                    /** @type {?} */
                    var url_1 = _this.urlFixer.fixDm(metadata._links.binary.href, _this.baseUrl);
                    /** @type {?} */
                    var dmDocumentId = _this.viewerFactoryService.getDocumentId(metadata);
                    if (_this.annotate) {
                        _this.annotationStoreService.getAnnotationSet(_this.baseUrl, dmDocumentId).subscribe(function (annotationSet) {
                            _this.buildComponent(metadata, url_1, annotationSet.body);
                        });
                    }
                    else {
                        _this.buildComponent(metadata, url_1, null);
                    }
                }
            }, function (err) {
                _this.log.error('An error has occured while fetching document' + err);
                _this.error = err;
            });
        }
        else {
            this.viewerComponent = this.viewerFactoryService.buildComponent(this.viewerAnchor.viewContainerRef, this.contentType, this.url, this.baseUrl, this.url, this.annotate, null, this.rotate);
        }
    };
    /**
     * @param {?} metadata
     * @param {?} url
     * @param {?=} annotationSet
     * @return {?}
     */
    DocumentViewerComponent.prototype.buildComponent = /**
     * @param {?} metadata
     * @param {?} url
     * @param {?=} annotationSet
     * @return {?}
     */
    function (metadata, url, annotationSet) {
        this.viewerFactoryService.buildComponent(this.viewerAnchor.viewContainerRef, metadata.mimeType, url, this.baseUrl, metadata._links.self.href, this.annotate, annotationSet, this.rotate);
    };
    DocumentViewerComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app-document-viewer',
                    template: "\n<ng-template appViewerAnchor></ng-template>\n\n<div class=\"grid-row\">\n  <div *ngIf=\"error\"  class=\"error-summary\" role=\"alert\" aria-labelledby=\"error-summary-heading-example-1\" tabindex=\"-1\">\n    <h2 class=\"heading-medium error-summary-heading\" id=\"error-summary-heading-example-1\">There was an error while loading your document.</h2>\n    <p>Response status was {{error.status}}.</p>\n  </div>\n</div>\n\n"
                }] }
    ];
    DocumentViewerComponent.ctorParameters = function () { return [
        { type: EmLoggerService },
        { type: ViewerFactoryService },
        { type: AnnotationStoreService },
        { type: UrlFixerService },
        { type: DocumentViewerService }
    ]; };
    DocumentViewerComponent.propDecorators = {
        viewerAnchor: [{ type: ViewChild, args: [ViewerAnchorDirective,] }],
        url: [{ type: Input }],
        annotate: [{ type: Input }],
        baseUrl: [{ type: Input }],
        isDM: [{ type: Input }],
        contentType: [{ type: Input }],
        rotate: [{ type: Input }]
    };
    return DocumentViewerComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var HmctsEmViewerUiModule = /** @class */ (function () {
    function HmctsEmViewerUiModule() {
    }
    HmctsEmViewerUiModule.decorators = [
        { type: NgModule, args: [{
                    imports: [
                        NgtUniversalModule,
                        CommonModule,
                        FormsModule,
                        HttpClientModule
                    ],
                    declarations: [
                        CommentsComponent,
                        CommentItemComponent,
                        ContextualToolbarComponent,
                        AnnotationPdfViewerComponent,
                        ImageViewerComponent,
                        UnsupportedViewerComponent,
                        DocumentViewerComponent,
                        ViewerAnchorDirective,
                        RotationComponent
                    ],
                    entryComponents: [
                        AnnotationPdfViewerComponent,
                        ImageViewerComponent,
                        UnsupportedViewerComponent,
                        RotationComponent
                    ],
                    providers: [
                        PdfAnnotateWrapper,
                        PdfWrapper,
                        PdfService,
                        AnnotationStoreService,
                        PdfAdapter,
                        NpaService,
                        ApiHttpService,
                        Utils,
                        UrlFixerService,
                        ViewerFactoryService,
                        DocumentViewerService,
                        RotationFactoryService,
                        PdfRenderService,
                        EmLoggerService
                    ],
                    exports: [
                        DocumentViewerComponent
                    ]
                },] }
    ];
    return HmctsEmViewerUiModule;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

export { HmctsEmViewerUiModule, AnnotationStoreService as ɵb, ApiHttpService as ɵf, PdfAnnotateWrapper as ɵh, PdfWrapper as ɵj, NpaService as ɵn, PdfAdapter as ɵd, PdfRenderService as ɵi, PdfService as ɵg, UrlFixerService as ɵu, Utils as ɵe, DocumentViewerComponent as ɵr, DocumentViewerService as ɵv, ViewerAnchorDirective as ɵs, EmLoggerService as ɵc, AnnotationPdfViewerComponent as ɵm, CommentItemComponent as ɵk, CommentsComponent as ɵa, ContextualToolbarComponent as ɵl, RotationFactoryService as ɵo, RotationComponent as ɵw, ImageViewerComponent as ɵp, UnsupportedViewerComponent as ɵq, ViewerFactoryService as ɵt };

//# sourceMappingURL=hmcts-annotation-ui-lib.js.map