import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-ClISz4NF.js';
import { c as createID } from './string.utils-vN03FcXN.js';
import { v as validateProp } from './props-CJZgTDla.js';
import { g as govForm, e as FormRadioClass, f as FormRadioSizes } from './form-DvhJiKwA.js';
import { g as govHost, a as toBoolAttr, t as toBoolAttrIfDefined } from './template-CoD1xawt.js';
import { F as Fragment } from './Fragment-5itQzbON.js';
import { A as AttributeObserver, a as ariaAttributes } from './attribute-Bz_RzYFb.js';
import { i as inheritAriaAttributes } from './accessibility-wqNV8djF.js';
import './gov.log-BtqD9K8d.js';
import './utils-CQvUntGY.js';
import './sizes-BcQO4NH2.js';
import './constants-BegH8u6i.js';
import './colors-U40vKHrs.js';
import './constants-aqe7GX2n.js';
import './constants-CysDgoMA.js';

const GovFormRadio = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.govFocus = createEvent(this, "gov-focus");
        this.govBlur = createEvent(this, "gov-blur");
        this.govChange = createEvent(this, "gov-change");
        this.hydrated = false;
        /**
         * When you can't use the form label.
         */
        this.noLabel = false;
        /**
         * Radio button state
         */
        this.checked = false;
        /**
         * Set whether the input is required or not. Please note that this is necessary for accessible inputs when the user is required to fill them.
         * When using this property you need to also set “novalidate” attribute to your form element to prevent browser from displaying its own validation errors.
         */
        this.required = false;
        /**
         * Makes the radio component disabled.
         * This prevents users from being able to interact with the radio, and conveys its inactive state to assistive technologies.
         */
        this.disabled = false;
        /**
         * Radio's size.
         */
        this.size = "m";
        this.inheritedAttributes = {};
        this.radioId = createID("GovRadio");
        this.h = govHost(this.host);
        this.f = govForm(this.h);
    }
    validateSize(newValue) {
        validateProp(FormRadioSizes, newValue, FormRadioClass.root);
    }
    watchControlAttrs() {
        this.passControlAttrs();
    }
    passControlAttrs() {
        this.f.passAttrToControl("size", this.size);
        this.f.passAttrToControl("invalid", toBoolAttr(this.invalid));
        this.f.passAttrToControl("disabled", toBoolAttr(this.disabled));
        this.f.passAttrToControl("type", "radio");
    }
    componentWillLoad() {
        this.inheritedAttributes = inheritAriaAttributes(this.host);
    }
    componentDidLoad() {
        this.attributeObserver = new AttributeObserver(this.host, (attributeName, newValue) => {
            this.onAriaAttributeChange(attributeName, newValue);
        });
        this.attributeObserver.startObserving(ariaAttributes);
    }
    async componentDidRender() {
        this.f.passAttrToLabel("identifier", this.identifier || this.radioId);
        this.f.passAttrToLabel("required", String(this.required));
        this.passControlAttrs();
    }
    connectedCallback() {
        this.hydrated = true;
    }
    disconnectedCallback() {
        var _a;
        (_a = this.attributeObserver) === null || _a === void 0 ? void 0 : _a.stopObserving();
    }
    onAriaAttributeChange(attributeName, newValue) {
        this.host.removeAttribute(attributeName);
        this.inheritedAttributes = Object.assign(Object.assign({}, this.inheritedAttributes), { [attributeName]: newValue });
    }
    render() {
        const wrapRadio = (children) => {
            if (this.noLabel) {
                return h("label", { class: FormRadioClass.label }, children);
            }
            return children;
        };
        return (h(Host, { class: FormRadioClass.root, hydrated: this.hydrated, checked: this.checked, size: this.size, invalid: toBoolAttrIfDefined(this.invalid) }, wrapRadio(h(Fragment, null, h("input", Object.assign({ class: FormRadioClass.input, id: this.identifier || this.radioId, type: "radio", value: this.value, name: this.name, checked: this.checked, disabled: this.disabled, onClick: this.onClickHandler.bind(this), onChange: this.onChangeHandler.bind(this), onFocus: this.onFocusHandler.bind(this), onBlur: this.onBlurHandler.bind(this), ref: el => (this.inputRef = el), required: this.required }, this.inheritedAttributes, { "aria-checked": this.checked, "aria-required": toBoolAttrIfDefined(this.required), "aria-invalid": toBoolAttrIfDefined(this.invalid), "aria-disabled": toBoolAttrIfDefined(this.disabled) })), h("span", null, h("slot", { name: "label" }))))));
    }
    onClickHandler(e) {
        e.stopPropagation();
    }
    onFocusHandler(e) {
        e.stopPropagation();
        this.govFocus.emit({
            component: FormRadioClass.root,
            value: this.value,
            checked: this.checked,
            originalEvent: e,
        });
    }
    onBlurHandler(e) {
        e.stopPropagation();
        this.govBlur.emit({
            component: FormRadioClass.root,
            value: this.value,
            checked: this.checked,
            originalEvent: e,
        });
    }
    onChangeHandler(e) {
        this.checked = e.target.checked;
        e.stopPropagation();
        this.govChange.emit({
            component: FormRadioClass.root,
            value: this.value,
            checked: this.checked,
            originalEvent: e,
        });
    }
    /**
     * Returns the reference of the native element
     */
    async getRef() {
        return this.inputRef;
    }
    get host() { return getElement(this); }
    static get watchers() { return {
        "size": ["validateSize", "watchControlAttrs"],
        "disabled": ["watchControlAttrs"],
        "invalid": ["watchControlAttrs"]
    }; }
};

export { GovFormRadio as gov_form_radio };
//# sourceMappingURL=gov-form-radio.entry.js.map

//# sourceMappingURL=gov-form-radio.entry.js.map