import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';

const RadioGroup = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.onChange = createEvent(this, "change", 7);
    this.uniqueName = Date.now().toString(36);
    this.name = undefined;
  }
  function(e) {
    e.stopPropagation();
    if (e.target.tagName !== 'TARO-RADIO-CORE')
      return;
    const target = e.target;
    if (target.checked) {
      const childList = this.el.querySelectorAll('taro-radio-core');
      childList.forEach(element => {
        if (element !== target) {
          element.checked = false;
        }
      });
      this.value = e.detail.value;
      this.onChange.emit({
        value: this.value
      });
    }
  }
  componentDidLoad() {
    const childList = this.el.querySelectorAll('taro-radio-core');
    childList.forEach((element) => {
      element.setAttribute('name', this.name || this.uniqueName);
    });
    Object.defineProperty(this.el, 'value', {
      get: () => {
        if (!this.value) {
          const childList = this.el.querySelectorAll('taro-radio-core');
          this.value = this.getValues(childList);
        }
        return this.value;
      },
      configurable: true
    });
  }
  getValues(childList) {
    let val = '';
    Array.from(childList)
      .forEach(element => {
      const checkbox = element.querySelector('input');
      if (checkbox === null || checkbox === void 0 ? void 0 : checkbox.checked) {
        val = checkbox.value || '';
      }
    });
    return val;
  }
  render() {
    return (h(Host, { class: 'weui-cells_radiogroup' }));
  }
  get el() { return this; }
}, [0, "taro-radio-group-core", {
    "name": [8]
  }, [[0, "radiochange", "function"]]]);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["taro-radio-group-core"];
  components.forEach(tagName => { switch (tagName) {
    case "taro-radio-group-core":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, RadioGroup);
      }
      break;
  } });
}

const TaroRadioGroupCore = RadioGroup;
const defineCustomElement = defineCustomElement$1;

export { TaroRadioGroupCore, defineCustomElement };

//# sourceMappingURL=taro-radio-group-core.js.map