{% comment %}
Properties:
- product: product
- use_variant: boolean
- price: price
- show_compare_price: boolean
- cart_item: cart item
- for_pattern_usage: boolean
- force_compare_price: price
- hide: boolean
- handle_price_range: boolean
- on_slider: boolean
- display_free: boolean
- cart_item_property_key: string
- cart_item_property_value: string
- single_price: boolean
{% endcomment %}

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

    if price
        assign compare_price = price
    elsif cart_item
        assign price = cart_item.original_line_price
        assign compare_price = price

        if show_compare_price and settings.show_compare_price != 'no' and cart_item.variant.compare_at_price != cart_item.final_line_price
            assign price = cart_item.final_line_price
            assign compare_price = cart_item.variant.compare_at_price | times: cart_item.quantity
        endif
    elsif target
        assign price = target.price
        assign compare_price = target.compare_at_price
    endif
-%}

{%- if for_pattern_usage -%}
    {{- price | money_with_currency -}}
{%- else -%}
    {%- if handle_price_range and cart_item == blank and product != blank and product.price_min != product.price_max -%}
        <span class="price-range">{{ 'product.price_from' | t }} 
    {%- endif -%}

    <span class="price {% if on_slider == true %} price-on-slider {%- endif -%} {% if single_price == true %} single-price {%- endif -%} {% if settings.show_compare_price == 'after' %} price-reverse{%- endif -%} {% if settings.show_compare_price == 'no' %} price-no-compare{%- endif -%} {% if hide %} hide{%- endif -%}">
        {%- capture output_compare_price -%}
            {%- if show_compare_price and price != compare_price and settings.show_compare_price != 'no' and force_compare_price == blank -%}
                {{- compare_price -}}
            {%- elsif force_compare_price != blank -%}
                {{- force_compare_price -}}
            {%- endif -%}
        {%- endcapture -%}

        <s {% if output_compare_price == '0' %} style="display: none;"{% else %}{% if discounted_price_text_color %} style="color: {{discounted_price_text_color  | color_to_hex}};" {% endif %}{% endif %} data-compare-price="{{ output_compare_price | floor }}" >{{ output_compare_price | money_with_currency }}</s> 
        
        <span data-price="{{ price | floor }}">
            {% assign cart_item_property = cart_item.properties[cart_item_property_key] %}
            {% if display_free == true and price == 0 and cart_item_property == cart_item_property_value %}
                {{ 'cart.free' | t }}
            {% else %}
                {{ price | money_with_currency }}
            {% endif %}
        </span>
    </span>

    {%- if handle_price_range and cart_item == blank and product != blank and product.price_min != product.price_max -%}
        </span>
    {%- endif -%}
{%- endif -%}