{#
  Copyright (C) 2020 CERN.
  Copyright (C) 2020 Northwestern University.
  Copyright (C) 2021 New York University.

  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.
#}

{%- set subjects = record.metadata.subjects -%}

{% if subjects %}
  {% set keywords = subjects|rejectattr("scheme")|list %}
  {% if keywords %}
  <dl class="details-list subjects" aria-label="{{ _('Keywords') }}">
    <dt class="hidden">{{ _('Keywords') }}</dt>
    {%- for subject in keywords %}
      <dd>
        <a href='/search?q=metadata.subjects.subject:"{{ subject.subject }}"'
           class="subject"
           title="{{ _('Search results for ') + subject.subject }}"
        >
          {{ subject.subject }}
        </a>
      </dd>
    {%- endfor %}
  </dl>
  {% endif %}

  {%- for scheme, subjects in subjects|selectattr("scheme")|groupby('scheme')|sort(attribute='scheme') %}
  <dl class="details-list subjects" aria-label="{{ _('Subjects') }}">
    <dt class="ui tiny header">{{scheme}}</dt>
    {%- for subject in subjects %}
    <dd>
      <a href='/search?q=metadata.subjects.subject:"{{ subject.subject }}"'
         class="subject"
         title="{{ _('Search results for ') + subject.subject }}"
      >
        {{ subject.subject }}
      </a>
    </dd>
    {%- endfor %}
  </dl>
  {%- endfor %}
{% endif %}
