/** Shopify CDN: Minification failed

Line 16:0 Unexpected "{"
Line 16:1 Expected identifier but found "%"
Line 16:38 Expected identifier but found "%"
Line 18:0 Unexpected "{"
Line 18:1 Expected identifier but found "%"
Line 20:0 Unexpected "{"
Line 20:1 Expected identifier but found "%"
Line 24:2 Unexpected "{"
Line 24:3 Expected identifier but found "%"
Line 26:0 Unexpected "{"
... and 13 more hidden warnings

**/
{% comment %} Pre-order button logic {% endcomment %}

{% assign current_variant = product.selected_or_first_available_variant %}

{% if current_variant.inventory_management == 'shopify' 
  and current_variant.inventory_policy == 'continue' 
  and current_variant.inventory_quantity <= 0 %}

  {% assign is_preorder = true %}

{% else %}

  {% assign is_preorder = false %}

{% endif %}

<div class="preorder-wrapper">
  {% if is_preorder %}
    <button
      type="submit"
      name="add"
      class="btn product-form__cart-submit"
      data-preorder="true"
    >
      Pre-order
    </button>
    <p class="preorder-message" style="margin-top: 8px; font-size: 0.875em; color: #555;">
      This item is available for pre-order and will ship once in stock.
    </p>
  {% else %}
    <button
      type="submit"
      name="add"
      class="btn product-form__cart-submit"
    >
      Add to cart
    </button>
  {% endif %}
</div>

<script>
  // Re-evaluate on variant change
  document.addEventListener('variant:change', function(event) {
    var variant = event.detail.variant;
    var wrapper = document.querySelector('.preorder-wrapper button');
    var message = document.querySelector('.preorder-message');

    if (!variant) return;

    if (
      variant.inventory_management === 'shopify' &&
      variant.inventory_policy === 'continue' &&
      variant.inventory_quantity <= 0
    ) {
      if (wrapper) wrapper.textContent = 'Pre-order';
      if (message) message.style.display = 'block';
    } else {
      if (wrapper) wrapper.textContent = 'Add to cart';
      if (message) message.style.display = 'none';
    }
  });
</script>
