{% extends 'admin/base.html.twig' %}

{% block title %}Kategoriler{% endblock %}
{% block page_title %}Kategori Yonetimi{% endblock %}

{% block body %}
    {# Actions bar #}
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between mb-6 gap-4">
        <div class="flex items-center gap-3">
            <a href="{{ path('admin_category_create') }}" class="btn-primary">
                <i class="fas fa-plus mr-2"></i> Yeni Kategori
            </a>
        </div>
    </div>

    {# Categories table #}
    <div class="card overflow-hidden">
        <div class="overflow-x-auto">
            <table class="table">
                <thead>
                    <tr>
                        <th class="w-12">Renk</th>
                        <th>Baslik</th>
                        <th>Slug</th>
                        <th>Ust Kategori</th>
                        <th>Durum</th>
                        <th>Haber Sayisi</th>
                        <th class="w-24">Islem</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-200 bg-white">
                    {% for category in categories %}
                        <tr>
                            <td>
                                {% if category.color %}
                                    <div class="w-6 h-6 rounded-full border border-gray-200" style="background-color: {{ category.color }};"></div>
                                {% else %}
                                    <div class="w-6 h-6 rounded-full border border-gray-200 bg-gray-100"></div>
                                {% endif %}
                            </td>
                            <td>
                                <div class="flex items-center gap-2">
                                    {% if category.icon %}
                                        <i class="{{ category.icon }} text-gray-500"></i>
                                    {% endif %}
                                    <a href="{{ path('admin_category_edit', {id: category.id}) }}"
                                       class="font-medium text-gray-900 hover:text-primary-600">
                                        {{ category.title }}
                                    </a>
                                    {% if category.isDefault %}
                                        <span class="inline-flex items-center rounded-full bg-blue-50 px-2 py-0.5 text-xs font-medium text-blue-700">
                                            Varsayilan
                                        </span>
                                    {% endif %}
                                </div>
                            </td>
                            <td class="text-gray-500 text-sm">
                                {{ category.slug }}
                            </td>
                            <td>
                                {% if category.parent %}
                                    <span class="badge-info">{{ category.parent.title }}</span>
                                {% else %}
                                    <span class="text-gray-400">-</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if category.status == 'active' %}
                                    <span class="badge-success">Aktif</span>
                                {% else %}
                                    <span class="badge-gray">Pasif</span>
                                {% endif %}
                            </td>
                            <td class="text-gray-500">
                                {{ category.newsCount }}
                            </td>
                            <td>
                                <div class="flex items-center gap-2">
                                    <a href="{{ path('admin_category_edit', {id: category.id}) }}"
                                       class="text-primary-600 hover:text-primary-900" title="Duzenle">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    <form method="post" action="{{ path('admin_category_delete', {id: category.id}) }}"
                                          onsubmit="return confirm('Bu kategoriyi silmek istediginize emin misiniz?')">
                                        <input type="hidden" name="_token" value="{{ csrf_token('delete_category_' ~ category.id) }}">
                                        <button type="submit" class="text-red-600 hover:text-red-900" title="Sil">
                                            <i class="fas fa-trash-alt"></i>
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    {% else %}
                        <tr>
                            <td colspan="7" class="text-center text-gray-500 py-12">
                                <i class="fas fa-folder-open text-4xl text-gray-300 mb-3 block"></i>
                                Henuz kategori eklenmemis.
                                <br>
                                <a href="{{ path('admin_category_create') }}" class="text-primary-600 hover:text-primary-500 mt-2 inline-block">
                                    Ilk kategoriyi ekleyin
                                </a>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
