{#
    Copyright (C) 2020 CERN.
    Copyright (C) 2020 Northwestern 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.
#}
{%- from "invenio_app_rdm/records/macros/creatibutors.html" import show_affiliations, show_creatibutors %}

{% if record.ui.contributors and record.ui.contributors.contributors %}
  {%- for group in record.ui.contributors.contributors|groupby('role.id')%}
  <div class="ui accordion">
    <div class="title">
      <h4><b>{{group.grouper | vocabulary_title('contributors.role', 'role')}}(s)</b></h4>
      {{ show_creatibutors(group.list, show_affiliations=True) }}
      {% if record.ui.contributors.affiliations %}
      <a style="cursor: pointer;" class="dropdown">
        <span class="up ui label small">show affiliations</span>
        <span class="down ui label small">hide affiliations</span>
      </a>
      {% endif %}
    </div>
    {% if record.ui.contributors.affiliations %}
    <div class="content">
      <div class="transition hidden">
        {{ show_affiliations(record.ui.contributors.affiliations) }}
      </div>
    </div>
    {% endif %}
  </div>
  {%- endfor %}
{% endif %}
