'use strict';

var index = require('./index-n_pDKBY2.js');
var frameworkDetection = require('./framework-detection-C_6nNXcS.js');
var domUtils = require('./dom-utils-dykhxr-_.js');

const radioButtonCss = ":root{--ifx-font-family:\"Source Sans 3\", 'Arial, sans-serif'}:host{display:inline-flex;--_ifx-fallback-display:none !important}._ifx-radiobutton-fallback{display:var(--_ifx-fallback-display);position:absolute !important;width:1px !important;height:1px !important;padding:0 !important;margin:-1px !important;overflow:hidden !important;clip:rect(0, 0, 0, 0) !important;border:0 !important}.radioButton__container{box-sizing:border-box;display:inline-flex;flex-direction:row;align-items:center;padding:0px;gap:8px;cursor:pointer;font-family:var(--ifx-font-family);outline:none}.radioButton__container.disabled{cursor:default}.radioButton__container.disabled .radioButton__wrapper{background-color:#BFBBBB;border-color:#BFBBBB}.radioButton__container.disabled .radioButton__wrapper:hover{background-color:#BFBBBB}.radioButton__container.disabled .radioButton__wrapper.checked{background-color:#FFFFFF;border-color:#BFBBBB}.radioButton__container.disabled .radioButton__wrapper.checked::after{background-color:#BFBBBB}.radioButton__container.disabled .radioButton__wrapper.checked .radioButton__wrapper-mark{background-color:#BFBBBB}.radioButton__container.disabled .radioButton__wrapper.checked:hover{border-color:#BFBBBB}.radioButton__container.disabled .radioButton__wrapper.checked:hover .radioButton__wrapper-mark{background-color:#BFBBBB}.radioButton__container.disabled .label{color:#BFBBBB}.radioButton__container:not(.disabled) .radioButton__wrapper.error{border-color:#CD002F}.radioButton__container:not(.disabled) .radioButton__wrapper.error:hover,.radioButton__container:not(.disabled) .radioButton__wrapper.error:focus-visible{border-color:#CD002F}.radioButton__container:not(.disabled) .radioButton__wrapper.error.checked::after{border-color:#CD002F;background-color:#CD002F}.radioButton__container:focus:not(.disabled) .radioButton__wrapper::before{content:\"\";position:absolute;width:calc(100% + 4px);height:calc(100% + 4px);top:50%;left:50%;transform:translate(-50%, -50%);border:2px solid #0A8276;border-radius:50%}.radioButton__container.m .radioButton__wrapper{width:24px;height:24px}.radioButton__container .radioButton__wrapper{width:20px;height:20px;position:relative;display:block;border-radius:50%;background-color:#FFFFFF;border:1px solid #575352}.radioButton__container .radioButton__wrapper .radioButton__wrapper-mark{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);background-color:#0A8276;border-radius:50%;display:flex;justify-content:center;align-items:center;border-color:transparent}.radioButton__container .radioButton__wrapper:hover{background-color:#EEEDED}.radioButton__container .radioButton__wrapper.checked{border-color:#0A8276}.radioButton__container .radioButton__wrapper.checked::after{content:\"\";position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);width:10px;height:10px;background-color:#0A8276;border-radius:50%}.radioButton__container .radioButton__wrapper.checked:hover{border-color:#08665C}.radioButton__container .radioButton__wrapper.checked:hover .radioButton__wrapper-mark{background-color:#08665C}.radioButton__container .label{display:flex;align-items:center;height:20px;font-style:normal;font-weight:400;font-size:0.875rem;line-height:1.25rem;color:#1D1D1D;flex:none;order:1;flex-grow:0}.radioButton__container .label.label-m{height:24px;font-size:1rem;line-height:1.5rem}";

