{% extends "base.html" %}

{% import "bootstrap5/utils.html" as bs_util %}
{% import "utils.html" as util %}

{% block title %}SeMRA{% endblock %}


{% macro count_column(counter, key, icon) -%}
<div class="col">
    {% set count, suffix = format_number(counter[key]) %}
    <i class="fa fa-{{ icon }}"></i>
    <h2 style="margin-bottom: 0">{{ count }}{{ suffix }}</h2>
    <p class="count-text ">{{ key }}</p>
</div>
{% endmacro %}

{% macro do_table(counter, label, is_concept=False, has_names=False) %}
<div class="card-body">
    <h6>{{ label }} Summary</h6>
</div>
<table class="table">
    <thead>
    <tr>
        <th>{{ label }}</th>
        {% if has_names %}
        <th>Name</th>
        {% endif %}
        <th>Count</th>
    </tr>
    </thead>
    <tbody>
    {% for key, count in counter.most_common() %}
    <tr>
        <td><code>
            {%- if is_concept -%}
            {% if has_names %}
            <a href="{{ url_for('view_concept', curie=key[0]) }}">{{ key[0] }}</a>
            {% else %}
            FAILURE!
            <a href="{{ url_for('view_concept', curie=key) }}">{{ key }}</a>
            {% endif %}
            {%- else -%}
            {% if has_names %}{{ key[0] }}{% else %}{{ key }}{% endif %}
            {%- endif -%}
        </code></td>
        {% if has_names %}
        <td>{{ key[1] }}</td>
        {% endif %}
        <td align="right">{{ "{:,}".format(count) }}</td>
    </tr>
    {% endfor %}
    </tbody>
</table>
{% endmacro %}

{% block content %}
<div class="container" style="margin-top: 50px; margin-bottom: 50px">
    {{ bs_util.render_messages(dismissible=True, container=False) }}
    <div class="row justify-content-md-center">
        <div class="col-8">
            <div class="card">
                <div class="card-body">
                    <h5 class="card-title">
                        Semantic Reasoning Assembler
                    </h5>
                    <div class="row text-center stats" style="padding-top: 1em; padding-bottom: 1em;">
                        {{ count_column(node_counter, "Concepts", "dna") }}
                        {{ count_column(node_counter, "Equivalence Classes", "dna") }}
                        {{ count_column(node_counter, "Mappings", "arrows-alt") }}
                        {{ count_column(node_counter, "Evidences", "book") }}
                        {{ count_column(node_counter, "Mapping Sets", "puzzle-piece") }}
                    </div>
                    <p>See the <a href="/docs">API Documentation</a>.</p>
                    <h6>Mapping Sets</h6>
                </div>
                <table class="table">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Version</th>
                        <th>License</th>
                        <th>Confidence</th>
                        <th>Evidences</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>Inferred</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td align="right">{{ "{:,}".format(evidence_type_counter["reasoned"]) }}</td>
                    </tr>
                    {% for mapping_set in mapping_sets %}
                    <tr>
                        <td><a href="{{ url_for('view_mapping_set', curie=mapping_set.curie) }}">{{ mapping_set.name
                            }}</a></td>
                        <td>{{ mapping_set.version }}</td>
                        <td>{% if mapping_set.license %}{{ mapping_set.license }}{% endif %}</td>
                        <td>{{ mapping_set.confidence }}</td>
                        <td align="right">{{ "{:,}".format(mapping_set_counter[mapping_set.curie]) }}</td>
                    </tr>
                    {% endfor %}
                    </tbody>
                </table>
                {{ do_table(evidence_type_counter, "Evidence Type") }}
                {{ do_table(predicate_counter, "Predicate") }}
                {{ do_table(justification_counter, "Mapping Justification") }}
                {{ do_table(prefix_counter, "Prefix", has_names=True) }}
                {{ do_table(author_counter, "Author", has_names=True) }}
                {{ do_table(high_matches_counter, "Potential Data Issues", is_concept=True, has_names=True) }}

                <div class="card-body">
                    <h6>Example Mappings</h6>
                </div>
                {{ util.mapping_table(example_mappings) }}
            </div>
        </div>
    </div>
</div>
{% endblock %}
