import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-c948674f.js';

const indexCss = ".taro-checkbox{display:inline-block;position:relative}.taro-checkbox_checked{display:inline-block;position:relative;top:5px;border:1px solid #d1d1d1;border-radius:3px;width:23px;height:23px;min-height:0;-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:0;background-color:#fff;vertical-align:0;font-size:23px;color:#1aad19}.taro-checkbox_checked:checked::before{display:inline-block;position:absolute;left:50%;top:50%;vertical-align:middle;text-decoration:inherit;text-align:center;text-transform:none;font-family:weui;font-style:normal;font-weight:normal;font-variant:normal;font-size:inherit;color:inherit;content:\"\\ea08\";-webkit-transform:translate(-50%, -48%) scale(0.73);transform:translate(-50%, -48%) scale(0.73);speak:none}";

const Checkbox = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.onChange = createEvent(this, "checkboxchange", 7);
    this.handleChange = (e) => {
      e.stopPropagation();
      this.onChange.emit({
        value: this.value
      });
    };
    this.name = undefined;
    this.value = '';
    this.color = undefined;
    this.id = undefined;
    this.checked = false;
    this.disabled = false;
    this.nativeProps = {};
    this.isWillLoadCalled = false;
  }
  watchId(newVal) {
    if (!this.isWillLoadCalled)
      return;
    if (newVal)
      this.inputEl.setAttribute('id', newVal);
  }
  componentWillLoad() {
    this.isWillLoadCalled = true;
  }
  componentDidRender() {
    this.id && this.el.removeAttribute('id');
  }
  render() {
    const { checked, name, color, value, disabled, nativeProps } = this;
    return (h(Host, { className: 'weui-cells_checkbox' }, h("input", Object.assign({ ref: dom => {
        if (!dom)
          return;
        this.inputEl = dom;
        if (this.id)
          dom.setAttribute('id', this.id);
      }, type: 'checkbox', value: value, name: name, class: 'taro-checkbox_checked', style: { color }, checked: checked, disabled: disabled, onChange: this.handleChange }, nativeProps)), h("slot", null)));
  }
  get el() { return getElement(this); }
  static get watchers() { return {
    "id": ["watchId"]
  }; }
};
Checkbox.style = indexCss;

const CheckboxGroup = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.onChange = createEvent(this, "change", 7);
    this.uniqueName = Date.now().toString(36);
    this.name = undefined;
  }
  function(e) {
    e.stopPropagation();
    if (e.target.tagName !== 'TARO-CHECKBOX-CORE')
      return;
    const childList = this.el.querySelectorAll('taro-checkbox-core');
    this.value = this.getValues(childList);
    this.onChange.emit({
      value: this.value
    });
  }
  componentDidLoad() {
    const childList = this.el.querySelectorAll('taro-checkbox-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-checkbox-core');
          this.value = this.getValues(childList);
        }
        return this.value;
      },
      configurable: true
    });
  }
  getValues(childList) {
    return Array.from(childList)
      .filter(element => {
      const checkbox = element.querySelector('input');
      return checkbox === null || checkbox === void 0 ? void 0 : checkbox.checked;
    })
      .map(element => element.value);
  }
  render() {
    return (h(Host, null));
  }
  get el() { return getElement(this); }
};

export { Checkbox as taro_checkbox_core, CheckboxGroup as taro_checkbox_group_core };

//# sourceMappingURL=taro-checkbox-core_2.entry.js.map