import { r as registerInstance, c as createEvent, h, H as Host, a as getElement } from './index-B2f84Zog.js';
import { m as messageId } from './form-C3xDZBme.js';
import { b as danger } from './index-D4ys0pep.js';

const pdsRadioGroupCss = ".sc-pds-radio-group-h{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;gap:var(--pine-dimension-sm)}.is-invalid.sc-pds-radio-group-h .pds-radio-group__message--error.sc-pds-radio-group{color:var(--pine-color-text-message-danger)}.pds-radio-group__label.sc-pds-radio-group{color:var(--pine-color-text-label);font:var(--pine-typography-heading-6);font-weight:var(--pine-font-weight-medium);letter-spacing:var(--pine-letter-spacing-heading-6)}.pds-radio-group__radios.sc-pds-radio-group{display:-ms-flexbox;display:flex;gap:var(--pds-radio-group-gap, var(--pine-dimension-xs))}.pds-radio-group__radios--row.sc-pds-radio-group{-ms-flex-align:start;align-items:flex-start;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:wrap;flex-wrap:wrap}.pds-radio-group__radios--column.sc-pds-radio-group{-ms-flex-direction:column;flex-direction:column}.pds-radio-group__message.sc-pds-radio-group{color:var(--pine-color-text-message);font:var(--pine-typography-body);width:100%}.pds-radio-group__message--error.sc-pds-radio-group{display:-ms-flexbox;display:flex;gap:var(--pine-dimension-2xs)}.pds-radio-group__message--error.sc-pds-radio-group pds-icon.sc-pds-radio-group{-webkit-margin-before:var(--pine-dimension-050);margin-block-start:var(--pine-dimension-050)}";

