{#
/**
 * @file
 * Layout component.
 *
 * Variables:
 * - content.content_top: Content top slot.
 * - content.sidebar_top_left: Top left sidebar slot.
 * - content.sidebar_top_left_attributes: Top left sidebar attributes.
 * - content.sidebar_top_right: Top right sidebar slot.
 * - content.sidebar_top_right_attributes: Top right sidebar attributes.
 * - content.main: Content slot.
 * - content_attributes: Content attributes.
 * - content.sidebar_bottom_left: Bottom left sidebar slot.
 * - content.sidebar_bottom_left_attributes: Bottom left sidebar attributes.
 * - content.sidebar_bottom_right: Bottom right sidebar slot.
 * - content.sidebar_bottom_right_attributes: Bottom right sidebar attributes.
 * - content.content_bottom: Content bottom slot.
 * - hide_sidebar_left: Whether to force hide the left sidebar.
 * - hide_sidebar_right: Whether to force hide the right sidebar.
 * - is_contained: Whether the page is to be contained.
 * - vertical_spacing: [string] With top, bottom or both vertical spaces.
 * - attributes: [string] Additional attributes.
 * - modifier_class: [string] Additional classes.
 */
#}

{% set has_sidebar_left = (content.sidebar_top_left is not empty or content.sidebar_bottom_left is not empty) and not hide_sidebar_left|default(false) %}
{% set has_sidebar_right = (content.sidebar_top_right is not empty or content.sidebar_bottom_right is not empty) and not hide_sidebar_right|default(false) %}

{% set is_contained = is_contained or has_sidebar_left or has_sidebar_right %}

{% set vertical_spacing = vertical_spacing != 'auto' ? vertical_spacing : has_sidebar_left or has_sidebar_right ? 'top' : '' %}

{% set no_sidebar_left_class = hide_sidebar_left ? 'ct-layout--no-sidebar-left' : '' %}
{% set no_sidebar_right_class = hide_sidebar_right ? 'ct-layout--no-sidebar-right' : '' %}
{% set no_tl_class = content.sidebar_top_left is empty or hide_sidebar_left ? 'ct-layout--no-top-left' : '' %}
{% set no_tr_class = content.sidebar_top_right is empty or hide_sidebar_right ? 'ct-layout--no-top-right' : '' %}
{% set no_bl_class = content.sidebar_bottom_left is empty or hide_sidebar_left ? 'ct-layout--no-bottom-left' : '' %}
{% set no_br_class = content.sidebar_bottom_right is empty or hide_sidebar_right ? 'ct-layout--no-bottom-right' : '' %}
{% set is_contained_class = is_contained ? 'container' : 'container-fluid' %}
{% set vertical_spacing_class = vertical_spacing in ['top', 'bottom', 'both'] ? 'ct-vertical-spacing--%s'|format(vertical_spacing) : '' %}

{% set modifier_class = '%s %s %s %s %s %s %s %s'|format(no_sidebar_left_class, no_sidebar_right_class, no_tl_class, no_tr_class, no_bl_class, no_br_class, vertical_spacing_class, modifier_class|default('')) %}
{% set modifier_class = modifier_class|trim %}

{% if content %}
  <main class="ct-layout {{ modifier_class -}}" role="main" data-layout-builder-layout="true" {% if attributes is not empty %}{{- attributes|raw -}}{% endif %}>
    {% block content_top_block %}
      {% if content.content_top is not empty %}
        {{- content.content_top|raw -}}
      {% endif %}
    {% endblock %}

    <div class="ct-layout__inner {{ is_contained_class }}">
      {% if content.main is not empty %}
        {% block content_block %}
          <section class="ct-layout__main" {% if content_attributes is not empty %}{{- content_attributes|raw -}}{% endif %}>
            {{- content.main|raw -}}
          </section>
        {% endblock %}
      {% endif %}

      {% if content.sidebar_top_left is not empty and has_sidebar_left %}
        {% block sidebar_top_left_block %}
          <aside class="ct-layout__sidebar_top_left" {% if content.sidebar_top_left_attributes is not empty %}{{- content.sidebar_top_left_attributes|raw -}}{% endif %}>
            {{- content.sidebar_top_left|raw -}}
          </aside>
        {% endblock %}
      {% endif %}

      {% if content.sidebar_top_right is not empty and has_sidebar_right %}
        {% block sidebar_top_right_block %}
          <aside class="ct-layout__sidebar_top_right" {% if content.sidebar_top_right_attributes is not empty %}{{- content.sidebar_top_right_attributes|raw -}}{% endif %}>
            {{- content.sidebar_top_right|raw -}}
          </aside>
        {% endblock %}
      {% endif %}

      {% if content.sidebar_bottom_left is not empty and has_sidebar_left %}
        {% block sidebar_bottom_left_block %}
          <aside class="ct-layout__sidebar_bottom_left" {% if content.sidebar_bottom_left_attributes is not empty %}{{- content.sidebar_bottom_left_attributes|raw -}}{% endif %}>
            {{- content.sidebar_bottom_left|raw -}}
          </aside>
        {% endblock %}
      {% endif %}

      {% if content.sidebar_bottom_right is not empty and has_sidebar_right %}
        {% block sidebar_bottom_right_block %}
          <aside class="ct-layout__sidebar_bottom_right" {% if content.sidebar_bottom_right_attributes is not empty %}{{- content.sidebar_bottom_right_attributes|raw -}}{% endif %}>
            {{- content.sidebar_bottom_right|raw -}}
          </aside>
        {% endblock %}
      {% endif %}
    </div>

    {% block content_bottom_block %}
      {% if content.content_bottom is not empty %}
        {{- content.content_bottom|raw -}}
      {% endif %}
    {% endblock %}
  </main>
{% endif %}
