{#
/**
 * @file
 * Theme override for a details element.
 *
 * Available variables
 * - attributes: A list of HTML attributes for the details element.
 * - errors: (optional) Any errors for this details element, may not be set.
 * - title: (optional) The title of the element, may not be set.
 * - description: (optional) The description of the element, may not be set.
 * - children: (optional) The children of the element, may not be set.
 * - value: (optional) The value of the element, may not be set.
 *
 * @see template_preprocess_details()
 */
#}
{% set heading = title %}
{% set body = children %}

{%
  set classes = [
    'panel',
    errors ? 'panel-danger' : 'panel-' ~ panel_type|clean_class,
  ]
%}
<div{{ attributes.addClass(classes).removeClass('form-wrapper') }}>
  {# Heading #}

  {% if heading %}
    {% block heading %}
      <div class="panel-heading">
        <header>
          {%
            set heading_classes = [
              'panel-title',
            ]
          %}
          {% if collapsible %}
            <a{{ heading_attributes.addClass(heading_classes) }} href="{{ target }}">{{ heading }}</a>
          {% else %}
            <div{{ heading_attributes.addClass(heading_classes) }}>{{ heading }}</div>
          {% endif %}
        </header>
      </div>
    {% endblock %}
  {% endif %}

  {# Body #}
  {% block body %}
    {%
      set body_classes = [
      'panel-body',
      collapsible ? 'panel-collapse',
      collapsible ? 'collapse',
      collapsible ? 'fade',
      errors or collapsible and not collapsed ? 'in',
      ]
    %}
    {%
      set description_classes = [
        'help-block',
        description and description.position == 'invisible' ? 'sr-only',
      ]
    %}

    <div{{ body_attributes.addClass(body_classes) }}>
      {% if description and description.position == 'before' %}
        <p{{ description.attributes.addClass(description_classes) }}>{{ description.content }}</p>
      {% endif %}
      {{ body }}
      {% if description and description.position == 'after' or description.position == 'invisible' %}
        <p{{ description.attributes.addClass(description_classes) }}>{{ description.content }}</p>
      {% endif %}
    </div>
  {% endblock %}

  {# Footer #}
  {% if footer %}
    {% block footer %}
      {%
        set footer_classes = [
          'panel-footer',
        ]
      %}
      <div{{ footer_attributes.addClass(footer_classes) }}>{{ footer }}</div>
    {% endblock %}
  {% endif %}

</div>
