{#
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: 2025 The Linux Foundation
#}

{#- Section: Repositories (HTML) -#}
{#- Renders the repositories section with repository activity tables -#}
{#-
    Context required:
        - repositories (dict): Repository data and counts
        - config (dict): Configuration options

    This section displays:
        - All repositories table with activity metrics
        - Matches production format: 7 columns, "Gerrit Project", "Days Inactive" as integer
-#}

{% if config.include_sections.repositories and repositories.has_repositories %}
<section id="repositories" class="report-section repositories-section">
    <h2>📊 {{ project.terminology.repositories }}</h2>

    <p>All data in this table represents all-time/current repository statistics, not time-bound metrics.</p>

    <table class="dt-enabled">
        <thead>
            <tr>
                <th>{{ project.terminology.repository }}</th>
                <th>Commits</th>
                <th>LOC</th>
                <th>Contributors</th>
                <th>Days Inactive</th>
                <th>Last Commit Date</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            {% for repo in repositories.all %}
            <tr>
                <td>
                    {% if repo.gerrit_url %}
                        <a href="{{ repo.gerrit_url }}" target="_blank">{{ repo.gerrit_project | default('Unknown') }}</a>
                    {% else %}
                        {{ repo.gerrit_project | default('Unknown') }}
                    {% endif %}
                </td>
                <td>{{ repo.total_commits | default(0) }}</td>
                <td>{{ repo.total_loc | default(0) }}</td>
                <td>{{ repo.unique_contributors | default(0) }}</td>
                <td>{{ repo.days_inactive | default(0) }}</td>
                <td>{{ repo.last_commit_date | default('N/A') }}</td>
                <td>{{ repo.activity_status | default('🛑') }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    <p><strong>Total:</strong> {{ repositories.all_count }} repositories</p>

</section>
{% endif %}
