'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-e1b469cd.js');

const Radio = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.onChange = index.createEvent(this, "radiochange", 7);
    this.handleClick = (e) => {
      e.stopPropagation();
      if (this.disabled)
        return;
      if (!this.checked)
        this.checked = true;
    };
    this.name = undefined;
    this.value = '';
    this.id = undefined;
    this.checked = false;
    this.disabled = false;
    this.nativeProps = {};
    this.isWillLoadCalled = false;
  }
  watchChecked(newVal) {
    if (!this.isWillLoadCalled)
      return;
    newVal && this.onChange.emit({ value: this.value });
  }
  watchId(newVal) {
    if (!this.isWillLoadCalled)
      return;
    if (newVal)
      this.inputEl.setAttribute('id', newVal);
  }
  componentDidRender() {
    this.id && this.el.removeAttribute('id');
  }
  componentWillLoad() {
    this.isWillLoadCalled = true;
  }
  render() {
    const { checked, name, value, disabled, nativeProps } = this;
    return (index.h(index.Host, { className: 'weui-cells_checkbox', onClick: this.handleClick }, index.h("input", Object.assign({ ref: dom => {
        if (!dom)
          return;
        this.inputEl = dom;
        if (this.id)
          dom.setAttribute('id', this.id);
      }, type: 'radio', name: name, value: value, class: 'weui-check', checked: checked, disabled: disabled, onChange: e => e.stopPropagation() }, nativeProps)), index.h("i", { class: 'weui-icon-checked' }), index.h("slot", null)));
  }
  get el() { return index.getElement(this); }
  static get watchers() { return {
    "checked": ["watchChecked"],
    "id": ["watchId"]
  }; }
};

const RadioGroup = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.onChange = index.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 (index.h(index.Host, { class: 'weui-cells_radiogroup' }));
  }
  get el() { return index.getElement(this); }
};

exports.taro_radio_core = Radio;
exports.taro_radio_group_core = RadioGroup;

//# sourceMappingURL=taro-radio-core_2.cjs.entry.js.map