{#
/**
 * @file
 * Theme override for a menu 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: HTML attributes for the containing element.
 *   - id: A valid HTML ID and guaranteed unique.
 * - title_attributes: HTML attributes for the title element.
 * - content_attributes: HTML attributes for the content element.
 * - 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.
 *
 * Headings should be used on navigation menus that consistently appear on
 * multiple pages. When this menu block's label is configured to not be
 * displayed, it is added via aria-label
 * (NOT made invisible using the 'visually-hidden' CSS class),
 * which still keeps it visible for screen-readers and assistive
 * technology. Headings (and aria-label) allow screen-reader and keyboard only users to navigate
 * to or skip the links.
 * See http://juicystudio.com/article/screen-readers-display-none.php and
 * http://www.w3.org/TR/WCAG-TECHS/H42.html
 * and https://www.w3.org/WAI/GL/wiki/Using_ARIA_landmarks_to_identify_regions_of_a_page
 * for more information.
 */
#}

{% set attributes = attributes|default(create_attribute()) %}

{% set menu_block_bem_block = menu_block_bem_block|default(false) %}
{% set menu_block_bem_element = menu_block_bem_element|default('nav') %}
{% set menu_block_bem_modifiers = menu_block_bem_modifiers|default([])|merge([
  base_plugin_id ? base_plugin_id|clean_class,
  derivative_plugin_id ? derivative_plugin_id|clean_class,
  configuration.view_mode ? 'view-mode-' ~ configuration.view_mode|clean_class,
  configuration.provider ? 'provider-' ~ configuration.provider|clean_class,
  plugin_id ? plugin_id|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 menu_block_bem_extra = menu_block_bem_extra|default([])|merge([
  'block--menu',
  'rsDropdownMenu',
  configuration.provider ? 'block-' ~ configuration.provider
]) %}

{% if attributes.id %}
  {% set heading_id = attributes.id|clean_class ~ '-heading' %}
{% else %}
  {% set heading_id = false %}
{% endif %}

{% set title_classes = [] %}

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

{# 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_id = 'heading-' ~ heading|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
#}
<nav {{ attributes.addClass(bem(menu_block_bem_block, menu_block_bem_element, menu_block_bem_modifiers, menu_block_bem_extra))|without('role', 'aria-labelledby') }}
  {% if configuration.label_display|default and heading|default %} aria-labelledby="{{heading_id}}"{% endif %}
  role="navigation"
>
  {{ title_prefix }}
  {% if configuration.label_display|default %}
    {{ include("@rocketship-theme-starter-atoms/02-text/00-headings/_heading.twig", {
      "heading_id": heading_id,
      "heading_level": heading_level,
      "heading": heading,
      "heading_display": configuration.label_display,
    }, with_context = false) }}
  {% endif %}
  {{ title_suffix }}
  {% block menu_block_content %}
    {{ content }}
  {% endblock menu_block_content %}
</nav>
