{% assign components = site.components | sort: 'title' %}
<section class="aside-module grid__item one-whole lap-one-half">
  <div class='brand-logo-container section'>
    {% if page.logo %}
      <img src='/images/supported_brands/{{ page.logo }}' />
    {% endif %}
  </div>

  {% assign file_parts = page.url | split: '/' | last | split: '.' %}

  {% if file_parts.size == 2 %}
    {% assign is_platform = true %}
    {% assign imp_name = file_parts[1] %}
    {% assign parent_name = file_parts[0] %}
    {% assign parent_url = parent_name | prepend: '/components/' | append: '/' %}
    {% assign parent_component = components | where: 'url', parent_url | first %}
  {% else %}
    {% assign is_platform = false %}
    {% assign imp_name = file_parts | first %}
  {% endif %}

  {% if is_platform and parent_name != 'sensor' %}
    <div class='section'>
      This is a platform for
      <a href='{{parent_component.url}}'>the {{parent_component.title}} component</a>.
    </div>

  {% elsif is_platform == false and imp_name != 'ifttt' %}

    {% assign platforms_found = false %}
    {% for component in components %}
      {% if component.url != page.url %}
        {% assign comp_imp_name = component.url | split: '/' | last | split: '.' | first %}
        {% if comp_imp_name == imp_name %}
          {% unless platforms_found %}
            {% assign platforms_found = true %}
            <h1 class='title delta'>Platforms</h1>
            <ul class='divided'>
          {% endunless %}
          <li><a href='{{component.url}}'>
            {{component.title}}
          </a></li>
        {% endif %}
      {% endif %}
    {% endfor %}

    {% if platforms_found %}
      </ul>
    {% endif %}

  {% endif %}


  {% assign related_found = false %}
  {% for component in components %}
    {% if component.url != page.url %}
      {% assign comp_file_parts = component.url | split: '/' | last | split: '.' %}
      {% if comp_file_parts.size == 2 %}
        {% assign comp_imp_name = comp_file_parts | last %}
      {% else %}
        {% assign comp_imp_name = comp_file_parts | first %}
      {% endif %}

      {% if comp_imp_name == imp_name %}
        {% unless related_found %}
          {% assign related_found = true %}
          <div class='section'>
          <h1 class='title delta'>Related components</h1>
          <ul class='divided'>
        {% endunless %}
        <li><a href='{{component.url}}'>
          {{component.title}}
        </a></li>
      {% endif %}
    {% endif %}
  {% endfor %}

  {% if related_found %}
    </ul>
    </div>
  {% endif %}



  {% if page.ha_category %}
    <div class='section'>
    <h1 class="title delta">Category {{page.ha_category}}</h1>
    <ul class='divided'>
    {% for component in components %}
      {% if component.ha_category == page.ha_category %}
        <li>
          {% if component.url == page.url %}
            {{component.title}}
          {% else %}
            <a href='{{component.url}}'>{{component.title}}</a>
          {% endif %}
        </li>
      {% endif %}
    {% endfor %}
    </ul>
    </div>
  {% endif %}
</section>
