{% extends "@Contao/content_element/_base.html.twig" %}
{% use "@Contao/component/_figure.html.twig" %}

{% block content %}
    {% if as_editor_view %}
        {% block editor_view %}
            <ul>
                {% for source_file in source_files %}
                    <li>
                        <span>{{ source_file.name }}</span>
                        <span class="size">({{ source_file.fileSize|format_bytes }})</span>
                    </li>
                {% endfor %}
            </ul>
        {% endblock %}
    {% else %}
        {{ block('figure_component') }}
    {% endif %}
{% endblock %}

{% block media %}
    {% set media_attributes = attrs(figure.media.attributes)
        .mergeWith(media_attributes|default)
    %}
    <{{ figure.media.type }}{{ media_attributes }}>
        {% for source_attributes in figure.media.sources %}
            {% do csp_source('media-src', source_attributes.src) %}
            <source{{ source_attributes }}>
        {% endfor %}
    </{{ figure.media.type }}>
{% endblock %}

{# Add metadata #}
{% block metadata %}
    {% for source_file in source_files %}
        {% set schemaOrgData = source_file.schemaOrgData|default({}) %}
        {% if figure.media.attributes.poster|default %}
            {% set schemaOrgData = schemaOrgData|merge({
                'thumbnailUrl': figure.media.attributes.poster
            }) %}
        {% endif %}
        {% do add_schema_org(schemaOrgData) %}
    {% endfor %}
{% endblock %}
