{#
/**
 * @file
 * Base+'s theme implementation to display a block.
 *
 * Available variables:
 * - plugin_id: The ID of the block implementation.
 * - label: The configured label of the block if visible.
 * - configuration: A list of the block's configuration values.
 *   - label: The configured label for the block.
 *   - label_display: The display settings for the label.
 *   - module: The module that provided this block plugin.
 *   - cache: The cache settings.
 *   - Block plugin specific settings will also be stored here.
 * - content: The content of this block.
 * - attributes: array of HTML attributes populated by modules, intended to
 *   be added to the main container tag of this template.
 *   - id: A valid HTML ID and guaranteed unique.
 * - title_attributes: Same as attributes, except applied to the main title
 *   tag that appears in the template.
 * - content_attributes: Same as attributes, except applied to the main content
 *   tag that appears in the template.
 * - title_prefix: Additional output populated by modules, intended to be
 *   displayed in front of the main title tag that appears in the template.
 * - title_suffix: Additional output populated by modules, intended to be
 *   displayed after the main title tag that appears in the template.
 *
 * @see template_preprocess_block()
 *
 * @ingroup themeable
 */
#}
{% block libraries %}
  {{ attach_library('basecore/hero-v2-block') }}
{% endblock %}
{%
  set classes = [
    'block',
    'block-' ~ configuration.provider|clean_class,
    'block-' ~ plugin_id|clean_class,
    'block-mt-hero-v2'
  ]
%}
{%
  set title_classes = [
    'title'
  ]
%}
{% set column_first_order = null %}
{% set column_second_order = null %}
{% set column_first_grid_classes = null %}
{% set column_second_grid_classes = null %}
{% set mt_vertical_aligment = content['#block_content'].field_mt_hero_v2_ver_alignment.value %}
{% if content['#block_content'].field_mt_hero_v2_hor_alignment.value == "image-right" %}
  {% set column_first_order = "order-lg-1 order-2" %}
  {% set column_second_order = "order-lg-2 text-end" %}
{% else %}
  {% set column_first_order = "order-lg-2 order-2" %}
  {% set column_second_order = "order-lg-1" %}
{% endif %}
{% if content['#block_content'].field_mt_hero_v2_layout.value == "two-col-33-67" %}
  {% set column_first_grid_classes = "col-lg-4 pt-xl-4 pt-0 hero-column-first" %}
  {% set column_second_grid_classes = "col-lg-8 hero-column-second" %}
  {% set columns = "two-columns" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "two-col-42-58" %}
  {% set column_first_grid_classes = "col-lg-5 pt-xl-4 pt-0 hero-column-first" %}
  {% set column_second_grid_classes = "col-lg-7 hero-column-second" %}
  {% set columns = "two-columns" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "two-col-50-50" %}
  {% set column_first_grid_classes = "col-lg-6 pt-xl-4 pt-0 hero-column-first" %}
  {% set column_second_grid_classes = "col-lg-6 hero-column-second" %}
  {% set columns = "two-columns" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "two-col-58-42" %}
  {% set column_first_grid_classes = "col-lg-7 pt-xl-4 pt-0 hero-column-first" %}
  {% set column_second_grid_classes = "col-lg-5 hero-column-second" %}
  {% set columns = "two-columns" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "two-col-67-33" %}
  {% set column_first_grid_classes = "col-lg-8 pt-xl-4 pt-0 hero-column-first" %}
  {% set column_second_grid_classes = "col-lg-4 hero-column-second" %}
  {% set columns = "two-columns" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "one-col-60 mt-image-first" %}
  {% set column_first_grid_classes = "col-lg-6 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set column_second_grid_classes = "col-lg-6 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set columns = "one-column image-first" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "one-col-80 mt-image-first" %}
  {% set column_first_grid_classes = "col-lg-8 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set column_second_grid_classes = "col-lg-8 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set columns = "one-column image-first" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "one-col-100 mt-image-first" %}
  {% set column_first_grid_classes = "col-lg-12 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set column_second_grid_classes = "col-lg-12 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set columns = "one-column image-first" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "one-col-60 mt-text-first" %}
  {% set column_first_grid_classes = "col-lg-6 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set column_second_grid_classes = "col-lg-6 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set columns = "one-column text-first" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "one-col-80 mt-text-first" %}
  {% set column_first_grid_classes = "col-lg-8 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set column_second_grid_classes = "col-lg-8 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set columns = "one-column text-first" %}
{% elseif content['#block_content'].field_mt_hero_v2_layout.value == "one-col-100 mt-text-first" %}
  {% set column_first_grid_classes = "col-lg-12 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set column_second_grid_classes = "col-lg-12 pt-lg-4 pt-0 me-auto ms-auto text-center" %}
  {% set columns = "one-column text-first" %}
{% endif %}
{# Build a safe href for the action link; avoid throwing if the route is missing. #}
{% set action_url = content.field_mt_hero_v2_action[0]['#url']|default(null) %}
{% set action_href = null %}
{% set action_target = null %}
{% if action_url %}
  {% if action_url.isExternal() %}
    {% set action_href = content['#block_content'].field_mt_hero_v2_action[0].uri %}
    {% set action_target = '_blank' %}
  {% elseif action_url.isRouted() %}
    {% set action_href = path(action_url.getRouteName(), action_url.getRouteParameters()) %}
  {% else %}
    {% set action_href = action_url.toString() %}
  {% endif %}
{% endif %}
{% set content_without_action = content|without('field_mt_hero_v2_image', 'field_mt_hero_v2_layout', 'field_mt_hero_v2_action') %}
{% set action_rendered = content.field_mt_hero_v2_action|render %}
{% if action_rendered and action_target %}
  {% set action_rendered = action_rendered|replace({'<a ':'<a target=\"' ~ action_target ~ '\" '}) %}
{% endif %}

<div{{ attributes.addClass(classes) }}>
  {{ title_prefix }}
  {% if label %}
    <h2{{ title_attributes.addClass(title_classes) }}>{{ label }}</h2>
  {% endif %}
  {{ title_suffix }}
  {% block content %}
    <div{{ content_attributes.addClass('content').addClass(columns).addClass(mt_vertical_aligment) }}>
      <div class="container">
        <div class="row {{ mt_vertical_aligment }}">
          <div class="{{ column_first_grid_classes }} {{ column_first_order }}">
            {% if columns == "one-column image-first" and content.field_mt_hero_v2_image|render %}
              <div class="mb-4 pb-5">
                {% if (action_rendered and action_href) %}
                  <div class="overlay-container">
                    <span class="overlay">
                      <a{% if action_target %} target="{{ action_target }}"{% endif %} class="overlay-target-link" href="{{ action_href }}"></a>
                    </span>
                    {{ content.field_mt_hero_v2_image }}
                  </div>
                {% else %}
                  {{ content.field_mt_hero_v2_image }}
                {% endif %}
              </div>
            {% endif %}
            {{ content_without_action }}
            {{ action_rendered|raw }}
            {% if columns == "one-column text-first" and content.field_mt_hero_v2_image|render %}
              <div class="mt-4 pt-5">
                {% if (action_rendered and action_href) %}
                  <div class="overlay-container">
                    <span class="overlay">
                      <a{% if action_target %} target="{{ action_target }}"{% endif %} class="overlay-target-link" href="{{ action_href }}"></a>
                    </span>
                    {{ content.field_mt_hero_v2_image }}
                  </div>
                {% else %}
                  {{ content.field_mt_hero_v2_image }}
                {% endif %}
              </div>
            {% endif %}
          </div>
          {% if columns == "two-columns" and content.field_mt_hero_v2_image|render %}
            <div class="{{ column_second_grid_classes }}  {{ column_second_order }}">
                {% if (action_rendered and action_href) %}
                  <div class="overlay-container">
                    <span class="overlay">
                      <a{% if action_target %} target="{{ action_target }}"{% endif %} class="overlay-target-link" href="{{ action_href }}"></a>
                    </span>
                    {{ content.field_mt_hero_v2_image }}
                  </div>
                {% else %}
                  {{ content.field_mt_hero_v2_image }}
                {% endif %}
            </div>
          {% endif %}
        </div>
      </div>

    </div>
  {% endblock %}
</div>
