{% sw_extends '@parent/storefront/page/product-detail/properties.html.twig' %}
{% block page_product_detail_properties_inner %}
<div class="product-detail-properties">
{% block page_product_detail_properties_container %}
<div class="row product-detail-properties-container">
<div class="col-12">
{# Variables will be set when this file is used inside oo-specifications #}
{% set condition = element.config.showMoreRenderCondition.value|default(false) %}
{% set limit = element.config.renderLimit.value|number_format %}
{% set limit = limit < 1 ? 9999 : limit %}
{% set limitExeeded = page.product.sortedProperties|length > limit %}
{% set showMore = condition == 'always' ? true
: condition == 'never' ? false
: condition == 'default' ? limitExeeded
: false
%}
{% set showMoreLink = element.config.showMoreLink.value|default('#') %}
{% block page_product_detail_properties_table %}
<table class="table table-striped product-detail-properties-table">
<tbody>
{# Keep track of things that are printed #}
{% set printedItems = [] %}
{% set printedGroups = [] %}
{# Print items that should be printed at top (ignoring the 'printgroup') #}
{% set topItems = page.product.sortedProperties.elements|filter(e => e.translated.customFields.custom_attributes_show_on_top == '1') %}
{% for item in topItems %}
{% set withinItemLimit = printedItems|length < limit %}
{% if withinItemLimit %}
{% sw_include '@Storefront/storefront/page/product-detail/property.html.twig' with {
group: item,
additionalClass: 'top-item'
} %}
{% endif %}
{# Add item to printeditems #}
{% set printedItems = printedItems|merge([item.id]) %}
{% endfor %}
{# Print items that are not printed at top #}
{% set normalItems = page.product.sortedProperties.elements %}
{# |filter(e => e.id not in printedItems) %} #}
{% for group in normalItems|sort((a, b) => a.translated.customFields.custom_attributes_category <=> b.translated.customFields.custom_attributes_category) %}
{% set withinItemLimit = printedItems|length < limit %}
{% if withinItemLimit %}
{% set hasAttributeGroup = (group.translated.customFields.custom_attributes_category is not empty)|default(false) %}
{% set attributeGroup = hasAttributeGroup ? group.translated.customFields.custom_attributes_category : '' %}
{% set first = attributeGroup not in printedGroups %}
{% set printedGroups = printedGroups|merge([attributeGroup]) %}
{# Print groupname before first item within the group #}
{% if hasAttributeGroup && first %}
<tr class="attributegroup-row"><td colspan="2" class="pt-4">{{attributeGroup}}</td></tr>
{% endif %}
{% sw_include '@Storefront/storefront/page/product-detail/property.html.twig' with {
group: group,
additionalClass: 'regular-item'
} %}
{% endif %}
{# Add item to printeditems #}
{% set printedItems = printedItems|merge([group.id]) %}
{% endfor %}
{% if showMore %}
<tr class="showmore-row"><td colspan="2"><a href="{{ showMoreLink }}">Toon meer</a></td></tr>
{% endif %}
</tbody>
</table>
{% endblock %}
</div>
</div>
{% endblock %}
</div>
{% endblock %}