import * as i0 from '@angular/core';
import { Component, ChangeDetectionStrategy, Input, NgModule } from '@angular/core';
import { ForgotPasswordModalComponent } from '@aztrix/components/forgot-password-modal';
import * as i1 from '@aztrix/components/overlay';
import { ValueEdit } from '@aztrix/components/value-edit';
import { Subscription } from 'rxjs';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i3 from '@angular/forms';
import { ReactiveFormsModule } from '@angular/forms';
import * as i4 from '@aztrix/icons';
import { IconsModule } from '@aztrix/icons';
import * as i5 from '@angular/material/form-field';
import { MatFormFieldModule } from '@angular/material/form-field';
import * as i6 from '@angular/material/input';
import { MatInputModule } from '@angular/material/input';
import * as i7 from '@aztrix/components/autofocus';
import { AutofocusModule } from '@aztrix/components/autofocus';
import * as i8 from '@aztrix/components/button';
import { ButtonModule } from '@aztrix/components/button';
import * as i9 from '@aztrix/helpers';
import { HelperPipesModule } from '@aztrix/helpers';

class PasswordEditComponent extends ValueEdit {
    constructor(_overlay, _elementRef, changeDetector) {
        super(changeDetector);
        this._overlay = _overlay;
        this._elementRef = _elementRef;
        this.forgotPasswordHint = false;
        this.saveInPasswordManager = true;
        this.minLength = 8;
        this.subscription = new Subscription();
    }
    ngOnChanges(changes) {
        if (changes.form && this.form) {
            this.subscription.unsubscribe();
            this.subscription = this.form.statusChanges.subscribe(() => {
                this._changeDetector.markForCheck();
            });
        }
        super.ngOnChanges(changes);
    }
    ngOnDestroy() {
        this.subscription.unsubscribe();
        super.ngOnDestroy();
    }
    openForgotPasswordModal() {
        this._overlay.createModal(this._elementRef, ForgotPasswordModalComponent, {
            title: 'modal.forgotPassword.title',
            init: (modal) => {
                modal.username = this.username;
            },
        });
    }
    get errors() {
        return Object.keys(this.form?.errors || []);
    }
    errorTranslationKey(errorType) {
        switch (errorType) {
            case 'minlength':
            case 'required':
                return 'password.format.requirement';
            case 'match':
                return 'password.format.match';
            case 'invalid':
                return 'password.incorrect';
            case 'same':
                return 'password.format.same';
            default:
                console.warn(`unknown errorType: ${errorType}`);
                return 'password.format.requirement';
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: PasswordEditComponent, deps: [{ token: i1.OverlayService }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: PasswordEditComponent, selector: "ax-password-edit", inputs: { username: "username", showToggle: "showToggle", forgotPasswordHint: "forgotPasswordHint", saveInPasswordManager: "saveInPasswordManager", minLength: "minLength" }, usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "<mat-form-field\n  class=\"c-input\"\n  [ngClass]=\"{'remove-subtext': !forgotPasswordHint && !hint && !errors.length}\"\n  appearance=\"outline\"\n  style=\"width: 100%\"\n>\n  <mat-label>{{ label || ('label.password' | translate) }}</mat-label>\n  <input\n    matInput\n    axAutofocus\n    [autofocus]=\"autofocus\"\n    [autocomplete]=\"saveInPasswordManager ? autocompleteAttr ?? 'current-password' : ''\"\n    [type]=\"passwordVisible || !saveInPasswordManager ? 'text' : 'password'\"\n    [ngStyle]=\"{\n      '-webkit-text-security': passwordVisible || saveInPasswordManager ? 'none' : 'disc'\n    }\"\n    [formControl]=\"form\"\n  />\n\n  <button\n    class=\"password-toggle\"\n    *ngIf=\"showToggle\"\n    axButton\n    matSuffix\n    icon-button\n    type=\"button\"\n    (click)=\"passwordVisible = !passwordVisible\"\n  >\n    <ax-icon\n      class=\"icon\"\n      matSuffix\n      [ariaLabel]=\"(passwordVisible ? 'label.hide' : 'label.show') | translate\"\n      [name]=\"passwordVisible ? 'eye' : 'eye-off'\"\n    ></ax-icon>\n  </button>\n  <mat-error *ngFor=\"let error of errors\">\n    <ax-icon name=\"alert-circle\"></ax-icon>\n    <span>{{ errorTranslationKey(error) | translate: {amount: minLength} }}</span>\n  </mat-error>\n  <mat-hint align=\"end\" class=\"forgot-password-hint\" *ngIf=\"forgotPasswordHint && hint\">\n    <button\n      class=\"forgot-password-button\"\n      axButton\n      color=\"primary\"\n      type=\"button\"\n      (click)=\"openForgotPasswordModal()\"\n    >\n      {{ hint }}\n    </button>\n  </mat-hint>\n  <mat-hint align=\"end\" *ngIf=\"!forgotPasswordHint && hint\">\n    <span>{{ hint }}</span>\n  </mat-hint>\n</mat-form-field>\n", styles: [".password-toggle{cursor:pointer}.icon{width:1rem;height:1rem}.forgot-password-button{text-transform:none;padding:0;height:24px}.forgot-password-button:hover{text-decoration:underline}\n"], dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { 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.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i4.IconComponent, selector: "ax-icon", inputs: ["name", "inline"] }, { kind: "component", type: i5.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i5.MatLabel, selector: "mat-label" }, { kind: "directive", type: i5.MatHint, selector: "mat-hint", inputs: ["align", "id"] }, { kind: "directive", type: i5.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "directive", type: i5.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "directive", type: i6.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: i7.AutofocusDirective, selector: "[axAutofocus]", inputs: ["autofocus"] }, { kind: "directive", type: i8.ButtonDirective, selector: "[axButton]", inputs: ["color", "labelHideMobile", "smallButton", "bigButton", "fullWidth", "filled", "outline", "icon-button", "hoverLabel", "hover", "lowercase", "disabled"] }, { kind: "pipe", type: i9.TranslatePipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: PasswordEditComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-password-edit', changeDetection: ChangeDetectionStrategy.OnPush, template: "<mat-form-field\n  class=\"c-input\"\n  [ngClass]=\"{'remove-subtext': !forgotPasswordHint && !hint && !errors.length}\"\n  appearance=\"outline\"\n  style=\"width: 100%\"\n>\n  <mat-label>{{ label || ('label.password' | translate) }}</mat-label>\n  <input\n    matInput\n    axAutofocus\n    [autofocus]=\"autofocus\"\n    [autocomplete]=\"saveInPasswordManager ? autocompleteAttr ?? 'current-password' : ''\"\n    [type]=\"passwordVisible || !saveInPasswordManager ? 'text' : 'password'\"\n    [ngStyle]=\"{\n      '-webkit-text-security': passwordVisible || saveInPasswordManager ? 'none' : 'disc'\n    }\"\n    [formControl]=\"form\"\n  />\n\n  <button\n    class=\"password-toggle\"\n    *ngIf=\"showToggle\"\n    axButton\n    matSuffix\n    icon-button\n    type=\"button\"\n    (click)=\"passwordVisible = !passwordVisible\"\n  >\n    <ax-icon\n      class=\"icon\"\n      matSuffix\n      [ariaLabel]=\"(passwordVisible ? 'label.hide' : 'label.show') | translate\"\n      [name]=\"passwordVisible ? 'eye' : 'eye-off'\"\n    ></ax-icon>\n  </button>\n  <mat-error *ngFor=\"let error of errors\">\n    <ax-icon name=\"alert-circle\"></ax-icon>\n    <span>{{ errorTranslationKey(error) | translate: {amount: minLength} }}</span>\n  </mat-error>\n  <mat-hint align=\"end\" class=\"forgot-password-hint\" *ngIf=\"forgotPasswordHint && hint\">\n    <button\n      class=\"forgot-password-button\"\n      axButton\n      color=\"primary\"\n      type=\"button\"\n      (click)=\"openForgotPasswordModal()\"\n    >\n      {{ hint }}\n    </button>\n  </mat-hint>\n  <mat-hint align=\"end\" *ngIf=\"!forgotPasswordHint && hint\">\n    <span>{{ hint }}</span>\n  </mat-hint>\n</mat-form-field>\n", styles: [".password-toggle{cursor:pointer}.icon{width:1rem;height:1rem}.forgot-password-button{text-transform:none;padding:0;height:24px}.forgot-password-button:hover{text-decoration:underline}\n"] }]
        }], ctorParameters: () => [{ type: i1.OverlayService }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }], propDecorators: { username: [{
                type: Input
            }], showToggle: [{
                type: Input
            }], forgotPasswordHint: [{
                type: Input
            }], saveInPasswordManager: [{
                type: Input
            }], minLength: [{
                type: Input
            }] } });

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

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

export { PasswordEditComponent, PasswordEditModule };
//# sourceMappingURL=aztrix-components-password-edit.mjs.map
