{% block component_product_table_container %}
{% set variants = page.product.customFields.variants %}
{% set ruleId = page.product.cheapestPrice.ruleId %}
{% set staplelength = product.calculatedPrices.elements|length - 1 %}
{% if variants|length > 0 %}
{% if page.product.calculatedPrices|length > 1 %}
{% set bestprice = false %}
{% for variant in variants|filter((variant) => variant.availableStock == true) %}
{% if variant.customFields.custom_units_piece_per_pu != 1 %}
{% set bestprice = true %}
{% endif %}
{% endfor %}
{% if bestprice == true %}
<div class="product-detail-table-container">
<table class="product-detail-table {% if product.calculatedPrices|length > 1 %}has-badge{% endif %}">
<tr class="table--header">
<th align="center" class="price-list-item">{{ "detail.TableArtNr"|trans|sw_sanitize }}</th>
<th align="center" class="price-list-item">Variante</th>
<th align="center" class="price-list-item">VE</th>
<th align="center"
class="price-list-item">{{ "detail.tableAvailable"|trans|sw_sanitize }}</th>
<th align="center"
class="price-list-item">{{ "detail.tableQuantity"|trans|sw_sanitize }}</th>
{% for price in product.calculatedPrices.elements %}
{% if loop.last == false and loop.index<=4 %}
<th align="center" class="price-list-item">
{% if product.calculatedPrices|length > 1 %}
<div class="discount-badge">
{% if loop.index == 1 %}-5%{% endif %}
{% if loop.index == 2 %}-8%{% endif %}
{% if loop.index == 3 %}-10%{% endif %}
{% if loop.index == 4 %}-12%{% endif %}
</div>
{% endif %}
{{ (price.quantity + 1) }} VE / Stück
</th>
{% endif %}
{% endfor %}
<th align="center"
class="price-list-item">{{ "detail.tableDesiredQuantityVE"|trans|sw_sanitize }}</th>
</tr>
<tr>
{% for variant in variants|filter((variant) => variant.availableStock == true) %}
{% if variant.customFields.custom_units_piece_per_pu !='1' %}
{% set pricesVariant = variant.prices.elements|sort((a, b) => a.quantityStart <=> b.quantityStart) %}
<tr>
<td>{{ variant.productNumber }}</td>
<td>
{% for variation in variant.variation %}
{% if loop.first %}{{ variation.option }}{% else %}, {{ variation.option }}{% endif %}
{% endfor %}
</td>
<td>{{ variant.customFields.custom_units_piece_per_pu }}</td>
<td class="d-flex">{% if variant.availableStock %} <span
class="delivery-status-indicator bg-success mx-auto"></span>{% endif %}</td>
<td>{{ (variant.price.elements|first.net/variant.customFields.custom_units_piece_per_pu)|round(2, 'floor')|currency }}</td>
{% set arrayRuleId = pricesVariant|filter((el) => el.ruleId == ruleId) %}
{% for i in 1..staplelength %}
{% set mainloop = loop.index + 1 %}
{% if mainloop <= 5 %}
<td align="center">
<strong>
{% for item in arrayRuleId %}
{% if loop.index == mainloop %}
{{ (item.price.elements|first.net/variant.customFields.custom_units_piece_per_pu)|round(2, 'floor')|currency }}
{% endif %}
{% endfor %}
</strong>
</td>
{% endif %}
{% endfor %}
<td>
{% sw_include '@Storefront/storefront/page/product-detail/buy-widget-form-table.html.twig' with {
productTable: variant
} %}
</td>
</tr>
{% endif %}
{% endfor %}
</table>
</div>
{% endif %}
{% endif %}
{% endif %}
{% endblock %}