import { h, Host } from '@stencil/core';
export class RadioGroup {
    componentDidLoad() {
        const isRadioChecked = this.host.querySelector('materials-radio[checked]');
        this.value = isRadioChecked ? isRadioChecked.value : null;
        this.materialsRadioNodes = Array.from(this.host.querySelectorAll('materials-radio'));
        this.materialsRadioNodes.forEach((radioEl) => {
            radioEl.addEventListener('change', (value) => this.handleEvent(value));
        });
    }
    handleEvent(event) {
        event.stopPropagation();
        this.value = event.detail;
        this.cleanNeighbors(this.value);
        this.change.emit(this.value);
    }
    cleanNeighbors(except) {
        this.materialsRadioNodes.filter(el => !except || el.value !== except).forEach(el => el.checked = false);
    }
    render() {
        return (h(Host, { class: { 'linebreak': this.linebreak } },
            this.label && h("span", null, this.label),
            h("slot", null)));
    }
    static get is() { return "materials-radio-group"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() { return {
        "$": ["radio-group.scss"]
    }; }
    static get styleUrls() { return {
        "$": ["radio-group.css"]
    }; }
    static get properties() { return {
        "name": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "name",
            "reflect": false
        },
        "linebreak": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "linebreak",
            "reflect": false
        },
        "value": {
            "type": "any",
            "mutable": true,
            "complexType": {
                "original": "any",
                "resolved": "any",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "value",
            "reflect": true
        },
        "label": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label",
            "reflect": false
        }
    }; }
    static get events() { return [{
            "method": "change",
            "name": "change",
            "bubbles": true,
            "cancelable": true,
            "composed": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "complexType": {
                "original": "any",
                "resolved": "any",
                "references": {}
            }
        }]; }
    static get elementRef() { return "host"; }
}
