{#
/**
 * @file
 * Vartheme BS5 Starter Kit implementation for the fieldset element and its children.
 *
 * Available variables:
 * - attributes: HTML attributes for the fieldset element.
 * - errors: (optional) Any errors for this fieldset element, may not be set.
 * - required: Boolean indicating whether the fieldset element is required.
 * - legend: The legend element containing the following properties:
 *   - title: Title of the fieldset, intended for use as the text of the legend.
 *   - attributes: HTML attributes to apply to the legend.
 * - description: The description element containing the following properties:
 *   - content: The description content of the fieldset.
 *   - attributes: HTML attributes to apply to the description container.
 * - children: The rendered child elements of the fieldset.
 * - prefix: The content to add before the fieldset children.
 * - suffix: The content to add after the fieldset children.
 *
 * @see template_preprocess_fieldset()
 */
#}
{%
  set classes = [
    'js-form-item',
    'form-item',
    'js-form-wrapper',
    'form-wrapper',
    'card',
    'mb-3',
  ]
%}
<fieldset{{ attributes.addClass(classes) }}>
  {%
    set legend_span_classes = [
      'fieldset-legend',
      'mb-0',
      required ? 'js-form-required',
      required ? 'form-required',
    ]
  %}
  
  {% if title_display != 'none' %}
    <div class="card-header">
      <legend{{ legend.attributes.addClass('m-0') }}>
        <label{{ legend_span.attributes.addClass(legend_span_classes) }}>{{ legend.title }}</label>
        {%- if required and title_display == 'before' -%}
          <span class="font-weight-bolder form-required--indicator ps-1 text-danger">*</span>
        {%- endif -%}
      </legend>
    </div>
  {% endif %}

  <div class="card-body fieldset-wrapper">
    {% if description_display == 'before' and description.content %}
      <small{{ description.attributes.addClass('description', 'form-text', 'text-muted') }}>{{ description.content }}</small>
    {% endif %}
    {% if errors %}
      <div>
        {{ errors }}
      </div>
    {% endif %}
    {% if prefix %}
      <span class="field-prefix">{{ prefix }}</span>
    {% endif %}
    {{ children }}
    {% if suffix %}
      <span class="field-suffix">{{ suffix }}</span>
    {% endif %}
    {% if description_display in ['after', 'invisible'] and description.content %}
      <small{{ description.attributes.addClass('description', 'form-text', 'text-muted') }}>{{ description.content }}</small>
    {% endif %}
  </div>
</fieldset>
