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

{% set content_layout_attributes = attrs()
    .addClass('media media--' ~ layout, layout and image)
    .mergeWith(content_layout_attributes|default)
%}

{# By default we add the layout attributes to the wrapper element. If you want to
 disable this behavior, set "default_content_layout" to false. #}
{% set attributes = attrs(attributes|default)
    .mergeWith(content_layout_attributes, default_content_layout is not defined or default_content_layout)
%}

{# Media #}
{% block text_media %}
    {% if image %}
        {% with {figure: image} %}{{ block('figure_component') }}{% endwith %}
    {% endif %}
{% endblock %}

{% block content %}
    {% if layout != 'below' %}
        {{ block('text_media') }}
    {% endif %}

    {# Richtext #}
    {% block text %}
        {% set text_attributes = attrs()
            .addClass('rte')
            .mergeWith(text_attributes|default)
        %}
        <div{% block text_attributes %}{{ text_attributes }}{% endblock %}>
            {{ text|csp_inline_styles|insert_tag_raw|encode_email|raw }}
        </div>
    {% endblock %}

    {% if layout == 'below' %}
        {{ block('text_media') }}
    {% endif %}
{% endblock %}
