{% extends "scanpipe/base.html" %}
{% load humanize %}

{% block title %}ScanCode.io: {{ project.name }} - Relations{% endblock %}

{% block content %}
  <div id="content-header" class="container is-max-widescreen mb-3">
    {% include 'scanpipe/includes/navbar_header.html' %}
    <section class="mx-5">
      <div class="is-flex is-justify-content-space-between">
        {% include 'scanpipe/includes/breadcrumb.html' with linked_project=True current="Relations" %}
        {% include 'scanpipe/includes/search_field.html' with extra_class="is-small" placeholder="Search to/ resources" %}
      </div>
      {% include 'scanpipe/includes/pagination_header_relations.html' %}
      {% include 'scanpipe/includes/filters_breadcrumb.html' with filterset=filter only %}
    </section>
  </div>

  <div id="codebase-relation-list" class="container is-fluid mb-3">
    <table class="table is-bordered is-narrow is-hoverable is-fullwidth">
      {% include 'scanpipe/includes/list_view_thead.html' %}
      <tbody>
        {% for relation in object_list %}
          <tr>
            <td class="break-all">
              {# CAUTION: Avoid relying on get_absolute_url to prevent unnecessary query triggers #}
              <a href="{% url 'resource_detail' project.slug relation.to_resource.path %}#viewer">{{ relation.to_resource.path }}</a>
            </td>
            <td class="break-all">
              <a href="?status={{ relation.to_resource.status }}" class="is-black-link">{{ relation.to_resource.status }}</a>
            </td>
            <td class="break-all">
              <a href="?map_type={{ relation.map_type }}" class="is-black-link">{{ relation.map_type }}</a>
              {% if relation.extra_data.path_score %}
                {{ relation.extra_data.path_score }}
              {% endif %}
              {% if relation.map_type == "path" and relation.to_resource.is_text and relation.from_resource.is_text %}
                <div>
                  <a href="{% url 'resource_diff' project.slug %}?from_path={{ relation.to_resource.path }}&to_path={{ relation.from_resource.path }}" target="_blank">diff</a>
                  {% if relation.extra_data.diff_ratio %}
                    ratio: {{ relation.extra_data.diff_ratio }}
                  {% endif %}
                </div>
              {% endif %}
            </td>
            <td class="break-all">
              <a href="{% url 'resource_detail' project.slug relation.from_resource.path %}#viewer">{{ relation.from_resource.path }}</a>
            </td>
          </tr>
        {% empty %}
          <tr>
            <td colspan="4" class="has-text-centered p-3">
              No Relations found. <a href="?">Clear search and filters</a>
            </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>

    {% if is_paginated %}
      {% include 'scanpipe/includes/pagination.html' with page_obj=page_obj %}
    {% endif %}
  </div>
{% endblock %}