/** Shopify CDN: Minification failed

Line 15:9 Expected identifier but found "addEventListener("
Line 18:4 Comments in CSS use "/* ... */" instead of "//"
Line 26:4 Comments in CSS use "/* ... */" instead of "//"
Line 42:2 Comments in CSS use "/* ... */" instead of "//"
Line 45:4 Comments in CSS use "/* ... */" instead of "//"
Line 74:6 Comments in CSS use "/* ... */" instead of "//"
Line 74:70 Unterminated string token
Line 75:6 Comments in CSS use "/* ... */" instead of "//"
Line 79:2 Comments in CSS use "/* ... */" instead of "//"
Line 103:6 Comments in CSS use "/* ... */" instead of "//"

**/
document.addEventListener('DOMContentLoaded', () => {
  const cartForm = document.querySelector('form[action="/cart"]');
  if (cartForm) {
    // Auto submit updates on quantity input change
    cartForm.addEventListener('change', event => {
      const tgt = event.target;
      if (tgt && tgt.matches('input[name^="updates"]')) {
        cartForm.submit();
      }
    });

    // Remove item buttons
    cartForm.querySelectorAll('button.cart-remove').forEach(button => {
      button.addEventListener('click', e => {
        e.preventDefault();
        const name = button.getAttribute('name');
        const value = button.getAttribute('value');
        const hidden = document.createElement('input');
        hidden.type = 'hidden';
        hidden.name = name;
        hidden.value = value;
        cartForm.appendChild(hidden);
        cartForm.submit();
      });
    });
  }

  // In cart‑drawer context (if using an AJAX drawer)
  const drawer = document.querySelector('.cart-drawer');
  if (drawer) {
    // Suppose your drawer has close button, remove, etc
    drawer.querySelectorAll('button.cart-remove').forEach(button => {
      button.addEventListener('click', e => {
        e.preventDefault();
        const variantId = button.dataset.variantId;
        updateDrawerLine(variantId, 0);
      });
    });

    drawer.querySelectorAll('input.quantity-input').forEach(input => {
      input.addEventListener('change', () => {
        const variantId = input.dataset.variantId;
        updateDrawerLine(variantId, input.value);
      });
    });

    function updateDrawerLine(variantId, qty) {
      fetch(`/cart/change.js`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ id: variantId, quantity: qty })
      })
      .then(r => r.json())
      .then(cart => {
        renderDrawer(cart);
      });
    }

    function renderDrawer(cart) {
      // A minimal re-render — you'll need to map cart object to DOM
      // e.g. update subtotal, update line items, etc.
    }
  }

  // Cart notification behavior (if you use it after adding from product page)
  const notif = document.querySelector('.cart-notification');
  if (notif) {
    notif.querySelectorAll('button.cart-remove').forEach(button => {
      button.addEventListener('click', e => {
        e.preventDefault();
        const variantId = button.dataset.variantId;
        updateNotificationLine(variantId, 0);
      });
    });

    function updateNotificationLine(variantId, qty) {
      fetch(`/cart/change.js`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ id: variantId, quantity: qty })
      })
      .then(r => r.json())
      .then(cart => {
        renderNotification(cart);
      });
    }

    function renderNotification(cart) {
      // Re-render the notification with updated info
    }
  }
});
