{% extends "core/site_base.html" %}
{% block tabtitle %}Data - Simmate{% endblock %}
{% block body %}
    {% simmate_setting "website.lock_data_redistribution" as LOCK_DATA_REDISTRIBUTION %}
    {# Header #}
    <section class="jumbotron text-center py-3">
        <div class="container">
            <h1 class="jumbotron-heading">Data Explorer</h1>
            <p class="lead text-muted">Each option below corresponds to a single table in our database. Select one to explore.</p>
        </div>
    </section>
    <div class="container-fluid mt-4">
        {# Main loop for sections #}
        {% for section_name, datasets in data_config.items %}
            {% if datasets and section_name != "HIDDEN" %}
                {# Section Heading #}
                <h4 class="mt-4 pb-2">{{ section_name }}</h4>
                {# Start of the table for the current section #}
                <div class="table-responsive mb-5">
                    <table class="table table-striped align-middle">
                        <thead class="table-primary">
                            <tr>
                                <th scope="col" style="width: 25%">Dataset</th>
                                <th scope="col" style="width: 15%">Entries (#)</th>
                                <th scope="col" style="width: 60%">Description</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for dataset in datasets %}
                                <tr>
                                    <td>
                                        {% if dataset.is_redistribution_allowed != False or not LOCK_DATA_REDISTRIBUTION %}
                                            {# the extra style is to make the link be the entire cell #}
                                            <a href="{% url 'data_explorer:table' dataset.table_name %}"
                                               style="display: block;
                                                      width: 100%;
                                                      height: 100%;
                                                      padding: 0;
                                                      text-decoration: none">
                                                {{ dataset.html_display_name }} <i class="bi bi-box-arrow-in-right"></i>
                                            </a>
                                        {% else %}
                                            <button type="button"
                                                    class="text-danger text-start border-0 p-0 m-0"
                                                    style="display: block;
                                                           width: 100%;
                                                           height: 100%;
                                                           padding: 0;
                                                           background-color: transparent;
                                                           text-decoration: none"
                                                    data-bs-toggle="popover"
                                                    data-bs-placement="right"
                                                    data-bs-title="Unavailable in Public Website"
                                                    data-bs-content="Simmate does not have permission to redistribute data from this provider. However, you can still use our python package to download the data *directly* from the third-party source. In other words, we can't give you their data ourselves, so you must get the data from the provider and then use simmate locally to work with it. The original data's Terms & Conditions will still apply.">
                                                {{ dataset.html_display_name }} <i class="bi bi-exclamation-triangle"></i>
                                            </button>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% with counts_dict|getitem:dataset.table_name as row_count %}
                                            {% if row_count is not None %}
                                                {{ row_count|floatformat:0|intcomma }}
                                            {% else %}
                                                <span class="text-muted fst-italic">---</span>
                                            {% endif %}
                                        {% endwith %}
                                    </td>
                                    <td>
                                        <small>{{ dataset.html_description_short }}</small>
                                    </td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                {# End of the table for the current section #}
            {% endif %}
        {% endfor %}
    </div>
{% endblock %}
