/* tslint:disable:component-selector one-variable-per-declaration */
import { Component } from '@angular/core';
import { Validators, UntypedFormControl } from '@angular/forms';
import { User } from '../user';
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 "@angular/common";
import * as i6 from "@angular/material/button";
import * as i7 from "@angular/material/form-field";
import * as i8 from "@angular/material/icon";
import * as i9 from "@angular/material/input";
import * as i10 from "@angular/material/card";
import * as i11 from "@angular/flex-layout/flex";
import * as i12 from "../password-requirement-check/password-requirement-check/password-requirement-check.component";
const errorMessages = {
    current_password: {
        required: 'Current password is required'
    },
    password: {
        required: 'New password is required',
        capitalLetter: 'Password should contain at-least 1 capital letter',
        symbol: 'Password should contain at-least 1 symbol',
        digit: 'Password should contain at-least 1 digit',
        minLength: 'Should have minimum length',
    },
    password_confirmation: {
        required: 'Confirm password is required',
        passwordMismatch: 'Password should match'
    }
};
export class ChangePasswordComponent {
    constructor(http, alertService, router, currentUserService, fb, errorHandler, formValidatorService) {
        this.http = http;
        this.alertService = alertService;
        this.router = router;
        this.currentUserService = currentUserService;
        this.fb = fb;
        this.errorHandler = errorHandler;
        this.formValidatorService = formValidatorService;
        this.passwordHide = true;
        this.passwordConfirmationHide = true;
        this.isWorking = false;
        this.passwordResetForm = fb.group({
            current_password: new UntypedFormControl('', Validators.required),
            password: new UntypedFormControl('', Validators.required),
            password_confirmation: new UntypedFormControl('', Validators.required),
        });
    }
    ngOnInit() {
        this.user = new User();
        this.currentUserService.getUserObservable(true).subscribe(user => {
            this.user = user;
        });
    }
    saveNewPassword() {
        if (!this.passwordResetForm.valid) {
            this.passwordResetForm.markAllAsTouched();
            return;
        }
        this.isWorking = true;
        this.http.patch('api/user/current/update-password', this.passwordResetForm.value).toPromise().then(res => {
            this.isWorking = false;
            this.alertService.addAlert('Successfully changed your password', 'success');
            this.router.navigate(['/dashboard']);
        }).catch(error => {
            this.errorHandler.handleError(error);
        }).finally(() => {
            this.isWorking = false;
        });
    }
    isFieldValid(field) {
        return this.formValidatorService.isFieldValid(field, this.passwordResetForm);
    }
    getErrorMessage(field) {
        return this.formValidatorService.getErrorMessage(field, this.passwordResetForm, errorMessages);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ChangePasswordComponent, deps: [{ token: i1.HttpService }, { token: i1.AlertService }, { token: i2.Router }, { token: i3.CurrentUserService }, { token: i4.UntypedFormBuilder }, { token: i1.ErrorHandlerService }, { token: i1.FormValidatorService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: ChangePasswordComponent, selector: "app-change-password", ngImport: i0, template: "<div class=\"h-100 d-flex justify-content-center align-items-center w-100\">\n  <div class=\"row w-100\">\n    <div class=\"col-lg-6 col-md-8 col-sm-10 col-xs-12 col-12 mx-auto\">\n      <mat-card>\n        <mat-card-title>\n          Update Your Password\n        </mat-card-title>\n        <mat-card-subtitle>\n          <small class=\"text-muted\" *ngIf=\"user?.is_temporary_password\">\n            You\u2019re currently using a temporary password, please change it to proceed\n          </small>\n        </mat-card-subtitle>\n        <form [formGroup]=\"passwordResetForm\" (ngSubmit)=\"saveNewPassword()\">\n          <mat-card-content fxLayout=\"column wrap\" fxLayoutGap=\"1rem\">\n            <mat-form-field fxFlex=\"100%\">\n              <mat-label>Current Password</mat-label>\n              <input matInput formControlName=\"current_password\"\n                     placeholder=\"Current Password\"\n                     type=\"password\"\n                     autocomplete=\"off\"\n                     required />\n              <mat-hint>Your current password.</mat-hint>\n              <mat-error *ngIf=\"isFieldValid('current_password')\">\n                {{getErrorMessage('current_password')}}\n              </mat-error>\n            </mat-form-field>\n            <mat-form-field fxFlex=\"100%\">\n              <mat-label>New Password</mat-label>\n              <input matInput formControlName=\"password\"\n                     placeholder=\"New Password\"\n                     [type]=\"passwordHide ? 'password' : 'text'\"\n                     autocomplete=\"off\"\n                     required />\n              <button matSuffix mat-icon-button (click)=\"passwordHide = !passwordHide\" type=\"button\">\n                <mat-icon>{{passwordHide ? 'visibility_off' : 'visibility'}}</mat-icon>\n              </button>\n              <mat-error *ngIf=\"isFieldValid('password')\">\n                {{getErrorMessage('password')}}\n              </mat-error>\n              <mat-hint>The new password you would like to use.</mat-hint>\n            </mat-form-field>\n            <mat-form-field fxFlex=\"100%\">\n              <mat-label>Confirm Password</mat-label>\n              <input matInput formControlName=\"password_confirmation\"\n                     placeholder=\"Confirm Password\"\n                     [type]=\"passwordConfirmationHide ? 'password' : 'text'\"\n                     autocomplete=\"off\" required />\n              <button matSuffix mat-icon-button (click)=\"passwordConfirmationHide = !passwordConfirmationHide\" type=\"button\">\n                <mat-icon>{{passwordConfirmationHide ? 'visibility_off' : 'visibility'}}</mat-icon>\n              </button>\n              <mat-error *ngIf=\"isFieldValid('password_confirmation')\">\n                {{getErrorMessage('password_confirmation')}}\n              </mat-error>\n            </mat-form-field>\n          </mat-card-content>\n          <div class=\"mt-2 mb-2\">\n            <techlify-password-requirement-check [password]=\"passwordResetForm.get('password').value\"></techlify-password-requirement-check>\n          </div>\n          <mat-card-actions fxLayoutAlign=\"end\">\n            <button mat-raised-button color=primary type=\"submit\" [disabled]=\"isWorking\">\n              Change Password\n            </button>\n          </mat-card-actions>\n        </form>\n      </mat-card>\n    </div>\n  </div>\n</div>\n", styles: [""], dependencies: [{ kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i6.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", exportAs: ["matButton"] }, { kind: "component", type: i6.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "component", type: i7.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i7.MatLabel, selector: "mat-label" }, { kind: "directive", type: i7.MatHint, selector: "mat-hint", inputs: ["align", "id"] }, { kind: "directive", type: i7.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "directive", type: i7.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "component", type: i8.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { 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: "component", type: i10.MatCard, selector: "mat-card", inputs: ["appearance"], exportAs: ["matCard"] }, { kind: "directive", type: i10.MatCardActions, selector: "mat-card-actions", inputs: ["align"], exportAs: ["matCardActions"] }, { kind: "directive", type: i10.MatCardContent, selector: "mat-card-content" }, { kind: "directive", type: i10.MatCardSubtitle, selector: "mat-card-subtitle, [mat-card-subtitle], [matCardSubtitle]" }, { kind: "directive", type: i10.MatCardTitle, selector: "mat-card-title, [mat-card-title], [matCardTitle]" }, { 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: "directive", type: i11.DefaultLayoutDirective, selector: "  [fxLayout], [fxLayout.xs], [fxLayout.sm], [fxLayout.md],  [fxLayout.lg], [fxLayout.xl], [fxLayout.lt-sm], [fxLayout.lt-md],  [fxLayout.lt-lg], [fxLayout.lt-xl], [fxLayout.gt-xs], [fxLayout.gt-sm],  [fxLayout.gt-md], [fxLayout.gt-lg]", inputs: ["fxLayout", "fxLayout.xs", "fxLayout.sm", "fxLayout.md", "fxLayout.lg", "fxLayout.xl", "fxLayout.lt-sm", "fxLayout.lt-md", "fxLayout.lt-lg", "fxLayout.lt-xl", "fxLayout.gt-xs", "fxLayout.gt-sm", "fxLayout.gt-md", "fxLayout.gt-lg"] }, { kind: "directive", type: i11.DefaultLayoutGapDirective, selector: "  [fxLayoutGap], [fxLayoutGap.xs], [fxLayoutGap.sm], [fxLayoutGap.md],  [fxLayoutGap.lg], [fxLayoutGap.xl], [fxLayoutGap.lt-sm], [fxLayoutGap.lt-md],  [fxLayoutGap.lt-lg], [fxLayoutGap.lt-xl], [fxLayoutGap.gt-xs], [fxLayoutGap.gt-sm],  [fxLayoutGap.gt-md], [fxLayoutGap.gt-lg]", inputs: ["fxLayoutGap", "fxLayoutGap.xs", "fxLayoutGap.sm", "fxLayoutGap.md", "fxLayoutGap.lg", "fxLayoutGap.xl", "fxLayoutGap.lt-sm", "fxLayoutGap.lt-md", "fxLayoutGap.lt-lg", "fxLayoutGap.lt-xl", "fxLayoutGap.gt-xs", "fxLayoutGap.gt-sm", "fxLayoutGap.gt-md", "fxLayoutGap.gt-lg"] }, { kind: "directive", type: i11.DefaultLayoutAlignDirective, selector: "  [fxLayoutAlign], [fxLayoutAlign.xs], [fxLayoutAlign.sm], [fxLayoutAlign.md],  [fxLayoutAlign.lg], [fxLayoutAlign.xl], [fxLayoutAlign.lt-sm], [fxLayoutAlign.lt-md],  [fxLayoutAlign.lt-lg], [fxLayoutAlign.lt-xl], [fxLayoutAlign.gt-xs], [fxLayoutAlign.gt-sm],  [fxLayoutAlign.gt-md], [fxLayoutAlign.gt-lg]", inputs: ["fxLayoutAlign", "fxLayoutAlign.xs", "fxLayoutAlign.sm", "fxLayoutAlign.md", "fxLayoutAlign.lg", "fxLayoutAlign.xl", "fxLayoutAlign.lt-sm", "fxLayoutAlign.lt-md", "fxLayoutAlign.lt-lg", "fxLayoutAlign.lt-xl", "fxLayoutAlign.gt-xs", "fxLayoutAlign.gt-sm", "fxLayoutAlign.gt-md", "fxLayoutAlign.gt-lg"] }, { kind: "directive", type: i11.DefaultFlexDirective, selector: "  [fxFlex], [fxFlex.xs], [fxFlex.sm], [fxFlex.md],  [fxFlex.lg], [fxFlex.xl], [fxFlex.lt-sm], [fxFlex.lt-md],  [fxFlex.lt-lg], [fxFlex.lt-xl], [fxFlex.gt-xs], [fxFlex.gt-sm],  [fxFlex.gt-md], [fxFlex.gt-lg]", inputs: ["fxFlex", "fxFlex.xs", "fxFlex.sm", "fxFlex.md", "fxFlex.lg", "fxFlex.xl", "fxFlex.lt-sm", "fxFlex.lt-md", "fxFlex.lt-lg", "fxFlex.lt-xl", "fxFlex.gt-xs", "fxFlex.gt-sm", "fxFlex.gt-md", "fxFlex.gt-lg"] }, { kind: "component", type: i12.PasswordRequirementCheckComponent, selector: "techlify-password-requirement-check", inputs: ["password", "email"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ChangePasswordComponent, decorators: [{
            type: Component,
            args: [{ selector: 'app-change-password', template: "<div class=\"h-100 d-flex justify-content-center align-items-center w-100\">\n  <div class=\"row w-100\">\n    <div class=\"col-lg-6 col-md-8 col-sm-10 col-xs-12 col-12 mx-auto\">\n      <mat-card>\n        <mat-card-title>\n          Update Your Password\n        </mat-card-title>\n        <mat-card-subtitle>\n          <small class=\"text-muted\" *ngIf=\"user?.is_temporary_password\">\n            You\u2019re currently using a temporary password, please change it to proceed\n          </small>\n        </mat-card-subtitle>\n        <form [formGroup]=\"passwordResetForm\" (ngSubmit)=\"saveNewPassword()\">\n          <mat-card-content fxLayout=\"column wrap\" fxLayoutGap=\"1rem\">\n            <mat-form-field fxFlex=\"100%\">\n              <mat-label>Current Password</mat-label>\n              <input matInput formControlName=\"current_password\"\n                     placeholder=\"Current Password\"\n                     type=\"password\"\n                     autocomplete=\"off\"\n                     required />\n              <mat-hint>Your current password.</mat-hint>\n              <mat-error *ngIf=\"isFieldValid('current_password')\">\n                {{getErrorMessage('current_password')}}\n              </mat-error>\n            </mat-form-field>\n            <mat-form-field fxFlex=\"100%\">\n              <mat-label>New Password</mat-label>\n              <input matInput formControlName=\"password\"\n                     placeholder=\"New Password\"\n                     [type]=\"passwordHide ? 'password' : 'text'\"\n                     autocomplete=\"off\"\n                     required />\n              <button matSuffix mat-icon-button (click)=\"passwordHide = !passwordHide\" type=\"button\">\n                <mat-icon>{{passwordHide ? 'visibility_off' : 'visibility'}}</mat-icon>\n              </button>\n              <mat-error *ngIf=\"isFieldValid('password')\">\n                {{getErrorMessage('password')}}\n              </mat-error>\n              <mat-hint>The new password you would like to use.</mat-hint>\n            </mat-form-field>\n            <mat-form-field fxFlex=\"100%\">\n              <mat-label>Confirm Password</mat-label>\n              <input matInput formControlName=\"password_confirmation\"\n                     placeholder=\"Confirm Password\"\n                     [type]=\"passwordConfirmationHide ? 'password' : 'text'\"\n                     autocomplete=\"off\" required />\n              <button matSuffix mat-icon-button (click)=\"passwordConfirmationHide = !passwordConfirmationHide\" type=\"button\">\n                <mat-icon>{{passwordConfirmationHide ? 'visibility_off' : 'visibility'}}</mat-icon>\n              </button>\n              <mat-error *ngIf=\"isFieldValid('password_confirmation')\">\n                {{getErrorMessage('password_confirmation')}}\n              </mat-error>\n            </mat-form-field>\n          </mat-card-content>\n          <div class=\"mt-2 mb-2\">\n            <techlify-password-requirement-check [password]=\"passwordResetForm.get('password').value\"></techlify-password-requirement-check>\n          </div>\n          <mat-card-actions fxLayoutAlign=\"end\">\n            <button mat-raised-button color=primary type=\"submit\" [disabled]=\"isWorking\">\n              Change Password\n            </button>\n          </mat-card-actions>\n        </form>\n      </mat-card>\n    </div>\n  </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.HttpService }, { type: i1.AlertService }, { type: i2.Router }, { type: i3.CurrentUserService }, { type: i4.UntypedFormBuilder }, { type: i1.ErrorHandlerService }, { type: i1.FormValidatorService }] });
//# sourceMappingURL=data:application/json;base64, 