import * as i0 from '@angular/core';
import { Directive, Inject, HostListener, Component, EventEmitter, Input, Output, Injectable, Self, Optional, NgModule } from '@angular/core';
import * as i5 from '@wm/components/base';
import { WidgetRef, register, StylableComponent, styler, provideAsWidgetRef, WmComponentsModule } from '@wm/components/base';
import { startsWith, forEach, remove, isEmpty, split, endsWith, findIndex, filter, sortBy, map, isString, isFunction } from 'lodash-es';
import * as i4 from '@angular/common/http';
import * as i2 from '@awesome-cordova-plugins/file/ngx';
import * as i3 from '@awesome-cordova-plugins/file-opener/ngx';
import * as i1$1 from '@wm/core';
import { addClass, setCSS, hasCordova, noop, removeClass, isIos, $appDigest, convertToBlob, transformFileURI, setAttr, removeAttr } from '@wm/core';
import * as i1 from '@wm/mobile/core';
import * as i3$1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2$1 from '@wm/components/basic/progress';
import { ProgressModule } from '@wm/components/basic/progress';

class AnchorDirective {
    constructor(widget) {
        this.widget = widget;
    }
    onClick() {
        let href = this.widget.hyperlink;
        if (href) {
            if (href.indexOf(':') >= 0 && !(startsWith(href, 'http://') || startsWith(href, 'https://'))) {
                return;
            }
            else if (startsWith(href, '#')) {
                window.location.href = window.location.origin + window.location.pathname + href;
                return;
            }
            else if (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.ɵɵdirectiveInject(WidgetRef)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: AnchorDirective, selectors: [["", "wmAnchor", ""]], hostBindings: function AnchorDirective_HostBindings(rf, ctx) { if (rf & 1) {
            i0.ɵɵlistener("click", function AnchorDirective_click_HostBindingHandler() { return ctx.onClick(); });
        } } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AnchorDirective, [{
        type: Directive,
        args: [{
                selector: '[wmAnchor]'
            }]
    }], () => [{ type: undefined, decorators: [{
                type: Inject,
                args: [WidgetRef]
            }] }], { onClick: [{
            type: 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?';
        addClass(this.elRef.nativeElement, DEFAULT_CLS$1);
        setCSS(this.elRef.nativeElement, 'display', 'block');
        if (hasCordova()) {
            this.getBuildMeta().then(buildMeta => {
                if (buildMeta && buildMeta.buildMode === 'DEVELOPMENT_MODE') {
                    this.file.removeFile(cordova.file.externalApplicationStorageDirectory, AUTO_UPDATE_FILENAME).catch(noop);
                    this.checkForUpdate()
                        .then(this.getUserConfirmation.bind(this), noop);
                }
            });
        }
    }
    cancel() {
        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;
            }, 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?';
        removeClass(this.elRef.nativeElement, 'hidden');
    }
    static { this.ɵfac = function AppUpdateComponent_Factory(t) { return new (t || AppUpdateComponent)(i0.ɵɵdirectiveInject(i1.DeviceService), i0.ɵɵdirectiveInject(i1.DeviceFileDownloadService), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i2.File), i0.ɵɵdirectiveInject(i3.FileOpener), i0.ɵɵdirectiveInject(i4.HttpClient)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵ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.ɵɵelementStart(0, "div", 0)(1, "div", 1)(2, "div", 2);
            i0.ɵɵelement(3, "span", 3);
            i0.ɵɵelementStart(4, "div", 4);
            i0.ɵɵelement(5, "div", 5);
            i0.ɵɵelementEnd()();
            i0.ɵɵelementStart(6, "div", 6)(7, "button", 7);
            i0.ɵɵlistener("click", function AppUpdateComponent_Template_button_click_7_listener() { return ctx.cancel(); });
            i0.ɵɵtext(8, "Skip update");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(9, "button", 8);
            i0.ɵɵlistener("click", function AppUpdateComponent_Template_button_click_9_listener() { return ctx.installLatestVersion(); });
            i0.ɵɵtext(10, "Update");
            i0.ɵɵelementEnd()()()();
        } if (rf & 2) {
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("textContent", ctx.message);
            i0.ɵɵadvance();
            i0.ɵɵproperty("hidden", !ctx.downloading);
            i0.ɵɵadvance();
            i0.ɵɵstyleProp("width", ctx.downloadProgress, "%");
            i0.ɵɵadvance(4);
            i0.ɵɵproperty("hidden", ctx.downloading);
        } }, dependencies: [i5.TextContentDirective], encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AppUpdateComponent, [{
        type: 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.DeviceService }, { type: i1.DeviceFileDownloadService }, { type: i0.ElementRef }, { type: i2.File }, { type: i3.FileOpener }, { type: i4.HttpClient }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵ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.ɵɵelement(0, "i", 22);
} }
function FileBrowserComponent_div_0_div_13_i_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i");
} if (rf & 2) {
    const file_r4 = i0.ɵɵnextContext().$implicit;
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵ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.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 17)(1, "div", 18);
    i0.ɵɵlistener("click", function FileBrowserComponent_div_0_div_13_Template_div_click_1_listener() { const file_r4 = i0.ɵɵrestoreView(_r3).$implicit; const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.onFileClick(file_r4)); });
    i0.ɵɵ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.ɵɵelementStart(4, "span", 21);
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const file_r4 = ctx.$implicit;
    i0.ɵɵadvance();
    i0.ɵɵclassProp("bg-primary", file_r4.isSelected);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", !file_r4.isFile);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", file_r4.isFile);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(file_r4.name);
} }
function FileBrowserComponent_div_0_button_15_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 23);
    i0.ɵɵlistener("click", function FileBrowserComponent_div_0_button_15_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r5); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.submit()); });
    i0.ɵɵtext(1, " Done ");
    i0.ɵɵelementStart(2, "span", 24);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(ctx_r1.selectedFiles.length);
} }
function FileBrowserComponent_div_0_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 1);
    i0.ɵɵelement(1, "div", 2);
    i0.ɵɵelementStart(2, "div", 3)(3, "div", 4)(4, "div", 5)(5, "div", 6)(6, "h4", 7)(7, "span", 8);
    i0.ɵɵlistener("click", function FileBrowserComponent_div_0_Template_span_click_7_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.onFileClick(ctx_r1.currentFolder.parent)); });
    i0.ɵɵelement(8, "i", 9);
    i0.ɵɵelementEnd();
    i0.ɵɵtext(9);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(10, "div", 10);
    i0.ɵɵlistener("click", function FileBrowserComponent_div_0_Template_div_click_10_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.refreshFolder()); });
    i0.ɵɵelement(11, "i", 11);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(12, "div", 12);
    i0.ɵɵtemplate(13, FileBrowserComponent_div_0_div_13_Template, 6, 5, "div", 13);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(14, "div", 14);
    i0.ɵɵtemplate(15, FileBrowserComponent_div_0_button_15_Template, 4, 1, "button", 15);
    i0.ɵɵelementStart(16, "button", 16);
    i0.ɵɵlistener("click", function FileBrowserComponent_div_0_Template_button_click_16_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.show = false); });
    i0.ɵɵtext(17, "Close");
    i0.ɵɵelementEnd()()()()()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵclassProp("in", ctx_r1.isVisible);
    i0.ɵɵadvance();
    i0.ɵɵclassProp("in", ctx_r1.isVisible);
    i0.ɵɵadvance(5);
    i0.ɵɵproperty("hidden", !!!ctx_r1.currentFolder.parent);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", ctx_r1.currentFolder.name, " ");
    i0.ɵɵadvance(4);
    i0.ɵɵproperty("ngForOf", ctx_r1.currentFolder.files);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", ctx_r1.selectedFiles && ctx_r1.selectedFiles.length > 0);
} }
class FileBrowserComponent {
    constructor(deviceService) {
        this.deviceService = deviceService;
        this.selectedFiles = [];
        this.submitEmitter = new 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 (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;
                    }
                    $appDigest();
                    return false;
                }
            });
        }
        else if (this.backButtonListenerDeregister) {
            this.backButtonListenerDeregister();
        }
    }
    submit() {
        const files = [];
        this.loadFileSize(this.selectedFiles).then(() => {
            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) {
        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 (!isEmpty(fileTypeToSelect)) {
                    fileTypeToShow = split(fileTypeToSelect, ',');
                    entries = filter(entries, e => {
                        // @ts-ignore
                        return !e.isFile || findIndex(fileTypeToShow, ext => endsWith(e.name, '.' + ext)) >= 0;
                    });
                }
                // @ts-ignore
                resolve(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.ɵɵdirectiveInject(i1.DeviceService)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵ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.ɵɵtemplate(0, FileBrowserComponent_div_0_Template, 18, 8, "div", 0);
        } if (rf & 2) {
            i0.ɵɵproperty("ngIf", ctx.isVisible && ctx.currentFolder);
        } }, dependencies: [i3$1.NgForOf, i3$1.NgIf], encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(FileBrowserComponent, [{
        type: 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.DeviceService }], { fileTypeToSelect: [{
            type: Input
        }], multiple: [{
            type: Input
        }], submitEmitter: [{
            type: Output,
            args: ['submit']
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵ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(map(filePaths, filePath => {
            if (filePath.indexOf('://') < 0) {
                filePath = 'file://' + filePath;
            }
            return convertToBlob(filePath);
        })).then(filesList => {
            return 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.ɵɵinject(i1$1.AbstractSpinnerService)); }; }
    static { this.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: FileSelectorService, factory: FileSelectorService.ɵfac, providedIn: 'root' }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(FileSelectorService, [{
        type: Injectable,
        args: [{ providedIn: 'root' }]
    }], () => [{ type: i1$1.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 (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 = transformFileURI(localPath);
                    this.componentInstance.imgSource = this._cacheUrl;
                });
            }
            else if (this._cacheUrl) {
                this.componentInstance.imgSource = this._cacheUrl;
            }
        }
    }
    set wmImageCache(val) {
        this._isEnabled = (hasCordova() && val === 'true');
    }
    getLocalPath(val) {
        if (hasCordova() && val && val.indexOf('{{') < 0 && val.startsWith('http')) {
            return this.deviceFileCacheService.getLocalPath(val, true, true, !this._isEnabled)
                .catch(noop);
        }
        return Promise.resolve(val);
    }
    static { this.ɵfac = function ImageCacheDirective_Factory(t) { return new (t || ImageCacheDirective)(i0.ɵɵdirectiveInject(WidgetRef, 2), i0.ɵɵdirectiveInject(i1.DeviceFileCacheService), i0.ɵɵdirectiveInject(i2.File)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: ImageCacheDirective, selectors: [["", "wmImageCache", ""]], inputs: { wmImageCache: "wmImageCache" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ImageCacheDirective, [{
        type: Directive,
        args: [{
                selector: '[wmImageCache]'
            }]
    }], () => [{ type: undefined, decorators: [{
                type: Self
            }, {
                type: Inject,
                args: [WidgetRef]
            }] }, { type: i1.DeviceFileCacheService }, { type: i2.File }], { wmImageCache: [{
            type: Input
        }] }); })();

const registerProps = () => {
    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.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵelement(1, "label", 4);
    i0.ɵɵelementStart(2, "button", 5);
    i0.ɵɵlistener("click", function NetworkInfoToasterComponent_div_0_div_1_Template_button_click_2_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.hideMessage()); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_NETWORK_NOT_AVAILABLE);
    i0.ɵɵadvance();
    i0.ɵɵproperty("textContent", ctx_r1.appLocale.LABEL_HIDE_NETWORK_INFO);
} }
function NetworkInfoToasterComponent_div_0_div_2_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵelement(1, "label", 4);
    i0.ɵɵelementStart(2, "button", 5);
    i0.ɵɵlistener("click", function NetworkInfoToasterComponent_div_0_div_2_Template_button_click_2_listener() { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.hideMessage()); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_SERVICE_NOT_AVAILABLE);
    i0.ɵɵadvance();
    i0.ɵɵproperty("textContent", ctx_r1.appLocale.LABEL_HIDE_NETWORK_INFO);
} }
function NetworkInfoToasterComponent_div_0_div_3_Template(rf, ctx) { if (rf & 1) {
    const _r4 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵelement(1, "label", 4);
    i0.ɵɵelementStart(2, "button", 5);
    i0.ɵɵlistener("click", function NetworkInfoToasterComponent_div_0_div_3_Template_button_click_2_listener() { i0.ɵɵrestoreView(_r4); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.hideMessage()); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "button", 6);
    i0.ɵɵlistener("click", function NetworkInfoToasterComponent_div_0_div_3_Template_button_click_3_listener() { i0.ɵɵrestoreView(_r4); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.connect()); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_SERVICE_AVAILABLE);
    i0.ɵɵadvance();
    i0.ɵɵproperty("textContent", ctx_r1.appLocale.LABEL_HIDE_NETWORK_INFO);
    i0.ɵɵadvance();
    i0.ɵɵproperty("textContent", ctx_r1.appLocale.LABEL_CONNECT_TO_SERVICE);
} }
function NetworkInfoToasterComponent_div_0_div_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵelement(1, "label", 4);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_SERVICE_CONNECTING);
} }
function NetworkInfoToasterComponent_div_0_div_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵelement(1, "label", 4);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("textContent", ctx_r1.appLocale.MESSAGE_SERVICE_CONNECTED);
} }
function NetworkInfoToasterComponent_div_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 1);
    i0.ɵɵ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.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("ngSwitch", ctx_r1.networkState);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngSwitchCase", -3);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngSwitchCase", -2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngSwitchCase", -1);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngSwitchCase", 0);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngSwitchCase", 1);
} }
const DEFAULT_CLS = 'network-info-toaster';
const WIDGET_CONFIG = { widgetType: 'wm-network-info-toaster', hostClass: DEFAULT_CLS };
var NetworkState;
(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";
})(NetworkState || (NetworkState = {}));
class NetworkInfoToasterComponent extends 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;
        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 = NetworkState.CONNECTED;
            autoHide = true;
        }
        else if (data.isConnecting) {
            this.networkState = NetworkState.CONNECTING;
        }
        else if (data.isServiceAvailable) {
            this.networkState = NetworkState.SERVICE_AVAILABLE_BUT_NOT_CONNECTED;
        }
        else if (data.isNetworkAvailable && !data.isServiceAvailable) {
            this.networkState = NetworkState.NETWORK_AVAIABLE_BUT_SERVICE_NOT_AVAILABLE;
        }
        else {
            this.networkState = NetworkState.NETWORK_NOT_AVAIABLE;
        }
        this.showMessage = (!(oldState === undefined && data.isConnected) && oldState !== this.networkState);
        if (autoHide && this.showMessage) {
            setTimeout(() => {
                this.showMessage = false;
                $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.ɵɵdirectiveInject(i1.NetworkService), i0.ɵɵdirectiveInject(i1$1.App), i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: NetworkInfoToasterComponent, selectors: [["", "wmNetworkInfoToaster", ""]], features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(NetworkInfoToasterComponent)
            ]), i0.ɵɵ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.ɵɵtemplate(0, NetworkInfoToasterComponent_div_0_Template, 6, 6, "div", 0);
        } if (rf & 2) {
            i0.ɵɵproperty("ngIf", ctx.showMessage);
        } }, dependencies: [i3$1.NgIf, i3$1.NgSwitch, i3$1.NgSwitchCase, i5.TextContentDirective], encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(NetworkInfoToasterComponent, [{
        type: Component,
        args: [{ selector: '[wmNetworkInfoToaster]', providers: [
                    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.NetworkService }, { type: i1$1.App }, { type: i0.Injector }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵ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.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 16);
    i0.ɵɵlistener("click", function ProcessManagerComponent_ng_container_0_li_4_button_9_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r1); const instance_r2 = i0.ɵɵnextContext().$implicit; return i0.ɵɵresetView(instance_r2.onStop()); });
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const instance_r2 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", instance_r2.stopButtonLabel, " ");
} }
function ProcessManagerComponent_ng_container_0_li_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "li", 7)(1, "div", 8)(2, "div", 9)(3, "label", 10);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(5, "div", 11)(6, "label", 12);
    i0.ɵɵtext(7);
    i0.ɵɵelementEnd()()();
    i0.ɵɵ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.ɵɵelement(10, "div", 15);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const instance_r2 = ctx.$implicit;
    i0.ɵɵnextContext(2);
    const progressTemplate_r3 = i0.ɵɵreference(2);
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate(instance_r2.name);
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", instance_r2.progressLabel, "");
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngTemplateOutlet", progressTemplate_r3)("ngTemplateOutletContext", i0.ɵɵpureFunction1(5, _c1, instance_r2));
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", instance_r2.onStop);
} }
function ProcessManagerComponent_ng_container_0_li_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "li", 7)(1, "label", 17);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" (", ctx_r3.queue.length, ") queued ");
} }
function ProcessManagerComponent_ng_container_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "div", 2)(2, "div", 3)(3, "ul", 4);
    i0.ɵɵ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.ɵɵelementEnd()()();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext();
    i0.ɵɵadvance(4);
    i0.ɵɵproperty("ngForOf", ctx_r3.getVisibleInstances(ctx_r3.instances));
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r3.queue.length > 0);
} }
function ProcessManagerComponent_ng_template_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "div", 18);
} }
const MAX_PROCESS = 3;
class ProcessManagerComponent {
    constructor(el) {
        this.el = el;
        this.isVisible = true;
        this.instances = [];
        this.queue = [];
        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) {
            setAttr(this.el.nativeElement, 'hidden', 'true');
            this.isVisible = false;
        }
        else if (!this.isVisible && hasInstancesToShow) {
            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(() => {
                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' && 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.ɵɵdirectiveInject(i0.ElementRef)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ProcessManagerComponent, selectors: [["", "wmProcessManager", ""]], features: [i0.ɵɵProvidersFeature([
                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.ɵɵ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.ɵɵtemplateRefExtractor);
        } if (rf & 2) {
            i0.ɵɵproperty("ngIf", ctx.instances.length > 0);
        } }, dependencies: [i3$1.NgForOf, i3$1.NgIf, i3$1.NgTemplateOutlet, i2$1.ProgressBarComponent], encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ProcessManagerComponent, [{
        type: Component,
        args: [{ selector: '[wmProcessManager]', providers: [
                    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.ElementRef }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵ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.ɵɵdefineInjectable({ token: ProcessManagementService, factory: ProcessManagementService.ɵfac, providedIn: 'root' }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ProcessManagementService, [{
        type: 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.ɵɵdefineNgModule({ type: BasicModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule,
            ProgressModule,
            WmComponentsModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BasicModule, [{
        type: NgModule,
        args: [{
                imports: [
                    CommonModule,
                    ProgressModule,
                    WmComponentsModule
                ],
                declarations: [...components],
                exports: [...components]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(BasicModule, { declarations: [AnchorDirective,
        AppUpdateComponent,
        FileBrowserComponent,
        ImageCacheDirective,
        NetworkInfoToasterComponent,
        ProcessManagerComponent], imports: [CommonModule,
        ProgressModule,
        WmComponentsModule], exports: [AnchorDirective,
        AppUpdateComponent,
        FileBrowserComponent,
        ImageCacheDirective,
        NetworkInfoToasterComponent,
        ProcessManagerComponent] }); })();

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

export { AnchorDirective, AppUpdateComponent, BasicModule, FileBrowserComponent, FileSelectorService, ImageCacheDirective, NetworkInfoToasterComponent, NetworkState, ProcessManagementService, ProcessManagerComponent };
//# sourceMappingURL=index.mjs.map
