/**
 * @fileoverview added by tsickle
 * Generated from: lib/change-password/change-password.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { __awaiter, __generator } from "tslib";
import { Component, Input, ViewChild } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { ModalController } from '@ionic/angular';
import { CurrentDeviceService, TaskManagerComponent, TaskManagerService } from '@iotize/ionic';
/** @type {?} */
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: ['', Validators.required],
            confirmPassword: [''],
            currentPassword: [''],
        });
        this.changePasswordTask = this.taskManager.createTask({
            id: TASK_ID,
            info: {
                title: 'Change user password',
                feedback: 'User password changed!'
            },
            exec: (/**
             * @return {?}
             */
            function () {
                return _this.changePassword();
            })
        });
    }
    Object.defineProperty(ChangePasswordComponent.prototype, "tap", {
        get: /**
         * @return {?}
         */
        function () {
            return this.currentDevice.tap;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ChangePasswordComponent.prototype, "password", {
        get: /**
         * @return {?}
         */
        function () {
            return (/** @type {?} */ (this.form.get('password')));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ChangePasswordComponent.prototype, "currentPassword", {
        get: /**
         * @return {?}
         */
        function () {
            return (/** @type {?} */ (this.form.get('currentPassword')));
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @return {?}
     */
    ChangePasswordComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
    };
    /**
     * @return {?}
     */
    ChangePasswordComponent.prototype.submit = /**
     * @return {?}
     */
    function () {
        this.error = undefined;
        this.changePasswordTaskComponent.execTask();
    };
    /**
     * @return {?}
     */
    ChangePasswordComponent.prototype.changePassword = /**
     * @return {?}
     */
    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, 4, , 5]);
                        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();
                        this.modalController.dismiss();
                        return [3 /*break*/, 5];
                    case 4:
                        err_1 = _a.sent();
                        this.showError(err_1);
                        return [3 /*break*/, 5];
                    case 5: return [2 /*return*/];
                }
            });
        });
    };
    /**
     * @return {?}
     */
    ChangePasswordComponent.prototype.dismiss = /**
     * @return {?}
     */
    function () {
        this.modalController.dismiss();
    };
    /**
     * @param {?} err
     * @return {?}
     */
    ChangePasswordComponent.prototype.showError = /**
     * @param {?} err
     * @return {?}
     */
    function (err) {
        this.error = err;
    };
    ChangePasswordComponent.decorators = [
        { type: Component, args: [{
                    selector: 'tap-change-password',
                    template: "<ion-header *ngIf=\"header\">\r\n\t<ion-toolbar color=\"primary\">\r\n\t\t<ion-buttons slot=\"start\">\r\n\t\t\t<ion-button (click)=\"modalController.dismiss()\">\r\n\t\t\t  <ion-icon name=\"arrow-back\"></ion-icon>\r\n\t\t\t</ion-button>\r\n\t\t</ion-buttons>\r\n\t\t<ion-title class=\"text-center\">\r\n\t\t\tChange profile password\r\n\t\t</ion-title>\r\n\t</ion-toolbar>\r\n</ion-header>\r\n<ion-content>\r\n\t<ion-grid>\r\n\t\t<ion-row>\r\n\t\t\t<ion-col class=\"ion-align-self-center\">\r\n\t\t\t\t<iotize-feedback-error [error]=\"error\"></iotize-feedback-error>\r\n\t\t\t\t<form (ngSubmit)=\"submit()\" [formGroup]=\"form\" (keydown.enter)=\"submit()\">\r\n\t\t\t\t\t<ion-item *ngIf=\"askCurrentPassword\">\r\n\t\t\t\t\t\t<ion-input [formControlName]=\"'currentPassword'\" placeholder=\"Current password\" required type=\"password\"></ion-input>\r\n\t\t\t\t\t</ion-item>\r\n\t\t\t\t\t<ion-item>\r\n\t\t\t\t\t\t<ion-input [formControlName]=\"'password'\" placeholder=\"New password\" required type=\"password\"></ion-input>\r\n\t\t\t\t\t</ion-item>\r\n\t\t\t\t\t<ion-item *ngIf=\"confirmPassword\">\r\n\t\t\t\t\t\t<ion-input [formControlName]=\"'confirmPassword'\" placeholder=\"Confirm new password\" required type=\"password\"></ion-input>\r\n\t\t\t\t\t</ion-item>\r\n\t\t\t\t\t<app-task-manager #changePasswordTaskComponent [task]=\"changePasswordTask\">\r\n\t\t\t\t\t\t<app-task-manager-action>\r\n\t\t\t\t\t\t\t<ion-item lines=\"none\">\r\n\t\t\t\t\t\t\t\t<ion-button size=\"default\" slot=\"end\" [disabled]=\"form['invalid']\" expand=\"block\" type=\"submit\">\r\n\t\t\t\t\t\t\t\t\t<ion-icon name=\"create\"></ion-icon>\r\n\t\t\t\t\t\t\t\t\tChange password\r\n\t\t\t\t\t\t\t\t</ion-button>\r\n\t\t\t\t\t\t\t</ion-item>\r\n\t\t\t\t\t\t</app-task-manager-action>\r\n\t\t\t\t\t\t<app-task-manager-delayed>\r\n\t\t\t\t\t\t\t<ion-item lines=\"none\">\r\n\t\t\t\t\t\t\t\t<ion-text class=\"ion-text-wrap\" slot=\"end\" color=\"warning\">\r\n\t\t\t\t\t\t\t\t\t<ion-icon name=\"alert\"></ion-icon>\r\n\t\t\t\t\t\t\t\t\tPlease reconnect Tap to change password\r\n\t\t\t\t\t\t\t\t</ion-text>\r\n\t\t\t\t\t\t\t\t<ion-button size=\"default\" color=\"warning\" app-task-manager-action-cancel>\r\n\t\t\t\t\t\t\t\t\t<ion-icon name=\"close\"></ion-icon>\r\n\t\t\t\t\t\t\t\t\tCancel\r\n\t\t\t\t\t\t\t\t</ion-button>\r\n\t\t\t\t\t\t\t</ion-item>\r\n\t\t\t\t\t\t</app-task-manager-delayed>\r\n\t\t\t\t\t\t<app-task-manager-running>\r\n\t\t\t\t\t\t\t<ion-item lines=\"none\">\r\n\t\t\t\t\t\t\t\t<ion-progress-bar type=\"indeterminate\"></ion-progress-bar>\r\n\t\t\t\t\t\t\t</ion-item>\r\n\t\t\t\t\t\t</app-task-manager-running>\r\n\t\t\t\t\t</app-task-manager>\r\n\t\t\t\t</form>\r\n\t\t\t</ion-col>\r\n\t\t</ion-row>\r\n\t</ion-grid>\r\n</ion-content>\r\n",
                    styles: [""]
                }] }
    ];
    /** @nocollapse */
    ChangePasswordComponent.ctorParameters = function () { return [
        { type: CurrentDeviceService },
        { type: ModalController },
        { type: FormBuilder },
        { type: TaskManagerService }
    ]; };
    ChangePasswordComponent.propDecorators = {
        changePasswordTaskComponent: [{ type: ViewChild, args: ['changePasswordTaskComponent', { static: true },] }],
        confirmPassword: [{ type: Input }],
        askCurrentPassword: [{ type: Input }],
        header: [{ type: Input }],
        userId: [{ type: Input }]
    };
    return ChangePasswordComponent;
}());
export { ChangePasswordComponent };
if (false) {
    /** @type {?} */
    ChangePasswordComponent.prototype.changePasswordTaskComponent;
    /** @type {?} */
    ChangePasswordComponent.prototype.confirmPassword;
    /** @type {?} */
    ChangePasswordComponent.prototype.askCurrentPassword;
    /** @type {?} */
    ChangePasswordComponent.prototype.header;
    /** @type {?} */
    ChangePasswordComponent.prototype.userId;
    /** @type {?} */
    ChangePasswordComponent.prototype.form;
    /** @type {?} */
    ChangePasswordComponent.prototype.promise$;
    /** @type {?} */
    ChangePasswordComponent.prototype.error;
    /** @type {?} */
    ChangePasswordComponent.prototype.loading;
    /** @type {?} */
    ChangePasswordComponent.prototype.changePasswordTask;
    /**
     * @type {?}
     * @protected
     */
    ChangePasswordComponent.prototype.currentDevice;
    /** @type {?} */
    ChangePasswordComponent.prototype.modalController;
    /**
     * @type {?}
     * @private
     */
    ChangePasswordComponent.prototype.formBuilder;
    /**
     * @type {?}
     * @private
     */
    ChangePasswordComponent.prototype.taskManager;
}
//# sourceMappingURL=data:application/json;base64, 