import{forwardRef,ɵɵdefineInjectable,Injectable,EventEmitter,Component,ChangeDetectionStrategy,ChangeDetectorRef,Injector,Input,Output,ViewChild,NgModule}from"@angular/core";import{CommonModule}from"@angular/common";import{NG_VALUE_ACCESSOR,NgControl}from"@angular/forms";const RADIO_VALUE_ACCESSOR={provide:NG_VALUE_ACCESSOR,useExisting:forwardRef(()=>RadioButton),multi:!0};class RadioControlRegistry{constructor(){this.accessors=[]}add(t,e){this.accessors.push([t,e])}remove(t){this.accessors=this.accessors.filter(e=>e[1]!==t)}select(t){this.accessors.forEach(e=>{this.isSameGroup(e,t)&&e[1]!==t&&e[1].writeValue(t.value)})}isSameGroup(t,e){return!!t[0].control&&(t[0].control.root===e.control.control.root&&t[1].name===e.name)}}RadioControlRegistry.ɵprov=ɵɵdefineInjectable({factory:function(){return new RadioControlRegistry},token:RadioControlRegistry,providedIn:"root"}),RadioControlRegistry.decorators=[{type:Injectable,args:[{providedIn:"root"}]}];class RadioButton{constructor(t,e,o){this.cd=t,this.injector=e,this.registry=o,this.onClick=new EventEmitter,this.onFocus=new EventEmitter,this.onBlur=new EventEmitter,this.onModelChange=(()=>{}),this.onModelTouched=(()=>{})}ngOnInit(){this.formControlName&&(this.control=this.injector.get(NgControl),this.checkName(),this.registry.add(this.control,this))}handleClick(t,e,o){t.preventDefault(),this.disabled||(this.select(t),o&&e.focus())}select(t){this.disabled||(this.inputViewChild.nativeElement.checked=!0,this.checked=!0,this.onModelChange(this.value),this.formControlName&&this.registry.select(this),this.onClick.emit(t))}writeValue(t){this.checked=t==this.value,this.inputViewChild&&this.inputViewChild.nativeElement&&(this.inputViewChild.nativeElement.checked=this.checked),this.cd.markForCheck()}registerOnChange(t){this.onModelChange=t}registerOnTouched(t){this.onModelTouched=t}setDisabledState(t){this.disabled=t,this.cd.markForCheck()}onInputFocus(t){this.focused=!0,this.onFocus.emit(t)}onInputBlur(t){this.focused=!1,this.onModelTouched(),this.onBlur.emit(t)}onChange(t){this.select(t)}focus(){this.inputViewChild.nativeElement.focus()}ngOnDestroy(){this.formControlName&&this.registry.remove(this)}checkName(){this.name&&this.formControlName&&this.name!==this.formControlName&&this.throwNameError(),!this.name&&this.formControlName&&(this.name=this.formControlName)}throwNameError(){throw new Error('\n If you define both a name and a formControlName attribute on your radio button, their values\n must match. Ex: