{% extends "base.html" %}
{% block title %}File Gallery - {{ config.BBS_NAME }}{% endblock %}
{% block content %}
<div class="bbs-header">
    <h1><i class="bi bi-folder"></i> File Gallery</h1>
</div>
{% if current_user.is_authenticated %}
<div class="text-end mb-3">
    <a href="{{ url_for('files.upload') }}" class="btn btn-primary"><i class="bi bi-upload"></i> Upload File</a>
</div>
{% endif %}
<div class="card">
    <div class="card-body p-0">
        <table class="table mb-0">
            <thead><tr><th>Filename</th><th>Uploader</th><th>Size</th><th>Type</th><th>Downloads</th><th>Date</th><th>Actions</th></tr></thead>
            <tbody>
                {% for f in uploads %}
                <tr>
                    <td>{{ f.original_filename }}</td>
                    <td><a href="{{ url_for('profile.view_user', username=f.user.username) }}">{{ f.user.username }}</a></td>
                    <td>{{ (f.file_size / 1024) | round(1) }} KB</td>
                    <td>{{ f.mime_type }}</td>
                    <td>{{ f.download_count }}</td>
                    <td>{{ f.created_at.strftime('%Y-%m-%d') }}</td>
                    <td>
                        <a href="{{ url_for('files.download', file_id=f.id) }}" class="btn btn-sm btn-primary"><i class="bi bi-download"></i></a>
                        {% if current_user.is_authenticated and (current_user.id == f.user_id or current_user.is_admin) %}
                        <form method="post" action="{{ url_for('files.delete_file', file_id=f.id) }}" class="d-inline">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <button type="submit" class="btn btn-sm btn-danger"><i class="bi bi-trash"></i></button>
                        </form>
                        {% endif %}
                    </td>
                </tr>
                {% else %}
                <tr><td colspan="7" class="text-center">No files uploaded yet.</td></tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}
