/** Shopify CDN: Minification failed

Line 16:0 Unexpected "{"
Line 16:1 Expected identifier but found "%"
Line 17:6 Unexpected "2"
Line 19:5 Expected identifier but found "%"
Line 21:21 Unexpected "="
Line 21:89 Unterminated string token
Line 24:1 Expected identifier but found "%"
Line 25:0 Unexpected "{"
Line 25:1 Expected identifier but found "%"
Line 25:26 Unexpected "{"
... and 43 more hidden warnings

**/
{%- comment -%}
  Buy 2 promo: quantity picker (1 pair / 2 pairs) above the Add to cart button.
  Rendered from the 'buy2_picker' product block:
    {% render 'buy2-picker', product: product, block: block, form_id: form_id, current_variant: current_variant %}

  The radios use name="quantity" and form="{{ form_id }}", so the theme's own add-to-cart
  (theme.utils.serialize reads form.elements) submits the chosen quantity. Nothing else to wire up.
  The discount itself comes from the automatic discount in Shopify admin, not from this code.
{%- endcomment -%}
{%- capture buy2_check -%}{%- render 'buy2-eligible', product: product -%}{%- endcapture -%}
{%- if buy2_check contains 'yes' and product.available -%}
  {%- liquid
    assign b2_pct = settings.buy2_percent | default: 15
    assign b2_min = settings.buy2_min_qty | default: 2
    assign b2_factor = 100 | minus: b2_pct
    assign v = current_variant | default: product.selected_or_first_available_variant
    assign each_cents = v.price | times: b2_factor | divided_by: 100.0 | round
    assign total_cents = v.price | times: b2_min | times: b2_factor | divided_by: 100.0 | round
  -%}
  <style>
    /* Price + reviews on one line, pill underneath (eligible products only) */
    .product-block--price{display:inline-block!important;vertical-align:top!important;position:relative;margin-right:12px!important;padding-bottom:36px}
    .product-block--price .buy2-pill{position:absolute;left:0;bottom:0;margin:0!important}
    .product-info__rating{display:inline-block!important;vertical-align:top!important;margin:4px 0 0!important}
  </style>
  <div class="product-block buy2-picker" data-buy2-picker data-percent="{{ b2_pct }}" data-min="{{ b2_min }}" {{ block.shopify_attributes }}>
    <fieldset class="buy2-picker__fieldset">
      <legend class="buy2-picker__legend">Quantity</legend>

      <label class="buy2-card buy2-card--single is-selected" data-buy2-card>
        <input class="buy2-card__input" type="radio" name="quantity" value="1" form="{{ form_id }}" checked>
        <span class="buy2-card__dot" aria-hidden="true"></span>
        <span class="buy2-card__title">1 pair <span class="buy2-card__sale" data-buy2-saleprice{% unless v.compare_at_price > v.price %} hidden{% endunless %}>Sale price</span></span>
        <span class="buy2-card__price">
          <s data-buy2-compare{% unless v.compare_at_price > v.price %} hidden{% endunless %}>{{ v.compare_at_price | money_without_trailing_zeros }}</s><span data-buy2-price>{{ v.price | money_without_trailing_zeros }}</span>
        </span>
      </label>

      <label class="buy2-card buy2-card--multi" data-buy2-card>
        <input class="buy2-card__input" type="radio" name="quantity" value="{{ b2_min }}" form="{{ form_id }}">
        <span class="buy2-card__dot" aria-hidden="true"></span>
        <span class="buy2-card__title">{{ b2_min }} pairs</span>
        <span class="buy2-card__price"><s data-buy2-orig>{{ v.price | money_without_trailing_zeros }}</s><span data-buy2-each>{{ each_cents | money_without_trailing_zeros }}</span> <small>each</small></span>
        <span class="buy2-card__chip">Extra {{ b2_pct }}% off</span>
        <span class="buy2-card__total"><span data-buy2-total>{{ total_cents | money_without_trailing_zeros }}</span> total</span>
        <span class="buy2-card__sub">Mix and match from the {{ settings.buy2_name }} Collection</span>
      </label>
    </fieldset>

    <script>
      (function () {
        var root = document.currentScript.parentNode;
        if (!root || !root.hasAttribute('data-buy2-picker')) return;
        var pct = parseFloat(root.getAttribute('data-percent')) || 15;
        var min = parseInt(root.getAttribute('data-min'), 10) || 2;
        var cards = root.querySelectorAll('[data-buy2-card]');

        root.addEventListener('change', function () {
          Array.prototype.forEach.call(cards, function (card) {
            card.classList.toggle('is-selected', card.querySelector('input').checked);
          });
        });

        function fmt(cents) {
          var out = (window.theme && theme.Currency && theme.settings)
            ? theme.Currency.formatMoney(cents, theme.settings.moneyFormat)
            : '$' + (cents / 100).toFixed(2);
          return out.replace(/\.00(?!\d)/, '');
        }
        function setText(sel, text) {
          var el = root.querySelector(sel);
          if (el) el.textContent = text;
        }

        document.addEventListener('variant:change', function (e) {
          var v = e.detail && e.detail.variant;
          if (!v) return;
          var each = Math.round(v.price * (100 - pct) / 100);
          var total = Math.round(v.price * min * (100 - pct) / 100);
          setText('[data-buy2-price]', fmt(v.price));
          setText('[data-buy2-orig]', fmt(v.price));
          setText('[data-buy2-each]', fmt(each));
          setText('[data-buy2-total]', fmt(total));
          var cmp = root.querySelector('[data-buy2-compare]');
          if (cmp) {
            if (v.compare_at_price > v.price) { cmp.textContent = fmt(v.compare_at_price); cmp.hidden = false; }
            else { cmp.hidden = true; }
          }
          var sale = root.querySelector('[data-buy2-saleprice]');
          if (sale) sale.hidden = !(v.compare_at_price > v.price);
        });
      })();
    </script>
  </div>
{%- endif -%}