/** Shopify CDN: Minification failed

Line 9:0 Unexpected "<"
Line 41:35 Comments in CSS use "/* ... */" instead of "//"
Line 75:29 Comments in CSS use "/* ... */" instead of "//"
Line 102:0 Unexpected "<"

**/
<script>
  document.addEventListener("DOMContentLoaded", function () {
    function rebindQuantityButtons() {
      document.querySelectorAll('.quantity__button').forEach(button => {
        button.addEventListener('click', event => {
          const input = button.closest('.quantity').querySelector('input');
          const currentValue = parseInt(input.value, 10);
          const step = parseInt(input.step) || 1;
          if (button.name === 'plus') {
            input.value = currentValue + step;
          } else if (button.name === 'minus' && currentValue > 0) {
            input.value = currentValue - step;
          }
          input.dispatchEvent(new Event('change'));
        });
      });
    }

    function updateCartSections() {
      const sections = ['main-cart', 'main-cart-footer'];
      const url = `${window.location.pathname}?sections=${sections.join(',')}`;
      return fetch(url)
        .then(response => response.text())
        .then(html => {
          const parser = new DOMParser().parseFromString(html, 'text/html');
          sections.forEach(id => {
            const newSection = parser.getElementById(id);
            const currentSection = document.getElementById(id);
            if (newSection && currentSection) {
              currentSection.innerHTML = newSection.innerHTML;
            }
          });
          rebindQuantityButtons(); // Rebind after update
        });
    }

    const quantityInputs = document.querySelectorAll("input[name='updates[]']");
    quantityInputs.forEach(input => {
      input.addEventListener("change", async function (e) {
        const newQuantity = parseInt(e.target.value);
        const line = parseInt(e.target.dataset.index);
        if (isNaN(newQuantity) || newQuantity < 0) return;

        try {
          const res = await fetch('/cart/change.js', {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json'
            },
            body: JSON.stringify({
              line: line,
              quantity: newQuantity
            })
          });

          if (res.ok) {
            await updateCartSections();
          } else {
            alert('Cart update failed.');
          }
        } catch (err) {
          console.error('Cart update error:', err);
        }
      });
    });

    rebindQuantityButtons(); // Bind once on initial load
  });

 /* ========================================== */
/* FIX: Dropdown Menu Behind Banner           */
/* DATE: 2025-07-23                           */
/* PURPOSE: Ensures header dropdown appears   */
/*          above banners and hero sections   */
/* ========================================== */

.header__menu-item {
  position: relative;
  z-index: 9999;
}

.header__menu-item details,
.header__menu-item summary {
  position: relative;
  z-index: 9999;
}

.header__submenu {
  position: absolute;
  z-index: 10000;
}
    

</script>
