import { Component } from '@angular/core';
import { Validators, UntypedFormControl } from '@angular/forms';
import * as i0 from "@angular/core";
import * as i1 from "../core";
import * as i2 from "@angular/router";
import * as i3 from "../user";
import * as i4 from "@angular/forms";
import * as i5 from "../user-config";
import * as i6 from "@angular/common";
import * as i7 from "@angular/material/button";
import * as i8 from "@angular/material/form-field";
import * as i9 from "@angular/material/input";
const errorMessages = {
    email: {
        required: 'Email is required',
        email: 'Invalid email'
    },
};
export class ForgotPasswordComponent {
    constructor(http, alerter, router, currentUserService, errorService, credentialService, fb, formValidatorService, userConfigService) {
        this.http = http;
        this.alerter = alerter;
        this.router = router;
        this.currentUserService = currentUserService;
        this.errorService = errorService;
        this.credentialService = credentialService;
        this.fb = fb;
        this.formValidatorService = formValidatorService;
        this.userConfigService = userConfigService;
        this.isWorking = false;
        this.forgotPasswordForm = fb.group({
            email: new UntypedFormControl('', [Validators.required, Validators.email]),
        });
        this.userConfig = this.userConfigService.getConfig();
    }
    ngOnInit() {
        if (this.credentialService.isAuthenticated) {
            this.router.navigate(['/dashboard']);
        }
    }
    sendOtp() {
        if (!this.forgotPasswordForm.valid) {
            return;
        }
        this.isWorking = true;
        this.http.post('api/forgot-password', this.forgotPasswordForm.value).subscribe({
            next: () => {
                this.alerter.addAlert('Please check you mail for updated password', 'success');
                this.router.navigate(['/login']);
                this.isWorking = false;
            }, error: () => this.isWorking = false
        });
    }
    /** Method to evaluate form fields*/
    isFieldValid(field) {
        return this.formValidatorService.isFieldValid(field, this.forgotPasswordForm);
    }
    /** Method to find error in form fields*/
    getErrorMessage(field) {
        return this.formValidatorService.getErrorMessage(field, this.forgotPasswordForm, errorMessages);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ForgotPasswordComponent, deps: [{ token: i1.HttpService }, { token: i1.AlertService }, { token: i2.Router }, { token: i3.CurrentUserService }, { token: i1.ErrorHandlerService }, { token: i1.CredentialsService }, { token: i4.UntypedFormBuilder }, { token: i1.FormValidatorService }, { token: i5.UserConfigService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: ForgotPasswordComponent, selector: "forgot-password", ngImport: i0, template: "<div class=\"h-100  row align-items-center mx-0\">\n    <div class=\"col\">\n        <header class=\"branding-block mb-0 mt-4\">\n            <div class=\"branding text-center\">\n                <a *ngIf=\"userConfig.appLogoUrl\" href=\"{{userConfig.appUrl}}\" target=\"_blank\">\n                    <img class=\"techlify-logo d-inline-block\" [src]=\"userConfig.appLogoUrl\" />\n                </a>\n            </div>\n            <div class=\"product-info text-center mt-2\">\n                <h3 class=\"product-name\">{{ userConfig.appName }}</h3>\n            </div>\n        </header>\n\n        <div id=\"login-form-wrapper\"\n            class=\"form-bordered mx-auto form-medium form-bordered form-centered form-horizontal mt-3 white-box\"\n            style=\"width:550px\">\n\n            <h4 class=\"section-title text-center mt-4\">RESET</h4>\n\n            <form [formGroup]=\"forgotPasswordForm\" (ngSubmit)=\"sendOtp()\" class=\"mt-4\">\n\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"offset-2 col-8\">\n                        <input matInput formControlName=\"email\" placeholder=\"Email\" type=\"email\" autocomplete=\"off\"\n                            required />\n                        <mat-error *ngIf=\"isFieldValid('email')\">{{getErrorMessage('email')}}</mat-error>\n                    </mat-form-field>\n                </div>\n\n                <div class=\"row mt-4\">\n                    <div class=\"col-12 text-center\">\n                        <button mat-raised-button color=\"primary\" class=\"w-50\" type=\"submit\"\n                            [disabled]=\"isWorking\">\n                            Send OTP\n                        </button>\n                    </div>\n                </div>\n            </form>\n        </div>\n\n        <div class=\"row mt-3 mr-0 ml-0\" *ngIf=\"userConfig.showSignup\">\n            <div class=\"col-12 text-center\">\n                <p>New to {{ userConfig.appName }}?</p>\n                <button mat-button class=\"btn btn-sm btn-secondary text-white\" style=\"width: 550px;\" type=\"button\"\n                    [routerLink]=\"['/signup']\">\n                    Create an account\n                </button>\n            </div>\n        </div>\n    </div>\n</div>\n", styles: ["#login-form-wrapper{margin-top:100px}#login-form-wrapper .branding-block{margin-bottom:60px}#login-form-wrapper .techlify-logo{height:40px;padding-right:10px;bottom:10px;position:relative}#login-form-wrapper .company-name{margin-bottom:0}:host{width:100%}.white-box{background-color:#fff;padding:10px}\n"], dependencies: [{ kind: "directive", type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i4.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i4.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: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i4.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i4.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i4.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: i7.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", exportAs: ["matButton"] }, { kind: "component", type: i8.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i8.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "directive", type: i9.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "directive", type: i2.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ForgotPasswordComponent, decorators: [{
            type: Component,
            args: [{ selector: 'forgot-password', template: "<div class=\"h-100  row align-items-center mx-0\">\n    <div class=\"col\">\n        <header class=\"branding-block mb-0 mt-4\">\n            <div class=\"branding text-center\">\n                <a *ngIf=\"userConfig.appLogoUrl\" href=\"{{userConfig.appUrl}}\" target=\"_blank\">\n                    <img class=\"techlify-logo d-inline-block\" [src]=\"userConfig.appLogoUrl\" />\n                </a>\n            </div>\n            <div class=\"product-info text-center mt-2\">\n                <h3 class=\"product-name\">{{ userConfig.appName }}</h3>\n            </div>\n        </header>\n\n        <div id=\"login-form-wrapper\"\n            class=\"form-bordered mx-auto form-medium form-bordered form-centered form-horizontal mt-3 white-box\"\n            style=\"width:550px\">\n\n            <h4 class=\"section-title text-center mt-4\">RESET</h4>\n\n            <form [formGroup]=\"forgotPasswordForm\" (ngSubmit)=\"sendOtp()\" class=\"mt-4\">\n\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"offset-2 col-8\">\n                        <input matInput formControlName=\"email\" placeholder=\"Email\" type=\"email\" autocomplete=\"off\"\n                            required />\n                        <mat-error *ngIf=\"isFieldValid('email')\">{{getErrorMessage('email')}}</mat-error>\n                    </mat-form-field>\n                </div>\n\n                <div class=\"row mt-4\">\n                    <div class=\"col-12 text-center\">\n                        <button mat-raised-button color=\"primary\" class=\"w-50\" type=\"submit\"\n                            [disabled]=\"isWorking\">\n                            Send OTP\n                        </button>\n                    </div>\n                </div>\n            </form>\n        </div>\n\n        <div class=\"row mt-3 mr-0 ml-0\" *ngIf=\"userConfig.showSignup\">\n            <div class=\"col-12 text-center\">\n                <p>New to {{ userConfig.appName }}?</p>\n                <button mat-button class=\"btn btn-sm btn-secondary text-white\" style=\"width: 550px;\" type=\"button\"\n                    [routerLink]=\"['/signup']\">\n                    Create an account\n                </button>\n            </div>\n        </div>\n    </div>\n</div>\n", styles: ["#login-form-wrapper{margin-top:100px}#login-form-wrapper .branding-block{margin-bottom:60px}#login-form-wrapper .techlify-logo{height:40px;padding-right:10px;bottom:10px;position:relative}#login-form-wrapper .company-name{margin-bottom:0}:host{width:100%}.white-box{background-color:#fff;padding:10px}\n"] }]
        }], ctorParameters: () => [{ type: i1.HttpService }, { type: i1.AlertService }, { type: i2.Router }, { type: i3.CurrentUserService }, { type: i1.ErrorHandlerService }, { type: i1.CredentialsService }, { type: i4.UntypedFormBuilder }, { type: i1.FormValidatorService }, { type: i5.UserConfigService }] });
//# sourceMappingURL=data:application/json;base64, 