/* ============================================================
   FI-NE & LACUEOR — B2B Partner Portal
   Scripts
   ============================================================ */

(function () {
  "use strict";

  /* ── Smooth anchor scroll offset for fixed topbar ────────── */
  document.querySelectorAll('a[href^="#"]').forEach(function (anchor) {
    anchor.addEventListener("click", function (e) {
      var target = document.querySelector(this.getAttribute("href"));
      if (!target) return;
      e.preventDefault();
      var offset = 80;
      var top =
        target.getBoundingClientRect().top +
        window.pageYOffset -
        offset;
      window.scrollTo({ top: top, behavior: "smooth" });
    });
  });

  /* ── Topbar shadow on scroll ─────────────────────────────── */
  var topbar = document.querySelector(".topbar");
  window.addEventListener(
    "scroll",
    function () {
      if (window.scrollY > 20) {
        topbar.style.boxShadow = "0 2px 24px rgba(0,0,0,0.08)";
      } else {
        topbar.style.boxShadow = "none";
      }
    },
    { passive: true }
  );

  /* ── Banner image selector ──────────────────────────────── */
  var bannerPicker = document.getElementById("banner-picker");
  var bannerImg = document.getElementById("brands-banner-img");
  if (bannerPicker && bannerImg) {
    bannerPicker.addEventListener("change", function () {
      var val = this.value;
      bannerImg.style.opacity = "0";
      setTimeout(function () {
        bannerImg.src = "asset/banner/" + val + ".png";
        bannerImg.style.opacity = "1";
      }, 200);
    });
  }
})();
