{% extends "layout/base.html" %}
{% set active_page = "dsreport" %}

{% block title %}Dataset Count Report{% endblock %}

{% block head %}
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js" integrity="sha512-aVKKRRi/Q/YV+4mjoKBsE4x3H+BkegoM/em46NNlCqNTmUYADjBbeNefNxYV7giUp0VxICtqdrbqU7iVaeZNXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.js"></script>
{% endblock %}
{% block content %}
    <div class="panel highlight">
        <h2 class="followed lonesome">Bulk Dataset Counts - {{ (datacube_products | length ) - (hidden_product_list | length) }} Products</h2>
        <div class="">
            Total indexed products: <span class="indexed-product-count">{{ datacube_products | length }}</span>,
            hidden products: <span class="hidden-product-count">{{ hidden_product_list | length }}</span> <br/>
            Download csv for all products dataset count
            <a href="{{ url_for('audit.dsreport_csv') }}" class="badge header-badge">
                csv
                <i class="fa-solid fa-file-csv" aria-hidden="true"></i>
            </a>
        </div>
    </div>
    <div class="panel">
        <p>
            An empty value means "all"
        </p>
        <table id="dscount-table" class="data-table">
                <thead>
                    <tr>
                        <th>Product Name</th>
                        <th>Year</th>
                        <th>Month</th>
                        <th class="numeric">Count</th>
                    </tr>
                </thead>

                <tbody>
                    {% for period, count in products_period_dscount.items() %}
                    {% if period[0] not in hidden_product_list %}
                        <tr id="{{period[0]}}-{{period[1] or ''}}-{{period[2] or ''}}">
                            <td>{{ period[0] }}</td>
                            <td>{{ period[1] or '' }}</td>
                            <td>{{ period[2] | month_name if period[2] else '' }}</td>
                            <td class="numeric {% if count == 0 %}muted{% endif %}">
                                <a href="{{ url_for('pages.product_page',
                                                product_name=period[0],
                                                year=period[1],
                                                month=period[2])
                                    }}">
                                    {{ count }}
                                </a>
                            </td>
                        </tr>
                    {% endif %}
                    {% endfor %}
                </tbody>
        </table>
    </div>
<script>
    $(document).ready( function () {
    $('#dscount-table').DataTable({
        paging: false,
    });
} );
</script>
{% endblock %}
