<table>
    <thead>
        <tr>
            <th class="sortable {% if sort_by == 'name' %}active{% endif %}" hx-get="/packages?page=1&flagged={{ flagged_filter }}&search={{ search }}&sort_by=name&sort_dir={% if sort_by == 'name' and sort_dir == 'asc' %}desc{% else %}asc{% endif %}" hx-target="#packages-table-container" hx-swap="innerHTML">
                {{ t('col_name', request.state.lang) }} <span class="sort-icon">{% if sort_by == 'name' %}{{ '▲' if sort_dir == 'asc' else '▼' }}{% else %}↕{% endif %}</span>
            </th>
            <th>{{ t('col_version', request.state.lang) }}</th>
            <th>{{ t('col_ecosystem', request.state.lang) }}</th>
            <th>{{ t('col_repo', request.state.lang) }}</th>
            <th class="sortable {% if sort_by == 'flagged' %}active{% endif %}" hx-get="/packages?page=1&flagged={{ flagged_filter }}&search={{ search }}&sort_by=flagged&sort_dir={% if sort_by == 'flagged' and sort_dir == 'asc' %}desc{% else %}asc{% endif %}" hx-target="#packages-table-container" hx-swap="innerHTML">
                {{ t('col_flagged', request.state.lang) }} <span class="sort-icon">{% if sort_by == 'flagged' %}{{ '▲' if sort_dir == 'asc' else '▼' }}{% else %}↕{% endif %}</span>
            </th>
            <th class="sortable {% if sort_by == 'total_findings' %}active{% endif %}" hx-get="/packages?page=1&flagged={{ flagged_filter }}&search={{ search }}&sort_by=total_findings&sort_dir={% if sort_by == 'total_findings' and sort_dir == 'asc' %}desc{% else %}asc{% endif %}" hx-target="#packages-table-container" hx-swap="innerHTML">
                {{ t('col_findings', request.state.lang) }} <span class="sort-icon">{% if sort_by == 'total_findings' %}{{ '▲' if sort_dir == 'asc' else '▼' }}{% else %}↕{% endif %}</span>
            </th>
            <th class="sortable {% if sort_by == 'last_scanned_at' %}active{% endif %}" hx-get="/packages?page=1&flagged={{ flagged_filter }}&search={{ search }}&sort_by=last_scanned_at&sort_dir={% if sort_by == 'last_scanned_at' and sort_dir == 'asc' %}desc{% else %}asc{% endif %}" hx-target="#packages-table-container" hx-swap="innerHTML">
                {{ t('col_last_scan', request.state.lang) }} <span class="sort-icon">{% if sort_by == 'last_scanned_at' %}{{ '▲' if sort_dir == 'asc' else '▼' }}{% else %}↕{% endif %}</span>
            </th>
        </tr>
    </thead>
    <tbody>
    {% for p in packages %}
        <tr>
            <td><a href="/packages/{{ p.pkg_name | urlencode }}/{{ p.pkg_ver | urlencode }}">{{ p.pkg_name }}</a></td>
            <td>{{ p.pkg_ver }}</td>
            <td>{{ p.ecosystem }}</td>
            <td>{{ p.repository }}</td>
            <td>{% if p.is_flagged %}<span class="flagged">YES</span>{% else %}<span class="clean">No</span>{% endif %}</td>
            <td>{{ p.findings_sum }}</td>
            <td>{{ p.last_scan.strftime('%Y-%m-%d %H:%M') if p.last_scan }}</td>
        </tr>
    {% endfor %}
    {% if not packages %}
        <tr>
            <td colspan="7" class="empty-state">{{ t('empty_no_packages', request.state.lang) }}</td>
        </tr>
    {% endif %}
    </tbody>
</table>

{% include "_pagination.html" %}
<small style="opacity: 0.5;">{{ t('total_packages', request.state.lang, total) }}</small>
