(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@iotize/tap/client/impl'), require('@iotize/tap/protocol/api'), require('@iotize/ionic'), require('@angular/router'), require('@ionic/angular'), require('@angular/common'), require('rxjs'), require('rxjs/operators'), require('@iotize/common/debug')) :
    typeof define === 'function' && define.amd ? define('@iotize/ionic/auth', ['exports', '@angular/core', '@angular/forms', '@iotize/tap/client/impl', '@iotize/tap/protocol/api', '@iotize/ionic', '@angular/router', '@ionic/angular', '@angular/common', 'rxjs', 'rxjs/operators', '@iotize/common/debug'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.iotize = global.iotize || {}, global.iotize.ionic = global.iotize.ionic || {}, global.iotize.ionic.auth = {}), global.ng.core, global.ng.forms, global.impl, global.api, global.iotize.ionic, global.ng.router, global.i3$1, global.ng.common, global.rxjs, global.rxjs.operators, global.debug$1));
}(this, (function (exports, i0, i3, impl, api, i1, i2, i3$1, i6, rxjs, operators, debug$1) { 'use strict';

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */
    /* global Reflect, Promise */
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b)
                if (Object.prototype.hasOwnProperty.call(b, p))
                    d[p] = b[p]; };
        return extendStatics(d, b);
    };
    function __extends(d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }
    var __assign = function () {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s)
                    if (Object.prototype.hasOwnProperty.call(s, p))
                        t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };
    function __rest(s, e) {
        var t = {};
        for (var p in s)
            if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
                t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                    t[p[i]] = s[p[i]];
            }
        return t;
    }
    function __decorate(decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
            r = Reflect.decorate(decorators, target, key, desc);
        else
            for (var i = decorators.length - 1; i >= 0; i--)
                if (d = decorators[i])
                    r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    }
    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); };
    }
    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
            return Reflect.metadata(metadataKey, metadataValue);
    }
    function __awaiter(thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try {
                step(generator.next(value));
            }
            catch (e) {
                reject(e);
            } }
            function rejected(value) { try {
                step(generator["throw"](value));
            }
            catch (e) {
                reject(e);
            } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }
    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function () { if (t[0] & 1)
                throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f)
                throw new TypeError("Generator is already executing.");
            while (_)
                try {
                    if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
                        return t;
                    if (y = 0, t)
                        op = [op[0] & 2, t.value];
                    switch (op[0]) {
                        case 0:
                        case 1:
                            t = op;
                            break;
                        case 4:
                            _.label++;
                            return { value: op[1], done: false };
                        case 5:
                            _.label++;
                            y = op[1];
                            op = [0];
                            continue;
                        case 7:
                            op = _.ops.pop();
                            _.trys.pop();
                            continue;
                        default:
                            if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                                _ = 0;
                                continue;
                            }
                            if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
                                _.label = op[1];
                                break;
                            }
                            if (op[0] === 6 && _.label < t[1]) {
                                _.label = t[1];
                                t = op;
                                break;
                            }
                            if (t && _.label < t[2]) {
                                _.label = t[2];
                                _.ops.push(op);
                                break;
                            }
                            if (t[2])
                                _.ops.pop();
                            _.trys.pop();
                            continue;
                    }
                    op = body.call(thisArg, _);
                }
                catch (e) {
                    op = [6, e];
                    y = 0;
                }
                finally {
                    f = t = 0;
                }
            if (op[0] & 5)
                throw op[1];
            return { value: op[0] ? op[1] : void 0, done: true };
        }
    }
    var __createBinding = Object.create ? (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
    }) : (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        o[k2] = m[k];
    });
    function __exportStar(m, o) {
        for (var p in m)
            if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
                __createBinding(o, m, p);
    }
    function __values(o) {
        var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
        if (m)
            return m.call(o);
        if (o && typeof o.length === "number")
            return {
                next: function () {
                    if (o && i >= o.length)
                        o = void 0;
                    return { value: o && o[i++], done: !o };
                }
            };
        throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
    }
    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m)
            return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
                ar.push(r.value);
        }
        catch (error) {
            e = { error: error };
        }
        finally {
            try {
                if (r && !r.done && (m = i["return"]))
                    m.call(i);
            }
            finally {
                if (e)
                    throw e.error;
            }
        }
        return ar;
    }
    /** @deprecated */
    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }
    /** @deprecated */
    function __spreadArrays() {
        for (var s = 0, i = 0, il = arguments.length; i < il; i++)
            s += arguments[i].length;
        for (var r = Array(s), k = 0, i = 0; i < il; i++)
            for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
                r[k] = a[j];
        return r;
    }
    function __spreadArray(to, from, pack) {
        if (pack || arguments.length === 2)
            for (var i = 0, l = from.length, ar; i < l; i++) {
                if (ar || !(i in from)) {
                    if (!ar)
                        ar = Array.prototype.slice.call(from, 0, i);
                    ar[i] = from[i];
                }
            }
        return to.concat(ar || Array.prototype.slice.call(from));
    }
    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }
    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n])
            i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try {
            step(g[n](v));
        }
        catch (e) {
            settle(q[0][3], e);
        } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length)
            resume(q[0][0], q[0][1]); }
    }
    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }
    function __asyncValues(o) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
    }
    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) {
            Object.defineProperty(cooked, "raw", { value: raw });
        }
        else {
            cooked.raw = raw;
        }
        return cooked;
    }
    ;
    var __setModuleDefault = Object.create ? (function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v });
    }) : function (o, v) {
        o["default"] = v;
    };
    function __importStar(mod) {
        if (mod && mod.__esModule)
            return mod;
        var result = {};
        if (mod != null)
            for (var k in mod)
                if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
                    __createBinding(result, mod, k);
        __setModuleDefault(result, mod);
        return result;
    }
    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }
    function __classPrivateFieldGet(receiver, state, kind, f) {
        if (kind === "a" && !f)
            throw new TypeError("Private accessor was defined without a getter");
        if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
            throw new TypeError("Cannot read private member from an object whose class did not declare it");
        return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
    }
    function __classPrivateFieldSet(receiver, state, value, kind, f) {
        if (kind === "m")
            throw new TypeError("Private method is not writable");
        if (kind === "a" && !f)
            throw new TypeError("Private accessor was defined without a setter");
        if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
            throw new TypeError("Cannot write private member to an object whose class did not declare it");
        return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
    }

    var TapAuthService = /** @class */ (function () {
        function TapAuthService() {
            try {
                this.options = JSON.parse(localStorage.getItem('TapAuthServiceStorage') || '{}');
            }
            catch (err) {
                this.options = {};
            }
            if (!this.options) {
                this.options = {};
            }
        }
        TapAuthService.prototype.store = function () {
            localStorage.setItem('TapAuthServiceStorage', JSON.stringify(this.options));
        };
        return TapAuthService;
    }());
    /** @nocollapse */ TapAuthService.ɵfac = function TapAuthService_Factory(t) { return new (t || TapAuthService)(); };
    /** @nocollapse */ TapAuthService.ɵprov = i0.ɵɵdefineInjectable({ token: TapAuthService, factory: TapAuthService.ɵfac, providedIn: 'root' });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TapAuthService, [{
                type: i0.Injectable,
                args: [{
                        providedIn: 'root',
                    }]
            }], function () { return []; }, null);
    })();

    function DeviceLoginComponent_ion_header_0_ion_back_button_3_Template(rf, ctx) {
        if (rf & 1) {
            i0.ɵɵelement(0, "ion-back-button", 19);
        }
        if (rf & 2) {
            i0.ɵɵproperty("defaultHref", "/device");
        }
    }
    function DeviceLoginComponent_ion_header_0_ion_button_4_Template(rf, ctx) {
        if (rf & 1) {
            var _r9_1 = i0.ɵɵgetCurrentView();
            i0.ɵɵelementStart(0, "ion-button", 20);
            i0.ɵɵlistener("click", function DeviceLoginComponent_ion_header_0_ion_button_4_Template_ion_button_click_0_listener() { i0.ɵɵrestoreView(_r9_1); var ctx_r8 = i0.ɵɵnextContext(2); return ctx_r8.dismiss(); });
            i0.ɵɵelement(1, "ion-icon", 21);
            i0.ɵɵelementEnd();
        }
    }
    function DeviceLoginComponent_ion_header_0_Template(rf, ctx) {
        if (rf & 1) {
            i0.ɵɵelementStart(0, "ion-header");
            i0.ɵɵelementStart(1, "ion-toolbar", 14);
            i0.ɵɵelementStart(2, "ion-buttons", 15);
            i0.ɵɵtemplate(3, DeviceLoginComponent_ion_header_0_ion_back_button_3_Template, 1, 1, "ion-back-button", 16);
            i0.ɵɵtemplate(4, DeviceLoginComponent_ion_header_0_ion_button_4_Template, 2, 0, "ion-button", 17);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(5, "ion-title", 18);
            i0.ɵɵtext(6);
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
        }
        if (rf & 2) {
            var ctx_r0 = i0.ɵɵnextContext();
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("ngIf", ctx_r0.backButton);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx_r0.closeButton);
            i0.ɵɵadvance(2);
            i0.ɵɵtextInterpolate1(" ", ctx_r0.title, " ");
        }
    }
    function DeviceLoginComponent_ion_item_17_Template(rf, ctx) {
        if (rf & 1) {
            i0.ɵɵelementStart(0, "ion-item");
            i0.ɵɵelementStart(1, "ion-label");
            i0.ɵɵtext(2, "Remember me");
            i0.ɵɵelementEnd();
            i0.ɵɵelement(3, "ion-toggle", 22);
            i0.ɵɵelementEnd();
        }
        if (rf & 2) {
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("formControlName", "rememberMe");
        }
    }
    function DeviceLoginComponent_ion_item_18_Template(rf, ctx) {
        if (rf & 1) {
            i0.ɵɵelementStart(0, "ion-item");
            i0.ɵɵelementStart(1, "ion-label");
            i0.ɵɵtext(2, "Automatic login on connection");
            i0.ɵɵelementEnd();
            i0.ɵɵelement(3, "ion-toggle", 22);
            i0.ɵɵelementEnd();
        }
        if (rf & 2) {
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("formControlName", "autoLogin");
        }
    }
    function DeviceLoginComponent_ion_button_20_Template(rf, ctx) {
        if (rf & 1) {
            var _r11_1 = i0.ɵɵgetCurrentView();
            i0.ɵɵelementStart(0, "ion-button", 23);
            i0.ɵɵlistener("click", function DeviceLoginComponent_ion_button_20_Template_ion_button_click_0_listener() { i0.ɵɵrestoreView(_r11_1); var ctx_r10 = i0.ɵɵnextContext(); return ctx_r10.cancelAction(); });
            i0.ɵɵelement(1, "ion-icon", 24);
            i0.ɵɵtext(2, " Cancel ");
            i0.ɵɵelementEnd();
        }
    }
    function DeviceLoginComponent_ion_item_24_Template(rf, ctx) {
        if (rf & 1) {
            i0.ɵɵelementStart(0, "ion-item", 9);
            i0.ɵɵelementStart(1, "ion-text", 25);
            i0.ɵɵelement(2, "ion-icon", 26);
            i0.ɵɵtext(3, " Please reconnect Tap to login ");
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
        }
    }
    function DeviceLoginComponent_ion_footer_25_Template(rf, ctx) {
        if (rf & 1) {
            i0.ɵɵelement(0, "ion-footer");
        }
    }
    var DeviceLoginComponent = /** @class */ (function () {
        function DeviceLoginComponent(tapService, router, platform, modalController, formBuilder, tapAuth) {
            this.tapService = tapService;
            this.router = router;
            this.platform = platform;
            this.modalController = modalController;
            this.formBuilder = formBuilder;
            this.tapAuth = tapAuth;
            /**
             * Refresh session state on login
             */
            this.refreshSessionState = true;
            this.header = true;
            this.footer = true;
            this.returnUrl = undefined;
            this.closeButton = true;
            this.backButton = false;
            this.enableAutoLogin = false;
            this.enableRememberMe = true;
            this.title = 'Tap login';
            this.onError = new i0.EventEmitter();
            this.loading = false;
            var defaultUsername = this.tapAuth.options.lastCredentials
                ? this.tapAuth.options.lastCredentials.username
                : '';
            var defaultPassword = ''; // this.tapAuth.options.lastCredentials ? this.tapAuth.options.lastCredentials.password : '';
            this.form = this.formBuilder.group({
                username: [defaultUsername, i3.Validators.required],
                password: [defaultPassword],
                rememberMe: [this.tapAuth.options.rememberMe],
                autoLogin: [this.tapAuth.options.autoLogin],
            });
        }
        Object.defineProperty(DeviceLoginComponent.prototype, "tap", {
            // unregisterBackAction: any;
            get: function () {
                return this.tapService.tap;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(DeviceLoginComponent.prototype, "rememberMe", {
            get: function () {
                return this.getField('rememberMe');
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(DeviceLoginComponent.prototype, "autoLogin", {
            get: function () {
                return this.getField('autoLogin');
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(DeviceLoginComponent.prototype, "username", {
            get: function () {
                return this.getField('username');
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(DeviceLoginComponent.prototype, "password", {
            get: function () {
                return this.getField('password');
            },
            enumerable: false,
            configurable: true
        });
        DeviceLoginComponent.prototype.getField = function (name) {
            var field = this.form.get(name);
            if (!field) {
                throw new Error("Internal error: missing input with [formControlName]=\"" + name + "\" in html template");
            }
            return field;
        };
        DeviceLoginComponent.prototype.ngOnInit = function () {
            var _this = this;
            this.sessionState$ = this.tap.auth.sessionState;
            this.connectionStateSub = this.tapService.connectionState.subscribe(function (event) { return __awaiter(_this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            if (!(event.newState === api.ConnectionState.CONNECTED)) return [3 /*break*/, 2];
                            if (!this.pendingLoginCall) return [3 /*break*/, 2];
                            return [4 /*yield*/, this._execCall(this.pendingLoginCall)];
                        case 1:
                            _a.sent();
                            _a.label = 2;
                        case 2: return [2 /*return*/];
                    }
                });
            }); });
            // this.unregisterBackAction = this.platform.registerBackButtonAction(() => {
            //   this.dismiss();
            // })
        };
        // ngOnDestroy() {
        //   // if (this.unregisterBackAction) this.unregisterBackAction();
        // }
        DeviceLoginComponent.prototype.login = function () {
            return __awaiter(this, void 0, void 0, function () {
                var username, password, rememberMe, autoLogin, options, loginCall;
                var _this = this;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            this.loading = true;
                            username = this.username.value;
                            password = this.password.value;
                            rememberMe = this.rememberMe.value;
                            autoLogin = this.autoLogin.value;
                            options = { username: username, password: password, rememberMe: rememberMe, autoLogin: autoLogin };
                            loginCall = function () { return __awaiter(_this, void 0, void 0, function () {
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0: return [4 /*yield*/, this.tapService.login(username, password, this.refreshSessionState)];
                                        case 1:
                                            _a.sent();
                                            return [2 /*return*/, options];
                                    }
                                });
                            }); };
                            return [4 /*yield*/, this._execCall(loginCall)];
                        case 1:
                            _a.sent();
                            return [2 /*return*/];
                    }
                });
            });
        };
        DeviceLoginComponent.prototype.dismiss = function () {
            return __awaiter(this, void 0, void 0, function () {
                var topOverlay;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, this.modalController.getTop()];
                        case 1:
                            topOverlay = _a.sent();
                            if (!topOverlay) return [3 /*break*/, 3];
                            return [4 /*yield*/, this.modalController.dismiss(topOverlay.id)];
                        case 2:
                            _a.sent();
                            _a.label = 3;
                        case 3: return [2 /*return*/];
                    }
                });
            });
        };
        DeviceLoginComponent.prototype.cancelAction = function () {
            this.pendingLoginCall = undefined;
            this.error = undefined;
            this.form.enable();
        };
        DeviceLoginComponent.prototype._execCall = function (call) {
            var _this = this;
            this.loading = true;
            return call()
                .then(function (options) { return __awaiter(_this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            this.tapAuth.options = {
                                autoLogin: options.autoLogin,
                                rememberMe: options.rememberMe,
                            };
                            if (options.rememberMe) {
                                this.tapAuth.options.lastCredentials = {
                                    username: options.username,
                                };
                            }
                            else {
                                this.tapAuth.options.lastCredentials = undefined;
                                this.tapAuth.options.autoLogin = false;
                            }
                            this.tapAuth.store();
                            if (!this.returnUrl) return [3 /*break*/, 2];
                            return [4 /*yield*/, this.router.navigateByUrl(this.returnUrl)];
                        case 1:
                            _a.sent();
                            _a.label = 2;
                        case 2:
                            this.pendingLoginCall = undefined;
                            this.form.enable();
                            return [4 /*yield*/, this.dismiss()];
                        case 3:
                            _a.sent();
                            return [2 /*return*/];
                    }
                });
            }); })
                .catch(function (err) {
                if (err.code === impl.TapClientError.Code.NotConnectedError ||
                    err.code === 'NfcTagLostError' ||
                    err.code === 'NfcNotConnectedError') {
                    _this.pendingLoginCall = call;
                    _this.form.disable();
                }
                else {
                    _this._onError(err);
                }
            })
                .then(function () {
                _this.loading = false;
            });
        };
        DeviceLoginComponent.prototype._onError = function (err) {
            this.error = err;
            this.onError.emit(err);
        };
        return DeviceLoginComponent;
    }());
    /** @nocollapse */ DeviceLoginComponent.ɵfac = function DeviceLoginComponent_Factory(t) { return new (t || DeviceLoginComponent)(i0.ɵɵdirectiveInject(i1.CurrentDeviceService), i0.ɵɵdirectiveInject(i2.Router), i0.ɵɵdirectiveInject(i3$1.Platform), i0.ɵɵdirectiveInject(i3$1.ModalController), i0.ɵɵdirectiveInject(i3.FormBuilder), i0.ɵɵdirectiveInject(TapAuthService)); };
    /** @nocollapse */ DeviceLoginComponent.ɵcmp = i0.ɵɵdefineComponent({ type: DeviceLoginComponent, selectors: [["tap-device-login"]], inputs: { refreshSessionState: "refreshSessionState", header: "header", footer: "footer", returnUrl: "returnUrl", closeButton: "closeButton", backButton: "backButton", enableAutoLogin: "enableAutoLogin", enableRememberMe: "enableRememberMe", title: "title" }, outputs: { onError: "onError" }, decls: 26, vars: 12, consts: [[4, "ngIf"], ["type", "indeterminate", 3, "hidden"], [1, "ion-align-self-center"], [3, "error"], [3, "formGroup", "ngSubmit", "keydown.enter"], [1, "ion-padding"], ["position", "floating"], ["type", "text", "placeholder", "Your username", 3, "formControlName"], ["type", "password", "placeholder", "Your password", 3, "formControlName"], ["lines", "none"], ["slot", "end", "color", "warning", "size", "default", 3, "click", 4, "ngIf"], ["slot", "end", "type", "submit", "size", "default", 3, "disabled"], ["slot", "start", "name", "log-in"], ["lines", "none", 4, "ngIf"], ["color", "primary"], ["slot", "start"], [3, "defaultHref", 4, "ngIf"], [3, "click", 4, "ngIf"], [1, "text-center"], [3, "defaultHref"], [3, "click"], ["name", "arrow-back"], [3, "formControlName"], ["slot", "end", "color", "warning", "size", "default", 3, "click"], ["slot", "start", "name", "close"], ["slot", "end", "color", "warning", 1, "ion-text-wrap"], ["name", "alert"]], template: function DeviceLoginComponent_Template(rf, ctx) {
            if (rf & 1) {
                i0.ɵɵtemplate(0, DeviceLoginComponent_ion_header_0_Template, 7, 3, "ion-header", 0);
                i0.ɵɵelementStart(1, "ion-content");
                i0.ɵɵelement(2, "ion-progress-bar", 1);
                i0.ɵɵelementStart(3, "ion-grid");
                i0.ɵɵelementStart(4, "ion-row");
                i0.ɵɵelementStart(5, "ion-col", 2);
                i0.ɵɵelement(6, "iotize-feedback-error", 3);
                i0.ɵɵelementStart(7, "form", 4);
                i0.ɵɵlistener("ngSubmit", function DeviceLoginComponent_Template_form_ngSubmit_7_listener() { return ctx.login(); })("keydown.enter", function DeviceLoginComponent_Template_form_keydown_enter_7_listener() { return ctx.login(); });
                i0.ɵɵelementStart(8, "div", 5);
                i0.ɵɵelementStart(9, "ion-item");
                i0.ɵɵelementStart(10, "ion-label", 6);
                i0.ɵɵtext(11, "Username");
                i0.ɵɵelementEnd();
                i0.ɵɵelement(12, "ion-input", 7);
                i0.ɵɵelementEnd();
                i0.ɵɵelementStart(13, "ion-item");
                i0.ɵɵelementStart(14, "ion-label", 6);
                i0.ɵɵtext(15, "Password");
                i0.ɵɵelementEnd();
                i0.ɵɵelement(16, "ion-input", 8);
                i0.ɵɵelementEnd();
                i0.ɵɵtemplate(17, DeviceLoginComponent_ion_item_17_Template, 4, 1, "ion-item", 0);
                i0.ɵɵtemplate(18, DeviceLoginComponent_ion_item_18_Template, 4, 1, "ion-item", 0);
                i0.ɵɵelementEnd();
                i0.ɵɵelementStart(19, "ion-item", 9);
                i0.ɵɵtemplate(20, DeviceLoginComponent_ion_button_20_Template, 3, 0, "ion-button", 10);
                i0.ɵɵelementStart(21, "ion-button", 11);
                i0.ɵɵelement(22, "ion-icon", 12);
                i0.ɵɵtext(23, " Login ");
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵtemplate(24, DeviceLoginComponent_ion_item_24_Template, 4, 0, "ion-item", 13);
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵtemplate(25, DeviceLoginComponent_ion_footer_25_Template, 1, 0, "ion-footer", 0);
            }
            if (rf & 2) {
                i0.ɵɵproperty("ngIf", ctx.header);
                i0.ɵɵadvance(2);
                i0.ɵɵproperty("hidden", !ctx.loading);
                i0.ɵɵadvance(4);
                i0.ɵɵproperty("error", ctx.error);
                i0.ɵɵadvance(1);
                i0.ɵɵproperty("formGroup", ctx.form);
                i0.ɵɵadvance(5);
                i0.ɵɵproperty("formControlName", "username");
                i0.ɵɵadvance(4);
                i0.ɵɵproperty("formControlName", "password");
                i0.ɵɵadvance(1);
                i0.ɵɵproperty("ngIf", ctx.enableRememberMe);
                i0.ɵɵadvance(1);
                i0.ɵɵproperty("ngIf", ctx.rememberMe.value && ctx.enableAutoLogin);
                i0.ɵɵadvance(2);
                i0.ɵɵproperty("ngIf", ctx.pendingLoginCall);
                i0.ɵɵadvance(1);
                i0.ɵɵproperty("disabled", ctx.loading || ctx.pendingLoginCall);
                i0.ɵɵadvance(3);
                i0.ɵɵproperty("ngIf", ctx.pendingLoginCall);
                i0.ɵɵadvance(1);
                i0.ɵɵproperty("ngIf", ctx.footer);
            }
        }, directives: [i6.NgIf, i3$1.IonContent, i3$1.IonProgressBar, i3$1.IonGrid, i3$1.IonRow, i3$1.IonCol, i1.ErrorFeedbackComponent, i3.ɵangular_packages_forms_forms_ba, i3.NgControlStatusGroup, i3.FormGroupDirective, i3$1.IonItem, i3$1.IonLabel, i3$1.IonInput, i3$1.TextValueAccessor, i3.NgControlStatus, i3.FormControlName, i3$1.IonButton, i3$1.IonIcon, i3$1.IonHeader, i3$1.IonToolbar, i3$1.IonButtons, i3$1.IonTitle, i3$1.IonBackButton, i3$1.IonBackButtonDelegate, i3$1.IonToggle, i3$1.BooleanValueAccessor, i3$1.IonText, i3$1.IonFooter], styles: ["ion-grid[_ngcontent-%COMP%]{height:100%;justify-content:center}"] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DeviceLoginComponent, [{
                type: i0.Component,
                args: [{
                        selector: 'tap-device-login',
                        templateUrl: './device-login.component.html',
                        styleUrls: ['./device-login.component.scss'],
                    }]
            }], function () { return [{ type: i1.CurrentDeviceService }, { type: i2.Router }, { type: i3$1.Platform }, { type: i3$1.ModalController }, { type: i3.FormBuilder }, { type: TapAuthService }]; }, { refreshSessionState: [{
                    type: i0.Input
                }], header: [{
                    type: i0.Input
                }], footer: [{
                    type: i0.Input
                }], returnUrl: [{
                    type: i0.Input
                }], closeButton: [{
                    type: i0.Input
                }], backButton: [{
                    type: i0.Input
                }], enableAutoLogin: [{
                    type: i0.Input
                }], enableRememberMe: [{
                    type: i0.Input
                }], title: [{
                    type: i0.Input
                }], onError: [{
                    type: i0.Output
                }] });
    })();

    var _c0 = ["changePasswordTaskComponent"];
    function ChangePasswordComponent_ion_header_0_Template(rf, ctx) {
        if (rf & 1) {
            var _r5_1 = i0.ɵɵgetCurrentView();
            i0.ɵɵelementStart(0, "ion-header");
            i0.ɵɵelementStart(1, "ion-toolbar", 15);
            i0.ɵɵelementStart(2, "ion-buttons", 16);
            i0.ɵɵelementStart(3, "ion-button", 17);
            i0.ɵɵlistener("click", function ChangePasswordComponent_ion_header_0_Template_ion_button_click_3_listener() { i0.ɵɵrestoreView(_r5_1); var ctx_r4 = i0.ɵɵnextContext(); return ctx_r4.modalController.dismiss(); });
            i0.ɵɵelement(4, "ion-icon", 18);
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(5, "ion-title", 19);
            i0.ɵɵtext(6, " Change profile password ");
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
        }
    }
    function ChangePasswordComponent_ion_item_7_Template(rf, ctx) {
        if (rf & 1) {
            i0.ɵɵelementStart(0, "ion-item");
            i0.ɵɵelement(1, "ion-input", 20);
            i0.ɵɵelementEnd();
        }
        if (rf & 2) {
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("formControlName", "currentPassword");
        }
    }
    function ChangePasswordComponent_ion_item_10_Template(rf, ctx) {
        if (rf & 1) {
            i0.ɵɵelementStart(0, "ion-item");
            i0.ɵɵelement(1, "ion-input", 21);
            i0.ɵɵelementEnd();
        }
        if (rf & 2) {
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("formControlName", "confirmPassword");
        }
    }
    var TASK_ID = 'change-user-password';
    var ChangePasswordComponent = /** @class */ (function () {
        function ChangePasswordComponent(currentDevice, modalController, formBuilder, taskManager) {
            var _this = this;
            this.currentDevice = currentDevice;
            this.modalController = modalController;
            this.formBuilder = formBuilder;
            this.taskManager = taskManager;
            this.confirmPassword = false;
            this.askCurrentPassword = false;
            this.header = true;
            this.userId = undefined;
            this.loading = false;
            this.form = this.formBuilder.group({
                password: ['', i3.Validators.required],
                confirmPassword: [''],
                currentPassword: [''],
            });
            this.changePasswordTask = this.taskManager.createTask({
                id: TASK_ID,
                info: {
                    title: 'Change user password',
                    feedback: 'User password changed!',
                },
                exec: function () {
                    return _this.changePassword();
                },
            });
        }
        Object.defineProperty(ChangePasswordComponent.prototype, "tap", {
            get: function () {
                return this.currentDevice.tap;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ChangePasswordComponent.prototype, "password", {
            get: function () {
                return i1.getFormFieldOrError(this.form, 'password');
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ChangePasswordComponent.prototype, "currentPassword", {
            get: function () {
                return i1.getFormFieldOrError(this.form, 'currentPassword');
            },
            enumerable: false,
            configurable: true
        });
        ChangePasswordComponent.prototype.submit = function () {
            this.error = undefined;
            this.changePasswordTaskComponent.execTask();
        };
        ChangePasswordComponent.prototype.changePassword = function () {
            return __awaiter(this, void 0, void 0, function () {
                var newPassword, err_1;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            _a.trys.push([0, 5, , 6]);
                            newPassword = this.password.value;
                            if (!this.askCurrentPassword) return [3 /*break*/, 2];
                            return [4 /*yield*/, this.tap.auth.login({
                                    username: this.tap.auth.sessionStateSnapshot.name,
                                    password: this.currentPassword.value,
                                })];
                        case 1:
                            _a.sent();
                            _a.label = 2;
                        case 2:
                            this.promise$ = this.tap.auth.changePassword(newPassword, this.userId);
                            return [4 /*yield*/, this.promise$];
                        case 3:
                            _a.sent();
                            return [4 /*yield*/, this.modalController.dismiss()];
                        case 4:
                            _a.sent();
                            return [3 /*break*/, 6];
                        case 5:
                            err_1 = _a.sent();
                            this.showError(err_1);
                            return [3 /*break*/, 6];
                        case 6: return [2 /*return*/];
                    }
                });
            });
        };
        ChangePasswordComponent.prototype.dismiss = function () {
            return __awaiter(this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, this.modalController.dismiss()];
                        case 1:
                            _a.sent();
                            return [2 /*return*/];
                    }
                });
            });
        };
        ChangePasswordComponent.prototype.showError = function (err) {
            this.error = err;
        };
        return ChangePasswordComponent;
    }());
    /** @nocollapse */ ChangePasswordComponent.ɵfac = function ChangePasswordComponent_Factory(t) { return new (t || ChangePasswordComponent)(i0.ɵɵdirectiveInject(i1.CurrentDeviceService), i0.ɵɵdirectiveInject(i3$1.ModalController), i0.ɵɵdirectiveInject(i3.FormBuilder), i0.ɵɵdirectiveInject(i1.TaskManagerService)); };
    /** @nocollapse */ ChangePasswordComponent.ɵcmp = i0.ɵɵdefineComponent({ type: ChangePasswordComponent, selectors: [["tap-change-password"]], viewQuery: function ChangePasswordComponent_Query(rf, ctx) {
            if (rf & 1) {
                i0.ɵɵviewQuery(_c0, 3);
            }
            if (rf & 2) {
                var _t = void 0;
                i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.changePasswordTaskComponent = _t.first);
            }
        }, inputs: { confirmPassword: "confirmPassword", askCurrentPassword: "askCurrentPassword", header: "header", userId: "userId" }, decls: 29, vars: 8, consts: [[4, "ngIf"], [1, "ion-align-self-center"], [3, "error"], [3, "formGroup", "ngSubmit", "keydown.enter"], ["placeholder", "New password", "required", "", "type", "password", 3, "formControlName"], [3, "task"], ["changePasswordTaskComponent", ""], ["lines", "none"], ["size", "default", "slot", "end", "expand", "block", "type", "submit", 3, "disabled"], ["name", "create"], ["slot", "end", "color", "warning", 1, "ion-text-wrap"], ["name", "alert"], ["size", "default", "color", "warning", "app-task-manager-action-cancel", ""], ["name", "close"], ["type", "indeterminate"], ["color", "primary"], ["slot", "start"], [3, "click"], ["name", "arrow-back"], [1, "text-center"], ["placeholder", "Current password", "required", "", "type", "password", 3, "formControlName"], ["placeholder", "Confirm new password", "required", "", "type", "password", 3, "formControlName"]], template: function ChangePasswordComponent_Template(rf, ctx) {
            if (rf & 1) {
                i0.ɵɵtemplate(0, ChangePasswordComponent_ion_header_0_Template, 7, 0, "ion-header", 0);
                i0.ɵɵelementStart(1, "ion-content");
                i0.ɵɵelementStart(2, "ion-grid");
                i0.ɵɵelementStart(3, "ion-row");
                i0.ɵɵelementStart(4, "ion-col", 1);
                i0.ɵɵelement(5, "iotize-feedback-error", 2);
                i0.ɵɵelementStart(6, "form", 3);
                i0.ɵɵlistener("ngSubmit", function ChangePasswordComponent_Template_form_ngSubmit_6_listener() { return ctx.submit(); })("keydown.enter", function ChangePasswordComponent_Template_form_keydown_enter_6_listener() { return ctx.submit(); });
                i0.ɵɵtemplate(7, ChangePasswordComponent_ion_item_7_Template, 2, 1, "ion-item", 0);
                i0.ɵɵelementStart(8, "ion-item");
                i0.ɵɵelement(9, "ion-input", 4);
                i0.ɵɵelementEnd();
                i0.ɵɵtemplate(10, ChangePasswordComponent_ion_item_10_Template, 2, 1, "ion-item", 0);
                i0.ɵɵelementStart(11, "app-task-manager", 5, 6);
                i0.ɵɵelementStart(13, "app-task-manager-action");
                i0.ɵɵelementStart(14, "ion-item", 7);
                i0.ɵɵelementStart(15, "ion-button", 8);
                i0.ɵɵelement(16, "ion-icon", 9);
                i0.ɵɵtext(17, " Change password ");
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementStart(18, "app-task-manager-delayed");
                i0.ɵɵelementStart(19, "ion-item", 7);
                i0.ɵɵelementStart(20, "ion-text", 10);
                i0.ɵɵelement(21, "ion-icon", 11);
                i0.ɵɵtext(22, " Please reconnect Tap to change password ");
                i0.ɵɵelementEnd();
                i0.ɵɵelementStart(23, "ion-button", 12);
                i0.ɵɵelement(24, "ion-icon", 13);
                i0.ɵɵtext(25, " Cancel ");
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementStart(26, "app-task-manager-running");
                i0.ɵɵelementStart(27, "ion-item", 7);
                i0.ɵɵelement(28, "ion-progress-bar", 14);
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
                i0.ɵɵelementEnd();
            }
            if (rf & 2) {
                i0.ɵɵproperty("ngIf", ctx.header);
                i0.ɵɵadvance(5);
                i0.ɵɵproperty("error", ctx.error);
                i0.ɵɵadvance(1);
                i0.ɵɵproperty("formGroup", ctx.form);
                i0.ɵɵadvance(1);
                i0.ɵɵproperty("ngIf", ctx.askCurrentPassword);
                i0.ɵɵadvance(2);
                i0.ɵɵproperty("formControlName", "password");
                i0.ɵɵadvance(1);
                i0.ɵɵproperty("ngIf", ctx.confirmPassword);
                i0.ɵɵadvance(1);
                i0.ɵɵproperty("task", ctx.changePasswordTask);
                i0.ɵɵadvance(4);
                i0.ɵɵproperty("disabled", ctx.form["invalid"]);
            }
        }, directives: [i6.NgIf, i3$1.IonContent, i3$1.IonGrid, i3$1.IonRow, i3$1.IonCol, i1.ErrorFeedbackComponent, i3.ɵangular_packages_forms_forms_ba, i3.NgControlStatusGroup, i3.FormGroupDirective, i3$1.IonItem, i3$1.IonInput, i3$1.TextValueAccessor, i3.RequiredValidator, i3.NgControlStatus, i3.FormControlName, i1.TaskManagerComponent, i1.TaskManagerActionComponent, i3$1.IonButton, i3$1.IonIcon, i1.TaskManagerDelayedComponent, i3$1.IonText, i1.TaskManagerActionCancelDirective, i1.TaskManagerRunningComponent, i3$1.IonProgressBar, i3$1.IonHeader, i3$1.IonToolbar, i3$1.IonButtons, i3$1.IonTitle], styles: [""] });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ChangePasswordComponent, [{
                type: i0.Component,
                args: [{
                        selector: 'tap-change-password',
                        templateUrl: './change-password.component.html',
                        styleUrls: ['./change-password.component.scss'],
                    }]
            }], function () { return [{ type: i1.CurrentDeviceService }, { type: i3$1.ModalController }, { type: i3.FormBuilder }, { type: i1.TaskManagerService }]; }, { changePasswordTaskComponent: [{
                    type: i0.ViewChild,
                    args: ['changePasswordTaskComponent', { static: true }]
                }], confirmPassword: [{
                    type: i0.Input
                }], askCurrentPassword: [{
                    type: i0.Input
                }], header: [{
                    type: i0.Input
                }], userId: [{
                    type: i0.Input
                }] });
    })();

    var debug = debug$1.createDebugger('@iotize/ionic:auth');

    var DEVICE_AUTH_GUARD_CONFIG = new i0.InjectionToken('DEVICE_AUTH_GUARD_CONFIG');
    var DeviceAuthGuard = /** @class */ (function () {
        // private routerData?: DeviceAuthGuardRouteData;
        function DeviceAuthGuard(tapService, router, config) {
            this.tapService = tapService;
            this.router = router;
            this.config = config;
            this.subscriptions = {};
            // this.setupSessionStateListener();
        }
        DeviceAuthGuard.prototype.canDeactivate = function (component, currentRoute, currentState, nextState) {
            // if (this.sessionStateSub) {
            //   this.sessionStateSub.unsubscribe();
            // }
            return true;
        };
        DeviceAuthGuard.prototype.canActivate = function (route, state) {
            var _this = this;
            this.setupSessionStateListener(route, state);
            if (!route.data.username) {
                return rxjs.of(true);
            }
            debug("Check is login as \"" + route.data.username + "\" to access \"" + route.url + "\"");
            return rxjs.from(this.tapService.isLoggedInAs(route.data.username)).pipe(operators.map(function (isLoggedAs) {
                if (!isLoggedAs) {
                    _this.onUnauthorized(state.url, route).catch(function (err) {
                        console.warn(err);
                    });
                }
                return isLoggedAs;
            }));
        };
        DeviceAuthGuard.prototype.onUnauthorized = function (returnUrl, activatedRoute) {
            return __awaiter(this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            debug("Not authorized to access this route \"" + activatedRoute.url + "\" -> redirect to \"" + this.config.loginUrl + "\"");
                            return [4 /*yield*/, this.router.navigate([this.config.loginUrl], {
                                    queryParams: { returnUrl: returnUrl },
                                })];
                        case 1:
                            _a.sent();
                            return [2 /*return*/];
                    }
                });
            });
        };
        /**
         * Listen to session state changes for the given route. It it's the active route, we redirect to login
         * @param activatedRoute  ActivatedRouteSnapshot
         * @param state RouterStateSnapshot
         */
        DeviceAuthGuard.prototype.setupSessionStateListener = function (activatedRoute, state) {
            var _this = this;
            if (state.url in this.subscriptions) {
                return this.subscriptions[state.url];
            }
            var subscription = this.tapService.sessionState.subscribe(function (event) { return __awaiter(_this, void 0, void 0, function () {
                var routeData, usernames;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            if (!this.router.isActive(state.url, true)) return [3 /*break*/, 2];
                            routeData = activatedRoute.data;
                            if (!(routeData &&
                                routeData.username &&
                                !routeData.disableAuthGuardOnPage)) return [3 /*break*/, 2];
                            usernames = Array.isArray(routeData.username)
                                ? routeData.username
                                : [routeData.username];
                            debug('DeviceAuthGuard', 'Active route: ', state.url, 'requires username(s)', usernames, "Current username: " + event.name);
                            if (!(usernames.indexOf(event.name) === -1)) return [3 /*break*/, 2];
                            return [4 /*yield*/, this.onUnauthorized(state.url, activatedRoute)];
                        case 1:
                            _a.sent();
                            _a.label = 2;
                        case 2: return [2 /*return*/];
                    }
                });
            }); });
            this.subscriptions[state.url] = subscription;
            return subscription;
        };
        return DeviceAuthGuard;
    }());
    /** @nocollapse */ DeviceAuthGuard.ɵfac = function DeviceAuthGuard_Factory(t) { return new (t || DeviceAuthGuard)(i0.ɵɵinject(i1.CurrentDeviceService), i0.ɵɵinject(i2.Router), i0.ɵɵinject(DEVICE_AUTH_GUARD_CONFIG)); };
    /** @nocollapse */ DeviceAuthGuard.ɵprov = i0.ɵɵdefineInjectable({ token: DeviceAuthGuard, factory: DeviceAuthGuard.ɵfac, providedIn: 'root' });
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DeviceAuthGuard, [{
                type: i0.Injectable,
                args: [{
                        providedIn: 'root',
                    }]
            }], function () {
            return [{ type: i1.CurrentDeviceService }, { type: i2.Router }, { type: undefined, decorators: [{
                            type: i0.Inject,
                            args: [DEVICE_AUTH_GUARD_CONFIG]
                        }] }];
        }, null);
    })();

    var TapAuthModule = /** @class */ (function () {
        function TapAuthModule() {
        }
        return TapAuthModule;
    }());
    /** @nocollapse */ TapAuthModule.ɵfac = function TapAuthModule_Factory(t) { return new (t || TapAuthModule)(); };
    /** @nocollapse */ TapAuthModule.ɵmod = i0.ɵɵdefineNgModule({ type: TapAuthModule });
    /** @nocollapse */ TapAuthModule.ɵinj = i0.ɵɵdefineInjector({ providers: [DeviceAuthGuard], imports: [[
                i1.LibCommonModule,
                i3.FormsModule,
                i3.ReactiveFormsModule,
                i1.TaskManagerUiModule,
            ]] });
    (function () {
        (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(TapAuthModule, { declarations: [DeviceLoginComponent, ChangePasswordComponent], imports: [i1.LibCommonModule,
                i3.FormsModule,
                i3.ReactiveFormsModule,
                i1.TaskManagerUiModule], exports: [DeviceLoginComponent, ChangePasswordComponent] });
    })();
    (function () {
        (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TapAuthModule, [{
                type: i0.NgModule,
                args: [{
                        declarations: [DeviceLoginComponent, ChangePasswordComponent],
                        exports: [DeviceLoginComponent, ChangePasswordComponent],
                        providers: [DeviceAuthGuard],
                        entryComponents: [DeviceLoginComponent, ChangePasswordComponent],
                        imports: [
                            i1.LibCommonModule,
                            i3.FormsModule,
                            i3.ReactiveFormsModule,
                            i1.TaskManagerUiModule,
                        ],
                    }]
            }], null, null);
    })();

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

    exports.ChangePasswordComponent = ChangePasswordComponent;
    exports.DEVICE_AUTH_GUARD_CONFIG = DEVICE_AUTH_GUARD_CONFIG;
    exports.DeviceAuthGuard = DeviceAuthGuard;
    exports.DeviceLoginComponent = DeviceLoginComponent;
    exports.TapAuthModule = TapAuthModule;
    exports.TapAuthService = TapAuthService;

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

})));
//# sourceMappingURL=iotize-ionic-auth.umd.js.map
