function setGroupCB(elGroup) {
  const elGroupCB = elGroup.querySelector(".log-group__name input");
  if (!elGroupCB) return;

  var fChecked=true;
  const aelModCB=elGroup.querySelectorAll("input[form='modules']");
  for(var elCB of aelModCB)
    if (!elCB.checked) {
      fChecked=false;
      break;
    }
  elGroupCB.checked=fChecked;
}

function _groupCBClick() {
  const elGroup = this.parentNode.parentNode;
  const aelModCB=elGroup.querySelectorAll("input[form='modules']");
  for(var elCB of aelModCB) elCB.checked=this.checked;
}

function _modCBClick() { setGroupCB(this.parentNode.parentNode); }

window.addEventListener("load", function() {
  const aelGroups=document.getElementsByClassName("module-groups__log-group");

  for(var elGroup of aelGroups) {
    var elGroupCB = elGroup.querySelector(".log-group__name input");
    if (!elGroupCB) continue;
    elGroupCB.addEventListener("click", _groupCBClick);
    setGroupCB(elGroup);
  }

  const aelModCB=document.querySelectorAll("input[form='modules']");
  for(var elCB of aelModCB) elCB.addEventListener("click", _modCBClick);
} );
