/**
 * @fileoverview added by tsickle
 * Generated from: lib/user/profile/components/ch-email/ch-email.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import * as tslib_1 from "tslib";
import { AlertService } from './../../../../widgets/entry-components/alert/services/alert.service';
import { PrevRouteService } from './../../../../routing/services/prev-route.service';
import { ChBaseComponent } from './../ch-base/ch-base.component';
import { Component, EventEmitter, Output } from '@angular/core';
import { Router } from '@angular/router';
import { Storage } from '@ionic/storage';
import { FormGroup, FormControl } from '@angular/forms';
var ChEmailComponent = /** @class */ (function (_super) {
    tslib_1.__extends(ChEmailComponent, _super);
    function ChEmailComponent(prevRouteService, alertService, router, storage) {
        var _this = _super.call(this, prevRouteService, router, storage) || this;
        _this.alertService = alertService;
        _this.callSave = new EventEmitter();
        return _this;
    }
    /**
     * @return {?}
     */
    ChEmailComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        this.reset();
    };
    /**
     * @return {?}
     */
    ChEmailComponent.prototype.reset = /**
     * @return {?}
     */
    function () {
        this.form = this.resetForm();
        this.getPractitionerEmail();
    };
    /**
     * @return {?}
     */
    ChEmailComponent.prototype.resetForm = /**
     * @return {?}
     */
    function () {
        return new FormGroup({
            email: new FormControl('')
        });
    };
    /**
     * @return {?}
     */
    ChEmailComponent.prototype.emailAlert = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.alertService.presentChangeEmail(this.form.value.email, (/**
         * @return {?}
         */
        function () { _this.save(); }));
    };
    /**
     * @return {?}
     */
    ChEmailComponent.prototype.save = /**
     * @return {?}
     */
    function () {
        this.setMustRelogin();
        if (this.form.valid) {
            this.callSave.emit(this.form.value.email);
        }
    };
    /**
     * @return {?}
     */
    ChEmailComponent.prototype.getPractitionerEmail = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.storage.get('user').then((/**
         * @param {?} user
         * @return {?}
         */
        function (user) {
            if (user) {
                _this.form.controls.email.setValue(user.email);
            }
        }));
    };
    ChEmailComponent.decorators = [
        { type: Component, args: [{
                    selector: 'inc-ch-email',
                    template: "<div *ngIf=\"mustLoginAgain\" class=\"ion-text-center\">\r\n  <h5>{{'NEED_LOGIN_E' | translate}}</h5>\r\n  <ion-button id=\"login-forpw\" [routerLink]=\"['/login', currentRoute]\">{{'LOGIN' | translate}}\r\n  </ion-button>\r\n</div>\r\n<span *ngIf=\"!mustLoginAgain\">\r\n  <form [formGroup]=\"form\" (ngSubmit)=\"emailAlert()\">\r\n    <ion-list>\r\n      <ion-text>\r\n        <h5>{{'EDIT_EMAIL' | translate}}</h5>\r\n      </ion-text>\r\n      <ion-item>\r\n        <ion-label position=\"floating\">{{'EMAIL' | translate}}\r\n          <span class=\"required\">*</span>\r\n        </ion-label>\r\n        <ion-input id=\"emailChange\" autofocus formControlName=\"email\" type=\"email\" name=\"email\" clearInput\r\n          pattern=\"[A-Za-z0-9._%+-]{3,}@[a-zA-Z]{3,}([.]{1}[a-zA-Z]{2,}|[.]{1}[a-zA-Z]{2,}[.]{1}[a-zA-Z]{2,})\" required>\r\n        </ion-input>\r\n      </ion-item>\r\n    </ion-list>\r\n    <div class=\"ion-float-right ion-margin-top\">\r\n      <ion-button id=\"emailReset\" fill=\"outline\" (click)=\"getPractitionerEmail()\" class=\"ion-margin-end\">\r\n        <ion-icon slot=\"start\" name=\"refresh\"></ion-icon>\r\n        {{'AGAIN_BUTTON' | translate}}\r\n      </ion-button>\r\n      <ion-button type=\"submit\" id=\"emailSubmit\" color=\"primary\" [disabled]=\"form.invalid || form.pristine\">\r\n        <ion-icon slot=\"start\" name=\"save\"></ion-icon>\r\n        {{'READY_BUTTON' | translate}}\r\n      </ion-button>\r\n    </div>\r\n  </form>\r\n</span>",
                    styles: [""]
                }] }
    ];
    /** @nocollapse */
    ChEmailComponent.ctorParameters = function () { return [
        { type: PrevRouteService },
        { type: AlertService },
        { type: Router },
        { type: Storage }
    ]; };
    ChEmailComponent.propDecorators = {
        callSave: [{ type: Output }]
    };
    return ChEmailComponent;
}(ChBaseComponent));
export { ChEmailComponent };
if (false) {
    /** @type {?} */
    ChEmailComponent.prototype.callSave;
    /**
     * @type {?}
     * @private
     */
    ChEmailComponent.prototype.alertService;
}
//# sourceMappingURL=data:application/json;base64, 