{#
/**
 * @file
 * Canvas Stark override for a media library fieldset.
 *
 * 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> element.
 * - description: The description element containing the following properties:
 *   - content: The description content of the <fieldset>.
 *   - attributes: HTML attributes to apply to the description container.
 * - description_display: Description display setting. It can have these values:
 *   - before: The description is output before the element.
 *   - after: The description is output after the element (default).
 *   - invisible: The description is output after the element, hidden visually
 *     but available to screen readers.
 * - 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()
 *
 * @ingroup themeable
 */
#}
{%
  set classes = [
  'js-form-item',
  'form-item',
  'js-form-wrapper',
  'form-wrapper',
]
%}
<fieldset{{ attributes.addClass(classes) }} data-canvas-media-library-fieldset='true'>
  <legend>
    <canvas-drupal-label
        title="{{ legend.title }}"
        {% if prop_link_data %}
          direct_linker_data="{{ prop_link_data }}"
        {% endif  %}
    >
    </canvas-drupal-label>
  </legend>

  {# If the prefix is the weight toggle, it is positioned above the wrapper. #}
  {% if prefix and prefix['weight_toggle'] is defined %}
    {{ prefix }}
  {% endif %}
  <div class="fieldset-wrapper" data-canvas-media-library-fieldset-wrapper='true'>
{#  @todo the designs don't include any uses of the prefix when it isn't the weight,
      but it's here as a comment in the event it needs inclusion later.

    {% if prefix and prefix['weight_toggle'] is not defined %}
      <span class="field-prefix">{{ prefix }}</span>
    {% endif %}
#}
    {% if errors %}
      <div>
        {{ errors }}
      </div>
    {% endif %}

    {% if suffix %}
      {#  The suffix is the "add media" button    #}
      {{ suffix }}
    {% endif %}
    {{ children }}
    {% if description.content %}
      <canvas-box width="100%" className="description" />
        {{ description.content }}
      <canvas-box>
    {% endif %}
  </div>
</fieldset>
