{#
  Copyright (C) 2020-2021 CERN.
  Copyright (C) 2020-2021 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/detail.html" import show_references, show_add_titles,
show_alternate_identifiers, show_related_identifiers, show_funding, show_dates %}

{% set rights = record.ui.get('rights') %}
{% set active = true %}

<h2 id="record-details-heading">{{ _('Additional details') }}</h2>

{# Tabs #}
<div role="tablist" class="ui top attached tabs menu">
  {% if record.ui.additional_titles %}
    <a role="tab"
       aria-selected="{{ active }}"
       aria-controls="additional-titles"
       data-tab="additional-titles"
       tabindex="0"
       class="{{ 'active' if active }} item"
       id="additional-titles-tab"
    >
      {{ _('Additional titles') }}
    </a>
    {% set active = false %}
  {% endif %}


  {% if metadata.identifiers %}
    <a role="tab"
       aria-selected="{{ active }}"
       aria-controls="identifiers"
       data-tab="identifiers"
       tabindex="0"
       class="{{ 'active' if active }} item"
       id="identifiers-tab"
    >
      {{ _('Identifiers') }}
    </a>
    {% set active = false %}
  {% endif %}

  {% if record.ui.related_identifiers %}
    <a role="tab"
       aria-selected="{{ active }}"
       aria-controls="related-works"
       data-tab="related-works"
       tabindex="0"
       class="{{ 'active' if active }} item"
       id="related-works-tab"
    >
      {{ _('Related works') }}
    </a>
    {% set active = false %}
  {% endif %}

  {% if rights %}
    <a role="tab"
       aria-selected="{{ active }}"
       aria-controls="licences"
       data-tab="licences"
       tabindex="0"
       class="{{ 'active' if active }} item"
       id="licences-tab"
    >
      {{ _('Licences') }}
    </a>
    {% set active = false %}
  {% endif %}

  {% if metadata.funding %}
    <a role="tab"
       aria-selected="{{ active }}"
       aria-controls="funding"
       data-tab="funding"
       tabindex="0"
       class="{{ 'active' if active }} item"
       id="funding-tab"
    >
      {{ _('Funding') }}
    </a>
    {% set active = false %}
  {% endif %}

  {% if record.ui.dates %}
    <a role="tab"
       aria-selected="{{ active }}"
       aria-controls="dates"
       data-tab="dates"
       tabindex="0"
       class="{{ 'active' if active }} item"
       id="dates-tab"
    >
      {{ _('Dates') }}
    </a>
    {% set active = false %}
  {% endif %}

  {% if metadata.references %}
    <a role="tab"
       aria-selected="{{ active }}"
       aria-controls="references"
       data-tab="references"
       tabindex="0"
       class="{{ 'active' if active }} item"
       id="references-tab"
    >
      {{ _('References') }}
    </a>
  {% endif %}
</div>

{# Content #}
{% set active = true %}

{% if record.ui.additional_titles %}
  <div role="tabpanel"
       class="ui bottom attached {{ 'active' if active }} tab segment"
       data-tab="additional-titles"
       aria-labelledby="additional-titles-tab"
       id="additional-titles"
       hidden="{{ not active }}"

  >
    <dl class="details-list">
      {{ show_add_titles(record.ui.additional_titles) }}
    </dl>
  </div>
  {% set active = false %}
{% endif %}

{% if metadata.identifiers %}
  <div role="tabpanel"
       class="ui bottom attached {{ 'active' if active }} tab segment"
       data-tab="identifiers"
       aria-labelledby="identifiers-tab"
       id="identifiers"
       hidden="{{ not active }}"
  >
    <dl class="details-list">
      {{ show_alternate_identifiers(metadata.identifiers) }}
    </dl>
  </div>
  {% set active = false %}
{% endif %}

{% if record.ui.related_identifiers %}
  <div role="tabpanel"
       class="ui bottom attached {{ 'active' if active }} tab segment"
       data-tab="related-works"
       aria-labelledby="related-works-tab"
       id="related-works"
       hidden="{{ not active }}"
  >
    <dl class="details-list">
      {{ show_related_identifiers(record.ui.related_identifiers) }}
    </dl>
  </div>
  {% set active = false %}
{% endif %}

{% if rights %}
  <div role="tabpanel"
       class="ui bottom attached {{ 'active' if active }} tab segment"
       data-tab="licences"
       aria-labelledby="licences-tab"
       id="licences"
       hidden="{{ not active }}"
  >
    <dl class="details-list">
    {%- include "invenio_app_rdm/records/details/licenses.html" %}
    </dl>
  </div>
  {% set active = false %}
{% endif %}

{% if metadata.funding %}
  <div role="tabpanel"
       class="ui bottom attached {{ 'active' if active }} tab segment"
       data-tab="funding"
       aria-labelledby="funding-tab"
       id="funding"
       hidden="{{ not active }}"
  >
    <dl class="details-list">
      {{ show_funding(metadata.funding) }}
    </dl>
  </div>
  {% set active = false %}
{% endif %}

{% if record.ui.dates %}
  <div role="tabpanel"
       class="ui bottom attached {{ 'active' if active }} tab segment"
       data-tab="dates"
       aria-labelledby="dates-tab"
       id="dates"
       hidden="{{ not active }}"
  >
    <dl class="details-list">
      {{ show_dates(record.ui.dates) }}
    </dl>
  </div>
  {% set active = false %}
{% endif %}

{% if metadata.references %}
  <div role="tabpanel"
       class="ui bottom attached {{ 'active' if active }} tab segment"
       data-tab="references"
       aria-labelledby="references-tab"
       id="references"
       hidden="{{ not active }}"
  >
    <dl class="details-list">
      {{ show_references(metadata.references) }}
    </dl>
  </div>
{% endif %}
