{#
/**
 * @file
 * Theme override 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.
 *   - provider: The module or other provider that provided this block plugin.
 *   - 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.
 * - 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()
 */

#}

{% set bem_block_block = bem_block_block|default('block') %}

{% set bem_block_element = bem_block_element|default(false) %}

{% set bem_modifiers = [
  configuration.view_mode ? 'view-mode-' ~ configuration.view_mode|clean_class,
  'provider-' ~ configuration.provider|clean_class,
  plugin_id|clean_class,
  attributes['data-bem'].originalId ? 'id-' ~ attributes['data-bem'].originalId|clean_class,
  attributes['data-bem'].region ? 'region-' ~ attributes['data-bem'].region|clean_class,
  attributes['data-bem'].type ? 'type-' ~ attributes['data-bem'].type|clean_class,
  configuration.view_mode and configuration.type ? configuration.type|clean_class ~ '--' ~ configuration.view_mode|clean_class,
] %}

{% set bem_block_modifiers = bem_block_modifiers|default([])|merge(bem_modifiers) %}
{% set block_type = block_type|default(false) %}

{% if attributes['data-bem'].type %}
  {% set block_type = attributes['data-bem'].type %}
{% endif %}


{% set bem_block_extra = bem_block_extra|default([])|merge(['block-' ~ configuration.provider]) %}

{% set heading_level = heading_level|default(2) %}

{# Always get the title value #}
{% if label|default %}
  {% set heading = label %}
{% else %}
  {% set heading = configuration.label %}
{% endif %}

{# Provide an ID we an use for reference purposes if needed #}
{% set heading_id = heading_id|default(false) %}
{% if attributes.id|default %}
  {% set heading_id = attributes.id|clean_class ~ '-heading' %}
{% else %}
  {% set heading_markup = heading['#markup'] ?: heading %}
  {% set heading_id = 'heading-' ~ heading_markup|clean_class ~ '-' ~ ("now"|date("Ydm")) %}
{% endif %}

{# Always use a descriptive label (block description) for your block
   If your title does not confirm to that, consider using a new field for your visible line of text (e.g. 'Surf to…')
   and visually hiding the real, properly descriptive, label (e.g. h2 'Main navigation' with class 'visually-hidden').
   As a last resort, if you can not add a real title, you can also use aria-label property with a descriptive text

   In the case of a lot of landmarks on the page, the aria stuff is also useful to distinguish navigations from each other:
   https://www.w3.org/WAI/GL/wiki/Using_ARIA_landmarks_to_identify_regions_of_a_page
#}
<div{{ attributes.addClass(bem(bem_block_block, bem_block_element, bem_block_modifiers, bem_block_extra)) }}
  {% if configuration.label_display|default and heading|default %} aria-labelledby="{{heading_id}}"{% endif %}
>
  {{ title_prefix }}
  {% block block_label %}
    {% if configuration.label_display|default %}
      {{ include("@rocketship-theme-starter-atoms/02-text/00-headings/_heading.twig", {
        heading_id,
        heading_level,
        heading,
        "heading_display": configuration.label_display
      }, with_context = false) }}
    {% endif %}
  {% endblock block_label %}
  {{ title_suffix }}

  {% block block_content %}
    {{ content }}
  {% endblock block_content %}
</div>
