<!-- templates/blog/category_management.html -->
{% extends "base.html" %}

{% block content %}
<div class="container mt-5">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2 class="text-primary">مدیریت دسته‌بندی‌ها</h2>
        <a href="{% url 'create-post' %}" class="btn btn-secondary">بازگشت</a>
    </div>
    <div class="card shadow-sm rounded">
        <div class="card-header bg-primary text-white">
            <h5 class="mb-0">لیست دسته‌بندی‌ها</h5>
        </div>
        <div class="card-body p-0">
            <table class="table table-hover mb-0">
                <thead class="table-light">
                    <tr>
                        <th>عنوان</th>
                        <th>والد</th>
                        <th class="text-center">عملیات</th>
                    </tr>
                </thead>
                <tbody>
                    {% for category in categories %}
                    <tr>
                        <td class="align-middle">{{ category.title }}</td>
                        <td class="align-middle">
                            {% if category.parent %}
                                {{ category.parent.title }}
                            {% else %}
                                <span class="text-muted">ندارد</span>
                            {% endif %}
                        </td>
                        <td class="text-center align-middle">
                            <form method="post" style="display: inline;">
                                {% csrf_token %}
                                <input type="hidden" name="category_id" value="{{ category.id }}">
                                <button type="submit" class="btn btn-danger btn-sm">
                                    حذف
                                </button>
                            </form>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
