'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-7a477838.js');
const randomIdGenerator_util = require('./randomIdGenerator.util-e7f4b6de.js');

const formRadiogroupCss = "";
const DigiFormRadiogroupStyle0 = formRadiogroupCss;

const FormRadiogroup = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.afOnGroupChange = index.createEvent(this, "afOnGroupChange", 7);
        this.radiobuttons = undefined;
        this.afValue = undefined;
        this.value = undefined;
        this.afName = randomIdGenerator_util.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 (index.h(index.Host, { key: '32ecef2c08cd9f37a95d782d8f0e631ad4037c69' }, index.h("div", { key: '1d4606fe5a994d4b79113568349147874d15b6ad', class: {
                'digi-form-radiogroup': true
            } }, index.h("digi-util-mutation-observer", { key: '1facc76b33e1b65428b5205ee074af6ae511bc74', onAfOnChange: (e) => this.radiobuttonChangeListener(e) }, index.h("slot", { key: '7b006ed18743cf5fdf7c432b80674b753a347aa7' })))));
    }
    get hostElement() { return index.getElement(this); }
    static get watchers() { return {
        "afValue": ["OnAfValueChange"],
        "value": ["OnValueChange"]
    }; }
};
FormRadiogroup.style = DigiFormRadiogroupStyle0;

exports.digi_form_radiogroup = FormRadiogroup;
