{# ---- Price formatting helpers ---- #}
{% set _sym = {'GBP':'£','EUR':'€','USD':'$'} %}
{% macro price_str(val, raw, cur) -%}
  {%- if raw -%}
    {{ raw }}
  {%- elif val is number -%}
    {{ (_sym.get(cur) or '') ~ ('%.2f'|format(val)) }}
  {%- else -%}
    {{ val or '' }}
  {%- endif -%}
{%- endmacro %}


{% macro set_prices(item, ns) -%}

{% set ns.sp_val = item.special_price or (item.oe_list_price and item.oe_list_price.special) %}
{% set ns.sp_raw = item.special_price_raw or (item.oe_list_price and item.oe_list_price.special_raw) %}
{% set ns.sp_cur = item.special_price_currency or (item.oe_list_price and item.oe_list_price.special_currency) %}

{% set ns.rp_val = item.regular_price or item.rrp or (item.oe_list_price and item.oe_list_price.rrp) %}
{% set ns.rp_raw = item.regular_price_raw or item.rrp_raw or (item.oe_list_price and item.oe_list_price.rrp_raw) %}
{% set ns.rp_cur = item.regular_price_currency or item.rrp_currency or (item.oe_list_price and item.oe_list_price.rrp_currency) %}

{% set ns.case_size_count = (item.case_size_count or 1) %}
{% set ns.rrp = item.rrp_raw[0] ~ "%.2f"|format(item.rrp * (ns.case_size_count)) %}
{% set ns.rrp_raw = item.rrp_raw %}

{%- endmacro %}


{% macro rrp(ns) -%}
  {% if ns.rrp %}
    <div class="text-base md:text-lgtext-stone-400">
      <span>rrp:</span>
      <span>
        {{ ns.rrp }}
      </span>
    </div>
  {% endif %}
{%- endmacro %}


{% macro card_price(item) %}


{# price block unchanged #}
    {% set _sym = {'GBP':'£','EUR':'€','USD':'$'} %}
    {% set sp_val = item.special_price or (item.oe_list_price and item.oe_list_price.special) %}
    {% set sp_raw = item.special_price_raw or (item.oe_list_price and item.oe_list_price.special_raw) %}
    {% set sp_cur = item.special_price_currency or (item.oe_list_price and item.oe_list_price.special_currency) %}
    {% set rp_val = item.regular_price or item.rrp or (item.oe_list_price and item.oe_list_price.rrp) %}
    {% set rp_raw = item.regular_price_raw or item.rrp_raw or (item.oe_list_price and item.oe_list_price.rrp_raw) %}
    {% set rp_cur = item.regular_price_currency or item.rrp_currency or (item.oe_list_price and item.oe_list_price.rrp_currency) %}
    {% set sp_str = sp_raw if sp_raw else ( (_sym.get(sp_cur, '') ~ ('%.2f'|format(sp_val))) if sp_val is number else (sp_val or '')) %}
    {% set rp_str = rp_raw if rp_raw else ( (_sym.get(rp_cur, '') ~ ('%.2f'|format(rp_val))) if rp_val is number else (rp_val or '')) %}
    <div class="mt-1 flex items-baseline gap-2 justify-center">
      {% if sp_val %}
        <div class="text-lg font-semibold text-emerald-700">{{ sp_str }}</div>
        {% if rp_val %}
          <div class="text-sm line-through text-stone-500">{{ rp_str }}</div>
        {% endif %}
      {% elif rp_val %}
        <div class="mt-1 text-lg font-semibold">{{ rp_str }}</div>
      {% endif %}
    </div>
{% endmacro %}
