{% extends "base.html" %}
{% block title %}Manage Categories{% endblock %}
{% block content %}
<div class="container mt-4">
    <h1>Manage Categories</h1>
    <form method="POST" class="mb-4">
        {{ form.hidden_tag() }}
        <div class="mb-3">
            {{ form.name.label(class="form-label") }}
            {{ form.name(class="form-control") }}
            {% for error in form.name.errors %}
                <span class="text-danger">{{ error }}</span>
            {% endfor %}
        </div>
        {{ form.submit(class="btn btn-primary") }}
    </form>
    {% if categories %}
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for category in categories %}
                    <tr>
                        <td>{{ category.name }}</td>
                        <td>
                            <form action="{{ url_for('gallery.delete_category', category_id=category.id) }}" method="POST" class="d-inline">
                                <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want to delete {{ category.name }}?')">Delete</button>
                            </form>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>No categories defined yet.</p>
    {% endif %}
</div>
{% endblock %}