{extends file=$layout}

{block name='content'}
  <section id="main" class="brands-page">

    {* Regroupe les marques par initiale (une seule passe, réutilisée par
       l'en-tête, l'index A→Z et la liste). *}
    {assign var='total_brands' value=$brands|count}
    {assign var='brands_by_letter' value=[]}
    {foreach from=$brands item=brand}
      {assign var='firstLetter' value=$brand.name|substr:0:1|upper}
      {if !isset($brands_by_letter.$firstLetter)}
        {assign var=tmp value=[]}
        {assign var='brands_by_letter' value=$brands_by_letter|@array_merge:[$firstLetter => $tmp]}
      {/if}
      {assign var=tmp value=$brands_by_letter.$firstLetter}
      {append var=tmp value=$brand}
      {assign var='brands_by_letter' value=$brands_by_letter|@array_merge:[$firstLetter => $tmp]}
    {/foreach}

    {block name='brand_header'}
      <header class="brand-hero">
        <p class="eyebrow">Boutique</p>
        <h1 class="display">Nos marques</h1>
        {if $total_brands}<p class="brand-hero-sub">{$total_brands} marque{if $total_brands > 1}s{/if} partenaires</p>{/if}
      </header>

      {if $brands_by_letter|@count}
        <nav class="brand-index" aria-label="Index alphabétique des marques">
          {foreach from=$brands_by_letter key=letter item=_group}
            <a href="#brand-{strtolower($letter)}">{$letter}</a>
          {/foreach}
        </nav>
      {/if}
    {/block}

    {block name='brand_list'}
      {foreach from=$brands_by_letter key=letter item=brands}
        <section id="brand-{strtolower($letter)}" class="brand-group">
          <h2 class="brand-group-letter"><span>{$letter}</span></h2>
          <ul class="brand-list">
            {foreach from=$brands item=brand}
              {include file='catalog/_partials/miniatures/brand.tpl' brand=$brand}
            {/foreach}
          </ul>
        </section>
      {/foreach}
    {/block}

  </section>
{/block}
