{% sw_extends '@Storefront/storefront/utilities/thumbnail.html.twig' %}
{% block thumbnail_utility %}
{% set foxDomainReplace = {} %}
{% if config('FuexcImageCDN.config.cdnUrl') and config('FuexcImageCDN.config.rewriteThumbnails') %}
{% set foxDomainReplace = {
"https://cdn.shopware.store": config('FuexcImageCDN.config.cdnUrl')|trim('/')
} %}
{% for salesChannelDomain in context.salesChannel.domains %}
{% set foxDomain = salesChannelDomain.url|split('//') %}
{% if foxDomain|length == 1 %}
{% set foxDomain = "#{(foxDomain[0]|split('/')[0])}" %}
{% elseif foxDomain|length == 2 %}
{% set foxDomain = "#{foxDomain[0]}//#{(foxDomain[1]|split('/')[0])}" %}
{% endif %}
{% set foxDomainReplace = foxDomainReplace|merge({
(foxDomain): config('FuexcImageCDN.config.cdnUrl')|trim('/')
}) %}
{% endfor %}
{% endif %}
{# allow the loading Stragy to be overridden from twig #}
{% if loadingStrategy is not defined %}
{% set loadingStrategy = "eager" %}
{% if config('FuexcImageCDN.config.lazyLoadImages') %}
{% set loadingStrategy = "lazy" %}
{% endif %}
{% endif %}
{{ parent() }}
{% endblock %}
{% block thumbnail_utility_img %}
{% if foxDomainReplace is not defined %}
{# Fallback for other plugins replacing the thumbnail_utility block and not calling parent #}
{% set foxDomainReplace = {} %}
{% endif %}
<img loading="{{ loadingStrategy }}" {% if load %}src="{{ media|sw_encode_media_url|replace(foxDomainReplace) }}" {% else %}data-src="{{ media|sw_encode_media_url|replace(foxDomainReplace) }}" {% endif %}
{% if media.thumbnails|length > 0 %}
{% if load %}srcset="{{ srcsetValue|replace(foxDomainReplace) }}" {% else %}data-srcset="{{ srcsetValue|replace(foxDomainReplace) }}" {% endif %}
{% if sizes['default'] %}
sizes="{{ sizes['default'] }}"
{% elseif sizes|length > 0 %}
sizes="{{ sizesValue }}"
{% endif %}
{% endif %}
{% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
/>
{% endblock %}