{% comment %}
  Renders a list of product's badge (regular, sale)

  Accepts:
  - product: {Object} Product Liquid object (optional)
  - use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing (optional)
  - class: {String} Adds a price class to the price element (optional)

  Usage:
  {% render 'badge-sale',
    product: product,
    use_variant: true,
    class: 'price and more'
  %}
{% endcomment %}

{%- liquid
  if use_variant
    assign target = product.selected_or_first_available_variant
  else
    assign target = product
  endif

  assign compare_at_price = target.compare_at_price
  assign price = target.price | default: 1999
-%}

{% if compare_at_price > price %}
  <div class='xo-badge-sale {{ class }}' id='Badge-{{ section.id }}-{{ product.id }}'>
    {{ 'products.product.on_sale' | t }}
  </div>
{% endif %}
