/* eslint-disable @angular-eslint/no-output-on-prefix */
import { ChangeDetectorRef, Component, EventEmitter, inject, input, Output, ViewChild, ViewEncapsulation, } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { FormFieldUtilsService } from '../../../services/form-field-utils.service';
import { FieldLabelComponent } from '../../../components/field-label/field-label.component';
import { NgClass, NgStyle } from '@angular/common';
import { TooltipDirective } from '@seniorsistemas/angular-components/tooltip';
import { PasswordStrengthModule } from '@seniorsistemas/angular-components/password-strength';
import { ButtonComponent } from '@seniorsistemas/angular-components/button';
import { InputTextModule } from 'primeng/inputtext';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "@seniorsistemas/angular-components/password-strength";
import * as i3 from "primeng/inputtext";
export class PasswordFieldComponent {
    changeDetectorRef = inject(ChangeDetectorRef);
    field = input.required();
    formControl = input.required();
    onInput = new EventEmitter();
    onFocus = new EventEmitter();
    onComplete = new EventEmitter();
    inputRef = null;
    ngUnsubscribe = new Subject();
    passwordVisible = false;
    formUtils = inject(FormFieldUtilsService);
    ngOnInit() {
        this.formUtils.switchEmptyStringToNull(this.formControl(), this.ngUnsubscribe);
        const field = this.field();
        this.onFocus.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (field.onFocus) {
                field.onFocus(event);
            }
        });
        this.onInput.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (field.onInput) {
                field.onInput(event);
            }
        });
        this.onComplete.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (field.onComplete) {
                field.onComplete(event);
            }
        });
    }
    ngOnDestroy() {
        this.ngUnsubscribe.next();
        this.ngUnsubscribe.complete();
    }
    onChangeVisible() {
        this.passwordVisible = !this.passwordVisible;
    }
    ngAfterViewInit() {
        this.changeDetectorRef.detectChanges();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: PasswordFieldComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: PasswordFieldComponent, isStandalone: true, selector: "ng-component", inputs: { field: { classPropertyName: "field", publicName: "field", isSignal: true, isRequired: true, transformFunction: null }, formControl: { classPropertyName: "formControl", publicName: "formControl", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { onInput: "onInput", onFocus: "onFocus", onComplete: "onComplete" }, viewQueries: [{ propertyName: "inputRef", first: true, predicate: ["inputRef"], descendants: true }], ngImport: i0, template: "@let _field = field();\n@if (inputRef) {\n    <s-field-label\n        [field]=\"_field\"\n        [fieldContainerRef]=\"inputRef\"\n    ></s-field-label>\n}\n\n<div\n    class=\"password-field\"\n    [ngClass]=\"{ 'password-field--toggle': _field.showToggle }\"\n>\n    <input\n        #inputRef\n        [type]=\"passwordVisible ? 'text' : 'password'\"\n        [id]=\"_field.id || _field.name\"\n        class=\"password-input\"\n        [name]=\"_field.name\"\n        [sTooltip]=\"_field.tooltip\"\n        tooltipPosition=\"top\"\n        [placeholder]=\"_field.placeholder ?? ''\"\n        [showDelay]=\"500\"\n        [maxLength]=\"_field.maxLength ?? 9999999\"\n        pInputText\n        [ngClass]=\"'mousetrap'\"\n        (blur)=\"_field.onBlur ? _field.onBlur($event) : null\"\n        (focus)=\"onFocus.next($event)\"\n        (input)=\"onInput.next($event)\"\n        [formControl]=\"formControl()\"\n        [ngStyle]=\"_field.style\"\n        [sPasswordStrength]=\"_field.passwordStrength ? _field.passwordStrength : false\"\n        [passwordStrengthDescription]=\"\n            _field.passwordStrengthOptions?.description ? _field.passwordStrengthOptions!.description : ''\n        \"\n        [passwordStrengthWeakTitle]=\"\n            _field.passwordStrengthOptions?.weakTitle ? _field.passwordStrengthOptions?.weakTitle : ''\n        \"\n        [passwordStrengthMediumTitle]=\"\n            _field.passwordStrengthOptions?.mediumTitle ? _field.passwordStrengthOptions?.mediumTitle : ''\n        \"\n        [passwordStrengthStrongTitle]=\"\n            _field.passwordStrengthOptions?.strongTitle ? _field.passwordStrengthOptions?.strongTitle : ''\n        \"\n        [passwordStrengthValidation]=\"_field.passwordStrengthOptions?.validation\"\n    />\n    @if (_field.showToggle) {\n        <span class=\"toggle-button\">\n            <s-button\n                [iconClass]=\"passwordVisible ? 'fas fa-eye-slash' : 'fas fa-eye'\"\n                priority=\"default\"\n                (clicked)=\"onChangeVisible()\"\n            >\n            </s-button>\n        </span>\n    }\n</div>\n\n", styles: ["s-text-field.ng-dirty.ng-invalid .password-input{border-color:#c13018}s-text-field.ng-dirty.ng-invalid .password-input:hover{border-color:highlight(#c13018)}.password-field{display:flex}.password-field--toggle .password-input{border-top-right-radius:0;border-bottom-right-radius:0;border-right:none}.password-field--toggle .toggle-button s-button button{border-bottom-left-radius:0;border-top-left-radius:0}.password-field:has(.password-input.ng-invalid.ng-dirty) s-button button{border:1px solid #c13018}.password-field:has(.password-input:focus) s-button button{border:1px solid #428bca}.password-field:has(.password-input:focus):has(button) .password-input{border-right:none}\n"], dependencies: [{ kind: "component", type: FieldLabelComponent, selector: "s-field-label", inputs: ["field", "fieldContainerRef"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: TooltipDirective, selector: "[sTooltip]", inputs: ["sTooltip", "tooltipPosition", "showDelay", "displayTime", "tooltipEvent", "escape", "visible", "mobileBehavior", "focusedInputRef", "checkTruncatedText"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.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: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "ngmodule", type: PasswordStrengthModule }, { kind: "directive", type: i2.PasswordStrengthDirective, selector: "[sPasswordStrength]", inputs: ["sPasswordStrength", "passwordStrengthValidation", "passwordStrengthPosition", "passwordStrengthWeakTitle", "passwordStrengthMediumTitle", "passwordStrengthStrongTitle", "passwordStrengthDescription"] }, { kind: "component", type: ButtonComponent, selector: "s-button", inputs: ["id", "label", "tooltip", "tooltipPosition", "iconClass", "rightIconClass", "caret", "styleClass", "baseZIndex", "disabled", "auxiliary", "type", "priority", "menuOptions", "size", "slide", "animation", "badge", "iconColor", "menuAriaLabel"], outputs: ["clicked"] }, { kind: "ngmodule", type: InputTextModule }, { kind: "directive", type: i3.InputText, selector: "[pInputText]", inputs: ["variant", "fluid", "pSize"] }], encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: PasswordFieldComponent, decorators: [{
            type: Component,
            args: [{ encapsulation: ViewEncapsulation.None, standalone: true, imports: [
                        FieldLabelComponent,
                        NgClass,
                        TooltipDirective,
                        ReactiveFormsModule,
                        NgStyle,
                        PasswordStrengthModule,
                        ButtonComponent,
                        InputTextModule,
                    ], template: "@let _field = field();\n@if (inputRef) {\n    <s-field-label\n        [field]=\"_field\"\n        [fieldContainerRef]=\"inputRef\"\n    ></s-field-label>\n}\n\n<div\n    class=\"password-field\"\n    [ngClass]=\"{ 'password-field--toggle': _field.showToggle }\"\n>\n    <input\n        #inputRef\n        [type]=\"passwordVisible ? 'text' : 'password'\"\n        [id]=\"_field.id || _field.name\"\n        class=\"password-input\"\n        [name]=\"_field.name\"\n        [sTooltip]=\"_field.tooltip\"\n        tooltipPosition=\"top\"\n        [placeholder]=\"_field.placeholder ?? ''\"\n        [showDelay]=\"500\"\n        [maxLength]=\"_field.maxLength ?? 9999999\"\n        pInputText\n        [ngClass]=\"'mousetrap'\"\n        (blur)=\"_field.onBlur ? _field.onBlur($event) : null\"\n        (focus)=\"onFocus.next($event)\"\n        (input)=\"onInput.next($event)\"\n        [formControl]=\"formControl()\"\n        [ngStyle]=\"_field.style\"\n        [sPasswordStrength]=\"_field.passwordStrength ? _field.passwordStrength : false\"\n        [passwordStrengthDescription]=\"\n            _field.passwordStrengthOptions?.description ? _field.passwordStrengthOptions!.description : ''\n        \"\n        [passwordStrengthWeakTitle]=\"\n            _field.passwordStrengthOptions?.weakTitle ? _field.passwordStrengthOptions?.weakTitle : ''\n        \"\n        [passwordStrengthMediumTitle]=\"\n            _field.passwordStrengthOptions?.mediumTitle ? _field.passwordStrengthOptions?.mediumTitle : ''\n        \"\n        [passwordStrengthStrongTitle]=\"\n            _field.passwordStrengthOptions?.strongTitle ? _field.passwordStrengthOptions?.strongTitle : ''\n        \"\n        [passwordStrengthValidation]=\"_field.passwordStrengthOptions?.validation\"\n    />\n    @if (_field.showToggle) {\n        <span class=\"toggle-button\">\n            <s-button\n                [iconClass]=\"passwordVisible ? 'fas fa-eye-slash' : 'fas fa-eye'\"\n                priority=\"default\"\n                (clicked)=\"onChangeVisible()\"\n            >\n            </s-button>\n        </span>\n    }\n</div>\n\n", styles: ["s-text-field.ng-dirty.ng-invalid .password-input{border-color:#c13018}s-text-field.ng-dirty.ng-invalid .password-input:hover{border-color:highlight(#c13018)}.password-field{display:flex}.password-field--toggle .password-input{border-top-right-radius:0;border-bottom-right-radius:0;border-right:none}.password-field--toggle .toggle-button s-button button{border-bottom-left-radius:0;border-top-left-radius:0}.password-field:has(.password-input.ng-invalid.ng-dirty) s-button button{border:1px solid #c13018}.password-field:has(.password-input:focus) s-button button{border:1px solid #428bca}.password-field:has(.password-input:focus):has(button) .password-input{border-right:none}\n"] }]
        }], propDecorators: { onInput: [{
                type: Output
            }], onFocus: [{
                type: Output
            }], onComplete: [{
                type: Output
            }], inputRef: [{
                type: ViewChild,
                args: ['inputRef']
            }] } });
//# sourceMappingURL=data:application/json;base64, 