import { Component , OnDestroy , Input , forwardRef , AfterViewInit , OnChanges , ElementRef , ViewChild , EventEmitter , Output } from '@angular/core' ; import { ControlValueAccessor , FormControl , NG_VALUE_ACCESSOR } from '@angular/forms' ; import { UntilDestroy , untilDestroyed } from '@ngneat/until-destroy' ; import { TranslateService } from '@ngx-translate/core' ; import { debounceTime } from 'rxjs/operators' ; import { distinctUntilChange , isEmpty } from '@gauzy/common-angular' ; import { NbComponentSize } from '@nebular/theme' ; import { TranslationBaseComponent } from '../../../../language-base' ; @ UntilDestroy ( { checkProperties : true } ) @ Component ( { selector : 'ngx-password-form-field' , templateUrl : './password.component.html' , providers : [ { provide : NG_VALUE_ACCESSOR , useExisting : forwardRef ( ( ) => PasswordFormFieldComponent ) , multi : true } ] } ) export class PasswordFormFieldComponent extends TranslationBaseComponent implements ControlValueAccessor , AfterViewInit , OnChanges , OnDestroy { showPassword : boolean = false ; private innerValue : any = '' ; onChange = ( _ ) => { } ; onTouched = ( _ ) => { } ; /**
     * Getter & Setter accessor including call the onchange callback
     */ get value ( ) : any { return this . innerValue ; } ; set value ( v ) { if ( v !== this . innerValue ) { this . innerValue = v ; } } _ctrl : FormControl = new FormControl ( ) ; get ctrl ( ) : FormControl { return this . _ctrl ; } @ Input ( ) set ctrl ( value ) { this . _ctrl = value ; } _placeholder : string ; get placeholder ( ) : string { return this . _placeholder ; } @ Input ( ) set placeholder ( value ) { this . _placeholder = value ; } _icon : boolean = true ; get icon ( ) : boolean { return this . _icon ; } @ Input ( ) set icon ( value ) { this . _icon = value ; } _id : string ; get id ( ) : string { return this . _id ; } @ Input ( ) set id ( value ) { this . _id = value ; } _fieldSize : NbComponentSize = 'medium' ; get fieldSize ( ) : NbComponentSize { return this . _fieldSize ; } @ Input ( ) set fieldSize ( value ) { this . _fieldSize = value ; } _ngClass : string ; get ngClass ( ) : string { return this . _ngClass ; } @ Input ( ) set ngClass ( value ) { this . _ngClass = value ; } @ Output ( ) onInputChanged = new EventEmitter < string > ( ) ; @ ViewChild ( 'input' ) inputRef : ElementRef ; constructor ( public readonly translateService ) { super ( translateService ) ; } ngOnChanges ( ) { } ngAfterViewInit ( ) { this . ctrl . valueChanges . pipe ( debounceTime ( 100 ) , distinctUntilChange ( ) , untilDestroyed ( this ) ) . subscribe ( ( ) => { if ( isEmpty ( this . ctrl . value ) ) { this . innerValue = '' ; this . inputRef . nativeElement . value = '' ; } this . onInputChanged . emit ( this . ctrl . value ) ; } ) ; } onInputChange ( e , value ) { this . innerValue = value ; this . onChange ( this . innerValue ) ; } writeValue ( value ) { this . innerValue = value ; } registerOnChange ( fn ) { this . onChange = fn ; } registerOnTouched ( fn ) { this . onTouched = fn ; } ngOnDestroy ( ) { } }