<!-- Taxon/_mainImage -->

{% if taxon.imagesByType('thumbnail') is not empty %}
    {% set image = taxon.imagesByType('thumbnail').first %}
    {% set path = image.path %}
{% elseif taxon.images.first %}
    {% set image = taxon.images.first %}
    {% set path = image.path %}
{% else %}
    {% set path = '//placehold.it/510x310' %}
{% endif %}

{%  set runtimeConfigurationImage = [
    {
        'media': '(max-width:380px)',
        'sizes' : '335px',
        'srcset':
        [
            {'width':'335', 'height': '202'},
        ]
    },
    {
        'media': '(max-width:575px)',
        'sizes' : '530px',
        'srcset':
        [
            {'width':'530', 'height': '320'},
        ]
    },
    {
        'media': '(max-width:767px)',
        'sizes' : '480px',
        'srcset':
        [
            {'width':'480', 'height': '290'},
        ]
    },
    {
        'media': '(max-width:991px)',
        'sizes' : '300px',
        'srcset':
        [
            {'width':'300', 'height': '182'},
        ]
    },
    {
        'media': '(max-width: 1199px)',
        'sizes' : '410px',
        'srcset':
        [
            {'width':'410', 'height': '248'},
        ]
    },
    {
        'sizes' : '510px',
        'srcset':
        [
            {'width':'510', 'height': '308'},
        ]
    },
]
%}

{% if image is defined and image.alt is defined and image.alt is not empty %}
    {% set alt = image.alt %}
{% else %}
    {% set alt = taxon.name|default('') %}
{% endif %}

{{ dedi_sylius_image_optimizer_for_image(
    path,
    alt,
    { 'class' : 'w-100 listing-header-img' },
    runtimeConfigurationImage
) }}
