text: import { r as registerInstance, d as createEvent, c as getIonMode, f as getElement, h, H as Host } from './chunk-8bad6bbf.js';
  
  class RadioGroup {
      constructor(hostRef) {
          registerInstance(this, hostRef);
          this.inputId = `ion-rg-${radioGroupIds++}`;
          this.labelId = `${this.inputId}-lbl`;
          this.radios = [];
          /**
           * If `true`, the radios can be deselected.
           */
          this.allowEmptySelection = false;
          /**
           * The name of the control, which is submitted with the form data.
           */
          this.name = this.inputId;
          this.ionChange = createEvent(this, "ionChange", 7);
      }
      valueChanged(value) {
          this.updateRadios();
          this.ionChange.emit({ value });
      }
      onRadioDidLoad(ev) {
          const radio = ev.target;
          radio.name = this.name;
          // add radio to internal list
          this.radios.push(radio);
          // this radio-group does not have a value
          // but this radio is checked, so let's set the
          // radio-group's value from the checked radio
          if (this.value == null && radio.checked) {
              this.value = radio.value;
          }
          else {
              this.updateRadios();
          }
      }
      onRadioDidUnload(ev) {
          const index = this.radios.indexOf(ev.target);
          if (index > -1) {
              this.radios.splice(index, 1);
          }
      }
      onRadioSelect(ev) {
          const selectedRadio = ev.target;
          if (selectedRadio) {
              this.value = selectedRadio.value;
          }
      }
      onRadioDeselect(ev) {
          if (this.allowEmptySelection) {
              const selectedRadio = ev.target;
              if (selectedRadio) {
                  selectedRadio.checked = false;
                  this.value = undefined;
              }
          }
      }
      componentDidLoad() {
          // Get the list header if it exists and set the id
          // this is used to set aria-labelledby
          let header = this.el.querySelector('ion-list-header');
          if (!header) {
              header = this.el.querySelector('ion-item-divider');
          }
          if (header) {
              const label = header.querySelector('ion-label');
              if (label) {
                  this.labelId = label.id = this.name + '-lbl';
              }
          }
          this.updateRadios();
      }
      updateRadios() {
          const value = this.value;
          let hasChecked = false;
          for (const radio of this.radios) {
              if (!hasChecked && radio.value === value) {
                  // correct value for this radio
                  // but this radio isn't checked yet
                  // and we haven't found a checked yet
                  hasChecked = true;
                  radio.checked = true;
              }
              else {
                  // this radio doesn't have the correct value
                  // or the radio group has been already checked
                  radio.checked = false;
              }
          }
      }
      hostData() {
          const mode = getIonMode(this);
          return {
              'role': 'radiogroup',
              'aria-labelledby': this.labelId,
              class: {
                  [`${mode}`]: true,
              }
          };
      }
      get el() { return getElement(this); }
      static get watchers() { return {
          "value": ["valueChanged"]
      }; }
      render() { return h(Host, this.hostData()); }
  }
  let radioGroupIds = 0;
  
  export { RadioGroup as ion_radio_group };
  