(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('ng2-pdfjs-viewer'), require('@eui/core'), require('@angular/common/http'), require('@ngx-translate/core'), require('@eui/components')) :
    typeof define === 'function' && define.amd ? define('@eui/externals/ux-document-viewer', ['exports', '@angular/core', '@angular/common', 'ng2-pdfjs-viewer', '@eui/core', '@angular/common/http', '@ngx-translate/core', '@eui/components'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.eui = global.eui || {}, global.eui.externals = global.eui.externals || {}, global.eui.externals["ux-document-viewer"] = {}), global.ng.core, global.ng.common, global.i5, global.i3, global.ng.common.http, global.i2, global.i1$1));
})(this, (function (exports, i0, common, i5, i3, i1, i2, i1$1) { 'use strict';

    function _interopNamespace(e) {
        if (e && e.__esModule) return e;
        var n = Object.create(null);
        if (e) {
            Object.keys(e).forEach(function (k) {
                if (k !== 'default') {
                    var d = Object.getOwnPropertyDescriptor(e, k);
                    Object.defineProperty(n, k, d.get ? d : {
                        enumerable: true,
                        get: function () { return e[k]; }
                    });
                }
            });
        }
        n["default"] = e;
        return Object.freeze(n);
    }

    var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
    var i5__namespace = /*#__PURE__*/_interopNamespace(i5);
    var i3__namespace = /*#__PURE__*/_interopNamespace(i3);
    var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
    var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
    var i1__namespace$1 = /*#__PURE__*/_interopNamespace(i1$1);

    var UxDocumentViewerConfig = /** @class */ (function () {
        function UxDocumentViewerConfig(values) {
            this.viewerWidth = '100%';
            this.viewerHeight = '600px';
            this.startPage = 1;
            this.startZoom = 'page-fit';
            this.isPrintable = true;
            this.isDownloadable = true;
            this.isOpenable = false;
            this.viewerFolder = '/assets/pdfjs';
            Object.assign(this, values);
        }
        return UxDocumentViewerConfig;
    }());

    var _c0 = ["viewer"];
    var UxDocumentViewerComponent = /** @class */ (function () {
        function UxDocumentViewerComponent(uxDocumentViewerConfig, httpClient, cdRef, translateService, asService) {
            var _this = this;
            this.httpClient = httpClient;
            this.cdRef = cdRef;
            this.translateService = translateService;
            this.asService = asService;
            this.viewerWidth = '100%';
            this.viewerHeight = '600px';
            this.startPage = 1;
            this.startZoom = 'page-fit';
            this.isPrintable = true;
            this.isDownloadable = true;
            this.isOpenable = false;
            this.e2eAttr = 'ux-document-viewer';
            this.viewerFolder = '/assets/pdfjs';
            if (uxDocumentViewerConfig) {
                this.config = uxDocumentViewerConfig;
                this.documentSrc = uxDocumentViewerConfig.documentSrc;
                this.viewerWidth = uxDocumentViewerConfig.viewerWidth;
                this.viewerHeight = uxDocumentViewerConfig.viewerHeight;
                this.startPage = uxDocumentViewerConfig.startPage;
                this.startZoom = uxDocumentViewerConfig.startZoom;
                this.isPrintable = uxDocumentViewerConfig.isPrintable;
                this.isDownloadable = uxDocumentViewerConfig.isDownloadable;
                this.isOpenable = uxDocumentViewerConfig.isOpenable;
                this.viewerFolder = uxDocumentViewerConfig.viewerFolder;
            }
            this.language = this.translateService.currentLang;
            this.languageSubscription = this.translateService.onLangChange.subscribe(function (event) {
                _this.resetLanguage(event.lang);
            });
        }
        UxDocumentViewerComponent.prototype.ngOnInit = function () {
            if (this.documentSrc) {
                this.loadDocument();
            }
        };
        UxDocumentViewerComponent.prototype.ngOnChanges = function (changes) {
            if (changes.documentSrc
                && changes.documentSrc.currentValue
                && changes.documentSrc.currentValue !== changes.documentSrc.previousValue) {
                this.loadDocument();
            }
        };
        UxDocumentViewerComponent.prototype.ngOnDestroy = function () {
            if (this.languageSubscription) {
                this.languageSubscription.unsubscribe();
            }
        };
        /**
         * If the URL is passed to PDFjs directly, the library is included in an iframe and does its own XMLHttpRequest
         * calls, it is a problem to intercept those calls to enrich them with OpenID headers. In case of Linearized PDF
         * documents there is also a lot of calls to the back-end, requesting partial content. This means every viewed
         * document would need potentially dozens of calls to get the header data and then the content as people scroll
         * up and down.
         * As a temporary solution, until something more robust is provided, the document is loaded up front and the
         * blob is passed to the library.
         */
        UxDocumentViewerComponent.prototype.loadDocument = function () {
            var _this = this;
            this.httpClient
                .get(this.documentSrc, { responseType: 'blob' })
                .subscribe(function (response) {
                _this.documentBlob = response;
                if (_this.viewer) {
                    _this.viewer.pdfSrc = response;
                    _this.viewer.refresh();
                }
                _this.cdRef.markForCheck();
            }, function (error) {
                console.error('ux-document-viewer error while loading document contents', error);
                _this.asService.growlError('Document viewer could not load the requested document.');
            });
        };
        UxDocumentViewerComponent.prototype.resetLanguage = function (language) {
            this.language = language;
            if (this.viewer) {
                this.viewer.locale = this.language;
                this.viewer.refresh();
            }
        };
        return UxDocumentViewerComponent;
    }());
    /** @nocollapse */ UxDocumentViewerComponent.ɵfac = function UxDocumentViewerComponent_Factory(t) { return new (t || UxDocumentViewerComponent)(i0__namespace.ɵɵdirectiveInject(i3.DYNAMIC_COMPONENT_CONFIG, 8), i0__namespace.ɵɵdirectiveInject(i1__namespace.HttpClient), i0__namespace.ɵɵdirectiveInject(i0__namespace.ChangeDetectorRef), i0__namespace.ɵɵdirectiveInject(i2__namespace.TranslateService), i0__namespace.ɵɵdirectiveInject(i3__namespace.UxAppShellService)); };
    /** @nocollapse */ UxDocumentViewerComponent.ɵcmp = i0__namespace.ɵɵdefineComponent({ type: UxDocumentViewerComponent, selectors: [["ux-document-viewer"]], viewQuery: function UxDocumentViewerComponent_Query(rf, ctx) {
            if (rf & 1) {
                i0__namespace.ɵɵviewQuery(_c0, true);
            }
            if (rf & 2) {
                var _t;
                i0__namespace.ɵɵqueryRefresh(_t = i0__namespace.ɵɵloadQuery()) && (ctx.viewer = _t.first);
            }
        }, inputs: { documentSrc: "documentSrc", viewerWidth: "viewerWidth", viewerHeight: "viewerHeight", startPage: "startPage", startZoom: "startZoom", isPrintable: "isPrintable", isDownloadable: "isDownloadable", isOpenable: "isOpenable", e2eAttr: "e2eAttr", viewerFolder: "viewerFolder" }, features: [i0__namespace.ɵɵNgOnChangesFeature], decls: 3, vars: 13, consts: [[1, "ux-document-viewer"], [3, "pdfSrc", "viewerFolder", "page", "zoom", "print", "download", "openFile", "locale"], ["viewer", ""]], template: function UxDocumentViewerComponent_Template(rf, ctx) {
            if (rf & 1) {
                i0__namespace.ɵɵelementStart(0, "div", 0);
                i0__namespace.ɵɵelement(1, "ng2-pdfjs-viewer", 1, 2);
                i0__namespace.ɵɵelementEnd();
            }
            if (rf & 2) {
                i0__namespace.ɵɵstyleProp("width", ctx.viewerWidth)("height", ctx.viewerHeight);
                i0__namespace.ɵɵattribute("data-e2e", ctx.e2eAttr);
                i0__namespace.ɵɵadvance(1);
                i0__namespace.ɵɵproperty("pdfSrc", ctx.documentBlob)("viewerFolder", ctx.viewerFolder)("page", ctx.startPage)("zoom", ctx.startZoom)("print", ctx.isPrintable)("download", ctx.isDownloadable)("openFile", ctx.isOpenable)("locale", ctx.language);
            }
        }, directives: [i5__namespace.PdfJsViewerComponent], encapsulation: 2 });
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(UxDocumentViewerComponent, [{
                type: i0.Component,
                args: [{
                        selector: 'ux-document-viewer',
                        templateUrl: './ux-document-viewer.component.html',
                    }]
            }], function () {
            return [{ type: UxDocumentViewerConfig, decorators: [{
                            type: i0.Optional
                        }, {
                            type: i0.Inject,
                            args: [i3.DYNAMIC_COMPONENT_CONFIG]
                        }] }, { type: i1__namespace.HttpClient }, { type: i0__namespace.ChangeDetectorRef }, { type: i2__namespace.TranslateService }, { type: i3__namespace.UxAppShellService }];
        }, { viewer: [{
                    type: i0.ViewChild,
                    args: ['viewer']
                }], documentSrc: [{
                    type: i0.Input
                }], viewerWidth: [{
                    type: i0.Input
                }], viewerHeight: [{
                    type: i0.Input
                }], startPage: [{
                    type: i0.Input
                }], startZoom: [{
                    type: i0.Input
                }], isPrintable: [{
                    type: i0.Input
                }], isDownloadable: [{
                    type: i0.Input
                }], isOpenable: [{
                    type: i0.Input
                }], e2eAttr: [{
                    type: i0.Input
                }], viewerFolder: [{
                    type: i0.Input
                }] });
    })();

    var UxDocumentViewerService = /** @class */ (function () {
        function UxDocumentViewerService(uxDynamicModalService) {
            this.uxDynamicModalService = uxDynamicModalService;
        }
        UxDocumentViewerService.prototype.openDocument = function (documentViewerConfig, uxDynamicModalConfig) {
            var bodyInjectedComponent = {
                component: UxDocumentViewerComponent,
                config: documentViewerConfig,
            };
            var defaultModalConfig = new i1$1.UxDynamicModalConfig({
                isFooterVisible: false,
                hasNoBodyPadding: true,
                bodyStyleClass: 'ux-document-viewer__modal',
                bodyInjectedComponent: bodyInjectedComponent,
            });
            var config = defaultModalConfig;
            if (uxDynamicModalConfig) {
                config = Object.assign(defaultModalConfig, uxDynamicModalConfig);
            }
            this.uxDynamicModalService.openModal(config);
        };
        return UxDocumentViewerService;
    }());
    /** @nocollapse */ UxDocumentViewerService.ɵfac = function UxDocumentViewerService_Factory(t) { return new (t || UxDocumentViewerService)(i0__namespace.ɵɵinject(i1__namespace$1.UxDynamicModalService)); };
    /** @nocollapse */ UxDocumentViewerService.ɵprov = i0__namespace.ɵɵdefineInjectable({ token: UxDocumentViewerService, factory: UxDocumentViewerService.ɵfac });
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(UxDocumentViewerService, [{
                type: i0.Injectable
            }], function () { return [{ type: i1__namespace$1.UxDynamicModalService }]; }, null);
    })();

    var UxDocumentViewerDirective = /** @class */ (function () {
        function UxDocumentViewerDirective(uxDocumentViewerService) {
            this.uxDocumentViewerService = uxDocumentViewerService;
        }
        UxDocumentViewerDirective.prototype.onClick = function (e) {
            var documentViewerConfig = this.uxDocumentViewerConfig ?
                Object.assign(new UxDocumentViewerConfig(this.uxDocumentViewerConfig), { documentSrc: this.href }) :
                new UxDocumentViewerConfig({
                    documentSrc: this.href,
                });
            this.uxDocumentViewerService.openDocument(documentViewerConfig, this.uxDocumentViewerModalConfig);
            i3.consumeEvent(e);
        };
        return UxDocumentViewerDirective;
    }());
    /** @nocollapse */ UxDocumentViewerDirective.ɵfac = function UxDocumentViewerDirective_Factory(t) { return new (t || UxDocumentViewerDirective)(i0__namespace.ɵɵdirectiveInject(UxDocumentViewerService)); };
    /** @nocollapse */ UxDocumentViewerDirective.ɵdir = i0__namespace.ɵɵdefineDirective({ type: UxDocumentViewerDirective, selectors: [["", "uxDocumentViewer", ""]], hostBindings: function UxDocumentViewerDirective_HostBindings(rf, ctx) {
            if (rf & 1) {
                i0__namespace.ɵɵlistener("click", function UxDocumentViewerDirective_click_HostBindingHandler($event) { return ctx.onClick($event); });
            }
        }, inputs: { href: "href", uxDocumentViewerConfig: "uxDocumentViewerConfig", uxDocumentViewerModalConfig: "uxDocumentViewerModalConfig" } });
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(UxDocumentViewerDirective, [{
                type: i0.Directive,
                args: [{
                        selector: '[uxDocumentViewer]'
                    }]
            }], function () { return [{ type: UxDocumentViewerService }]; }, { href: [{
                    type: i0.Input
                }], uxDocumentViewerConfig: [{
                    type: i0.Input
                }], uxDocumentViewerModalConfig: [{
                    type: i0.Input
                }], onClick: [{
                    type: i0.HostListener,
                    args: ['click', ['$event']]
                }] });
    })();

    var UxDocumentViewerComponentModule = /** @class */ (function () {
        function UxDocumentViewerComponentModule() {
        }
        return UxDocumentViewerComponentModule;
    }());
    /** @nocollapse */ UxDocumentViewerComponentModule.ɵmod = i0__namespace.ɵɵdefineNgModule({ type: UxDocumentViewerComponentModule });
    /** @nocollapse */ UxDocumentViewerComponentModule.ɵinj = i0__namespace.ɵɵdefineInjector({ factory: function UxDocumentViewerComponentModule_Factory(t) { return new (t || UxDocumentViewerComponentModule)(); }, providers: [
            UxDocumentViewerService,
        ], imports: [[
                common.CommonModule,
                i5.PdfJsViewerModule,
            ]] });
    (function () {
        (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(UxDocumentViewerComponentModule, { declarations: [UxDocumentViewerComponent,
                UxDocumentViewerDirective], imports: [common.CommonModule,
                i5.PdfJsViewerModule], exports: [UxDocumentViewerComponent,
                UxDocumentViewerDirective] });
    })();
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(UxDocumentViewerComponentModule, [{
                type: i0.NgModule,
                args: [{
                        imports: [
                            common.CommonModule,
                            i5.PdfJsViewerModule,
                        ],
                        declarations: [
                            UxDocumentViewerComponent,
                            UxDocumentViewerDirective,
                        ],
                        exports: [
                            UxDocumentViewerComponent,
                            UxDocumentViewerDirective,
                        ],
                        providers: [
                            UxDocumentViewerService,
                        ],
                        entryComponents: [
                            UxDocumentViewerComponent,
                        ],
                    }]
            }], null, null);
    })();

    /**
     * Generated bundle index. Do not edit.
     */

    exports.UxDocumentViewerComponent = UxDocumentViewerComponent;
    exports.UxDocumentViewerComponentModule = UxDocumentViewerComponentModule;
    exports.UxDocumentViewerConfig = UxDocumentViewerConfig;
    exports.UxDocumentViewerDirective = UxDocumentViewerDirective;
    exports.UxDocumentViewerService = UxDocumentViewerService;

    Object.defineProperty(exports, '__esModule', { value: true });

}));
//# sourceMappingURL=eui-externals-ux-document-viewer.umd.js.map
