document.addEventListener("DOMContentLoaded", () => {
  const rows = document.querySelectorAll(".invoice-row");
  const btn = document.getElementById("creditBtn");
  const form = document.getElementById("creditForm");

  let selectedId = null;

  rows.forEach((row) => {
    row.addEventListener("click", () => {
      // Alte Markierung entfernen
      rows.forEach((r) => r.classList.remove("table-active"));

      // Neue markieren
      row.classList.add("table-active");

      selectedId = row.dataset.id;

      // Button aktivieren
      btn.disabled = false;

      // Ziel setzen
      form.action = `/invoices/${selectedId}/credit`;
    });
  });
});
