{#
/**
 * @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.
 * - component_prop_name: The name of the component prop this media library widget is for.
 *   Only set when rendered inside the ComponentInstanceForm; absent otherwise.
 *
 * @see template_preprocess_fieldset()
 *
 * @ingroup themeable
 */
#}
{%
  set classes = [
  'js-form-item',
  'form-item',
  'js-form-wrapper',
  'form-wrapper',
]
%}
<drupal-canvas-media-library-fieldset>
  <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>

    <div class="fieldset-wrapper" data-canvas-media-library-fieldset-wrapper='true'>
      {% if prefix %}
        <span class="field-prefix">{{ prefix }}</span>
      {% endif %}

      {% if errors %}
        <div>
          {{ errors }}
        </div>
      {% endif %}
      {#
        Only render default image preview when component_prop_name is set.
        While this template is used for all media library widgets (including those
        in regular entity forms), component_prop_name is only passed to the template
        during Canvas component editing. This ensures the Canvas-specific default
        image preview functionality only appears in the appropriate context.
        @see \Drupal\canvas\Hook\ReduxIntegratedFieldWidgetsHooks::fieldWidgetCompleteFormAlter()
      #}
      {% if component_prop_name %}
        <canvas-default-image-preview prop_name="{{ component_prop_name }}"></canvas-default-image-preview>
      {% endif %}
     {{ children }}
      {% if suffix %}
        {#  The suffix is the "add media" button    #}
        {{ suffix }}
      {% endif %}
      {% if description.content %}
        <canvas-description description="{{ description.content|render|e('html_attr') }}" ></canvas-description>
      {% endif %}
    </div>
</fieldset>
</drupal-canvas-media-library-fieldset>
