{#
  Copyright (C) 2020 CERN.
  Copyright (C) 2020 Northwestern University.
  Copyright (C) 2021 TU Wien.

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

{%- from "invenio_app_rdm/records/macros/creatibutors.html" import affiliations_accordion, show_creatibutors %}

<div class="ui grid">
  {% if record.ui.creators and record.ui.creators.creators %}
    <div class="row ui accordion affiliations">
      <div class="sixteen wide mobile twelve wide tablet thirteen wide computer column">
          <dl class="creatibutors" aria-label="{{ _('Creators list') }}">
            <dt class="hidden">{{ _('Creators') }}</dt>
              {{ show_creatibutors(record.ui.creators.creators, show_affiliations=True) }}
          </dl>
      </div>

        {# Todo: get full list of all affiliations (both creators & contributors) e.g.
        record.ui.affiliation and merge to one accordion #}
        {% if record.ui.creators and record.ui.creators.affiliations %}
          {{ affiliations_accordion('creators', record.ui.creators.affiliations)}}
        {% endif %}

    </div>
  {% endif %}

  {% if record.ui.contributors and record.ui.contributors.contributors %}
    <div class="row ui accordion affiliations">
      <div class="sixteen wide mobile twelve wide tablet thirteen wide computer column">

          {%- for group in record.ui.contributors.contributors|groupby('role.title')%}
          <dl class="creatibutors" aria-label="{{ _('Contributors list') }}">
              <dt class="text-muted">{{group.grouper}}{%- if group.list|length > 1 -%}s{%- endif -%}:</dt>
              {{ show_creatibutors(group.list, show_affiliations=True) }}
          </dl>
          {%- endfor %}
      </div>

      {% if record.ui.contributors and record.ui.contributors.affiliations %}
        {{ affiliations_accordion('contributors', record.ui.contributors.affiliations)}}
      {% endif %}

    </div>
  {% endif %}
</div>
