{%- comment -%}
  One configurator option card (radio/checkbox row), extracted from
  bs-product-configurator.liquid so the strap tree can render cards in two
  passes (straps row, then the Halo add-on) without duplicating this block.

  Accepts: variant (the model variant owning the group templates), av (the
  addon variant), gkey, input_type, checked, disabled, ephemeral (booleans),
  wide (halo add-on: spans the tree's full width), index (fine-print sup).

  Card anatomy follows the landing configurator (home.html .bsx-card): visible
  check indicator top-left, thumb, title + description + callout chip, price
  right. Store deltas: Roman 400 only, store tokens, 18/24 type.

  Callout chip: addon.callout metafield; violet accent via addon.callout_accent.
  Both are data now — the old title-keyed fallback maps were ported into the
  variants' metafields (Aug 2026) and removed from here.
{%- endcomment -%}

{%- liquid
  comment
    Sold out is not the same as `disabled`. Disabled means the data says this
    was never a choice here (the ephemeral Soft Strap, the cushion the Halo
    forces on you) — the card stays quiet and the configurator owns it. Sold out
    means inventory ran out on an option that IS a choice, so it has to say so
    rather than just fade, and it can never be the one that ships checked: the
    metaobject's checked list is stale the moment stock hits zero, and a checked
    sold-out option would price a bundle the cart then refuses.
  endcomment
  assign soldout = false
  if av.available == false
    assign soldout = true
    assign checked = false
  endif
  assign soldout_label = shop.metaobjects.product_misc.live.sold_out | default: 'Sold out'

  assign card_title = av.title
  if title_override != blank
    assign card_title = title_override
  endif

  assign card_img = av.image
  if card_img == blank and img_override != blank
    assign card_img = img_override
  endif

  assign card_desc = av.metafields.addon.description.value

  assign callout = av.metafields.addon.callout.value
  assign accent = false
  if av.metafields.addon.callout_accent.value == true
    assign accent = true
  endif

  comment
    The chip and the price slot are different columns of the same row, so when
    they carry the same word the card just says it twice — which is what the
    Soft Strap did: chip "Included", price "Included", and the pair read out
    back to back in the accessible name. The chip is the one that gives way; the
    price column is the card's fixed anatomy and every other row fills it.
    Compared rather than special-cased on the title, so a localized pair
    ("Inclus" / "Inclus") collapses the same way.
  endcomment
  assign ptext = av.metafields.addon.price_text.value | first
  if callout != blank and ptext != blank
    assign callout_probe = callout | downcase | strip
    assign ptext_probe = ptext | downcase | strip
    if callout_probe == ptext_probe
      assign callout = blank
    endif
  endif
-%}

{%- comment -%} store.selector_class = the admin's per-variant styling hook
  (the VRChat band is data value "bs2e-vrc"); bs-product.css keys off the
  data-style value, same contract as the model picker's cards. {%- endcomment -%}
<div class="bsp-opt{% if wide %} bsp-opt--wide{% endif %}{% if soldout %} bsp-opt--soldout{% endif %}{% if checked and disabled %} bsp-opt--locked{% endif %}"{% if av.metafields.store.selector_class.value != blank %} data-style="{{ av.metafields.store.selector_class.value | strip | escape }}"{% endif %}>
  <input type="{{ input_type }}" name="bsp-addon-{{ gkey | escape }}" id="bsp-a-{{ variant.id }}-{{ av.id }}"
    value="{{ av.id }}" data-cents="{{ av.price }}" data-title="{{ card_title | escape }}" data-sku="{{ av.sku | escape }}"
    data-ship-date="{{ av.metafields.store.ship_date.value }}"
    {%- capture _eta_msg -%}{% render 'bs-eta-msg', variant: av %}{%- endcapture -%}
    data-ship-msg="{{ _eta_msg | strip | escape }}"
    data-eta-parts="{% for _pp in av.metafields.store.eta_text.value %}{{ _pp.system.handle }}{% unless forloop.last %},{% endunless %}{% endfor %}"
    {% if av.metafields.addon.ships_separately.value %}data-ships-separately="1"{% endif %}
    {% if ephemeral %}data-ephemeral="1"{% endif %}
    {% if soldout %}data-soldout="1"{% endif %}
    {% if checked %}checked{% endif %} {% if disabled or soldout %}disabled{% endif %}>
  <label for="bsp-a-{{ variant.id }}-{{ av.id }}">
    <span class="bsp-opt-check" aria-hidden="true"></span>
    {%- if card_img != blank -%}
      <span class="bsp-opt-thumb"><img src="{{ card_img | image_url: width: 160 }}" alt="" loading="lazy"></span>
    {%- endif -%}
    <span class="bsp-opt-body">
      <span class="bsp-opt-title">{{ card_title }}{% if av.metafields.addon.fine_print.value != blank %}<sup>{{ index }}</sup>{% endif %}</span>
      {%- if card_desc != blank -%}
        <span class="bsp-opt-sub">{{ card_desc }}</span>
      {%- endif -%}
      {%- if callout != blank -%}
        <span class="bsp-opt-chip{% if accent %} bsp-opt-chip--accent{% endif %}">{{ callout }}</span>
      {%- endif -%}
    </span>
    {%- comment -%} ptext is resolved in the liquid block above — the chip needs
    to see it before it decides whether to render {%- endcomment -%}
    {%- comment -%} data-original carries the sold-out word too: the halo/cushion
    interlock restores a card's price from it, and restoring a price onto a card
    that cannot be bought would undo the only thing saying so. {%- endcomment -%}
    {%- if soldout -%}
      <span class="bsp-opt-price bsp-opt-price--soldout" data-price data-original="{{ soldout_label | escape }}">{{ soldout_label }}</span>
    {%- elsif ptext != blank -%}
      <span class="bsp-opt-price bsp-opt-price--included" data-price data-original="{{ ptext | escape }}">{{ ptext }}</span>
    {%- else -%}
      <span class="bsp-opt-price" data-price data-original="+ {{ av.price | money_with_currency }}">+ {{ av.price | money_with_currency }}</span>
    {%- endif -%}
  </label>
</div>
