{% extends "layouts/admin.twig" %}

{% block title %}{{ ta.media|default('Media') }} - {{ ta.admin_title|default('CodePress Admin') }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-images"></i> {{ ta.media|default('Media') }}</h2>
    <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="collapse" data-bs-target="#uploadForm">
        <i class="bi bi-cloud-upload"></i> {{ ta.upload|default('Upload') }}
    </button>
</div>

<div class="collapse mb-4" id="uploadForm">
    <div class="card shadow-sm">
        <div class="card-body">
            <form method="POST" action="/admin/media?dir={{ subdir|url_encode }}" enctype="multipart/form-data">
                <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
                <div class="mb-3">
                    <label for="file" class="form-label">{{ ta.select_files|default('Bestanden selecteren') }}</label>
                    <input type="file" class="form-control" id="file" name="file[]" multiple accept="image/*,video/*,audio/*">
                </div>
                <button type="submit" class="btn btn-success">
                    <i class="bi bi-cloud-upload"></i> {{ ta.upload|default('Uploaden') }}
                </button>
            </form>
        </div>
    </div>
</div>

<div class="card shadow-sm">
    <div class="card-body">
        <div class="row g-4">
            {% for item in items %}
                {% if not item.is_dir and item.extension in ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'] %}
                <div class="col-md-3">
                    <div class="card shadow-sm">
                        <img src="/content/{{ item.path|url_encode }}" class="card-img-top" alt="{{ item.name }}">
                        <div class="card-body p-2">
                            <p class="card-text small text-muted text-truncate">{{ item.name }}</p>
                        </div>
                    </div>
                </div>
                {% endif %}
            {% else %}
            <div class="col-12">
                <p class="text-muted text-center">{{ ta.no_media|default('Geen media bestanden gevonden.') }}</p>
            </div>
            {% endfor %}
        </div>
    </div>
</div>
{% endblock %}