{#
Copyright (C) 2020 CERN.

Invenio RDM Records is free software; you can redistribute it and/or modify
it under the terms of the MIT License; see LICENSE file for more details.
#}
{%- if external_resources -%}
<div class="sidebar-container">
  <h2 class="ui small top attached header">{{ _('External resources')}}</h2>
  <div id="external-resource" aria-label="{{ _('External resources') }}" class="ui bottom attached segment rdm-sidebar external resource">

    {# dynamically create the list of external resources #}
    {%- for section, external_resources in external_resources | groupby("content.section") -%}
      <h3 class="ui small header">{{ section }}</h3>
      <ul class="ui relaxed list no-bullet">

        {%- for resource in external_resources -%}

          {%- if resource -%}
            {%- if resource.template -%}
              {# It's up to the template to render the `resource` as it wishes #}
              {%- include resource.template %}
            {%- else -%}
              {# Default rendering #}
              <li class="item">

                {% if resource.content.icon %}
                  <img class="ui image" src="{{ resource.content.icon }}" alt="" width="32">
                {% endif %}

                <div class="content">
                  <a
                    class="header"
                    href="{{resource.content.url}}"
                    target="_blank"
                    rel="noreferrer"
                  >{{ resource.content.title }}
                  </a>

                  {% if resource.content.subtitle %}
                    <p class="description">
                      {{ resource.content.subtitle }}
                    </p>
                  {%- endif -%}

                </div>
              </li>
            {%- endif -%}
          {%- endif -%}
        {%- endfor -%}
      </ul>
    {%- endfor -%}
  </div>
</div>
{%- endif -%}

