{#
    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.
#}
{%- 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.title')%}
  <div class="ui accordion creatibutors">
    <div class="title">
      <h2 class="header">{{group.grouper}}(s)</h2>
      {{ 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 %}
