How to use JavaScript to set tabindex on an anchor tag when a condition exists?

In the snippet below, if an element contains a specific class, then all links inside that element are to be set to tabindex="0", otherwise tabindex="-1".

I’m getting an error – Uncaught TypeError: links.setAttribute is not a function and I’m unsure how to fix this?

const panels = document.querySelectorAll(".panels");

Array.prototype.forEach.call(panels, (panel) => {  
  const links = document.querySelectorAll(".panel p a");
  
  if (panel.classList.contains("active")) {
    links.setAttribute("tabindex", "0");
  } else {
    links.setAttribute("tabindex", "-1");
  }
});
<div class="panels">
  <div class="panel active">
    <p>Hello <a href="#">World</a>. I am <a href="#">with</a> you.</p>
  </div>
  
  <div class="panel">
    <p>Hello <a href="#">World</a>. I am <a href="#">with</a> you.</p>
  </div>  
</div>