{% sw_extends '@Storefront/storefront/element/cms-element-text.html.twig' %}
{% block element_text %}
{% set config = element.fieldConfig.elements %}
{% set customId = 'cms-el-' ~ random(5) ~ element.id ~ random(5) %}
{% if 'blurred-text-box' in config.cssClass.value %}
{# use color as fallback #}
{% set fallbackColor = theme_config('sw-color-brand-primary') %}
{% set fallbackBackground = "linear-gradient(#{fallbackColor}, #{fallbackColor})" %}
{# use background image from section as fallback #}
{% set mediaId = section.backgroundMediaId %}
{% set mediaCollection = searchMedia([mediaId], context.context) %}
{% set mediaItem = mediaCollection.get(mediaId) %}
{% if mediaItem.url %}
{% set fallbackBackground = "url('#{mediaItem.url}')" %}
{% endif %}
{# use (biggest) thumbnail as fallback #}
{% if mediaItem.thumbnails.elements %}
{% for thumbnail in mediaItem.thumbnails.elements |filter((a, b) => (a.width > b.width ? 1 : -1)) %}
{% if loop.first and thumbnail.url %}
{% set fallbackBackground = "url('#{thumbnail.url}')" %}
{% endif %}
{% endfor %}
{% endif %}
{# implement fallback css #}
<style>
{{ '#' ~ customId }}::before {
background-image: {{ fallbackBackground |raw }};
}
</style>
{% endif %}
{% set elementClasses = [config.cssClass.value, 'cms-element-' ~ element.type] %}
<div id="{{ customId }}"
class="{{ elementClasses|join(' ') }}{% if config.verticalAlign.value %} has-vertical-alignment{% endif %}">
{% block element_text_alignment %}
{{ parent() }}
{% endblock %}
</div>
{% endblock %}