import { h, Host } from "@stencil/core";
import { FormGroupClass, FormGroupOrientation, FormGroupSizes, FormRadioGroupClass } from "./constants";
import { govHost } from "../../../helpers/Dom/template";
import { validateProp } from "../../../helpers/Validate/props";
import { tick } from "../../../utils/stencil.utils";
export class GovFormRadioGroup {
    constructor() {
        /**
         * Gap's size.
         */
        this.gap = undefined;
        /**
         * Elements orientation
         */
        this.orientation = 'vertical';
        /**
         * Group's value
         */
        this.value = undefined;
        this.handleChange = (event) => {
            event.stopPropagation();
            this.value = event.detail.value;
            this.govChange.emit({
                value: this.value,
                component: FormRadioGroupClass.root,
            });
        };
        this.h = govHost(this.host);
    }
    validateGap(newValue) {
        if (newValue) {
            validateProp(FormGroupSizes, newValue, FormGroupClass.root);
        }
    }
    validateOrientation(newValue) {
        if (newValue) {
            validateProp(FormGroupOrientation, newValue, FormGroupClass.root);
        }
    }
    componentWillLoad() {
        this.validateGap(this.gap);
        this.validateOrientation(this.orientation);
    }
    componentDidRender() {
        tick(() => this.rerenderComponent());
    }
    rerenderComponent() {
        this.host.querySelectorAll('gov-form-radio').forEach((element) => {
            if (!element.hasAttribute('listener-attached')) {
                element.addEventListener('gov-change', this.handleChange);
            }
            element.setAttribute('listener-attached', 'true');
            element.checked = element.value === this.value;
        });
    }
    render() {
        return (h(Host, { key: 'ff3703e838e4b031b4826be5e54679bf64872eb4', gap: this.gap, class: this.h.classes(FormGroupClass.root), value: this.value }, h("slot", { key: 'a2536dadd509602565fd860ebc6d9c4a148b468c' })));
    }
    static get is() { return "gov-form-radio-group"; }
    static get originalStyleUrls() {
        return {
            "$": ["gov-form-group.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["gov-form-group.css"]
        };
    }
    static get properties() {
        return {
            "gap": {
                "type": "string",
                "attribute": "gap",
                "mutable": false,
                "complexType": {
                    "original": "FormGroupSizesType",
                    "resolved": "\"2xl\" | \"l\" | \"m\" | \"s\" | \"xs\"",
                    "references": {
                        "FormGroupSizesType": {
                            "location": "import",
                            "path": "./constants",
                            "id": "../../../packages/core/src/components/gov-form/group/constants.ts::FormGroupSizesType"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Gap's size."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "undefined"
            },
            "orientation": {
                "type": "string",
                "attribute": "orientation",
                "mutable": false,
                "complexType": {
                    "original": "FormGroupOrientationType",
                    "resolved": "\"horizontal\" | \"vertical\"",
                    "references": {
                        "FormGroupOrientationType": {
                            "location": "import",
                            "path": "./constants",
                            "id": "../../../packages/core/src/components/gov-form/group/constants.ts::FormGroupOrientationType"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Elements orientation"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'vertical'"
            },
            "value": {
                "type": "string",
                "attribute": "value",
                "mutable": true,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Group's value"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "undefined"
            }
        };
    }
    static get events() {
        return [{
                "method": "govChange",
                "name": "gov-change",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Emitted when the checkbox change value."
                },
                "complexType": {
                    "original": "FormRadioGroupEvent",
                    "resolved": "FormRadioGroupEvent",
                    "references": {
                        "FormRadioGroupEvent": {
                            "location": "import",
                            "path": "./gov-form-group.types",
                            "id": "../../../packages/core/src/components/gov-form/group/gov-form-group.types.ts::FormRadioGroupEvent"
                        }
                    }
                }
            }];
    }
    static get elementRef() { return "host"; }
    static get watchers() {
        return [{
                "propName": "gap",
                "methodName": "validateGap"
            }, {
                "propName": "orientation",
                "methodName": "validateOrientation"
            }];
    }
}
//# sourceMappingURL=gov-form-radio-group.js.map
