import * as i0 from '@angular/core';
import { EventEmitter, Directive, Input, Output, forwardRef, Component, ChangeDetectionStrategy } from '@angular/core';
import * as i1$1 from '@angular/common';
import { CommonModule } from '@angular/common';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import * as i1 from '@ironsource/fusion-ui/services/unique-id';
import { RadioComponent } from '@ironsource/fusion-ui/components/radio/v4';

class RadioGroupBaseComponent {
    /**
     * radio buttons group name
     */
    set name(value) {
        this._name = value;
    }
    /**
     * disabled (all group)
     */
    set disabled(value) {
        this._disabled = value;
    }
    /**
     * radiobutton option: interface RadioGroupOptions
     */
    set options(value) {
        this._options = value;
    }
    get name() {
        return this._name;
    }
    get disabled() {
        return this._disabled;
    }
    get options() {
        return this._options;
    }
    get selected() {
        return this._selected;
    }
    constructor(uniqueIdService) {
        this.uniqueIdService = uniqueIdService;
        /**
         * radiobutton inline direction
         */
        this.inline = false;
        /** @internal */
        this.selectedChange = new EventEmitter();
        this._disabled = false;
        this._options = [];
        /**
         * Method to call when value has changes.
         * @internal
         */
        this.propagateChange = (_) => { };
        /**
         * Method to call when the component is touched (when it was is clicked).
         * @internal
         */
        this.propagateTouched = () => { };
    }
    ngOnInit() {
        const grUniq = this.uniqueIdService.getUniqueId();
        this.name = 'is-rbgroup-' + (this.name || grUniq);
        this.id = 'is-rbgroup-' + grUniq;
    }
    /** @internal */
    isSelected(option) {
        return option === this.selected || option?.id === this.selected?.id;
    }
    /** @internal */
    setSelected(radioValue, option) {
        this._selected = option;
        this.selectedChange.emit(this.selected);
        this.propagateChange(this.selected);
    }
    /**
     * update value from model to the component
     * @internal
     */
    writeValue(value) {
        this._selected = value;
        if (this._selected?.disabled) {
            this._disabled = true;
        }
    }
    /**
     * Informs the outside world about changes.
     * see method propagateChange call - this.propagateChange(this.model);
     * @internal
     */
    registerOnChange(fn) {
        this.propagateChange = fn;
    }
    /**
     * on click
     * @internal
     */
    registerOnTouched(fn) {
        this.propagateTouched = fn;
    }
    /**
     * on set form controll enabled / disabled
     * also do UI Component enabled / disabled
     * @internal
     */
    setDisabledState(isDisabled) {
        this._disabled = isDisabled;
    }
    static { this.ɵfac = function RadioGroupBaseComponent_Factory(t) { return new (t || RadioGroupBaseComponent)(i0.ɵɵdirectiveInject(i1.UniqueIdService)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: RadioGroupBaseComponent, inputs: { name: "name", inline: "inline", disabled: "disabled", options: "options" }, outputs: { selectedChange: "selectedChange" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(RadioGroupBaseComponent, [{
        type: Directive
    }], () => [{ type: i1.UniqueIdService }], { name: [{
            type: Input
        }], inline: [{
            type: Input
        }], disabled: [{
            type: Input
        }], options: [{
            type: Input
        }], selectedChange: [{
            type: Output
        }] }); })();

function RadioGroupComponent_fusion_radio_1_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "fusion-radio", 2);
    i0.ɵɵlistener("changed", function RadioGroupComponent_fusion_radio_1_Template_fusion_radio_changed_0_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r3); const option_r1 = restoredCtx.$implicit; const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.setSelected($event, option_r1)); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const option_r1 = ctx.$implicit;
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("name", ctx_r0.name)("value", option_r1.id)("label", option_r1.label)("selected", ctx_r0.isSelected(option_r1))("disabled", ctx_r0.disabled || option_r1.disabled);
} }
class RadioGroupComponent extends RadioGroupBaseComponent {
    static { this.ɵfac = /*@__PURE__*/ (() => { let ɵRadioGroupComponent_BaseFactory; return function RadioGroupComponent_Factory(t) { return (ɵRadioGroupComponent_BaseFactory || (ɵRadioGroupComponent_BaseFactory = i0.ɵɵgetInheritedFactory(RadioGroupComponent)))(t || RadioGroupComponent); }; })(); }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: RadioGroupComponent, selectors: [["fusion-radio-group"]], hostAttrs: [1, "fusion-v4"], standalone: true, features: [i0.ɵɵProvidersFeature([
                {
                    provide: NG_VALUE_ACCESSOR,
                    useExisting: forwardRef(() => RadioGroupComponent),
                    multi: true
                }
            ]), i0.ɵɵInheritDefinitionFeature, i0.ɵɵStandaloneFeature], decls: 2, vars: 4, consts: [[1, "fu-radio-group-wrapper"], [3, "name", "value", "label", "selected", "disabled", "changed", 4, "ngFor", "ngForOf"], [3, "name", "value", "label", "selected", "disabled", "changed"]], template: function RadioGroupComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵtemplate(1, RadioGroupComponent_fusion_radio_1_Template, 1, 5, "fusion-radio", 1);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵclassProp("fu-direction-row", ctx.inline);
            i0.ɵɵattribute("id", ctx.id);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngForOf", ctx.options);
        } }, dependencies: [CommonModule, i1$1.NgForOf, RadioComponent], styles: [".fusion-v4[_ngcontent-%COMP%]{--spacing-tockenset: 0px;--spacing-25: 2px;--spacing-50: 4px;--spacing-75: 6px;--spacing-100: 8px;--spacing-125: 10px;--spacing-150: 12px;--spacing-200: 16px;--spacing-250: 20px;--spacing-300: 24px;--spacing-400: 32px;--spacing-500: 40px;--spacing-600: 48px;--spacing-700: 56px;--spacing-800: 64px;--spacing-900: 72px;--spacing-1000: 80px}[_nghost-%COMP%]   .fu-radio-group-wrapper[_ngcontent-%COMP%]{display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;gap:var(--spacing-100, 8px)}[_nghost-%COMP%]   .fu-radio-group-wrapper.fu-direction-row[_ngcontent-%COMP%]{flex-direction:row;align-items:center}"], changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(RadioGroupComponent, [{
        type: Component,
        args: [{ selector: 'fusion-radio-group', standalone: true, imports: [CommonModule, RadioComponent], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'fusion-v4' }, providers: [
                    {
                        provide: NG_VALUE_ACCESSOR,
                        useExisting: forwardRef(() => RadioGroupComponent),
                        multi: true
                    }
                ], template: "<div class=\"fu-radio-group-wrapper\" [attr.id]=\"id\" [class.fu-direction-row]=\"inline\">\n    <fusion-radio\n        *ngFor=\"let option of options\"\n        [name]=\"name\"\n        [value]=\"option.id\"\n        [label]=\"option.label\"\n        [selected]=\"isSelected(option)\"\n        [disabled]=\"disabled || option.disabled\"\n        (changed)=\"setSelected($event, option)\"\n    ></fusion-radio>\n</div>\n\n", styles: [".fusion-v4{--spacing-tockenset: 0px;--spacing-25: 2px;--spacing-50: 4px;--spacing-75: 6px;--spacing-100: 8px;--spacing-125: 10px;--spacing-150: 12px;--spacing-200: 16px;--spacing-250: 20px;--spacing-300: 24px;--spacing-400: 32px;--spacing-500: 40px;--spacing-600: 48px;--spacing-700: 56px;--spacing-800: 64px;--spacing-900: 72px;--spacing-1000: 80px}:host .fu-radio-group-wrapper{display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;gap:var(--spacing-100, 8px)}:host .fu-radio-group-wrapper.fu-direction-row{flex-direction:row;align-items:center}\n"] }]
    }], null, null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(RadioGroupComponent, { className: "RadioGroupComponent", filePath: "radio-group.component.ts", lineNumber: 23 }); })();

/**
 * Generated bundle index. Do not edit.
 */

export { RadioGroupComponent };
//# sourceMappingURL=ironsource-fusion-ui-components-radio-group-v4.mjs.map
