import { Directive , ElementRef , forwardRef , HostListener , Inject , NgModule } from '@angular/core' ; import { FormsModule , NG_VALUE_ACCESSOR } from '@angular/forms' ; import { registerElement , BaseValueAccessor } from '@nativescript/angular' ; import { View } from '@nativescript/core' ; function convertToInt ( value ) { let normalizedValue ; if ( value === undefined || value === null ) { normalizedValue = 0 ; } else { if ( typeof value === 'number' ) { normalizedValue = value ; } else { const parsedValue = parseInt ( value . toString ( ) , 10 ) ; normalizedValue = isNaN ( parsedValue ) ? 0 : parsedValue ; } } return Math . round ( normalizedValue ) ; } registerElement ( 'CheckBox' , ( ) => require ( '../checkbox' ) . CheckBox ) ; const CHECKED_VALUE_ACCESSOR = { provide : NG_VALUE_ACCESSOR , useExisting : forwardRef ( ( ) => CheckedValueAccessor ) , multi : true } ; export type CheckableView = { checked : boolean ; } & View ; /**
 * The accessor for setting checked property and listening to changes that is used by the
 *  NgModel directives.
 *
 *  ### Example
 *  ```
 *  <CheckBox [(ngModel)]="model.test">
 *  ```
  @ Directive ( { selector : 'CheckBox[ngModel], CheckBox[formControlName], CheckBox[formControl], checkBox[ngModel], checkBox[formControlName], checkBox[formControl], check-box[ngModel], check-box[formControlName], check-box[formControl]' , providers : [ CHECKED_VALUE_ACCESSOR ] } ) export class CheckedValueAccessor extends BaseValueAccessor < CheckableView > { constructor ( @ Inject ( ElementRef ) elementRef ) { super ( elementRef . nativeElement ) ; } @ HostListener ( 'checkedChange' , [ '$event' ] ) public checkedChangeListener ( event ) { this . onChange ( event . value ) ; } public onTouched = ( ) => { } ; public writeValue ( value ) { this . view . checked = value ; } public registerOnTouched ( fn ) { this . onTouched = fn ; } } @ NgModule ( { declarations : [ CheckedValueAccessor ] , providers : [ ] , imports : [ FormsModule ] , exports : [ FormsModule , CheckedValueAccessor ] } ) export class TNSCheckBoxModule { }