{% extends "base.html" %}

{% block gcontent %}
    {% if form is defined %}
        {{ render_form(form) }}
    {% endif %}

    <div class="panel{% if matches %} panel-info{% else %} panel-warning{% endif %}">
        <div class="panel-heading">
            <h3 class="panel-title">
                {% if matches %} Retrieved {% else %} No {% endif %}
                grounding results for <span class="text-muted">{{ text }}</span>
            </h3>
        </div>
        <div class="panel-body">
            {% if context %}
            <p>
                Using context: <i>{{ context }}</i>
            </p>
            {% endif %}
            <p>
                {% if matches %}
                The table below contains the retrieved Groundings ordered by decreasing
                score. The standard name for the entry is given in the Name column.
                Additional groundings are provided for some entries where a match was
                found to an equivalent term in a namespace different from the primary
                grounding's.
                {% else %}
                No matches were found for the given input. Please try a different
                entity text or modify the context or organism filters.
                {% endif %}
            </p>
        </div>
        {% if matches %}
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th class="text-center">Grounding <i class="far fa-question-circle" title="The identifier the grounded term given as a compact URI (CURIE)."></i></th>
                <th class="text-center">Name <i class="far fa-question-circle" title="The standardized name of the grounded term."></i></th>
                <th class="text-center">Score <i class="far fa-question-circle" title="The score associated with the grounding match, used for ranking matches."></i></th>
                <th class="text-center">Additional groundings <i class="far fa-question-circle" title="Identifiers equivalent to the one appearing under Grounding, formatted as compact URIs (CURIEs)."></i></th>
            </tr>
            </thead>
            <tbody class="text-center">
            {% for match in matches %}
                <tr>
                    {% set match_curie = match.term.get_curie() %}
                    <td>
                        <a class="label label-primary" href="{{ match['url'] }}" target="_blank">
                            {{ match_curie }}
                        </a>&nbsp; <a href="{{ match['url'] }}" target="_blank"><i class="fa fa-external-link-alt"></i></a>
                    </td>
                    <td>{{ match['term']['entry_name'] }}</td>
                    <td class="text-right">{{ match['score'] | round(4) }}</td>
                    <td>
                        {% for xref_curie, xref_url in match.get_grounding_dict().items() %}
                            {% if xref_curie != match_curie %}
                                <a class="label label-info" href="{{ xref_url }}" target="_blank">
                                    {{ xref_curie }}
                                </a>&nbsp; <a href="{{ xref_url }}" target="_blank"><i class="fa fa-external-link-alt"></i></a>
                            {% endif %}
                        {% endfor %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        {% endif %}
    </div>
{% endblock %}
