import { p as proxyCustomElement, H, c as createEvent, h, d as Host } from './p-a53686b3.js';
import { r as randomIdGenerator } from './p-ffe5c0e8.js';
import { d as defineCustomElement$2 } from './p-2f619b66.js';

const formRadiogroupCss = "";
const DigiFormRadiogroupStyle0 = formRadiogroupCss;

const FormRadiogroup = /*@__PURE__*/ proxyCustomElement(class FormRadiogroup extends H {
    constructor() {
        super();
        this.__registerHost();
        this.afOnGroupChange = createEvent(this, "afOnGroupChange", 7);
        this.radiobuttons = undefined;
        this.afValue = undefined;
        this.value = undefined;
        this.afName = randomIdGenerator('digi-form-radiogroup');
    }
    OnAfValueChange(value) {
        this.value = value;
    }
    OnValueChange(value) {
        this.afValue = value;
        this.setRadiobuttons(value);
    }
    radiobuttonChangeListener(e) {
        if (Array.from(this.radiobuttons).includes(e.target)) {
            e.preventDefault();
            this.afValue = e.detail.target.value;
            this.afOnGroupChange.emit(e);
        }
    }
    componentDidLoad() {
        this.setRadiobuttons(this.value || this.afValue);
        if (this.value)
            this.afValue = this.value;
    }
    setRadiobuttons(value) {
        this.radiobuttons = this.hostElement.querySelectorAll('digi-form-radiobutton');
        this.radiobuttons.forEach((r) => {
            r.afName = this.afName;
            if (value && r.afValue == value) {
                r.setAttribute('af-checked', 'true');
            }
        });
    }
    render() {
        return (h(Host, { key: '32ecef2c08cd9f37a95d782d8f0e631ad4037c69' }, h("div", { key: '1d4606fe5a994d4b79113568349147874d15b6ad', class: {
                'digi-form-radiogroup': true
            } }, h("digi-util-mutation-observer", { key: '1facc76b33e1b65428b5205ee074af6ae511bc74', onAfOnChange: (e) => this.radiobuttonChangeListener(e) }, h("slot", { key: '7b006ed18743cf5fdf7c432b80674b753a347aa7' })))));
    }
    get hostElement() { return this; }
    static get watchers() { return {
        "afValue": ["OnAfValueChange"],
        "value": ["OnValueChange"]
    }; }
    static get style() { return DigiFormRadiogroupStyle0; }
}, [6, "digi-form-radiogroup", {
        "afValue": [1025, "af-value"],
        "value": [1025],
        "afName": [1, "af-name"],
        "radiobuttons": [32]
    }, undefined, {
        "afValue": ["OnAfValueChange"],
        "value": ["OnValueChange"]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["digi-form-radiogroup", "digi-util-mutation-observer"];
    components.forEach(tagName => { switch (tagName) {
        case "digi-form-radiogroup":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, FormRadiogroup);
            }
            break;
        case "digi-util-mutation-observer":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const DigiFormRadiogroup = FormRadiogroup;
const defineCustomElement = defineCustomElement$1;

export { DigiFormRadiogroup, defineCustomElement };
