<script>
  // collapse vulns in remediations
  const remediations = document.querySelectorAll(".js-remediation");
  remediations.forEach((remediation) => {
    remediation.parentElement.classList.toggle("shown");
    remediation.addEventListener("click", remediationClick);
  })

  // hide all panes
  const allPanes = document.querySelectorAll(`[data-pane]`);
  allPanes.forEach((pane) => {
    pane.classList.remove('shown');
  });
  // set first nav item as active & un-hide it's pane
  const remediationNav = document.querySelectorAll(".js-nav");
  remediationNav.forEach((nav) => {
    nav.addEventListener("click", navClick);
  })
  if (remediationNav && remediationNav.length > 0) {
    remediationNav[0].classList.add('active');
    const targetPaneData = remediationNav[0].dataset && remediationNav[0].dataset.toggle;
    if (targetPaneData) {
      showPane(targetPaneData);
    }
  }

  function remediationClick() {
    this.parentElement.classList.toggle("shown");
  }

  function navClick() {
    const remediationNav = document.querySelectorAll(".js-nav");
    remediationNav.forEach((nav) => {
      nav.classList.remove('active');
    });
    this.classList.toggle('active');
    const targetPaneData = this.dataset && this.dataset.toggle;
    if (targetPaneData) {
      showPane(targetPaneData);
    }
  }

  function showPane(targetPaneData) {
    const targetPanes = document.querySelectorAll(`[data-pane='${targetPaneData}']`);
    if (targetPanes) {
      const allPanes = document.querySelectorAll(`[data-pane]`);
      allPanes.forEach((pane) => {
        pane.classList.remove('shown');
      });
      targetPanes[0].classList.add('shown');
    }
  }
</script>
