(function () {
  "use strict";

  var yearEl = document.getElementById("year");
  if (yearEl) yearEl.textContent = new Date().getFullYear();

  // Nav active on scroll
  var sections = document.querySelectorAll("section[id]");
  var navLinks = document.querySelectorAll(".navbar .nav-link[href^='#']");

  function onScroll() {
    var y = window.scrollY + 100;
    sections.forEach(function (sec) {
      var id = sec.getAttribute("id");
      if (!id) return;
      var top = sec.offsetTop;
      var h = sec.offsetHeight;
      if (y >= top && y < top + h) {
        navLinks.forEach(function (a) {
          a.classList.toggle("active", a.getAttribute("href") === "#" + id);
        });
      }
    });
  }

  window.addEventListener("scroll", onScroll, { passive: true });
  onScroll();

  // Form — client-side (replace with your backend)
  var form = document.getElementById("prijava-form");
  if (form) {
    form.addEventListener("submit", function (e) {
      e.preventDefault();
      var btn = form.querySelector('button[type="submit"]');
      var orig = btn.textContent;
      btn.disabled = true;
      btn.textContent = "Šaljemo...";
      setTimeout(function () {
        alert("Hvala! Prijava je primljena. Javićemo vam se uskoro na ostavljeni kontakt.");
        form.reset();
        btn.disabled = false;
        btn.textContent = orig;
      }, 800);
    });
  }
})();