const RadioButton = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.ifxChange = index.createEvent(this, "ifxChange", 7);
        this.ifxError = index.createEvent(this, "ifxError", 7);
        this.disabled = false;
        this.error = false;
        this.size = "s";
        this.internalChecked = false;
        this.hasSlot = false;
    }
    async isChecked() {
        return this.internalChecked;
    }
    componentWillLoad() {
        // Fallback for form association
        this.fallbackInput = document.createElement('input');
        this.fallbackInput.type = 'radio';
        this.fallbackInput.hidden = true;
        this.fallbackInput.className = '_ifx-radiobutton-fallback';
        this.fallbackInput.style.cssText = `
      display: none !important;
      position: absolute !important;
      opacity: 0 !important;
      pointer-events: none !important;
      width: 0 !important;
      height: 0 !important;
    `;
        this.fallbackInput.setAttribute('aria-hidden', 'true');
        this.fallbackInput.tabIndex = -1;
        this.el.appendChild(this.fallbackInput);
        // Initial state
        this.internalChecked = this.checked || false;
        this.hasSlot = !!this.el.querySelector('[slot]') || this.el.innerHTML.trim() !== '';
    }
    async componentDidLoad() {
        if (!domUtils.isNestedInIfxComponent(this.el)) {
            const framework = frameworkDetection.detectFramework();
            frameworkDetection.trackComponent('ifx-radio-button', await framework);
        }
    }
    handleCheckedChange(newValue) {
        this.internalChecked = newValue;
    }
    updateFormValue() {
        // Update both ElementInternals and fallback input
        // if (this.internals?.setFormValue) {
        //   this.internals.setFormValue(this.internalChecked ? this.value : null);
        // }
        this.fallbackInput.checked = this.internalChecked;
        this.fallbackInput.name = this.name;
        this.fallbackInput.value = this.value;
        this.fallbackInput.disabled = this.disabled;
    }
    errorChanged(newValue, oldValue) {
        if (newValue !== oldValue) {
            this.ifxError.emit(newValue);
        }
    }
    handleRadioButtonClick(event) {
        if (this.disabled) {
            event.stopPropagation();
            return;
        }
        this.inputElement.click();
        this.internalChecked = this.inputElement.checked;
        this.checked = this.internalChecked;
        this.ifxChange.emit(this.internalChecked);
        const changeEvent = new CustomEvent('change', {
            bubbles: true,
            composed: true,
            detail: { checked: this.internalChecked }
        });
        this.el.dispatchEvent(changeEvent);
    }
    handleKeyDown(ev) {
        if ([' ', 'Enter'].includes(ev.key)) {
            ev.preventDefault();
            this.handleRadioButtonClick(new PointerEvent('click'));
        }
    }
    handleExternalChange(event) {
        const target = event.target;
        if (target === this.el || target.tagName.toLowerCase() !== 'ifx-radio-button')
            return;
        if (target.getAttribute('name') === this.name) {
            this.internalChecked = false;
        }
    }
    render() {
        return (index.h("div", { key: 'cfacddd9fcb1feebcf926fb2a7e441e56e511759', role: "radio", "aria-checked": String(this.internalChecked), "aria-disabled": String(this.disabled), class: `radioButton__container ${this.size} ${this.disabled ? 'disabled' : ''}`, onClick: (e) => this.handleRadioButtonClick(e), tabindex: this.disabled ? -1 : 0 }, index.h("div", { key: 'badf42cd6e21d2a2b647da3d1cd29c403590ef26', class: `radioButton__wrapper 
            ${this.internalChecked ? 'checked' : ''}  
            ${this.error ? 'error' : ''}` }, this.internalChecked && index.h("div", { key: '950b1c9cd2fdaebe227da8d22147f6680652672f', class: "radioButton__wrapper-mark" })), this.hasSlot && (index.h("div", { key: '86c20225f259e41f6d55299e91f9cbd3616df8d9', class: `label ${this.size === "m" ? "label-m" : ""}` }, index.h("slot", { key: '346d7d0732bf33d9363a717e99453b3b32332a11' }))), index.h("input", { key: '3bddb087935626e217325a290de6ec0444d2b2b2', type: "radio", hidden: true, ref: el => this.inputElement = el, name: this.name, value: this.value, checked: this.internalChecked, disabled: this.disabled, onClick: (e) => e.stopPropagation() })));
    }
    get el() { return index.getElement(this); }
    static get watchers() { return {
        "checked": ["handleCheckedChange"],
        "internalChecked": ["updateFormValue"],
        "error": ["errorChanged"]
    }; }
};
RadioButton.style = radioButtonCss;

exports.ifx_radio_button = RadioButton;
//# sourceMappingURL=ifx-radio-button.entry.cjs.js.map

//# sourceMappingURL=ifx-radio-button.cjs.entry.js.map