{"version":3,"file":"eui-components-eui-input-radio.mjs","sources":["../../eui-input-radio/eui-input-radio.component.ts","../../eui-input-radio/index.ts","../../eui-input-radio/eui-components-eui-input-radio.ts"],"sourcesContent":["import {\n    DoCheck,\n    ElementRef,\n    HostBinding,\n    Input,\n    OnChanges,\n    Renderer2,\n    SimpleChanges,\n    OnInit,\n    Component,\n    HostListener,\n    inject,\n} from '@angular/core';\nimport { ControlValueAccessor, NgControl } from '@angular/forms';\nimport { InputDirective } from '@eui/components/shared';\nimport { coerceBooleanProperty, BooleanInput } from '@angular/cdk/coercion';\n\n/**\n * @description\n * Radio input component for selecting a single value from a set of mutually exclusive options.\n * Integrates with Angular forms (both reactive and template-driven) and provides custom EUI styling.\n * Implements ControlValueAccessor for seamless form integration with validation states and error handling.\n * Automatically manages checked state, value binding, and form control synchronization.\n * Must be applied as an attribute directive to native HTML radio input elements.\n *\n * @usageNotes\n * ### Basic Usage\n * ```html\n * <!-- Template-driven forms -->\n * <div>\n *   <input euiInputRadio type=\"radio\" name=\"size\" value=\"small\" [(ngModel)]=\"selectedSize\" id=\"size-small\" />\n *   <label for=\"size-small\">Small</label>\n * </div>\n * <div>\n *   <input euiInputRadio type=\"radio\" name=\"size\" value=\"medium\" [(ngModel)]=\"selectedSize\" id=\"size-medium\" />\n *   <label for=\"size-medium\">Medium</label>\n * </div>\n * <div>\n *   <input euiInputRadio type=\"radio\" name=\"size\" value=\"large\" [(ngModel)]=\"selectedSize\" id=\"size-large\" />\n *   <label for=\"size-large\">Large</label>\n * </div>\n * ```\n *\n * ### Reactive Forms\n * ```html\n * <form [formGroup]=\"myForm\">\n *   <div>\n *     <input euiInputRadio type=\"radio\" formControlName=\"plan\" value=\"basic\" id=\"plan-basic\" />\n *     <label for=\"plan-basic\">Basic Plan</label>\n *   </div>\n *   <div>\n *     <input euiInputRadio type=\"radio\" formControlName=\"plan\" value=\"premium\" id=\"plan-premium\" />\n *     <label for=\"plan-premium\">Premium Plan</label>\n *   </div>\n * </form>\n * ```\n *\n * ```typescript\n * myForm = this.fb.group({\n *   plan: ['basic', Validators.required]\n * });\n * ```\n *\n * ### With Validation\n * ```html\n * <form [formGroup]=\"form\">\n *   <div>\n *     <input euiInputRadio type=\"radio\" formControlName=\"option\" value=\"yes\" id=\"opt-yes\" />\n *     <label for=\"opt-yes\">Yes</label>\n *   </div>\n *   <div>\n *     <input euiInputRadio type=\"radio\" formControlName=\"option\" value=\"no\" id=\"opt-no\" />\n *     <label for=\"opt-no\">No</label>\n *   </div>\n *   <div *ngIf=\"form.get('option')?.invalid && form.get('option')?.touched\" class=\"error\">\n *     Please select an option\n *   </div>\n * </form>\n * ```\n *\n * ### Disabled State\n * ```html\n * <input euiInputRadio type=\"radio\" name=\"status\" value=\"active\" [disabled]=\"true\" id=\"status-active\" />\n * <label for=\"status-active\">Active (disabled)</label>\n * ```\n *\n * ### Accessibility\n * - Always associate radio inputs with labels using for/id attributes\n * - Group related radio buttons with the same name attribute\n * - Use fieldset and legend for radio button groups\n * - Provide clear, descriptive labels for each option\n * - Invalid state automatically applies aria-invalid\n * - Keyboard navigation: Tab to focus, Space to select\n *\n * ### Notes\n * - Radio buttons with the same name are mutually exclusive\n * - Automatically generates unique IDs if not provided\n * - Invalid state styling applied when form control is invalid\n * - Supports readonly mode to prevent changes\n * - Value can be string, number, or boolean\n * - Integrates with Angular form validation\n * - Use with eui-label components for consistent styling\n *\n * @example\n * <input euiInputRadio type=\"radio\" name=\"option\" value=\"1\" [(ngModel)]=\"selected\" id=\"opt-1\" />\n * <label for=\"opt-1\">Option 1</label>\n */\n@Component({\n    // eslint-disable-next-line @angular-eslint/component-selector\n    selector: 'input[euiInputRadio]',\n    styleUrls: ['./eui-input-radio.scss'],\n    template: '',\n})\nexport class EuiInputRadioComponent extends InputDirective implements OnInit, DoCheck, OnChanges, ControlValueAccessor {\n    /**\n     * Gets or sets whether the radio input is in an invalid state.\n     * This can be set manually or will be automatically set when used with form validation.\n     *\n     * @property {boolean} isInvalid - The invalid state of the radio input\n     */\n    @Input()\n    public get isInvalid(): boolean {\n        return this._isInvalid || null;\n    }\n    public set isInvalid(state: BooleanInput) {\n        this.setInvalid(state);\n    }\n    protected _isInvalid: boolean;\n\n    /**\n     * Gets the CSS classes for the radio input component.\n     * Combines base classes with invalid state modifier if applicable.\n     *\n     * @returns {string} Space-separated list of CSS classes\n     */\n    @HostBinding('class')\n    public get class(): string {\n        return [super.getCssClasses('eui-input-radio'), this._isInvalid ? 'eui-input-radio--invalid' : ''].join(' ').trim();\n    }\n    @HostBinding('attr.type') protected type = 'radio';\n\n    /**\n     * Gets or sets the default checked state of the radio input.\n     * This is different from the current checked state and represents the initial value.\n     *\n     * @property {any} defaultChecked - The default checked state\n     */\n    @HostBinding('attr.checked')\n    @Input('checked')\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    public get defaultChecked(): any {\n        return this._defaultChecked ? '' : null;\n    }\n    public set defaultChecked(value: BooleanInput) {\n        this._defaultChecked = coerceBooleanProperty(value);\n\t\tthis._renderer.setProperty(this._elementRef.nativeElement, 'checked', this._defaultChecked);\n    }\n    protected _defaultChecked: boolean;\n\n    /**\n     * Gets whether the radio input is currently selected.\n     *\n     * @returns {boolean} True if the radio input is selected, false otherwise\n     */\n    public get selected(): boolean {\n        return this._elementRef?.nativeElement.checked;\n    }\n\n    /**\n     * Gets or sets the value of the radio input.\n     * The value can be of any type and will be used when the radio is selected in a form group.\n     *\n     * @property {any} value - The value associated with this radio input\n     */\n    @Input()\n    // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    get value(): any {\n        return this._value;\n    }\n    set value(value) {\n        this._value = value;\n        if (typeof value === 'number' || typeof value === 'boolean' || !!value) {\n            this._elementRef.nativeElement.value = this._value;\n        }\n    }\n    private _value;\n    protected ngControl = inject(NgControl, { optional: true, self: true })!;\n    protected _elementRef: ElementRef<HTMLInputElement> = inject<ElementRef<HTMLInputElement>>(ElementRef);\n    protected _renderer: Renderer2 = inject(Renderer2);\n\n    constructor() {\n        super();\n\n        // Firefox fix: set type to radio before first ngDoCheck runs\n        this._elementRef.nativeElement.type = 'radio';\n\n        // if there's no id attribute set one\n        if (!this._elementRef.nativeElement.id) {\n            this.setIdAttribute();\n        }\n\n        // register control valueAccessor\n        if (this.ngControl) {\n            this.ngControl.valueAccessor = this;\n        }\n    }\n\n    /**\n     * Initializes the component.\n     * Sets up form control validation status subscription and handles initial state.\n     */\n    ngOnInit(): void {\n        super.ngOnInit();\n\n        // in case control value is null set the default one (isChecked) and sync Control State\n        // if (this.ngControl?.control?.value === null) {\n        // this.ngControl.control.setValue('', { emitModelToViewChange: false });\n        // changing Model Expression after view checked, so detect changes\n        // TODO: check why although it's checked .checked returns false\n        // this.ngControl.viewToModelUpdate(this._checked);\n        // this._cd.detectChanges();\n        // }\n\n        if (this.ngControl) {\n            this.ngControl.statusChanges.subscribe((status) => {\n                this.isInvalid = status === 'INVALID';\n                this.euiDanger = this.isInvalid;\n            });\n        }\n    }\n\n    /**\n     * Performs change detection and updates invalid state based on form control status.\n     */\n    ngDoCheck(): void {\n        if (this.ngControl) {\n            this.isInvalid = this.ngControl.invalid && this.ngControl.touched;\n        }\n    }\n\n    /**\n     * Handles changes to component inputs. Specifically, handles changes to\n     * readonly and invalid states.\n     *\n     * @param {SimpleChanges} changes - Object containing changed properties\n     */\n    ngOnChanges(changes: SimpleChanges): void {\n        // when readonly changes hide other radio (input+label)\n        if (changes['readonly']) {\n            const readonly = coerceBooleanProperty(changes['readonly']?.currentValue);\n            if (readonly) {\n                this._renderer.setAttribute(this._elementRef.nativeElement, 'readonly', null);\n            } else {\n                this._renderer.removeAttribute(this._elementRef.nativeElement, 'readonly');\n            }\n        }\n\n        if (changes['isInvalid']) {\n            if (changes['isInvalid'].currentValue) {\n                this._renderer.addClass(this._elementRef.nativeElement, 'eui-input-radio--invalid');\n            } else {\n                this._renderer.removeClass(this._elementRef.nativeElement, 'eui-input-radio--invalid');\n            }\n        }\n    }\n\n    /**\n     * Implements ControlValueAccessor.writeValue.\n     * Updates the checked state based on the form control value.\n     *\n     * @param {string} obj - The value to write\n     */\n    writeValue(obj: string): void {\n        // set checked state based if the radio value matches the control's one\n        this._elementRef.nativeElement.checked = this._value === obj;\n    }\n\n    /**\n     * Registers a callback function that is called when the control's value changes.\n     *\n     * @param {Function} fn - The callback function\n     */\n    // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    registerOnChange(fn: any): void {\n        this.onChange = fn;\n    }\n\n    /**\n     * Registers a callback function that is called when the control is touched.\n     *\n     * @param {Function} fn - The callback function\n     */\n    // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    registerOnTouched(fn: any): void {\n        this.onTouched = fn;\n    }\n\n    /**\n     * Sets the disabled state of the radio input.\n     *\n     * @param {boolean} isDisabled - Whether the radio input should be disabled\n     */\n    setDisabledState?(isDisabled: boolean): void {\n        this.disabled = isDisabled;\n    }\n\n    /**\n     * Handles change events on the radio input.\n     * Updates the model value when the radio selection changes.\n     *\n     * @param {Event} event - The change event\n     */\n    @HostListener('change', ['$any($event)'])\n\tprotected onCheckedChanged(event: Event): void {\n\t\tconst target = event.target as HTMLInputElement;\n\t\tthis._defaultChecked = target.checked;\n\t\tthis.onChange(target.value === 'on' ? null : target.value);\n\t\tthis.onTouched(target.value);\n\t}\n\n    /**\n     * Handles space key press events. Prevents selection changes when the input\n     * is readonly.\n     *\n     * @param {KeyboardEvent} event - The keyboard event\n     */\n    @HostListener('keydown.space', ['$any($event)'])\n    protected onSpacePressed(event: KeyboardEvent): void {\n        if (this.readonly) {\n            event.preventDefault();\n            event.stopPropagation();\n        }\n    }\n\n    /**\n     * Sets the invalid state of the radio input.\n     * Updates both the internal state and the visual appearance.\n     *\n     * @param {boolean} state - The invalid state to set\n     */\n    protected setInvalid(state): void {\n        // in case it's controlled by NgControl override\n        this._isInvalid = this.control ? this.control.invalid && this.control.touched : coerceBooleanProperty(state);\n\n        // set BaseDirective Attribute\n        this.euiDanger = this._isInvalid;\n    }\n\n    // eslint-disable-next-line @typescript-eslint/no-unused-vars\n    protected onChange = (_): void => {\n        /* Nothing to be Done so far */\n    };\n\n    // eslint-disable-next-line @typescript-eslint/no-unused-vars\n    protected onTouched = (_): void => {\n        /* Nothing to be Done so far */\n    };\n}\n","import { EuiInputRadioComponent } from './eui-input-radio.component';\n\nexport * from './eui-input-radio.component';\n\nexport const EUI_INPUT_RADIO = [\n    EuiInputRadioComponent,\n] as const;\n\n// export { EuiInputRadioComponent as EuiInputRadio } from './eui-input-radio.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFG;AAOG,MAAO,sBAAuB,SAAQ,cAAc,CAAA;AACtD;;;;;AAKG;AACH,IAAA,IACW,SAAS,GAAA;AAChB,QAAA,OAAO,IAAI,CAAC,UAAU,IAAI,IAAI;IAClC;IACA,IAAW,SAAS,CAAC,KAAmB,EAAA;AACpC,QAAA,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;IAC1B;AAGA;;;;;AAKG;AACH,IAAA,IACW,KAAK,GAAA;AACZ,QAAA,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,IAAI,CAAC,UAAU,GAAG,0BAA0B,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;IACvH;AAGA;;;;;AAKG;AACH,IAAA,IAGW,cAAc,GAAA;QACrB,OAAO,IAAI,CAAC,eAAe,GAAG,EAAE,GAAG,IAAI;IAC3C;IACA,IAAW,cAAc,CAAC,KAA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