{% set tab_items = [] %}
{% set tab_id = 'coach-viewer' %}

{% for tab in layout %}
  {% if loop.index0 in coaches|keys %}
    {% set tab_text %}
      <div class="selected">{{ tab.selected }}</div>
      <div class="unselected">{{ tab.unselected }}</div>
    {% endset %}
    {% set tab_content %}
      <div class="title">{{ coaches[loop.index0].title }}</div>
      {{ coaches[loop.index0].image }}
    {% endset %}
    {% set tab_item = {
      "tbid": 'coach-viewer-' ~ loop.index0,
      "title": tab_text,
      "content": tab_content,
      "first": tab.is_selected,
    } %}

    {% set tab_items = tab_items|merge([tab_item]) %}
  {% endif %}
{% endfor %}

{% if tab_items is not empty %}
<div class="coach-viewer-wrapper">
  {{ pattern('bs-tabs-items', {
    'items': tab_items,
    'pid': tab_id,
  }, 'tbi_h') }}
  <div class="key">
  {% for item in key %}
    <div class="key-item">
      {{ item.image }}
      <div class="text">{{ item.text }}</div>
    </div>
  {% endfor %}
  </div>
</div>
{% endif %}
