{% 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 %}
{# TODO: @zenit - check on sw update #}
{# activate load per default. If it is not activated only a data-src is set instead of the src tag. #}
{% if load is not defined %}
{% set load = true %}
{% endif %}
{# By default no original image will be loaded as soon as thumbnails are available. #}
{# When set to true the orginal image will be loaded when the viewport is greater than the largest available thumbnail. #}
{% if loadOriginalImage is not defined %}
{% set loadOriginalImage = false %}
{% endif %}
{# By default the srcset sizes will be calculated automatically if `columns` are present and no `sizes` are configured. #}
{# When set to false the sizes attribute will not be generated automatically. #}
{% if autoColumnSizes is not defined %}
{% set autoColumnSizes = true %}
{% endif %}
{% if attributes is not defined %}
{% set attributes = {} %}
{% endif %}
{% if attributes.alt is not defined and media.translated.alt is defined %}
{% set attributes = attributes|merge({'alt': media.translated.alt}) %}
{% endif %}
{% if attributes.title is not defined and media.translated.title is defined %}
{% set attributes = attributes|merge({'title': media.translated.title}) %}
{% endif %}
{# uses cms block column count and all available thumbnails to determine the correct image size for the current viewport #}
{% if media.thumbnails|length > 0 %}
{% set sizes = {
'sm': theme_config('breakpoint.sm') ~'px',
'md': theme_config('breakpoint.md') ~'px',
'lg': theme_config('breakpoint.lg') ~'px',
'xl': theme_config('breakpoint.xl') ~'px',
'xxl': "1900px",
} %}
{% set thumbnails = media.thumbnails|sort|reverse %}
{# generate srcset with all available thumbnails #}
{% set srcsetValue %}{% apply spaceless %}
{% if loadOriginalImage %}{{ media|sw_encode_media_url }} {{ thumbnails|first.width + 1 }}w, {% endif %}{% for thumbnail in thumbnails|reverse %}{{ thumbnail.url | sw_encode_url }} {{ thumbnail.width }}w{% if not loop.last %}, {% endif %}{% endfor %}
{% endapply %}{% endset %}
{# generate sizes #}
{% set sizesValue %}{% apply spaceless %}
{% set breakpoint = {
'sm': theme_config('breakpoint.sm'),
'md': theme_config('breakpoint.md'),
'lg': theme_config('breakpoint.lg'),
'xl': theme_config('breakpoint.xl'),
'xxl': "1900"
} %}
{% if thumbnails|first.width > breakpoint|reverse|first %}
{# @deprecated @zenit tag:v3.1.0 - Variable `maxWidth` and parent condition will be removed #}
{% set maxWidth = thumbnails|first.width %}
{% endif %}
{% for key, value in breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}
{% endapply %}{% endset %}
{% endif %}
{% if foxDomainReplace is not defined %}
{# Fallback for other plugins replacing the thumbnail_utility block and not calling parent #}
{% set foxDomainReplace = {} %}
{% endif %}
<img loading="{% if attributes.loading %}{{ attributes.loading }}{% else %}{{ loadingStrategy }}{% endif %}" {% 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 %}
/>