{% comment %}
Copyright (C) 2017-2019  The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
{% endcomment %}

{% load swh_templatetags %}

{% if swh_ids %}

  <div id="swh-identifiers" style="display: none;">
    {% if swh_ids|length > 1 %}
      <a id="right-handle" class="handle ui-slideouttab-handle ui-slideouttab-handle-rounded"><i class="fa fa-link fa-rotate-90 fa-fw"></i>Permalinks</a>
    {% else %}
      <a id="right-handle" class="handle ui-slideouttab-handle ui-slideouttab-handle-rounded"><i class="fa fa-link fa-rotate-90 fa-fw"></i>Permalink</a>
    {% endif %}
    <div id="swh-identifiers-content">
      <p>
        To reference or cite the objects present in the Software Heritage archive, permalinks based on <a href="https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html">persistent identifiers</a>
        must be used instead of copying and pasting the url from the address bar of the browser (as there is no guarantee the current URI
        scheme will remain the same over time).
        <br/>
        <br/>
        Select below a type of object currently browsed in order to display its associated persistent identifier and permalink.
      </p>

      <ul class="nav nav-pills ml-auto p-2">
        {% for swh_id in swh_ids %}
          {% if forloop.first %}
            <li class="nav-item">
              <a class="nav-link active" href="#swh-id-tab-{{ swh_id.object_type }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
                <i class="{{ swh_id.object_icon }} fa-fw"></i>{{ swh_id.object_type }}
              </a>
            </li>
          {% else %}
            <li class="nav-item">
              <a class="nav-link" href="#swh-id-tab-{{ swh_id.object_type }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
                  <i class="{{ swh_id.object_icon }} fa-fw"></i>{{ swh_id.object_type }}
              </a>
            </li>
          {% endif %}
        {% endfor %}
      </ul>

      <div class="tab-content">
        {% for swh_id in swh_ids %}
          {% if forloop.first %}
            <div class="tab-pane active" id="swh-id-tab-{{ swh_id.object_type }}">
          {% else %}
            <div class="tab-pane" id="swh-id-tab-{{ swh_id.object_type }}">
          {% endif %}
            <div class="card">
              <div class="card-body swh-id-ui">
                {% if snapshot_context and snapshot_context.origin_info %}
                  <img class="swh-badge swh-badge-origin" src="{% url 'swh-badge' 'origin' snapshot_context.origin_info.url %}"
                       onclick="swh.webapp.showBadgeInfoModal('origin', '{{ snapshot_context.origin_info.url }}')"
                       title="Click to display badge integration info">
                {% endif %}
                <img class="swh-badge swh-badge-{{ swh_id.object_type }}" src="{% url 'swh-badge' swh_id.object_type swh_id.object_id %}"
                     onclick="swh.webapp.showBadgeInfoModal('{{ swh_id.object_type }}', $(this).parent().find('.swh-id').text())"
                     title="Click to display badge integration info">
                <pre><a class="swh-id" id="{{ swh_id.swh_id }}" href="{{ swh_id.swh_id_url }}">{{ swh_id.swh_id }}</a></pre>
                {% if swh_id.show_options %}
                  <div class="float-left">
                    <form id="swh-id-options">
                      {% if snapshot_context and snapshot_context.origin_info %}
                        <div class="form-check swh-id-option">
                          <input class="form-check-input swh-id-option-origin" value="option-origin" type="checkbox"
                                id="swh-id-option-origin-{{ swh_id.object_type }}"
                                data-swh-origin="{{ snapshot_context.origin_info.url }}"
                                onclick="swh.browse.swhIdOptionOriginToggled(event)">
                          <label class="form-check-label" for="swh-id-option-origin-{{ swh_id.object_type }}">Add origin info</label>
                        </div>
                      {% endif %}
                      {% if swh_id.object_type == 'content' %}
                        <div class="form-check swh-id-option">
                          <input class="form-check-input swh-id-option-lines" value="option-lines" type="checkbox"
                                id="swh-id-option-lines-{{ swh_id.object_type }}"
                                onclick="swh.browse.swhIdOptionLinesToggled(event)">
                          <label class="form-check-label" for="swh-id-option-lines-{{ swh_id.object_type }}">Add selected lines info</label>
                        </div>
                      {% endif %}
                    </form>
                  </div>
                {% endif %}
                <div class="float-right">
                  <button type="button" class="btn btn-default btn-sm btn-swh-id-copy"
                          title="Copy persistent identifier to clipboard">
                    <i class="fa fa-clipboard fa-fw" aria-hidden="true"></i>Copy identifier
                  <button type="button" class="btn btn-default btn-sm btn-swh-id-url-copy"
                          title="Copy url resolving the persistent identifier to clipboard">
                    <i class="fa fa-clipboard fa-fw" aria-hidden="true"></i>Copy permalink
                  </button>
                </div>
              </div>
            </div>
          </div>
        {% endfor %}
      </div>
    </div>
  </div>
{% endif %}
