(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@wm/components/base'), require('lodash-es'), require('@angular/common/http'), require('@awesome-cordova-plugins/file/ngx'), require('@awesome-cordova-plugins/file-opener/ngx'), require('@wm/core'), require('@wm/mobile/core'), require('@angular/common'), require('@wm/components/basic/progress')) :
    typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@wm/components/base', 'lodash-es', '@angular/common/http', '@awesome-cordova-plugins/file/ngx', '@awesome-cordova-plugins/file-opener/ngx', '@wm/core', '@wm/mobile/core', '@angular/common', '@wm/components/basic/progress'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.wm = global.wm || {}, global.wm.mobile = global.wm.mobile || {}, global.wm.mobile.components = global.wm.mobile.components || {}, global.wm.mobile.components.basic = {}), global.ng.core, global.wm.components.base, global._, global.ng.common.http, global.awesomeCordova.plugins, global.awesomeCordova.plugins, global.wm.core, global.wm.mobile.core, global.ng.common, global.wm.components.basic.progress));
})(this, (function (exports, i0, i5, lodashEs, i4, i2, i3, i1$1, i1, i3$1, i2$1) { 'use strict';

    function _interopNamespaceDefault(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__*/_interopNamespaceDefault(i0);
    var i5__namespace = /*#__PURE__*/_interopNamespaceDefault(i5);
    var i4__namespace = /*#__PURE__*/_interopNamespaceDefault(i4);
    var i2__namespace = /*#__PURE__*/_interopNamespaceDefault(i2);
    var i3__namespace = /*#__PURE__*/_interopNamespaceDefault(i3);
    var i1$1__namespace = /*#__PURE__*/_interopNamespaceDefault(i1$1);
    var i1__namespace = /*#__PURE__*/_interopNamespaceDefault(i1);
    var i3$1__namespace = /*#__PURE__*/_interopNamespaceDefault(i3$1);
    var i2$1__namespace = /*#__PURE__*/_interopNamespaceDefault(i2$1);

    class AnchorDirective {
        constructor(widget) {
            this.widget = widget;
        }
        onClick() {
            let href = this.widget.hyperlink;
            if (href) {
                if (href.indexOf(':') >= 0 && !(lodashEs.startsWith(href, 'http://') || lodashEs.startsWith(href, 'https://'))) {
                    return;
                }
                else if (lodashEs.startsWith(href, '#')) {
                    window.location.href = window.location.origin + window.location.pathname + href;
                    return;
                }
                else if (lodashEs.startsWith(href, '//')) {
                    href = 'https:' + href;
                }
                if (window['cordova']) {
                    window.open(href, this.widget.target);
                }
            }
        }
        static { this.ɵfac = function AnchorDirective_Factory(t) { return new (t || AnchorDirective)(i0__namespace.ɵɵdirectiveInject(i5.WidgetRef)); }; }
        static { this.ɵdir = /*@__PURE__*/ i0__namespace.ɵɵdefineDirective({ type: AnchorDirective, selectors: [["", "wmAnchor", ""]], hostBindings: function AnchorDirective_HostBindings(rf, ctx) { if (rf & 1) {
                i0__namespace.ɵɵlistener("click", function AnchorDirective_click_HostBindingHandler() { return ctx.onClick(); });
            } } }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AnchorDirective, [{
            type: i0.Directive,
            args: [{
                    selector: '[wmAnchor]'
                }]
        }], () => [{ type: undefined, decorators: [{
                    type: i0.Inject,
                    args: [i5.WidgetRef]
                }] }], { onClick: [{
                type: i0.HostListener,
                args: ['click']
            }] }); })();

    const _c0$3 = ["wmAppUpdate", ""];
    const DEFAULT_CLS$1 = 'app-update-dialog modal fade in hidden';
    const AUTO_UPDATE_FILENAME = 'app-auto-update.apk';
    class AppUpdateComponent {
        constructor(deviceService, fileDownloadService, elRef, file, fileOpener, http) {
            this.deviceService = deviceService;
            this.fileDownloadService = fileDownloadService;
            this.elRef = elRef;
            this.file = file;
            this.fileOpener = fileOpener;
            this.http = http;
            this.downloadProgress = 0;
            this.downloading = false;
            this.message = 'There is an update available. Would you like to update the app?';
            i1$1.addClass(this.elRef.nativeElement, DEFAULT_CLS$1);
            i1$1.setCSS(this.elRef.nativeElement, 'display', 'block');
            if (i1$1.hasCordova()) {
                this.getBuildMeta().then(buildMeta => {
                    if (buildMeta && buildMeta.buildMode === 'DEVELOPMENT_MODE') {
                        this.file.removeFile(cordova.file.externalApplicationStorageDirectory, AUTO_UPDATE_FILENAME).catch(i1$1.noop);
                        this.checkForUpdate()
                            .then(this.getUserConfirmation.bind(this), i1$1.noop);
                    }
                });
            }
        }
        cancel() {
            i1$1.addClass(this.elRef.nativeElement, 'hidden');
        }
        installLatestVersion() {
            const apkFile = cordova.file.externalApplicationStorageDirectory + AUTO_UPDATE_FILENAME, downloadLink = `${this._buildMeta.host}/appBuild/rest/mobileBuilds/android/download?token=${this._buildMeta.token}&buildNumber=${this._buildMeta.latestBuildNumber}&fileName=${AUTO_UPDATE_FILENAME}&releaseVersion=${this._buildMeta.platformVersion}`, progressObserver = { next: e => { this.downloadProgress = (e.loaded / e.total) * 100; }, error: null, complete: null };
            this.fileDownloadService.download(downloadLink, false, cordova.file.externalApplicationStorageDirectory, AUTO_UPDATE_FILENAME, progressObserver).then(() => {
                this.fileOpener.open(apkFile, 'application/vnd.android.package-archive');
            }, function () {
                this.message = 'Failed to download latest version.';
            });
            this.message = `Downloading the latest version [${this._buildMeta.latestVersion}].`;
            this.downloading = true;
        }
        checkForUpdate() {
            return new Promise((resolve, reject) => {
                this.http.get(`${this._buildMeta.host}/appBuild/rest/mobileBuilds/latest_build?token=${this._buildMeta.token}&releaseVersion=${this._buildMeta.platformVersion}`)
                    .toPromise()
                    .then((response) => {
                    const latestBuildNumber = response.success.body.buildNumber, latestVersion = response.success.body.version;
                    if (this._buildMeta.buildNumber < latestBuildNumber) {
                        this._buildMeta.latestBuildNumber = latestBuildNumber;
                        this._buildMeta.latestVersion = latestVersion;
                        resolve(latestBuildNumber);
                    }
                    else {
                        reject();
                    }
                }, reject);
            });
        }
        getBuildMeta() {
            if (!this._buildMeta) {
                return this.file.readAsText(cordova.file.applicationDirectory + 'www/', 'build_meta.json')
                    .then(data => {
                    this._buildMeta = JSON.parse(data);
                    return this._buildMeta;
                }, i1$1.noop);
            }
            return Promise.resolve(this._buildMeta);
        }
        getUserConfirmation() {
            this.downloadProgress = 0;
            this.downloading = false;
            this.message = 'There is an update available. Would you like to update the app?';
            i1$1.removeClass(this.elRef.nativeElement, 'hidden');
        }
        static { this.ɵfac = function AppUpdateComponent_Factory(t) { return new (t || AppUpdateComponent)(i0__namespace.ɵɵdirectiveInject(i1__namespace.DeviceService), i0__namespace.ɵɵdirectiveInject(i1__namespace.DeviceFileDownloadService), i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(i2__namespace.File), i0__namespace.ɵɵdirectiveInject(i3__namespace.FileOpener), i0__namespace.ɵɵdirectiveInject(i4__namespace.HttpClient)); }; }
        static { this.ɵcmp = /*@__PURE__*/ i0__namespace.ɵɵdefineComponent({ type: AppUpdateComponent, selectors: [["", "wmAppUpdate", ""]], attrs: _c0$3, decls: 11, vars: 5, consts: [[1, "modal-dialog"], [1, "modal-content"], [1, "modal-body"], [3, "textContent"], [1, "progress", 3, "hidden"], [1, "progress-bar"], [1, "modal-footer"], ["type", "button", "data-dismiss", "modal", 1, "btn", "btn-default", 3, "click"], ["type", "button", 1, "btn", "btn-primary", 3, "click", "hidden"]], template: function AppUpdateComponent_Template(rf, ctx) { if (rf & 1) {
                i0__namespace.ɵɵelementStart(0, "div", 0)(1, "div", 1)(2, "div", 2);
                i0__namespace.ɵɵelement(3, "span", 3);
                i0__namespace.ɵɵelementStart(4, "div", 4);
                i0__namespace.ɵɵelement(5, "div", 5);
                i0__namespace.ɵɵelementEnd()();
                i0__namespace.ɵɵelementStart(6, "div", 6)(7, "button", 7);
                i0__namespace.ɵɵlistener("click", function AppUpdateComponent_Template_button_click_7_listener() { return ctx.cancel(); });
                i0__namespace.ɵɵtext(8, "Skip update");
                i0__namespace.ɵɵelementEnd();
                i0__namespace.ɵɵelementStart(9, "button", 8);
                i0__namespace.ɵɵlistener("click", function AppUpdateComponent_Template_button_click_9_listener() { return ctx.installLatestVersion(); });
                i0__namespace.ɵɵtext(10, "Update");
                i0__namespace.ɵɵelementEnd()()()();
            } if (rf & 2) {
                i0__namespace.ɵɵadvance(3);
                i0__namespace.ɵɵproperty("textContent", ctx.message);
                i0__namespace.ɵɵadvance();
                i0__namespace.ɵɵproperty("hidden", !ctx.downloading);
                i0__namespace.ɵɵadvance();
                i0__namespace.ɵɵstyleProp("width", ctx.downloadProgress, "%");
                i0__namespace.ɵɵadvance(4);
                i0__namespace.ɵɵproperty("hidden", ctx.downloading);
            } }, dependencies: [i5__namespace.TextContentDirective], encapsulation: 2 }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AppUpdateComponent, [{
            type: i0.Component,
            args: [{ selector: '[wmAppUpdate]', template: "<div class=\"modal-dialog\">\n    <div class=\"modal-content\"> \n        <div class=\"modal-body\"> \n            <span [textContent]=\"message\"></span>\n            <div class=\"progress\" [hidden]=\"!downloading\">\n                <div class=\"progress-bar\" [style.width.%]=\"downloadProgress\"></div>\n            </div>\n        </div>\n        <div class=\"modal-footer\"> \n            <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\" (click)=\"cancel()\">Skip update</button>\n            <button type=\"button\" class=\"btn btn-primary\" [hidden]=\"downloading\" (click)=\"installLatestVersion()\">Update</button>\n        </div>\n    </div>\n</div>" }]
        }], () => [{ type: i1__namespace.DeviceService }, { type: i1__namespace.DeviceFileDownloadService }, { type: i0__namespace.ElementRef }, { type: i2__namespace.File }, { type: i3__namespace.FileOpener }, { type: i4__namespace.HttpClient }], null); })();
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassDebugInfo(AppUpdateComponent, { className: "AppUpdateComponent", filePath: "app-update/app-update.component.ts", lineNumber: 20 }); })();

    const _c0$2 = ["wmMobileFileBrowser", ""];
    function FileBrowserComponent_div_0_div_13_i_2_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelement(0, "i", 22);
    } }
    function FileBrowserComponent_div_0_div_13_i_3_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelement(0, "i");
    } if (rf & 2) {
        const file_r4 = i0__namespace.ɵɵnextContext().$implicit;
        const ctx_r1 = i0__namespace.ɵɵnextContext(2);
        i0__namespace.ɵɵclassMapInterpolate1("file-icon wi wi-file ", ctx_r1.getFileExtension(file_r4.name), "");
    } }
    function FileBrowserComponent_div_0_div_13_Template(rf, ctx) { if (rf & 1) {
        const _r3 = i0__namespace.ɵɵgetCurrentView();
        i0__namespace.ɵɵelementStart(0, "div", 17)(1, "div", 18);
        i0__namespace.ɵɵlistener("click", function FileBrowserComponent_div_0_div_13_Template_div_click_1_listener() { const file_r4 = i0__namespace.ɵɵrestoreView(_r3).$implicit; const ctx_r1 = i0__namespace.ɵɵnextContext(2); return i0__namespace.ɵɵresetView(ctx_r1.onFileClick(file_r4)); });
        i0__namespace.ɵɵtemplate(2, FileBrowserComponent_div_0_div_13_i_2_Template, 1, 0, "i", 19)(3, FileBrowserComponent_div_0_div_13_i_3_Template, 1, 3, "i", 20);
        i0__namespace.ɵɵelementStart(4, "span", 21);
        i0__namespace.ɵɵtext(5);
        i0__namespace.ɵɵelementEnd()()();
    } if (rf & 2) {
        const file_r4 = ctx.$implicit;
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵclassProp("bg-primary", file_r4.isSelected);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngIf", !file_r4.isFile);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngIf", file_r4.isFile);
        i0__namespace.ɵɵadvance(2);
        i0__namespace.ɵɵtextInterpolate(file_r4.name);
    } }
    function FileBrowserComponent_div_0_button_15_Template(rf, ctx) { if (rf & 1) {
        const _r5 = i0__namespace.ɵɵgetCurrentView();
        i0__namespace.ɵɵelementStart(0, "button", 23);
        i0__namespace.ɵɵlistener("click", function FileBrowserComponent_div_0_button_15_Template_button_click_0_listener() { i0__namespace.ɵɵrestoreView(_r5); const ctx_r1 = i0__namespace.ɵɵnextContext(2); return i0__namespace.ɵɵresetView(ctx_r1.submit()); });
        i0__namespace.ɵɵtext(1, " Done ");
        i0__namespace.ɵɵelementStart(2, "span", 24);
        i0__namespace.ɵɵtext(3);
        i0__namespace.ɵɵelementEnd()();
    } if (rf & 2) {
        const ctx_r1 = i0__namespace.ɵɵnextContext(2);
        i0__namespace.ɵɵadvance(3);
        i0__namespace.ɵɵtextInterpolate(ctx_r1.selectedFiles.length);
    } }
    function FileBrowserComponent_div_0_Template(rf, ctx) { if (rf & 1) {
        const _r1 = i0__namespace.ɵɵgetCurrentView();
        i0__namespace.ɵɵelementStart(0, "div", 1);
        i0__namespace.ɵɵelement(1, "div", 2);
        i0__namespace.ɵɵelementStart(2, "div", 3)(3, "div", 4)(4, "div", 5)(5, "div", 6)(6, "h4", 7)(7, "span", 8);
        i0__namespace.ɵɵlistener("click", function FileBrowserComponent_div_0_Template_span_click_7_listener() { i0__namespace.ɵɵrestoreView(_r1); const ctx_r1 = i0__namespace.ɵɵnextContext(); return i0__namespace.ɵɵresetView(ctx_r1.onFileClick(ctx_r1.currentFolder.parent)); });
        i0__namespace.ɵɵelement(8, "i", 9);
        i0__namespace.ɵɵelementEnd();
        i0__namespace.ɵɵtext(9);
        i0__namespace.ɵɵelementEnd();
        i0__namespace.ɵɵelementStart(10, "div", 10);
        i0__namespace.ɵɵlistener("click", function FileBrowserComponent_div_0_Template_div_click_10_listener() { i0__namespace.ɵɵrestoreView(_r1); const ctx_r1 = i0__namespace.ɵɵnextContext(); return i0__namespace.ɵɵresetView(ctx_r1.refreshFolder()); });
        i0__namespace.ɵɵelement(11, "i", 11);
        i0__namespace.ɵɵelementEnd()();
        i0__namespace.ɵɵelementStart(12, "div", 12);
        i0__namespace.ɵɵtemplate(13, FileBrowserComponent_div_0_div_13_Template, 6, 5, "div", 13);
        i0__namespace.ɵɵelementEnd();
        i0__namespace.ɵɵelementStart(14, "div", 14);
        i0__namespace.ɵɵtemplate(15, FileBrowserComponent_div_0_button_15_Template, 4, 1, "button", 15);
        i0__namespace.ɵɵelementStart(16, "button", 16);
        i0__namespace.ɵɵlistener("click", function FileBrowserComponent_div_0_Template_button_click_16_listener() { i0__namespace.ɵɵrestoreView(_r1); const ctx_r1 = i0__namespace.ɵɵnextContext(); return i0__namespace.ɵɵresetView(ctx_r1.show = false); });
        i0__namespace.ɵɵtext(17, "Close");
        i0__namespace.ɵɵelementEnd()()()()()();
    } if (rf & 2) {
        const ctx_r1 = i0__namespace.ɵɵnextContext();
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵclassProp("in", ctx_r1.isVisible);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵclassProp("in", ctx_r1.isVisible);
        i0__namespace.ɵɵadvance(5);
        i0__namespace.ɵɵproperty("hidden", !!!ctx_r1.currentFolder.parent);
        i0__namespace.ɵɵadvance(2);
        i0__namespace.ɵɵtextInterpolate1(" ", ctx_r1.currentFolder.name, " ");
        i0__namespace.ɵɵadvance(4);
        i0__namespace.ɵɵproperty("ngForOf", ctx_r1.currentFolder.files);
        i0__namespace.ɵɵadvance(2);
        i0__namespace.ɵɵproperty("ngIf", ctx_r1.selectedFiles && ctx_r1.selectedFiles.length > 0);
    } }
    class FileBrowserComponent {
        constructor(deviceService) {
            this.deviceService = deviceService;
            this.selectedFiles = [];
            this.submitEmitter = new i0.EventEmitter();
        }
        getFileExtension(fileName) {
            const extIndex = fileName ? fileName.lastIndexOf('.') : -1;
            if (extIndex > 0) {
                return fileName.substring(extIndex + 1);
            }
            return '';
        }
        ngOnDestroy() {
            if (this.backButtonListenerDeregister) {
                this.backButtonListenerDeregister();
            }
        }
        onFileClick(file) {
            if (file.isFile) {
                if (file.isSelected) {
                    this.deselectFile(file);
                }
                else {
                    this.selectFile(file);
                }
            }
            else {
                this.goToFolder(file);
            }
        }
        set show(flag) {
            let rootDir = cordova.file.externalRootDirectory;
            this.isVisible = flag;
            if (flag) {
                if (!this.currentFolder) {
                    if (i1$1.isIos()) {
                        rootDir = cordova.file.documentsDirectory;
                    }
                    resolveLocalFileSystemURL(rootDir, root => this.goToFolder(root));
                }
                this.backButtonListenerDeregister = this.deviceService.onBackButtonTap(() => {
                    if (this.isVisible) {
                        if (this.currentFolder.parent) {
                            this.onFileClick(this.currentFolder.parent);
                        }
                        else {
                            this.isVisible = false;
                        }
                        i1$1.$appDigest();
                        return false;
                    }
                });
            }
            else if (this.backButtonListenerDeregister) {
                this.backButtonListenerDeregister();
            }
        }
        submit() {
            const files = [];
            this.loadFileSize(this.selectedFiles).then(() => {
                lodashEs.forEach(this.selectedFiles, function (f) {
                    f.isSelected = false;
                    // @ts-ignore
                    files.push({ path: f.nativeURL,
                        name: f.name,
                        size: f.size });
                });
                this.selectedFiles = [];
                this.isVisible = false;
                this.submitEmitter.next({ files: files });
            });
        }
        deselectFile(file) {
            lodashEs.remove(this.selectedFiles, file);
            file.isSelected = false;
        }
        goToFolder(folder) {
            if (!folder.files) {
                this.loadFolder(folder, this.fileTypeToSelect)
                    .then(files => {
                    folder.files = files;
                    folder.parent = this.currentFolder;
                    this.currentFolder = folder;
                });
            }
            else {
                this.currentFolder = folder;
            }
        }
        loadFileSize(files) {
            return Promise.all(files.map(f => {
                return new Promise((resolve, reject) => {
                    f.file(o => {
                        f.size = o.size;
                        resolve();
                    }, reject);
                });
            }));
        }
        loadFolder(folder, fileTypeToSelect) {
            return new Promise((resolve, reject) => {
                let fileTypeToShow;
                folder.createReader().readEntries((entries) => {
                    if (!lodashEs.isEmpty(fileTypeToSelect)) {
                        fileTypeToShow = lodashEs.split(fileTypeToSelect, ',');
                        entries = lodashEs.filter(entries, e => {
                            // @ts-ignore
                            return !e.isFile || lodashEs.findIndex(fileTypeToShow, ext => lodashEs.endsWith(e.name, '.' + ext)) >= 0;
                        });
                    }
                    // @ts-ignore
                    resolve(lodashEs.sortBy(entries, e => (e.isFile ? '1_' : '0_') + e.name.toLowerCase()));
                }, reject);
            });
        }
        refreshFolder() {
            return this.loadFolder(this.currentFolder, this.fileTypeToSelect)
                .then(files => this.currentFolder.files = files);
        }
        selectFile(file) {
            if (!this.multiple && this.selectedFiles.length > 0) {
                this.selectedFiles[0].isSelected = false;
                this.selectedFiles = [];
            }
            this.selectedFiles.push(file);
            file.isSelected = true;
        }
        static { this.ɵfac = function FileBrowserComponent_Factory(t) { return new (t || FileBrowserComponent)(i0__namespace.ɵɵdirectiveInject(i1__namespace.DeviceService)); }; }
        static { this.ɵcmp = /*@__PURE__*/ i0__namespace.ɵɵdefineComponent({ type: FileBrowserComponent, selectors: [["", "wmMobileFileBrowser", ""]], inputs: { fileTypeToSelect: "fileTypeToSelect", multiple: "multiple" }, outputs: { submitEmitter: "submit" }, attrs: _c0$2, decls: 1, vars: 1, consts: [["class", "app-file-browser", 4, "ngIf"], [1, "app-file-browser"], [1, "modal-backdrop", "fade"], [1, "modal", "fade", 2, "display", "block"], [1, "modal-dialog"], [1, "modal-content"], [1, "modal-header", "clearfix"], [1, "modal-title", "pull-left"], [3, "click", "hidden"], [1, "wi", "wi-long-arrow-left"], [1, "selected-file-button", "pull-right", 3, "click"], [1, "wi", "wi-refresh"], [1, "modal-body"], ["class", "file-info-box", 4, "ngFor", "ngForOf"], [1, "modal-footer"], ["type", "button", "class", "btn btn-primary", 3, "click", 4, "ngIf"], ["type", "button", 1, "btn", "btn-default", 3, "click"], [1, "file-info-box"], [1, "file-info", 3, "click"], ["class", "file-icon wi wi-folder", 4, "ngIf"], [3, "class", 4, "ngIf"], [1, "file-name"], [1, "file-icon", "wi", "wi-folder"], ["type", "button", 1, "btn", "btn-primary", 3, "click"], [1, "badge", "badge-light"]], template: function FileBrowserComponent_Template(rf, ctx) { if (rf & 1) {
                i0__namespace.ɵɵtemplate(0, FileBrowserComponent_div_0_Template, 18, 8, "div", 0);
            } if (rf & 2) {
                i0__namespace.ɵɵproperty("ngIf", ctx.isVisible && ctx.currentFolder);
            } }, dependencies: [i3$1__namespace.NgForOf, i3$1__namespace.NgIf], encapsulation: 2 }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(FileBrowserComponent, [{
            type: i0.Component,
            args: [{ selector: '[wmMobileFileBrowser]', template: "<div class=\"app-file-browser\" *ngIf=\"isVisible && currentFolder\">\n    <div class=\"modal-backdrop fade\" [class.in]=\"isVisible\"></div>\n    <div class=\"modal fade\" style=\"display: block;\" [class.in]=\"isVisible\" >\n        <div class=\"modal-dialog\">\n            <div class=\"modal-content\">\n                <div class=\"modal-header clearfix\">\n                    <h4 class=\"modal-title pull-left\">\n                        <span (click)=\"onFileClick(currentFolder.parent)\" [hidden]=\"!!!currentFolder.parent\">\n                            <i class=\"wi wi-long-arrow-left\"></i>\n                        </span>\n                     {{currentFolder.name}}\n                    </h4>\n                    <div class=\"selected-file-button pull-right\" (click)=\"refreshFolder()\">\n                        <i class=\"wi wi-refresh\"></i>\n                    </div>\n                </div>\n                <div class=\"modal-body\">\n                    <div class=\"file-info-box\" *ngFor=\"let file of currentFolder.files\">\n                        <div class=\"file-info\"  [class.bg-primary]=\"file.isSelected\" (click)=\"onFileClick(file)\">\n                            <i class=\"file-icon wi wi-folder\" *ngIf=\"!file.isFile\"></i>\n                            <i class=\"file-icon wi wi-file {{getFileExtension(file.name)}}\" *ngIf=\"file.isFile\"></i>\n                            <span class=\"file-name\">{{file.name}}</span>\n                        </div>\n                    </div>\n                </div>\n                <div class=\"modal-footer\">\n                    <button type=\"button\" class=\"btn btn-primary\" *ngIf=\"selectedFiles && selectedFiles.length > 0\" (click)=\"submit()\">\n                        Done <span class=\"badge badge-light\">{{selectedFiles.length}}</span>\n                    </button>\n                    <button type=\"button\" class=\"btn btn-default\" (click)=\"show = false;\">Close</button>\n                </div>\n            </div>\n        </div>\n    </div>\n</div>" }]
        }], () => [{ type: i1__namespace.DeviceService }], { fileTypeToSelect: [{
                type: i0.Input
            }], multiple: [{
                type: i0.Input
            }], submitEmitter: [{
                type: i0.Output,
                args: ['submit']
            }] }); })();
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassDebugInfo(FileBrowserComponent, { className: "FileBrowserComponent", filePath: "file-browser/file-browser.component.ts", lineNumber: 28 }); })();

    class FileSelectorService {
        static { this.SERVICE_NAME = 'FileSelectorService'; }
        constructor(spinnerService) {
            this.spinnerService = spinnerService;
        }
        selectAudio(multiple = false) {
            var spinnerId = this.spinnerService.show("");
            return new Promise((resolve, reject) => {
                cordova.wavemaker.filePicker.selectAudio(multiple, resolve, reject);
            }).then(files => this.getFiles(files))
                .then((paths) => {
                this.spinnerService.hide(spinnerId);
                return paths;
            });
        }
        setFileBrowser(f) {
            this.fileBrowserComponent = f;
        }
        selectFiles(multiple = false, fileTypeToSelect) {
            var spinnerId = this.spinnerService.show("");
            return new Promise((resolve, reject) => {
                cordova.wavemaker.filePicker.selectFiles(multiple, resolve, reject);
            }).then(files => this.getFiles(files))
                .then((paths) => {
                this.spinnerService.hide(spinnerId);
                return paths;
            });
        }
        selectImages(multiple = false) {
            var spinnerId = this.spinnerService.show("");
            return new Promise((resolve, reject) => {
                cordova.wavemaker.filePicker.selectImage(multiple, resolve, reject);
            }).then(files => this.getFiles(files))
                .then((paths) => {
                this.spinnerService.hide(spinnerId);
                return paths;
            });
        }
        selectVideos(multiple = false) {
            var spinnerId = this.spinnerService.show("");
            return new Promise((resolve, reject) => {
                cordova.wavemaker.filePicker.selectVideo(multiple, resolve, reject);
            }).then(files => this.getFiles(files))
                .then((paths) => {
                this.spinnerService.hide(spinnerId);
                return paths;
            });
        }
        /**
         * Converts the file to blob using filepath
         * @param filePaths, array of file paths
         * @returns fileObj having name, path, content
         */
        getFiles(filePaths) {
            // @ts-ignore
            return Promise.all(lodashEs.map(filePaths, filePath => {
                if (filePath.indexOf('://') < 0) {
                    filePath = 'file://' + filePath;
                }
                return i1$1.convertToBlob(filePath);
            })).then(filesList => {
                return lodashEs.map(filesList, fileObj => {
                    const path = fileObj.filepath;
                    return {
                        name: path.split('/').pop(),
                        path: path,
                        content: fileObj.blob,
                        size: fileObj.blob.size
                    };
                });
            });
        }
        static { this.ɵfac = function FileSelectorService_Factory(t) { return new (t || FileSelectorService)(i0__namespace.ɵɵinject(i1$1__namespace.AbstractSpinnerService)); }; }
        static { this.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: FileSelectorService, factory: FileSelectorService.ɵfac, providedIn: 'root' }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(FileSelectorService, [{
            type: i0.Injectable,
            args: [{ providedIn: 'root' }]
        }], () => [{ type: i1$1__namespace.AbstractSpinnerService }], null); })();

    const DEFAULT_IMAGE = 'resources/images/imagelists/default-image.png';
    class ImageCacheDirective {
        constructor(componentInstance, deviceFileCacheService, file) {
            this.componentInstance = componentInstance;
            this.deviceFileCacheService = deviceFileCacheService;
            this.file = file;
            this._isEnabled = false;
            this._lastUrl = '';
        }
        ngDoCheck() {
            if (lodashEs.isString(this.componentInstance.imgSource)
                && this.componentInstance.imgSource.startsWith('http')) {
                if (this._lastUrl !== this.componentInstance.imgSource) {
                    this._lastUrl = this.componentInstance.imgSource;
                    this.componentInstance.imgSource = DEFAULT_IMAGE;
                    this.getLocalPath(this._lastUrl).then((localPath) => {
                        this._cacheUrl = i1$1.transformFileURI(localPath);
                        this.componentInstance.imgSource = this._cacheUrl;
                    });
                }
                else if (this._cacheUrl) {
                    this.componentInstance.imgSource = this._cacheUrl;
                }
            }
        }
        set wmImageCache(val) {
            this._isEnabled = (i1$1.hasCordova() && val === 'true');
        }
        getLocalPath(val) {
            if (i1$1.hasCordova() && val && val.indexOf('{{') < 0 && val.startsWith('http')) {
                return this.deviceFileCacheService.getLocalPath(val, true, true, !this._isEnabled)
                    .catch(i1$1.noop);
            }
            return Promise.resolve(val);
        }
        static { this.ɵfac = function ImageCacheDirective_Factory(t) { return new (t || ImageCacheDirective)(i0__namespace.ɵɵdirectiveInject(i5.WidgetRef, 2), i0__namespace.ɵɵdirectiveInject(i1__namespace.DeviceFileCacheService), i0__namespace.ɵɵdirectiveInject(i2__namespace.File)); }; }
        static { this.ɵdir = /*@__PURE__*/ i0__namespace.ɵɵdefineDirective({ type: ImageCacheDirective, selectors: [["", "wmImageCache", ""]], inputs: { wmImageCache: "wmImageCache" } }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(ImageCacheDirective, [{
            type: i0.Directive,
            args: [{
                    selector: '[wmImageCache]'
                }]
        }], () => [{ type: undefined, decorators: [{
                    type: i0.Self
                }, {
                    type: i0.Inject,
                    args: [i5.WidgetRef]
                }] }, { type: i1__namespace.DeviceFileCacheService }, { type: i2__namespace.File }], { wmImageCache: [{
                type: i0.Input
            }] }); })();

    const registerProps = () => {
        i5.register('wm-network-info-toaster', new Map([]));
    };

    const _c0$1 = ["wmNetworkInfoToaster", ""];
    function NetworkInfoToasterComponent_div_0_div_1_Template(rf, ctx) { if (rf & 1) {
        const _r1 = i0__namespace.ɵɵgetCurrentView();
        i0__namespace.ɵɵelementStart(0, "div", 3);
        i0__namespace.ɵɵelement(1, "label", 4);
        i0__namespace.ɵɵelementStart(2, "button", 5);
        i0__namespace.ɵɵlistener("click", function NetworkInfoToasterComponent_div_0_div_1_Template_button_click_2_listener() { i0__namespace.ɵɵrestoreView(_r1); const ctx_r1 = i0__namespace.ɵɵnextContext(2); return i0__namespace.ɵɵresetView(ctx_r1.hideMessage()); });
        i0__namespace.ɵɵelementEnd()();
    } if (rf & 2) {
        const ctx_r1 = i0__namespace.ɵɵnextContext(2);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_NETWORK_NOT_AVAILABLE);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("textContent", ctx_r1.appLocale.LABEL_HIDE_NETWORK_INFO);
    } }
    function NetworkInfoToasterComponent_div_0_div_2_Template(rf, ctx) { if (rf & 1) {
        const _r3 = i0__namespace.ɵɵgetCurrentView();
        i0__namespace.ɵɵelementStart(0, "div", 3);
        i0__namespace.ɵɵelement(1, "label", 4);
        i0__namespace.ɵɵelementStart(2, "button", 5);
        i0__namespace.ɵɵlistener("click", function NetworkInfoToasterComponent_div_0_div_2_Template_button_click_2_listener() { i0__namespace.ɵɵrestoreView(_r3); const ctx_r1 = i0__namespace.ɵɵnextContext(2); return i0__namespace.ɵɵresetView(ctx_r1.hideMessage()); });
        i0__namespace.ɵɵelementEnd()();
    } if (rf & 2) {
        const ctx_r1 = i0__namespace.ɵɵnextContext(2);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_SERVICE_NOT_AVAILABLE);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("textContent", ctx_r1.appLocale.LABEL_HIDE_NETWORK_INFO);
    } }
    function NetworkInfoToasterComponent_div_0_div_3_Template(rf, ctx) { if (rf & 1) {
        const _r4 = i0__namespace.ɵɵgetCurrentView();
        i0__namespace.ɵɵelementStart(0, "div", 3);
        i0__namespace.ɵɵelement(1, "label", 4);
        i0__namespace.ɵɵelementStart(2, "button", 5);
        i0__namespace.ɵɵlistener("click", function NetworkInfoToasterComponent_div_0_div_3_Template_button_click_2_listener() { i0__namespace.ɵɵrestoreView(_r4); const ctx_r1 = i0__namespace.ɵɵnextContext(2); return i0__namespace.ɵɵresetView(ctx_r1.hideMessage()); });
        i0__namespace.ɵɵelementEnd();
        i0__namespace.ɵɵelementStart(3, "button", 6);
        i0__namespace.ɵɵlistener("click", function NetworkInfoToasterComponent_div_0_div_3_Template_button_click_3_listener() { i0__namespace.ɵɵrestoreView(_r4); const ctx_r1 = i0__namespace.ɵɵnextContext(2); return i0__namespace.ɵɵresetView(ctx_r1.connect()); });
        i0__namespace.ɵɵelementEnd()();
    } if (rf & 2) {
        const ctx_r1 = i0__namespace.ɵɵnextContext(2);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_SERVICE_AVAILABLE);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("textContent", ctx_r1.appLocale.LABEL_HIDE_NETWORK_INFO);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("textContent", ctx_r1.appLocale.LABEL_CONNECT_TO_SERVICE);
    } }
    function NetworkInfoToasterComponent_div_0_div_4_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelementStart(0, "div", 3);
        i0__namespace.ɵɵelement(1, "label", 4);
        i0__namespace.ɵɵelementEnd();
    } if (rf & 2) {
        const ctx_r1 = i0__namespace.ɵɵnextContext(2);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_SERVICE_CONNECTING);
    } }
    function NetworkInfoToasterComponent_div_0_div_5_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelementStart(0, "div", 3);
        i0__namespace.ɵɵelement(1, "label", 4);
        i0__namespace.ɵɵelementEnd();
    } if (rf & 2) {
        const ctx_r1 = i0__namespace.ɵɵnextContext(2);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_SERVICE_CONNECTED);
    } }
    function NetworkInfoToasterComponent_div_0_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelementStart(0, "div", 1);
        i0__namespace.ɵɵtemplate(1, NetworkInfoToasterComponent_div_0_div_1_Template, 3, 2, "div", 2)(2, NetworkInfoToasterComponent_div_0_div_2_Template, 3, 2, "div", 2)(3, NetworkInfoToasterComponent_div_0_div_3_Template, 4, 3, "div", 2)(4, NetworkInfoToasterComponent_div_0_div_4_Template, 2, 1, "div", 2)(5, NetworkInfoToasterComponent_div_0_div_5_Template, 2, 1, "div", 2);
        i0__namespace.ɵɵelementEnd();
    } if (rf & 2) {
        const ctx_r1 = i0__namespace.ɵɵnextContext();
        i0__namespace.ɵɵproperty("ngSwitch", ctx_r1.networkState);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngSwitchCase", -3);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngSwitchCase", -2);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngSwitchCase", -1);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngSwitchCase", 0);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngSwitchCase", 1);
    } }
    const DEFAULT_CLS = 'network-info-toaster';
    const WIDGET_CONFIG = { widgetType: 'wm-network-info-toaster', hostClass: DEFAULT_CLS };
    exports.NetworkState = void 0;
    (function (NetworkState) {
        NetworkState[NetworkState["CONNECTED"] = 1] = "CONNECTED";
        NetworkState[NetworkState["CONNECTING"] = 0] = "CONNECTING";
        NetworkState[NetworkState["SERVICE_AVAILABLE_BUT_NOT_CONNECTED"] = -1] = "SERVICE_AVAILABLE_BUT_NOT_CONNECTED";
        NetworkState[NetworkState["NETWORK_AVAIABLE_BUT_SERVICE_NOT_AVAILABLE"] = -2] = "NETWORK_AVAIABLE_BUT_SERVICE_NOT_AVAILABLE";
        NetworkState[NetworkState["NETWORK_NOT_AVAIABLE"] = -3] = "NETWORK_NOT_AVAIABLE";
    })(exports.NetworkState || (exports.NetworkState = {}));
    class NetworkInfoToasterComponent extends i5.StylableComponent {
        static { this.initializeProps = registerProps(); }
        constructor(networkService, app, inj, explicitContext) {
            super(inj, WIDGET_CONFIG, explicitContext);
            this.networkService = networkService;
            this.showMessage = false;
            this.isServiceConnected = false;
            this.isServiceAvailable = false;
            i5.styler(this.$element, this);
            this.isServiceAvailable = this.networkService.isAvailable();
            this.isServiceConnected = this.networkService.isConnected();
            this._listenerDestroyer = app.subscribe('onNetworkStateChange', (data) => {
                this.renderMessage(data);
            });
            this.renderMessage();
        }
        renderMessage(data) {
            data = data || this.networkService.getState();
            const oldState = this.networkState;
            let autoHide = false;
            if (data.noServiceRequired) {
                return false;
            }
            if (data.isConnected) {
                this.networkState = exports.NetworkState.CONNECTED;
                autoHide = true;
            }
            else if (data.isConnecting) {
                this.networkState = exports.NetworkState.CONNECTING;
            }
            else if (data.isServiceAvailable) {
                this.networkState = exports.NetworkState.SERVICE_AVAILABLE_BUT_NOT_CONNECTED;
            }
            else if (data.isNetworkAvailable && !data.isServiceAvailable) {
                this.networkState = exports.NetworkState.NETWORK_AVAIABLE_BUT_SERVICE_NOT_AVAILABLE;
            }
            else {
                this.networkState = exports.NetworkState.NETWORK_NOT_AVAIABLE;
            }
            this.showMessage = (!(oldState === undefined && data.isConnected) && oldState !== this.networkState);
            if (autoHide && this.showMessage) {
                setTimeout(() => {
                    this.showMessage = false;
                    i1$1.$appDigest();
                }, 5000);
            }
        }
        connect() {
            this.networkService.connect();
        }
        hideMessage() {
            this.showMessage = false;
        }
        ngOnDestroy() {
            this._listenerDestroyer();
            super.ngOnDestroy();
        }
        static { this.ɵfac = function NetworkInfoToasterComponent_Factory(t) { return new (t || NetworkInfoToasterComponent)(i0__namespace.ɵɵdirectiveInject(i1__namespace.NetworkService), i0__namespace.ɵɵdirectiveInject(i1$1__namespace.App), i0__namespace.ɵɵdirectiveInject(i0__namespace.Injector), i0__namespace.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
        static { this.ɵcmp = /*@__PURE__*/ i0__namespace.ɵɵdefineComponent({ type: NetworkInfoToasterComponent, selectors: [["", "wmNetworkInfoToaster", ""]], features: [i0__namespace.ɵɵProvidersFeature([
                    i5.provideAsWidgetRef(NetworkInfoToasterComponent)
                ]), i0__namespace.ɵɵInheritDefinitionFeature], attrs: _c0$1, decls: 1, vars: 1, consts: [["class", "network-info-toaster-content", 3, "ngSwitch", 4, "ngIf"], [1, "network-info-toaster-content", 3, "ngSwitch"], ["class", "info", 4, "ngSwitchCase"], [1, "info"], [1, "message", 3, "textContent"], [1, "btn", "btn-default", "hide-btn", 3, "click", "textContent"], [1, "btn", "btn-primary", "connect-btn", 3, "click", "textContent"]], template: function NetworkInfoToasterComponent_Template(rf, ctx) { if (rf & 1) {
                i0__namespace.ɵɵtemplate(0, NetworkInfoToasterComponent_div_0_Template, 6, 6, "div", 0);
            } if (rf & 2) {
                i0__namespace.ɵɵproperty("ngIf", ctx.showMessage);
            } }, dependencies: [i3$1__namespace.NgIf, i3$1__namespace.NgSwitch, i3$1__namespace.NgSwitchCase, i5__namespace.TextContentDirective], encapsulation: 2 }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(NetworkInfoToasterComponent, [{
            type: i0.Component,
            args: [{ selector: '[wmNetworkInfoToaster]', providers: [
                        i5.provideAsWidgetRef(NetworkInfoToasterComponent)
                    ], template: "<div class=\"network-info-toaster-content\" [ngSwitch]=\"networkState\" *ngIf=\"showMessage\">\n    <div class=\"info\" *ngSwitchCase=\"-3\">\n       <label class=\"message\" [textContent]=\"appLocale.MESSAGE_NETWORK_NOT_AVAILABLE\"></label>\n       <button class=\"btn btn-default hide-btn\" (click)=\"hideMessage()\" [textContent]=\"appLocale.LABEL_HIDE_NETWORK_INFO\"></button>\n    </div>\n    <div class=\"info\" *ngSwitchCase=\"-2\">\n       <label class=\"message\" [textContent]=\"appLocale.MESSAGE_SERVICE_NOT_AVAILABLE\"></label>\n       <button class=\"btn btn-default hide-btn\" (click)=\"hideMessage()\" [textContent]=\"appLocale.LABEL_HIDE_NETWORK_INFO\"></button>\n    </div>\n    <div class=\"info\" *ngSwitchCase=\"-1\">\n       <label class=\"message\" [textContent]=\"appLocale.MESSAGE_SERVICE_AVAILABLE\"></label>\n       <button class=\"btn btn-default hide-btn\" (click)=\"hideMessage()\" [textContent]=\"appLocale.LABEL_HIDE_NETWORK_INFO\"></button>\n       <button class=\"btn btn-primary connect-btn\" (click)=\"connect()\" [textContent]=\"appLocale.LABEL_CONNECT_TO_SERVICE\"></button>\n    </div>\n    <div class=\"info\" *ngSwitchCase=\"0\">\n       <label class=\"message\" [textContent]=\"appLocale.MESSAGE_SERVICE_CONNECTING\"></label>\n    </div>\n    <div class=\"info\" *ngSwitchCase=\"1\">\n       <label class=\"message\" [textContent]=\"appLocale.MESSAGE_SERVICE_CONNECTED\"></label>\n    </div>\n</div>" }]
        }], () => [{ type: i1__namespace.NetworkService }, { type: i1$1__namespace.App }, { type: i0__namespace.Injector }, { type: undefined, decorators: [{
                    type: i0.Inject,
                    args: ['EXPLICIT_CONTEXT']
                }, {
                    type: i0.Optional
                }] }], null); })();
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassDebugInfo(NetworkInfoToasterComponent, { className: "NetworkInfoToasterComponent", filePath: "network-info-toaster/network-info-toaster.component.ts", lineNumber: 28 }); })();

    const _c0 = ["wmProcessManager", ""];
    const _c1 = a0 => ({ instance: a0 });
    function ProcessManagerComponent_ng_container_0_li_4_ng_template_8_Template(rf, ctx) { }
    function ProcessManagerComponent_ng_container_0_li_4_button_9_Template(rf, ctx) { if (rf & 1) {
        const _r1 = i0__namespace.ɵɵgetCurrentView();
        i0__namespace.ɵɵelementStart(0, "button", 16);
        i0__namespace.ɵɵlistener("click", function ProcessManagerComponent_ng_container_0_li_4_button_9_Template_button_click_0_listener() { i0__namespace.ɵɵrestoreView(_r1); const instance_r2 = i0__namespace.ɵɵnextContext().$implicit; return i0__namespace.ɵɵresetView(instance_r2.onStop()); });
        i0__namespace.ɵɵtext(1);
        i0__namespace.ɵɵelementEnd();
    } if (rf & 2) {
        const instance_r2 = i0__namespace.ɵɵnextContext().$implicit;
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵtextInterpolate1(" ", instance_r2.stopButtonLabel, " ");
    } }
    function ProcessManagerComponent_ng_container_0_li_4_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelementStart(0, "li", 7)(1, "div", 8)(2, "div", 9)(3, "label", 10);
        i0__namespace.ɵɵtext(4);
        i0__namespace.ɵɵelementEnd()();
        i0__namespace.ɵɵelementStart(5, "div", 11)(6, "label", 12);
        i0__namespace.ɵɵtext(7);
        i0__namespace.ɵɵelementEnd()()();
        i0__namespace.ɵɵtemplate(8, ProcessManagerComponent_ng_container_0_li_4_ng_template_8_Template, 0, 0, "ng-template", 13)(9, ProcessManagerComponent_ng_container_0_li_4_button_9_Template, 2, 1, "button", 14);
        i0__namespace.ɵɵelement(10, "div", 15);
        i0__namespace.ɵɵelementEnd();
    } if (rf & 2) {
        const instance_r2 = ctx.$implicit;
        i0__namespace.ɵɵnextContext(2);
        const progressTemplate_r3 = i0__namespace.ɵɵreference(2);
        i0__namespace.ɵɵadvance(4);
        i0__namespace.ɵɵtextInterpolate(instance_r2.name);
        i0__namespace.ɵɵadvance(3);
        i0__namespace.ɵɵtextInterpolate1(" ", instance_r2.progressLabel, "");
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngTemplateOutlet", progressTemplate_r3)("ngTemplateOutletContext", i0__namespace.ɵɵpureFunction1(5, _c1, instance_r2));
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngIf", instance_r2.onStop);
    } }
    function ProcessManagerComponent_ng_container_0_li_5_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelementStart(0, "li", 7)(1, "label", 17);
        i0__namespace.ɵɵtext(2);
        i0__namespace.ɵɵelementEnd()();
    } if (rf & 2) {
        const ctx_r3 = i0__namespace.ɵɵnextContext(2);
        i0__namespace.ɵɵadvance(2);
        i0__namespace.ɵɵtextInterpolate1(" (", ctx_r3.queue.length, ") queued ");
    } }
    function ProcessManagerComponent_ng_container_0_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelementContainerStart(0);
        i0__namespace.ɵɵelementStart(1, "div", 2)(2, "div", 3)(3, "ul", 4);
        i0__namespace.ɵɵtemplate(4, ProcessManagerComponent_ng_container_0_li_4_Template, 11, 7, "li", 5)(5, ProcessManagerComponent_ng_container_0_li_5_Template, 3, 1, "li", 6);
        i0__namespace.ɵɵelementEnd()()();
        i0__namespace.ɵɵelementContainerEnd();
    } if (rf & 2) {
        const ctx_r3 = i0__namespace.ɵɵnextContext();
        i0__namespace.ɵɵadvance(4);
        i0__namespace.ɵɵproperty("ngForOf", ctx_r3.getVisibleInstances(ctx_r3.instances));
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngIf", ctx_r3.queue.length > 0);
    } }
    function ProcessManagerComponent_ng_template_1_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelement(0, "div", 18);
    } }
    const MAX_PROCESS = 3;
    class ProcessManagerComponent {
        constructor(el) {
            this.el = el;
            this.isVisible = true;
            this.instances = [];
            this.queue = [];
            i1$1.addClass(this.el.nativeElement, 'app-global-progress-bar modal default');
        }
        createInstance(name, min = 0, max = 100) {
            const instance = {
                max: max,
                min: min,
                name: name,
                onStop: null,
                progressLabel: '',
                show: min !== max,
                stopButtonLabel: 'Cancel',
                value: 0
            };
            const api = {
                get: (propertyName) => instance[propertyName],
                set: (propertyName, propertyValue) => this.setInstaceProperty(instance, propertyName, propertyValue),
                destroy: () => this.removeInstance(instance)
            };
            return this.addToQueue(instance).then(() => api);
        }
        getVisibleInstances() {
            return this.instances.filter(i => i.show);
        }
        ngDoCheck() {
            const hasInstancesToShow = !!this.instances.find(i => i.show);
            if (this.isVisible && !hasInstancesToShow) {
                i1$1.setAttr(this.el.nativeElement, 'hidden', 'true');
                this.isVisible = false;
            }
            else if (!this.isVisible && hasInstancesToShow) {
                i1$1.removeAttr(this.el.nativeElement, 'hidden');
                this.isVisible = true;
            }
        }
        addToQueue(instance) {
            return new Promise(resolve => {
                this.queue.push(() => {
                    if (this.instances.length < MAX_PROCESS) {
                        this.instances.push(instance);
                        resolve(instance);
                    }
                    else {
                        return false;
                    }
                });
                this.flushQueue();
            });
        }
        flushQueue() {
            if (this.queue.length > 0 && this.queue[0]() !== false) {
                this.queue.shift();
                this.flushQueue();
            }
        }
        removeInstance(instance) {
            return new Promise(resolve => {
                setTimeout(() => {
                    lodashEs.remove(this.instances, instance);
                    this.flushQueue();
                    resolve();
                }, 1000);
            });
        }
        setInstaceProperty(instance, propertyName, propertyValue) {
            if (propertyName === 'value') {
                if (instance.value >= instance.max) {
                    propertyValue = instance.max;
                }
                instance.value = propertyValue;
                instance.progressLabel = instance.value + '/' + instance.max;
            }
            else if (propertyName === 'onStop' && lodashEs.isFunction(propertyValue)) {
                instance.onStop = () => {
                    propertyValue();
                    return this.removeInstance(instance);
                };
            }
            else {
                instance[propertyName] = propertyValue;
            }
            instance.show = instance.min !== instance.max;
        }
        static { this.ɵfac = function ProcessManagerComponent_Factory(t) { return new (t || ProcessManagerComponent)(i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef)); }; }
        static { this.ɵcmp = /*@__PURE__*/ i0__namespace.ɵɵdefineComponent({ type: ProcessManagerComponent, selectors: [["", "wmProcessManager", ""]], features: [i0__namespace.ɵɵProvidersFeature([
                    i5.provideAsWidgetRef(ProcessManagerComponent)
                ])], attrs: _c0, decls: 3, vars: 1, consts: [["progressTemplate", ""], [4, "ngIf"], [1, "modal-dialog", "app-dialog"], [1, "modal-content"], [1, "instance-list", "list-unstyled"], ["class", "instance-list-item", 4, "ngFor", "ngForOf"], ["class", "instance-list-item", 4, "ngIf"], [1, "instance-list-item"], [1, "row"], [1, "col-xs-8"], [1, "app-global-progress-bar-name", "h6"], [1, "col-xs-4", "app-global-progress-bar-progress-label-col"], [1, "app-global-progress-bar-progress-label", "h6"], [3, "ngTemplateOutlet", "ngTemplateOutletContext"], ["class", "btn btn-secondary pull-right stop-btn", 3, "click", 4, "ngIf"], [2, "clear", "both"], [1, "btn", "btn-secondary", "pull-right", "stop-btn", 3, "click"], [1, "global-progress-bar-ui-primary-label", "h6"], ["wmProgressBar", "", "minvalue.bind", "instance.min", "maxvalue.bind", "instance.max", "datavalue.bind", "instance.value"]], template: function ProcessManagerComponent_Template(rf, ctx) { if (rf & 1) {
                i0__namespace.ɵɵtemplate(0, ProcessManagerComponent_ng_container_0_Template, 6, 2, "ng-container", 1)(1, ProcessManagerComponent_ng_template_1_Template, 1, 0, "ng-template", null, 0, i0__namespace.ɵɵtemplateRefExtractor);
            } if (rf & 2) {
                i0__namespace.ɵɵproperty("ngIf", ctx.instances.length > 0);
            } }, dependencies: [i3$1__namespace.NgForOf, i3$1__namespace.NgIf, i3$1__namespace.NgTemplateOutlet, i2$1__namespace.ProgressBarComponent], encapsulation: 2 }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(ProcessManagerComponent, [{
            type: i0.Component,
            args: [{ selector: '[wmProcessManager]', providers: [
                        i5.provideAsWidgetRef(ProcessManagerComponent)
                    ], template: "<ng-container *ngIf=\"instances.length > 0\">\n   <div class=\"modal-dialog app-dialog\">\n       <div class=\"modal-content\">\n           <ul class=\"instance-list list-unstyled\">\n               <li *ngFor=\"let instance of getVisibleInstances(instances); index as i\" class=\"instance-list-item\">\n                   <div class=\"row\">\n                       <div class=\"col-xs-8\">\n                           <label class=\"app-global-progress-bar-name h6\">{{instance.name}}</label>\n                       </div>\n                       <div class=\"col-xs-4 app-global-progress-bar-progress-label-col\">\n                           <label class=\"app-global-progress-bar-progress-label h6\">\n                                   {{instance.progressLabel}}</label>\n                       </div>\n                   </div>\n                   <ng-template [ngTemplateOutlet]=\"progressTemplate\" [ngTemplateOutletContext]=\"{instance: instance}\"></ng-template>\n                   <button class=\"btn btn-secondary pull-right stop-btn\" *ngIf=\"instance.onStop\" (click)=\"instance.onStop();\">\n                       {{instance.stopButtonLabel}}\n                   </button>\n                   <div style=\"clear: both;\"></div>\n               </li>\n               <li class=\"instance-list-item\" *ngIf=\"queue.length > 0\">\n                   <label class=\"global-progress-bar-ui-primary-label h6\">\n                       ({{queue.length}}) queued\n                   </label>\n               </li>\n           </ul>\n       </div>\n   </div>\n</ng-container>\n<ng-template #progressTemplate let-instance=\"instance\">\n    <div wmProgressBar minvalue.bind=\"instance.min\" maxvalue.bind=\"instance.max\" datavalue.bind=\"instance.value\"></div>\n</ng-template>" }]
        }], () => [{ type: i0__namespace.ElementRef }], null); })();
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassDebugInfo(ProcessManagerComponent, { className: "ProcessManagerComponent", filePath: "process-manager/process-manager.component.ts", lineNumber: 33 }); })();

    class ProcessManagementService {
        static { this.SERVICE_NAME = 'ProcessManagementService'; }
        setUIComponent(processManagerComponent) {
            this.processManagerComponent = processManagerComponent;
        }
        /**
         * Returns a promise that will be resolved when an instance is available. At max, 3 instances can only run
         * in parallel and rest has to wait till a process is completed.
         *
         * A progress instance has the following properties.
         *
         *   1) min {number} minimum value, default value is 0 </br>
         *   2) max {number} maximum value, default value is 100 </br>
         *   3) value {number} progress value </br>
         *   4) progressLabel {string} process name </br>
         *   5) stopButtonLabel {string} label for stop button, default value is 'Cancel' </br>
         *   6) onStop {function} function to invoke when stop button is clicked. </br>
         *
         * A progress instance has 3 methods </br>
         *   1) set(property, value) -- sets value to the corresponding property </br>
         *   2) get(property) -- returns property value </br>
         *   3) destroy() -- closes the instance. </br>
         *
         * A progress instance will get auto closed when value and max are equal or when destroy method is called.
         *
         * @param {string} name name of the process whose progress is going to be shown
         * @param {number} min minimum value
         * @param {number} max maximum value
         *
         * @returns {object} a promise
         */
        createInstance(name, min, max) {
            if (!this.processManagerComponent) {
                return Promise.reject('ProcessManagerComponent is missing');
            }
            return this.processManagerComponent.createInstance(name, min, max);
        }
        static { this.ɵfac = function ProcessManagementService_Factory(t) { return new (t || ProcessManagementService)(); }; }
        static { this.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: ProcessManagementService, factory: ProcessManagementService.ɵfac, providedIn: 'root' }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(ProcessManagementService, [{
            type: i0.Injectable,
            args: [{ providedIn: 'root' }]
        }], null, null); })();

    const components = [
        AnchorDirective,
        AppUpdateComponent,
        FileBrowserComponent,
        ImageCacheDirective,
        NetworkInfoToasterComponent,
        ProcessManagerComponent
    ];
    class BasicModule {
        static { this.ɵfac = function BasicModule_Factory(t) { return new (t || BasicModule)(); }; }
        static { this.ɵmod = /*@__PURE__*/ i0__namespace.ɵɵdefineNgModule({ type: BasicModule }); }
        static { this.ɵinj = /*@__PURE__*/ i0__namespace.ɵɵdefineInjector({ imports: [i3$1.CommonModule,
                i2$1.ProgressModule,
                i5.WmComponentsModule] }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(BasicModule, [{
            type: i0.NgModule,
            args: [{
                    imports: [
                        i3$1.CommonModule,
                        i2$1.ProgressModule,
                        i5.WmComponentsModule
                    ],
                    declarations: [...components],
                    exports: [...components]
                }]
        }], null, null); })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(BasicModule, { declarations: [AnchorDirective,
            AppUpdateComponent,
            FileBrowserComponent,
            ImageCacheDirective,
            NetworkInfoToasterComponent,
            ProcessManagerComponent], imports: [i3$1.CommonModule,
            i2$1.ProgressModule,
            i5.WmComponentsModule], exports: [AnchorDirective,
            AppUpdateComponent,
            FileBrowserComponent,
            ImageCacheDirective,
            NetworkInfoToasterComponent,
            ProcessManagerComponent] }); })();

    exports.AnchorDirective = AnchorDirective;
    exports.AppUpdateComponent = AppUpdateComponent;
    exports.BasicModule = BasicModule;
    exports.FileBrowserComponent = FileBrowserComponent;
    exports.FileSelectorService = FileSelectorService;
    exports.ImageCacheDirective = ImageCacheDirective;
    exports.NetworkInfoToasterComponent = NetworkInfoToasterComponent;
    exports.ProcessManagementService = ProcessManagementService;
    exports.ProcessManagerComponent = ProcessManagerComponent;

}));
