export default class SelectionHeader {
  updateCheckbox() {
    this.updatingValue = true;
    try {
      const value = this.headerCheckStatusGetter();
      this.checkBox.indeterminate = value == undefined;
      this.checkBox.value = value;
    }
    finally {
      this.updatingValue = false;
    }
  }
  init(params) {
    params.context.selectionHeader = this;
    const valueSetter = params.context.headerCheckStatusSetter;
    this.headerCheckStatusGetter = params.context.headerCheckStatusGetter;
    this.element = document.createElement('div');
    this.element.classList.add("ag-header__selection-checkbox");
    this.checkBox = document.createElement('ez-check');
    this.checkBox.style.setProperty("--ez-check--focus--background-color", "transparent");
    this.checkBox.style.setProperty("--ez-check--hover--background-color", "transparent");
    this.element.append(this.checkBox);
    this.updateCheckbox();
    this.element.addEventListener('ezChange', (evt) => {
      if (!this.updatingValue) {
        valueSetter(evt.detail);
      }
    });
  }
  getGui() {
    return this.element;
  }
  destroy() {
    this.element.remove();
    this.element = null;
  }
  refresh(_params) {
    return false;
  }
}
