import { __decorate, __metadata } from 'tslib';
import * as i0 from '@angular/core';
import { ElementRef, Component, ChangeDetectionStrategy, NgModule } from '@angular/core';
import * as i1 from '@angular/forms';
import { Validators, UntypedFormBuilder, ReactiveFormsModule } from '@angular/forms';
import { UntilDestroy } from '@ngneat/until-destroy';
import * as i2 from '@aztrix/components/password-edit';
import { PasswordEditModule } from '@aztrix/components/password-edit';
import * as i3 from '@aztrix/components/button';
import { ButtonModule } from '@aztrix/components/button';
import * as i4 from '@aztrix/helpers';
import { HelperPipesModule } from '@aztrix/helpers';
import { CommonModule } from '@angular/common';
import { IconsModule } from '@aztrix/icons';

let ChangePasswordModalComponent = class ChangePasswordModalComponent {
    constructor(_elementRef, _formBuilder) {
        this._elementRef = _elementRef;
        this._formBuilder = _formBuilder;
        this.passwordGroup = this._formBuilder.group({
            password: ['', [Validators.required, Validators.minLength(8)]],
            newPassword: ['', [Validators.required, Validators.minLength(8)]],
            retype: ['', [Validators.required, Validators.minLength(8)]],
        }, {
            validators: (formGroup) => {
                const [password, newPassword, retype] = [
                    formGroup.get('password'),
                    formGroup.get('newPassword'),
                    formGroup.get('retype'),
                ];
                if (!newPassword.value || !retype.valid) {
                    return null;
                }
                if (newPassword.value !== retype.value) {
                    retype.setErrors({ match: true });
                    return { match: true };
                }
                else if (newPassword.value === password.value) {
                    newPassword.setErrors({ same: true });
                    retype.setErrors({ same: true });
                    return { same: true };
                }
                else {
                    newPassword.setErrors(null);
                    retype.setErrors(null);
                    return null;
                }
            },
        });
    }
    executeChangeAction() {
        if (this.passwordGroup.valid) {
            this.didClickChange({
                password: this.passwordGroup.get('password').value,
                newPassword: this.passwordGroup.get('newPassword').value,
            });
            this.passwordGroup.disable();
        }
    }
    setPasswordInvalid() {
        this.passwordGroup.enable();
        this.passwordGroup.get('password').setValue(null);
        this.passwordGroup.get('password').setErrors({ invalid: true });
        this._elementRef.nativeElement.querySelector('.mat-form-field input').focus();
    }
};
ChangePasswordModalComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ChangePasswordModalComponent, deps: [{ token: i0.ElementRef }, { token: i1.UntypedFormBuilder }], target: i0.ɵɵFactoryTarget.Component });
ChangePasswordModalComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.5", type: ChangePasswordModalComponent, selector: "ax-change-password-modal", ngImport: i0, template: "<form [formGroup]=\"passwordGroup\" class=\"modal-content-wrapper\">\n  <ax-password-edit\n    [form]=\"passwordGroup.get('password')\"\n    [label]=\"'modal.changePassword.password.old' | translate\"\n    showToggle=\"true\"\n  ></ax-password-edit>\n  <div class=\"new-password-wrapper\">\n    <ax-password-edit\n      [form]=\"passwordGroup.get('newPassword')\"\n      [label]=\"'modal.changePassword.password' | translate\"\n      showToggle=\"true\"\n      autocomplete=\"new-password\"\n    ></ax-password-edit>\n    <ax-password-edit\n      [form]=\"passwordGroup.get('retype')\"\n      [label]=\"'modal.changePassword.password.retype' | translate\"\n      showToggle=\"true\"\n      autocomplete=\"new-password\"\n    ></ax-password-edit>\n  </div>\n  <div class=\"h-button-wrapper\">\n    <button\n      axButton\n      (click)=\"executeChangeAction()\"\n      color=\"primary\"\n      [disabled]=\"!passwordGroup.valid\"\n      filled\n    >\n      {{ 'label.change' | translate }}\n    </button>\n  </div>\n</form>\n", styles: [":host{display:block}ax-password-edit{padding-bottom:.75rem;display:block}.new-password-wrapper{margin-top:.75rem}.new-password-wrapper ax-password-edit{display:block}.new-password-wrapper ax-password-edit:first-child{padding-top:0}.new-password-wrapper ax-password-edit:last-child{padding-bottom:0}\n"], dependencies: [{ kind: "component", type: i2.PasswordEditComponent, selector: "ax-password-edit", inputs: ["profileType", "username", "showToggle", "forgotPasswordHint", "pendingLink", "saveInPasswordManager", "minLength"] }, { kind: "directive", type: i3.ButtonDirective, selector: "[axButton]", inputs: ["color", "labelHideMobile", "smallButton", "bigButton", "fullWidth", "filled", "outline", "icon-button", "hoverLabel", "hover", "lowercase", "disabled"] }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "pipe", type: i4.TranslatePipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
ChangePasswordModalComponent = __decorate([
    UntilDestroy(),
    __metadata("design:paramtypes", [ElementRef, UntypedFormBuilder])
], ChangePasswordModalComponent);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ChangePasswordModalComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-change-password-modal', changeDetection: ChangeDetectionStrategy.OnPush, template: "<form [formGroup]=\"passwordGroup\" class=\"modal-content-wrapper\">\n  <ax-password-edit\n    [form]=\"passwordGroup.get('password')\"\n    [label]=\"'modal.changePassword.password.old' | translate\"\n    showToggle=\"true\"\n  ></ax-password-edit>\n  <div class=\"new-password-wrapper\">\n    <ax-password-edit\n      [form]=\"passwordGroup.get('newPassword')\"\n      [label]=\"'modal.changePassword.password' | translate\"\n      showToggle=\"true\"\n      autocomplete=\"new-password\"\n    ></ax-password-edit>\n    <ax-password-edit\n      [form]=\"passwordGroup.get('retype')\"\n      [label]=\"'modal.changePassword.password.retype' | translate\"\n      showToggle=\"true\"\n      autocomplete=\"new-password\"\n    ></ax-password-edit>\n  </div>\n  <div class=\"h-button-wrapper\">\n    <button\n      axButton\n      (click)=\"executeChangeAction()\"\n      color=\"primary\"\n      [disabled]=\"!passwordGroup.valid\"\n      filled\n    >\n      {{ 'label.change' | translate }}\n    </button>\n  </div>\n</form>\n", styles: [":host{display:block}ax-password-edit{padding-bottom:.75rem;display:block}.new-password-wrapper{margin-top:.75rem}.new-password-wrapper ax-password-edit{display:block}.new-password-wrapper ax-password-edit:first-child{padding-top:0}.new-password-wrapper ax-password-edit:last-child{padding-bottom:0}\n"] }]
        }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.UntypedFormBuilder }]; } });

class ChangePasswordModalModule {
}
ChangePasswordModalModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ChangePasswordModalModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
ChangePasswordModalModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.5", ngImport: i0, type: ChangePasswordModalModule, declarations: [ChangePasswordModalComponent], imports: [CommonModule,
        IconsModule,
        PasswordEditModule,
        HelperPipesModule,
        ButtonModule,
        ReactiveFormsModule], exports: [ChangePasswordModalComponent] });
ChangePasswordModalModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ChangePasswordModalModule, imports: [CommonModule,
        IconsModule,
        PasswordEditModule,
        HelperPipesModule,
        ButtonModule,
        ReactiveFormsModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ChangePasswordModalModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [ChangePasswordModalComponent],
                    imports: [
                        CommonModule,
                        IconsModule,
                        PasswordEditModule,
                        HelperPipesModule,
                        ButtonModule,
                        ReactiveFormsModule,
                    ],
                    exports: [ChangePasswordModalComponent],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { ChangePasswordModalComponent, ChangePasswordModalModule };
//# sourceMappingURL=aztrix-components-change-password-modal.mjs.map
//# sourceMappingURL=aztrix-components-change-password-modal.mjs.map
