import { Component, Output, EventEmitter } from '@angular/core';
import { UserService } from '@c8y/client';
import { LoginService } from './login.service';
import { LoginViews } from './login.model';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/client";
import * as i2 from "./login.service";
import * as i3 from "@angular/forms";
import * as i4 from "../i18n/c8y-translate.directive";
import * as i5 from "@angular/common";
import * as i6 from "../forms/form-group.component";
import * as i7 from "../forms/required-input-placeholder.directive";
import * as i8 from "../i18n/c8y-translate.pipe";
export class RecoverPasswordComponent {
    constructor(users, loginService) {
        this.users = users;
        this.loginService = loginService;
        this.onChangeView = new EventEmitter();
        this.LOGIN_VIEWS = LoginViews;
        this.isLoading = false;
        this.model = {
            email: '',
            tenantId: ''
        };
    }
    ngOnInit() {
        this.model.tenantId = this.loginService.getTenant();
    }
    async resetPassword() {
        try {
            this.isLoading = true;
            const { res } = await this.users.sendPasswordResetMail(this.model.email, this.model.tenantId);
            if (res.status === 200) {
                this.loginService.addSuccessMessage('password_reset_requested');
            }
        }
        finally {
            this.loginService.reset();
            this.isLoading = false;
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: RecoverPasswordComponent, deps: [{ token: i1.UserService }, { token: i2.LoginService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: RecoverPasswordComponent, selector: "c8y-recover-password", outputs: { onChangeView: "onChangeView" }, ngImport: i0, template: "<form #resetForm=\"ngForm\" class=\"loginForm\" (ngSubmit)=\"resetPassword()\" novalidate>\n  <div class=\"legend form-block center\" translate>Forgot password?</div>\n  <c8y-form-group class=\"tenantField\" id=\"tenantField\" *ngIf=\"loginService.showTenant()\">\n    <label translate>Tenant ID</label>\n    <input\n      [(ngModel)]=\"model.tenantId\"\n      #tenantId=\"ngModel\"\n      type=\"text\"\n      name=\"tenantId\"\n      autocapitalize=\"off\"\n      autocorrect=\"off\"\n      class=\"form-control\"\n      placeholder=\"{{ 'Tenant ID' | translate }}\"\n      required\n    />\n  </c8y-form-group>\n\n  <c8y-form-group>\n    <label translate>Email address</label>\n    <input\n      [(ngModel)]=\"model.email\"\n      #email=\"ngModel\"\n      type=\"text\"\n      name=\"email\"\n      autocapitalize=\"off\"\n      autocorrect=\"off\"\n      class=\"form-control\"\n      placeholder=\"{{ 'Email address' | translate }}\"\n      email\n      required\n    />\n  </c8y-form-group>\n\n  <button\n    title=\"{{ 'Reset password' | translate }}\"\n    [disabled]=\"!resetForm.form.valid || isLoading\"\n    type=\"submit\"\n    class=\"btn btn-primary btn-lg btn-block form-group\"\n  >\n    {{ 'Reset password' | translate }}\n  </button>\n  <div class=\"text-center m-t-8\">\n    <button\n      type=\"submit\"\n      title=\"{{ 'Login' | translate }}\"\n      class=\"btn btn-link btn-sm\"\n      (click)=\"onChangeView.emit({ view: LOGIN_VIEWS.Credentials })\"\n    >\n      {{ 'Login' | translate }}\n    </button>\n  </div>\n</form>\n", dependencies: [{ kind: "directive", type: i3.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i3.EmailValidator, selector: "[email][formControlName],[email][formControl],[email][ngModel]", inputs: ["email"] }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i3.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i4.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i6.FormGroupComponent, selector: "c8y-form-group", inputs: ["hasError", "hasWarning", "hasSuccess", "novalidation", "status"] }, { kind: "directive", type: i7.RequiredInputPlaceholderDirective, selector: "input[required], input[formControlName]" }, { kind: "pipe", type: i8.C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: RecoverPasswordComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-recover-password', template: "<form #resetForm=\"ngForm\" class=\"loginForm\" (ngSubmit)=\"resetPassword()\" novalidate>\n  <div class=\"legend form-block center\" translate>Forgot password?</div>\n  <c8y-form-group class=\"tenantField\" id=\"tenantField\" *ngIf=\"loginService.showTenant()\">\n    <label translate>Tenant ID</label>\n    <input\n      [(ngModel)]=\"model.tenantId\"\n      #tenantId=\"ngModel\"\n      type=\"text\"\n      name=\"tenantId\"\n      autocapitalize=\"off\"\n      autocorrect=\"off\"\n      class=\"form-control\"\n      placeholder=\"{{ 'Tenant ID' | translate }}\"\n      required\n    />\n  </c8y-form-group>\n\n  <c8y-form-group>\n    <label translate>Email address</label>\n    <input\n      [(ngModel)]=\"model.email\"\n      #email=\"ngModel\"\n      type=\"text\"\n      name=\"email\"\n      autocapitalize=\"off\"\n      autocorrect=\"off\"\n      class=\"form-control\"\n      placeholder=\"{{ 'Email address' | translate }}\"\n      email\n      required\n    />\n  </c8y-form-group>\n\n  <button\n    title=\"{{ 'Reset password' | translate }}\"\n    [disabled]=\"!resetForm.form.valid || isLoading\"\n    type=\"submit\"\n    class=\"btn btn-primary btn-lg btn-block form-group\"\n  >\n    {{ 'Reset password' | translate }}\n  </button>\n  <div class=\"text-center m-t-8\">\n    <button\n      type=\"submit\"\n      title=\"{{ 'Login' | translate }}\"\n      class=\"btn btn-link btn-sm\"\n      (click)=\"onChangeView.emit({ view: LOGIN_VIEWS.Credentials })\"\n    >\n      {{ 'Login' | translate }}\n    </button>\n  </div>\n</form>\n" }]
        }], ctorParameters: () => [{ type: i1.UserService }, { type: i2.LoginService }], propDecorators: { onChangeView: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 