{% extends "moderation/admin/base.html" %}
{% load static %}

{% block moderation_content %}
<div class="submission-list">
    <h1 class="mb-6 text-2xl font-bold">Photo Submissions</h1>
    
    <div class="mb-6 filters">
        <form method="get" class="flex space-x-4">
            <select name="status" class="form-select">
                <option value="">All Statuses</option>
                <option value="PENDING" {% if request.GET.status == 'PENDING' %}selected{% endif %}>Pending</option>
                <option value="APPROVED" {% if request.GET.status == 'APPROVED' %}selected{% endif %}>Approved</option>
                <option value="REJECTED" {% if request.GET.status == 'REJECTED' %}selected{% endif %}>Rejected</option>
                <option value="AUTO_APPROVED" {% if request.GET.status == 'AUTO_APPROVED' %}selected{% endif %}>Auto Approved</option>
            </select>
            <button type="submit" class="btn btn-primary">Filter</button>
        </form>
    </div>

    {% for submission in submissions %}
    <div class="submission-card">
        <div class="submission-header">
            <div>
                <h3 class="text-lg font-semibold">
                    Photo for {{ submission.content_type.name }}: {{ submission.content_object }}
                </h3>
                <div class="submission-meta">
                    Submitted by {{ submission.user.username }} on {{ submission.submitted_at|date:"M d, Y H:i" }}
                </div>
            </div>
            <div class="status-badge status-{{ submission.status|lower }}">
                {{ submission.get_status_display }}
            </div>
        </div>

        <div class="submission-details">
            <div class="mb-4 photo-preview">
                <img src="{{ submission.photo.url }}" alt="Submitted photo" class="max-w-lg rounded">
            </div>
            {% if submission.caption %}
            <div class="mb-2">
                <strong>Caption:</strong> {{ submission.caption }}
            </div>
            {% endif %}
            {% if submission.date_taken %}
            <div class="mb-2">
                <strong>Date Taken:</strong> {{ submission.date_taken|date:"M d, Y" }}
            </div>
            {% endif %}
        </div>

        {% if submission.status == 'PENDING' %}
        <form method="post" class="mt-4">
            {% csrf_token %}
            <input type="hidden" name="submission_id" value="{{ submission.id }}">
            <div class="review-notes">
                <label class="block mb-2">Review Notes:</label>
                <textarea name="review_notes" rows="3" class="w-full"></textarea>
            </div>
            <div class="action-buttons">
                <button type="submit" name="action" value="approve" class="btn-approve">
                    Approve
                </button>
                <button type="submit" name="action" value="reject" class="btn-reject">
                    Reject
                </button>
            </div>
        </form>
        {% else %}
        <div class="mt-4">
            <strong>Reviewed by:</strong> {{ submission.reviewed_by.username }}
            <br>
            <strong>Review Notes:</strong> {{ submission.review_notes }}
        </div>
        {% endif %}
    </div>
    {% empty %}
    <div class="py-8 text-center text-gray-500">
        No submissions found.
    </div>
    {% endfor %}

    {% if is_paginated %}
    <div class="mt-6 pagination">
        <span class="step-links">
            {% if page_obj.has_previous %}
                <a href="?page=1">&laquo; first</a>
                <a href="?page={{ page_obj.previous_page_number }}">previous</a>
            {% endif %}

            <span class="current">
                Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
            </span>

            {% if page_obj.has_next %}
                <a href="?page={{ page_obj.next_page_number }}">next</a>
                <a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
            {% endif %}
        </span>
    </div>
    {% endif %}
</div>
{% endblock %}
