{% set value_is_set = value is defined and value is not null %}
{% if item.getBehaviorCountStock() == constant("Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE") %}
    {% if value_is_set %}
        {{ _self.badge_stock_start(value) }}
        {{ _self.badge_stock_renewable(item.behaviorStockWeek) }}
        {{ value }} {{ item.getUnit().getUnit() }}
        {{ _self.badge_stock_end() }}
    {% else %}
        {{ _self.no_stock(item.behaviorStockWeek) }}
    {% endif %}
{% elseif item.getBehaviorCountStock() == constant("Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY") %}
    {% if value_is_set %}
        {{ _self.badge_stock_start(value) }}
        {{ _self.badge_stock_renewable(item.behaviorStockWeek) }}
        {{ value }} pièce{% if value > 1 %}s{% endif %}
        {{ _self.badge_stock_end() }}
    {% else %}
        {{ _self.no_stock(item.behaviorStockWeek) }}
    {% endif %}
{% elseif item.getBehaviorCountStock() == constant("Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT") %}
    {% set available_quantity_products = item.getAvailableQuantityInherited() %}
    {% if available_quantity_products > 0 %}
        {{ _self.badge_stock_start(available_quantity_products) }}
        {{ _self.badge_stock_renewable(item.behaviorStockWeek) }}
        {{ available_quantity_products }} pièce{% if available_quantity_products > 1 %}s{% endif %} (déclinaisons)
        {{ _self.badge_stock_end() }}
    {% else %}
        {{ _self.no_stock(item.behaviorStockWeek) }}
    {% endif %}
{% elseif item.getBehaviorCountStock() == constant("Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED") %}
    <span class="badge badge-success">Illimité</span>
{% endif %}

{% macro no_stock(behaviorStockWeek) %}
    <span class="badge badge-danger">
                {{ _self.badge_stock_renewable(behaviorStockWeek) }}
            Pas de stock
    </span>
{% endmacro %}

{% macro badge_stock_renewable(behaviorStockWeek) %}
    {% if behaviorStockWeek == constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_STOCK_WEEK_RENEWABLE') %}
        R
    {% elseif behaviorStockWeek == constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_STOCK_WEEK_RENEWABLE_VALIDATION') %}
        RV
    {% elseif behaviorStockWeek == constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_STOCK_WEEK_NON_RENEWABLE') %}
        NR
    {% endif %}
{% endmacro %}

{% macro badge_stock_start(value) %}
    {% if value > 0 %}
        {% set badge_class = 'badge-success' %}
    {% else %}
        {% set badge_class = 'badge-danger' %}
    {% endif %}
<span class="badge {{ badge_class }}">
{% endmacro %}

    {% macro badge_stock_end() %}
    </span>
{% endmacro %}
