{% comment %}
  Renders a breadcrumb

  Accepts:
  - style: {String} Modified style to use for breadcrumb--current text

  Usage:
  {% render 'breadcrumb' %}
{% endcomment %}

{% liquid
  if section.settings.breadcrumb_hide
    assign display = 'none'
  else
    assign display = 'block'
  endif
  if section.settings.breadcrumb_hide_mobile
    assign display_mobile = 'none'
  else
    assign display_mobile = 'block'
  endif
%}

{%- unless template == 'index' or template == 'cart' or template == 'list-collections' or template == '404' -%}
  {%- assign t = template | split: '.' | first -%}
  <nav class='breadcrumb' style='--display-mobile:{{ display_mobile }}' role='navigation' aria-label='breadcrumb'>
    <ol class='breadcrumb__list' style='--justify:{{ section.settings.breadcrumb_align | default: 'center' }}'>
      <li class='breadcrumb__item'>
        <a class='breadcrumb__link' href='/'>{{ 'general.home' | t }}</a>
        <span class='breadcrumb__separator'>
          {% render 'icon', name: 'arrow-right', icon_size: '8' %}
        </span>
      </li>
      {%- case t -%}
        {%- when 'page' -%}
          <li class='breadcrumb__item'>
            <a class='breadcrumb__link' href='{{ page.url }}' aria-current='page'>{{ page.title }}</a>
            <span class='breadcrumb__separator'>
              {% render 'icon', name: 'arrow-right', icon_size: '8' %}
            </span>
          </li>
        {%- when 'product' -%}
          {%- if collection.url -%}
            <li class='breadcrumb__item'>
              {{ collection.title | link_to: collection.url }}
              <span class='breadcrumb__separator'>
                {% render 'icon', name: 'arrow-right', icon_size: '8' %}
              </span>
            </li>
          {%- endif -%}
          <li class='breadcrumb__item breadcrumb__item--current' style='--display:{{ display }}'>
            <a
              class='breadcrumb__link breadcrumb--current breadcrumb--{{ style }}'
              href='{{ product.url }}'
              aria-current='page'
            >
              {{- product.title -}}
            </a>
          </li>
        {%- when 'collection' and collection.handle -%}
          {%- if current_tags -%}
            <li class='breadcrumb__item'>
              {{ collection.title | link_to: collection.url }}
              <span class='breadcrumb__separator'>
                {% render 'icon', name: 'arrow-right', icon_size: '8' %}
              </span>
            </li>
            <li class='breadcrumb__item breadcrumb__item--current' style='--display:{{ display }}'>
              {%- capture tag_url -%}{{ collection.url }}/{{ current_tags | join: "+" }}{%- endcapture -%}
              <a
                class='breadcrumb__link breadcrumb--current breadcrumb--{{ style }}'
                href='{{ tag_url }}'
                aria-current='page'
              >
                {{- current_tags | join: ' + ' -}}
              </a>
            </li>
          {%- else -%}
            <li class='breadcrumb__item breadcrumb__item--current' style='--display:{{ display }}'>
              <a
                class='breadcrumb__link breadcrumb--current breadcrumb--{{ style }}'
                style='--display:{{ display }}'
                href='{{ collection.url }}'
                aria-current='page'
              >
                {{- collection.title -}}
              </a>
            </li>
          {%- endif -%}
        {%- when 'blog' -%}
          {%- if current_tags -%}
            <li class='breadcrumb__item'>
              {{ blog.title | link_to: blog.url }}
              <span class='breadcrumb__separator'>
                {% render 'icon', name: 'arrow-right', icon_size: '8' %}
              </span>
            </li>
            <li class='breadcrumb__item breadcrumb__item--current' style='--display:{{ display }}'>
              {%- capture tag_url -%}{{ blog.url }}/tagged/{{ current_tags | join: "+" }}{%- endcapture -%}
              <a
                class='breadcrumb__link breadcrumb--current breadcrumb--{{ style }}'
                href='{{ tag_url }}'
                aria-current='page'
              >
                {{- current_tags | join: ' + ' -}}
              </a>
            </li>
          {%- else -%}
            <li class='breadcrumb__item breadcrumb__item--current' style='--display:{{ display }}'>
              <a
                class='breadcrumb__link breadcrumb--current breadcrumb--{{ style }}'
                href='{{ blog.url }}'
                aria-current='page'
              >
                {{- blog.title -}}
              </a>
            </li>
          {%- endif -%}
        {%- when 'article' -%}
          <li class='breadcrumb__item'>
            {{ blog.title | link_to: blog.url }}
            <span class='breadcrumb__separator'>
              {% render 'icon', name: 'arrow-right', icon_size: '8' %}
            </span>
          </li>
          <li class='breadcrumb__item breadcrumb__item--current' style='--display:{{ display }}'>
            <a
              class='breadcrumb__link breadcrumb--current breadcrumb--{{ style }}'
              href='{{ article.url }}'
              aria-current='page'
            >
              {{- article.title -}}
            </a>
          </li>
        {%- else -%}
          <li class='breadcrumb__item breadcrumb__item--current' style='--display:{{ display }}'>
            <a
              class='breadcrumb__link breadcrumb--current breadcrumb--{{ style }}'
              href='{{ request.path }}'
              aria-current='page'
            >
              {{- page_title -}}
            </a>
          </li>
      {%- endcase -%}
    </ol>
  </nav>
{%- endunless -%}
