{% block frosh_product_compare_add_to_compare_box %}
{% set showIconOnly = config('FroshProductCompare.config.showIconOnly') %}
{# @var product \Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity #}
<div class="compare-button">
{% set addToCompareOptions = { productId: product.id, showIconOnly: showIconOnly, defaultText: 'froshProductCompare.general.addToCompare'|trans|sw_sanitize, addedText: 'froshProductCompare.general.removeFromCompare'|trans|sw_sanitize } %}
{% block frosh_product_compare_add_to_compare_button %}
<div style="display: flex; margin-bottom: 20px;">
<input id="checkCompare_{{id}}" class="custom-checkbox-custom-symbol" checkbox-id="{{id}}" type="checkbox" name="scales">
<div style="display: table-cell; vertical-align: middle; line-height: 15px; margin-left: 7px; text-align: left; color:black;">
<span class="almarenaRegular" style="font-size:13px;">PRODUKT <br> VERGLEICHEN</span>
</div>
</div>
{% if showIconOnly %}
<button hidden id="checked_{{ id }}" data-add-to-compare-button="true" data-add-to-compare-button-options="{{ addToCompareOptions|json_encode }}" class="btn btn-block btn-compare" title="{{ 'froshProductCompare.general.addToCompare'|trans|striptags }}">{# {% sw_icon 'bag-product' style { 'size': 'sm', 'color': 'primary' } %} #}</button>
{% else %}
<button hidden id="checked_{{ id }}" data-add-to-compare-button="true" data-add-to-compare-button-options="{{ addToCompareOptions|json_encode }}" class="btn btn-block btn-compare" title="{{ 'froshProductCompare.general.addToCompare'|trans|striptags }}">{# {{ "froshProductCompare.general.addToCompare"|trans|sw_sanitize }} #}</button>
{% endif %}
{% endblock %}
</div>
<script>
(()=>{
const myInterval = setInterval(()=>{
if (!window.$) return;
clearInterval(myInterval);
$(()=>{
const storedList = localStorage.getItem("compare-widget-added-products");
if (storedList) {
const productList = JSON.parse(storedList);
const idToCheck = $('#checkCompare_{{id}}').attr("checkbox-id");
$('#checkCompare_{{id}}').prop('checked', productList.includes(idToCheck));
}
$('#checkCompare_{{id}}').change(()=>$('#checked_{{id}}').trigger('click'));
});
}, 100);
})();
</script>
{% endblock %}