import { coerceAttrBoolean, FormItemWidth, isTemplateRef } from '@alauda/ui';
import { ChangeDetectionStrategy, Component, Input, forwardRef, } from '@angular/core';
import { NG_VALIDATORS, NG_VALUE_ACCESSOR, } from '@angular/forms';
import { decode, encode } from 'ab64';
import { assocPath } from 'ramda';
import { BaseNestedFormControlPure } from '../../core/public-api';
import { STRONG_PASSWORD_SPECIAL_CHARS } from '../../validators/public-api';
import * as i0 from "@angular/core";
function PasswordInputComponent_aui_icon_7_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "aui-icon", 9);
    i0.ɵɵlistener("click", function PasswordInputComponent_aui_icon_7_Template_aui_icon_click_0_listener() { i0.ɵɵrestoreView(_r5); const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.showPassword = !ctx_r4.showPassword); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("icon", ctx_r1.showPassword ? "basic:eye_s" : "basic:eye_slash_s");
} }
function PasswordInputComponent_div_8_ng_container_1_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainer(0);
} }
function PasswordInputComponent_div_8_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, PasswordInputComponent_div_8_ng_container_1_ng_container_1_Template, 1, 0, "ng-container", 13);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r6 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngTemplateOutlet", ctx_r6.hint);
} }
function PasswordInputComponent_div_8_ng_template_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtext(0);
} if (rf & 2) {
    const ctx_r8 = i0.ɵɵnextContext(2);
    i0.ɵɵtextInterpolate1(" ", ctx_r8.hint, " ");
} }
function PasswordInputComponent_div_8_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 10);
    i0.ɵɵtemplate(1, PasswordInputComponent_div_8_ng_container_1_Template, 2, 1, "ng-container", 11);
    i0.ɵɵtemplate(2, PasswordInputComponent_div_8_ng_template_2_Template, 1, 1, "ng-template", null, 12, i0.ɵɵtemplateRefExtractor);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const _r7 = i0.ɵɵreference(3);
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r2.isTemplateRef(ctx_r2.hint))("ngIfElse", _r7);
} }
function PasswordInputComponent_aui_form_item_11_aui_icon_8_Template(rf, ctx) { if (rf & 1) {
    const _r13 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "aui-icon", 9);
    i0.ɵɵlistener("click", function PasswordInputComponent_aui_form_item_11_aui_icon_8_Template_aui_icon_click_0_listener() { i0.ɵɵrestoreView(_r13); const ctx_r12 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r12.showPassword = !ctx_r12.showPassword); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r11 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("icon", ctx_r11.showPassword ? "basic:eye_s" : "basic:eye_slash_s");
} }
const _c0 = function (a0) { return { notMatch: a0 }; };
function PasswordInputComponent_aui_form_item_11_Template(rf, ctx) { if (rf & 1) {
    const _r15 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "aui-form-item", 0)(1, "label", 1);
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "translate");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "aui-input-group", 2)(5, "input", 14, 15);
    i0.ɵɵlistener("ngModelChange", function PasswordInputComponent_aui_form_item_11_Template_input_ngModelChange_5_listener($event) { i0.ɵɵrestoreView(_r15); const ctx_r14 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r14.confirmPassword = $event); });
    i0.ɵɵpipe(7, "pure");
    i0.ɵɵelementEnd();
    i0.ɵɵtemplate(8, PasswordInputComponent_aui_form_item_11_aui_icon_8_Template, 1, 1, "aui-icon", 5);
    i0.ɵɵelementEnd();
    i0.ɵɵelement(9, "acl-errors-mapper", 7);
    i0.ɵɵpipe(10, "translate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const _r10 = i0.ɵɵreference(6);
    const ctx_r3 = i0.ɵɵnextContext();
    i0.ɵɵproperty("width", ctx_r3.width);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(3, 10, "confirm_password"));
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("required", ctx_r3.required);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("type", ctx_r3.showPassword ? "text" : "password")("ngModel", ctx_r3.confirmPassword)("required", ctx_r3.required)("aclValidateFn", i0.ɵɵpipeBind2(7, 12, ctx_r3.model, ctx_r3.validateConfirmPassword));
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("ngIf", ctx_r3.toggleable);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("errors", _r10 == null ? null : _r10.errors)("errorsMapper", i0.ɵɵpureFunction1(17, _c0, i0.ɵɵpipeBind1(10, 15, "confirm_password_not_match")));
} }
const _c1 = function (a0) { return { chars: a0 }; };
const _c2 = function (a0) { return { pattern: a0 }; };
export class PasswordInputComponent extends BaseNestedFormControlPure {
    constructor() {
        super(...arguments);
        this.specialChars = STRONG_PASSWORD_SPECIAL_CHARS;
        this.strongPassword = true;
        this.enableConfirm = true;
        this.width = 'medium';
        this.toggleable = true;
        this.encoding = {
            encode,
            decode,
        };
        this.showPassword = false;
        this.confirmPassword = '';
        this.isTemplateRef = isTemplateRef;
        this._required = true;
    }
    set required(required) {
        this._required = coerceAttrBoolean(required);
    }
    get required() {
        return this._required;
    }
    ngOnInit() {
        this.confirmPassword = this.encoding.decode(this.initPassword ?? '');
    }
    valueIn(v) {
        return this.encoding.decode(v ?? '');
    }
    modelOut(v) {
        return this.encoding.encode(v);
    }
    validate() {
        let errors = super.validate();
        if (coerceAttrBoolean(this.enableConfirm) &&
            this.confirmPassword !== this.model) {
            errors = assocPath(['confirmPassword', 'notMatch'], true, errors);
        }
        return errors;
    }
    validateConfirmPassword(password) {
        return (control) => {
            if (!password) {
                return null;
            }
            return password !== control.value ? { notMatch: true } : null;
        };
    }
}
PasswordInputComponent.ɵfac = /*@__PURE__*/ function () { let ɵPasswordInputComponent_BaseFactory; return function PasswordInputComponent_Factory(t) { return (ɵPasswordInputComponent_BaseFactory || (ɵPasswordInputComponent_BaseFactory = i0.ɵɵgetInheritedFactory(PasswordInputComponent)))(t || PasswordInputComponent); }; }();
PasswordInputComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: PasswordInputComponent, selectors: [["acl-password-input"]], inputs: { initPassword: "initPassword", label: "label", hint: "hint", specialChars: "specialChars", strongPassword: "strongPassword", enableConfirm: "enableConfirm", width: "width", toggleable: "toggleable", encoding: "encoding", required: "required" }, features: [i0.ɵɵProvidersFeature([
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: forwardRef(() => PasswordInputComponent),
                multi: true,
            },
            {
                provide: NG_VALIDATORS,
                useExisting: forwardRef(() => PasswordInputComponent),
                multi: true,
            },
        ]), i0.ɵɵInheritDefinitionFeature], decls: 12, vars: 22, consts: [[3, "width"], ["auiFormItemLabel", ""], ["auiFormItemControl", "", 1, "tw-flex-1", 3, "required"], ["aui-input", "", "name", "password", "autocomplete", "new-password", 3, "type", "ngModel", "required", "aclStrongPassword", "specialChars", "ngModelChange"], ["password", "ngModel"], ["auiInputSuffix", "", "class", "tw-icon-m tw-cursor-pointer hover:tw-text-primary", 3, "icon", "click", 4, "ngIf"], ["auiFormItemHint", "", 4, "ngIf"], ["auiFormItemError", "", 3, "errors", "errorsMapper"], [3, "width", 4, "ngIf"], ["auiInputSuffix", "", 1, "tw-icon-m", "tw-cursor-pointer", "hover:tw-text-primary", 3, "icon", "click"], ["auiFormItemHint", ""], [4, "ngIf", "ngIfElse"], ["defaultDescription", ""], [4, "ngTemplateOutlet"], ["aui-input", "", "name", "confirmPassword", "autocomplete", "new-password", 3, "type", "ngModel", "required", "aclValidateFn", "ngModelChange"], ["confirm", "ngModel"]], template: function PasswordInputComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵelementStart(0, "aui-form-item", 0)(1, "label", 1);
        i0.ɵɵtext(2);
        i0.ɵɵpipe(3, "translate");
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(4, "aui-input-group", 2)(5, "input", 3, 4);
        i0.ɵɵlistener("ngModelChange", function PasswordInputComponent_Template_input_ngModelChange_5_listener($event) { return ctx.emitModel($event); });
        i0.ɵɵelementEnd();
        i0.ɵɵtemplate(7, PasswordInputComponent_aui_icon_7_Template, 1, 1, "aui-icon", 5);
        i0.ɵɵelementEnd();
        i0.ɵɵtemplate(8, PasswordInputComponent_div_8_Template, 4, 2, "div", 6);
        i0.ɵɵelement(9, "acl-errors-mapper", 7);
        i0.ɵɵpipe(10, "translate");
        i0.ɵɵelementEnd();
        i0.ɵɵtemplate(11, PasswordInputComponent_aui_form_item_11_Template, 11, 19, "aui-form-item", 8);
    } if (rf & 2) {
        const _r0 = i0.ɵɵreference(6);
        i0.ɵɵproperty("width", ctx.width);
        i0.ɵɵadvance(2);
        i0.ɵɵtextInterpolate(ctx.label || i0.ɵɵpipeBind1(3, 13, "password"));
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("required", ctx.required);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("type", ctx.showPassword ? "text" : "password")("ngModel", ctx.model)("required", ctx.required)("aclStrongPassword", ctx.strongPassword)("specialChars", ctx.specialChars);
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("ngIf", ctx.toggleable);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.hint);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("errors", _r0 == null ? null : _r0.errors)("errorsMapper", i0.ɵɵpureFunction1(20, _c2, i0.ɵɵpipeBind2(10, 15, "strong_password_pattern_tip", i0.ɵɵpureFunction1(18, _c1, _r0 == null ? null : _r0.errors == null ? null : _r0.errors.pattern == null ? null : _r0.errors.pattern.needSpecialChar == null ? null : _r0.errors.pattern.needSpecialChar.requiredChars))));
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("ngIf", ctx.enableConfirm);
    } }, encapsulation: 2, changeDetection: 0 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PasswordInputComponent, [{
        type: Component,
        args: [{ selector: 'acl-password-input', changeDetection: ChangeDetectionStrategy.OnPush, providers: [
                    {
                        provide: NG_VALUE_ACCESSOR,
                        useExisting: forwardRef(() => PasswordInputComponent),
                        multi: true,
                    },
                    {
                        provide: NG_VALIDATORS,
                        useExisting: forwardRef(() => PasswordInputComponent),
                        multi: true,
                    },
                ], template: "<aui-form-item [width]=\"width\">\n  <label auiFormItemLabel>{{ label || ('password' | translate) }}</label>\n  <aui-input-group\n    class=\"tw-flex-1\"\n    auiFormItemControl\n    [required]=\"required\"\n  >\n    <input\n      aui-input\n      [type]=\"showPassword ? 'text' : 'password'\"\n      name=\"password\"\n      #password=\"ngModel\"\n      [ngModel]=\"model\"\n      (ngModelChange)=\"emitModel($event)\"\n      autocomplete=\"new-password\"\n      [required]=\"required\"\n      [aclStrongPassword]=\"strongPassword\"\n      [specialChars]=\"specialChars\"\n    />\n    <aui-icon\n      *ngIf=\"toggleable\"\n      auiInputSuffix\n      class=\"tw-icon-m tw-cursor-pointer hover:tw-text-primary\"\n      [icon]=\"showPassword ? 'basic:eye_s' : 'basic:eye_slash_s'\"\n      (click)=\"showPassword = !showPassword\"\n    ></aui-icon>\n  </aui-input-group>\n  <div\n    *ngIf=\"hint\"\n    auiFormItemHint\n  >\n    <ng-container *ngIf=\"isTemplateRef(hint); else defaultDescription\">\n      <ng-container *ngTemplateOutlet=\"hint\"></ng-container>\n    </ng-container>\n    <ng-template #defaultDescription>\n      {{ hint }}\n    </ng-template>\n  </div>\n  <acl-errors-mapper\n    auiFormItemError\n    [errors]=\"password?.errors\"\n    [errorsMapper]=\"{\n      pattern:\n        'strong_password_pattern_tip'\n        | translate\n          : { chars: password?.errors?.pattern?.needSpecialChar?.requiredChars }\n    }\"\n  ></acl-errors-mapper>\n</aui-form-item>\n<aui-form-item\n  *ngIf=\"enableConfirm\"\n  [width]=\"width\"\n>\n  <label auiFormItemLabel>{{ 'confirm_password' | translate }}</label>\n  <aui-input-group\n    class=\"tw-flex-1\"\n    auiFormItemControl\n    [required]=\"required\"\n  >\n    <input\n      aui-input\n      [type]=\"showPassword ? 'text' : 'password'\"\n      name=\"confirmPassword\"\n      #confirm=\"ngModel\"\n      [(ngModel)]=\"confirmPassword\"\n      autocomplete=\"new-password\"\n      [required]=\"required\"\n      [aclValidateFn]=\"model | pure: validateConfirmPassword\"\n    />\n    <aui-icon\n      *ngIf=\"toggleable\"\n      auiInputSuffix\n      class=\"tw-icon-m tw-cursor-pointer hover:tw-text-primary\"\n      [icon]=\"showPassword ? 'basic:eye_s' : 'basic:eye_slash_s'\"\n      (click)=\"showPassword = !showPassword\"\n    ></aui-icon>\n  </aui-input-group>\n  <acl-errors-mapper\n    auiFormItemError\n    [errors]=\"confirm?.errors\"\n    [errorsMapper]=\"{\n      notMatch: 'confirm_password_not_match' | translate\n    }\"\n  ></acl-errors-mapper>\n</aui-form-item>\n" }]
    }], null, { initPassword: [{
            type: Input
        }], label: [{
            type: Input
        }], hint: [{
            type: Input
        }], specialChars: [{
            type: Input
        }], strongPassword: [{
            type: Input
        }], enableConfirm: [{
            type: Input
        }], width: [{
            type: Input
        }], toggleable: [{
            type: Input
        }], encoding: [{
            type: Input
        }], required: [{
            type: Input
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 