{#
  Copyright (C) 2020 CERN.
  Copyright (C) 2020 Northwestern University.
  Copyright (C) 2021 TU Wien.
  Copyright (C) 2022 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.
#}

{%- if config.get("APP_RDM_RECORD_EXPORTERS") -%}
  {# if no export formats are specified, don't bother showing the box #}
  <div class="sidebar-container">
    <h2 class="ui medium top attached header mt-0">{{ _('Export') }}</h2>
    <div id="export-record" class="ui segment bottom attached exports rdm-sidebar">

      {# dynamically create the list of export formats #}
      {% set formats = [] %}

      {%- for fmt, val in config.get("APP_RDM_RECORD_EXPORTERS", {}).items() -%}
        {%- set name = val.get("name", fmt) -%}
        {% if is_preview %}
          {%- set export_url = url_for('invenio_app_rdm_records.record_export', pid_value=record.id, export_format=fmt, preview=1) -%}
        {% else %}
          {%- set export_url = url_for('invenio_app_rdm_records.record_export', pid_value=record.id, export_format=fmt) -%}
        {% endif %}

        {% set formats = formats.append({ 'name': name, 'export_url': export_url }) %}
      {%- endfor -%}

      <div id="recordExportDownload" data-formats='{{ formats | tojson }}'></div>
    </div>
  </div>
{%- endif -%}