const PdsRadioGroup = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.pdsRadioGroupChange = createEvent(this, "pdsRadioGroupChange");
        /**
         * Layout direction for the radio group.
         * @defaultValue column
         */
        this.direction = 'column';
        /**
         * Spacing between radio items. Accepts t-shirt sizes (none, xxs, xs, sm, md, lg, xl, xxl) or core spacing tokens (025, 050, 100, etc.).
         * @defaultValue xs
         */
        this.gap = 'xs';
        /**
         * Determines whether or not the radio group is disabled.
         * @defaultValue false
         */
        this.disabled = false;
        /**
         * Determines whether or not the radio group is invalid.
         * @defaultValue false
         */
        this.invalid = false;
        /**
         * Determines whether or not the radio group is required.
         * @defaultValue false
         */
        this.required = false;
    }
    handlePropsChange() {
        this.updateChildRadios();
    }
    handleRadioChange(event) {
        const target = event.target;
        // Only handle events from radio inputs
        if (target.type !== 'radio') {
            return;
        }
        // Only emit if the radio is being checked (not unchecked)
        if (target.checked) {
            const radioElement = target.closest('pds-radio');
            if (radioElement) {
                this.pdsRadioGroupChange.emit({
                    checked: true,
                    value: radioElement.value,
                    componentId: radioElement.componentId,
                });
            }
        }
    }
    updateChildRadios() {
        const radios = this.el.querySelectorAll('pds-radio');
        radios.forEach((radio) => {
            if (this.name) {
                radio.setAttribute('name', this.name);
            }
            else {
                radio.removeAttribute('name');
            }
            if (this.disabled) {
                radio.setAttribute('disabled', 'true');
            }
            else {
                radio.removeAttribute('disabled');
            }
            if (this.invalid) {
                radio.setAttribute('invalid', 'true');
            }
            else {
                radio.removeAttribute('invalid');
            }
            if (this.required) {
                radio.setAttribute('required', 'true');
            }
            else {
                radio.removeAttribute('required');
            }
        });
    }
    componentWillLoad() {
        // Generate stable group ID once during initialization
        // This ensures DOM stability and accessibility relationships remain consistent across re-renders
        if (this.componentId) {
            this._groupId = this.componentId;
        }
        else {
            // Generate unique ID with fallback for test environments where crypto.randomUUID may not be available
            const uniqueId = typeof crypto !== 'undefined' && crypto.randomUUID
                ? crypto.randomUUID()
                : `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
            this._groupId = `radio-group-${uniqueId}`;
        }
    }
    componentDidLoad() {
        if (!this.name) {
            console.warn('pds-radio-group: name prop is required for proper radio group functionality');
        }
        this.updateChildRadios();
    }
    classNames() {
        const classNames = [];
        if (this.invalid) {
            classNames.push('is-invalid');
        }
        // The host always uses flex-direction: column, so the label stays above.
        // The direction prop now only affects the .pds-radio-group__radios container.
        // No class needed on host for direction.
        return classNames.join(' ');
    }
    getGapValue() {
        // Map t-shirt sizes to dimension tokens
        const gapMap = {
            none: '0',
            xxs: 'var(--pine-dimension-xxs)',
            xs: 'var(--pine-dimension-xs)',
            sm: 'var(--pine-dimension-sm)',
            md: 'var(--pine-dimension-md)',
            lg: 'var(--pine-dimension-lg)',
            xl: 'var(--pine-dimension-xl)',
            xxl: 'var(--pine-dimension-xxl)',
        };
        // If it's a t-shirt size, use the mapped value
        if (gapMap[this.gap]) {
            return gapMap[this.gap];
        }
        // Otherwise, assume it's a dimension token like "100", "200", etc.
        return `var(--pine-dimension-${this.gap})`;
    }
    getAriaDescribedBy() {
        const messageIds = [];
        if (this.errorMessage) {
            messageIds.push(messageId(this._groupId, 'error'));
        }
        if (this.helperMessage) {
            messageIds.push(messageId(this._groupId, 'helper'));
        }
        return messageIds.length > 0 ? messageIds.join(' ') : undefined;
    }
    render() {
        const gapValue = this.getGapValue();
        const ariaDescribedBy = this.getAriaDescribedBy();
        return (h(Host, { key: '53949e8e878887189482a13e0402402b8ee79c46', class: this.classNames(), id: this._groupId, role: "group", "aria-describedby": ariaDescribedBy, style: {
                '--pds-radio-group-gap': gapValue,
            } }, this.groupLabel && (h("div", { key: '9aa547ff0b60d1eb78ab6806c552391c119c6511', class: "pds-radio-group__label" }, this.groupLabel)), h("div", { key: '5bad4f6d4c685eca8a97b574511f21b93bdf4821', class: {
                'pds-radio-group__radios': true,
                'pds-radio-group__radios--row': this.direction === 'row',
                'pds-radio-group__radios--column': this.direction === 'column',
            } }, h("slot", { key: 'ffd76f30b308f124e1df925b2fe354ffb80f59bc', onSlotchange: () => this.updateChildRadios() })), this.helperMessage && (h("div", { key: 'ea8995384b1e1c1e98d01d704bd969a97bfd2b2a', class: "pds-radio-group__message", id: messageId(this._groupId, 'helper') }, this.helperMessage)), this.errorMessage && (h("div", { key: '30726bc368c7ad2820ae4cb43faf0a45e94a51e8', class: "pds-radio-group__message pds-radio-group__message--error", id: messageId(this._groupId, 'error'), "aria-live": "assertive" }, h("pds-icon", { key: 'acc00b6e36ead10cc5cc01033ad0f619bd75f5da', icon: danger, size: "small" }), this.errorMessage))));
    }
    get el() { return getElement(this); }
    static get watchers() { return {
        "name": ["handlePropsChange"],
        "disabled": ["handlePropsChange"],
        "invalid": ["handlePropsChange"],
        "required": ["handlePropsChange"]
    }; }
};
PdsRadioGroup.style = pdsRadioGroupCss;

export { PdsRadioGroup as pds_radio_group };
//# sourceMappingURL=pds-radio-group.entry.js.map
