{#
/**
 * @file
 * Theme override of a container used to wrap child elements.
 *
 * Used for grouped form items. Can also be used as a theme wrapper for any
 * renderable element, to surround it with a <div> and HTML attributes.
 * See \Drupal\Core\Render\Element\RenderElement for more
 * information on the #theme_wrappers render array property, and
 * \Drupal\Core\Render\Element\container for usage of the container render
 * element.
 *
 * Available variables:
 * - attributes: HTML attributes for the containing element.
 * - children: The rendered child elements of the container.
 * - has_parent: A flag to indicate that the container has one or more parent
     containers.
 *
 * @see template_preprocess_container()
 */
#}

{% set bem_container_extra = bem_container_extra|default([]) %}
{% set bem_container_modifiers = bem_container_modifiers|default([]) %}

{# if container part of a form, start with 'form' as block class #}

{#
  For targetting the container with the buttons in it,
  use: 'form-actions' in attributes.class|keys
#}
{% if has_parent and ('container' in render_var(attributes['data-drupal-selector']) or 'actions' in render_var(attributes['data-drupal-selector']) ) %}
  {% set bem_container_block = bem_container_block|default('form') %}
  {% set bem_container_element = bem_container_element|default('group') %}
{% else %}
  {#
    By default, container could be used anywhere (not just form)
    and doesn't output much info, so keep BEM limited.
  #}
  {% set bem_container_block = bem_container_block|default('group') %}
{% endif %}

{# Add our normal attributes classes + the some custom ones as extra's. #}
{%
  set classes = [
    has_parent ? 'js-form-wrapper',
    has_parent ? 'form-wrapper',
  ]
%}

{% set bem_container_extra = bem_container_extra|merge(classes) %}

<div{{ attributes.addClass(bem(bem_container_block, bem_container_element, bem_container_modifiers, bem_container_extra)) }}>
  {{ children }}
</div>
