{#
/**
 * @file
 * Vartheme BS5 Starter Kit implementation for views to display rows in a grid.
 *
 * Available variables:
 * - attributes: HTML attributes for the wrapping element.
 * - title: The title of this group of rows.
 * - view: The view object.
 * - rows: The rendered view results.
 * - options: The view plugin style options.
 *   - row_class_default: A flag indicating whether default classes should be
 *     used on rows.
 *   - col_class_default: A flag indicating whether default classes should be
 *     used on data_rows.
 * - items: A list of grid items. Each item contains a list of rows or data_rows.
 *   The order in what comes first (row or data_row) depends on which alignment
 *   type is chosen (horizontal or vertical).
 *   - attributes: HTML attributes for each row or data_row.
 *   - content: A list of data_rows or rows. Each row or data_row contains:
 *     - attributes: HTML attributes for each row or data_row.
 *     - content: The row or data_row contents.
 *
 * @see template_preprocess_views_view_grid()
 */
#}
{% set col_xs = ((col_xs is defined and col_xs != 'none') ? [col_xs] : []) %}
{% set col_sm = ((col_sm is defined and col_sm != 'none') ? [col_sm] : []) %}
{% set col_md = ((col_md is defined and col_md != 'none') ? [col_md] : []) %}
{% set col_lg = ((col_lg is defined and col_lg != 'none') ? [col_lg] : []) %}
{% set col_xl = ((col_xl is defined and col_xl != 'none') ? [col_xl] : []) %}
{% set col_xxl = ((col_xxl is defined and col_xxl != 'none') ? [col_xxl] : []) %}

{% set grid_utility_classes = grid_utility_classes ?? [] %}
{% set column_utility_classes = column_utility_classes ?? [] %}

{%
  set classes = [
    'views-view-grid',
    'grid',
    'row',
    'clearfix'
  ]|merge(grid_utility_classes)
%}

{% if not attributes %}
  {% set attributes = create_attribute() %}
{% endif %}

{% set attributes = attributes.addClass(classes) %}

{% if title %}
  {% include 'vartheme_bs5:heading' with {
      html_tag: 'h3',
      content: title
    }
  %}
{% endif %}

{% if rows is iterable %}
  <div{{ attributes }}>
    {% for data_row in rows %}
      {% set data_row_attributes = create_attribute() %}
      {% set data_row_classes = []|merge(column_utility_classes)|merge(col_xs)|merge(col_sm)|merge(col_md)|merge(col_lg)|merge(col_xl)|merge(col_xxl) %}
      {% set data_row_attributes = data_row_attributes.addClass(data_row_classes) %}
      <div{{ data_row_attributes }}>
        {{ data_row }}
      </div>
    {% endfor %}
  </div>
{% endif %}
