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

{% block title %}Etiketler{% endblock %}
{% block page_title %}Etiket Yonetimi{% endblock %}

{% block body %}
    <div class="grid grid-cols-1 lg:grid-cols-12 gap-6">
        {# Left column - Tag list (8/12) #}
        <div class="lg:col-span-8">
            {# Search bar #}
            <div class="mb-4">
                <form method="get" action="{{ path('admin_tags') }}" class="flex gap-2">
                    <div class="flex-1 relative">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fas fa-search text-gray-400"></i>
                        </div>
                        <input type="text" name="q" value="{{ search }}"
                               class="form-input w-full pl-10"
                               placeholder="Etiket ara...">
                    </div>
                    <button type="submit" class="btn-primary">
                        <i class="fas fa-search mr-1"></i> Ara
                    </button>
                    {% if search %}
                        <a href="{{ path('admin_tags') }}" class="btn-outline">
                            <i class="fas fa-times mr-1"></i> Temizle
                        </a>
                    {% endif %}
                </form>
            </div>

            {# Tags table #}
            <div class="card overflow-hidden">
                <div class="overflow-x-auto">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>Etiket</th>
                                <th>Slug</th>
                                <th>Haber Sayisi</th>
                                <th class="w-24">Islem</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-200 bg-white">
                            {% for tag in tags %}
                                <tr>
                                    <td>
                                        {% if editTag is defined and editTag and editTag.id == tag.id %}
                                            <form method="post" action="{{ path('admin_tag_edit', {id: tag.id}) }}" class="flex items-center gap-2">
                                                <input type="hidden" name="_token" value="{{ csrf_token('tag_form') }}">
                                                <input type="text" name="name" value="{{ tag.name }}" class="form-input text-sm" required>
                                                <input type="text" name="slug" value="{{ tag.slug }}" class="form-input text-sm" placeholder="slug">
                                                <button type="submit" class="text-green-600 hover:text-green-800" title="Kaydet">
                                                    <i class="fas fa-check"></i>
                                                </button>
                                                <a href="{{ path('admin_tags') }}" class="text-gray-400 hover:text-gray-600" title="Iptal">
                                                    <i class="fas fa-times"></i>
                                                </a>
                                            </form>
                                        {% else %}
                                            <span class="inline-flex items-center rounded-full bg-gray-100 px-3 py-1 text-sm font-medium text-gray-800">
                                                <i class="fas fa-tag text-xs text-gray-400 mr-1.5"></i>
                                                {{ tag.name }}
                                            </span>
                                        {% endif %}
                                    </td>
                                    <td class="text-gray-500 text-sm">
                                        {{ tag.slug }}
                                    </td>
                                    <td>
                                        <span class="inline-flex items-center rounded-full bg-blue-50 px-2 py-0.5 text-xs font-medium text-blue-700">
                                            {{ tag.newsCount }}
                                        </span>
                                    </td>
                                    <td>
                                        <div class="flex items-center gap-2">
                                            <a href="{{ path('admin_tag_edit', {id: tag.id}) }}"
                                               class="text-primary-600 hover:text-primary-900" title="Duzenle">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                            <form method="post" action="{{ path('admin_tag_delete', {id: tag.id}) }}"
                                                  onsubmit="return confirm('Bu etiketi silmek istediginize emin misiniz?')">
                                                <input type="hidden" name="_token" value="{{ csrf_token('delete_tag_' ~ tag.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="4" class="text-center text-gray-500 py-12">
                                        <i class="fas fa-tags text-4xl text-gray-300 mb-3 block"></i>
                                        {% if search %}
                                            "{{ search }}" icin sonuc bulunamadi.
                                        {% else %}
                                            Henuz etiket eklenmemis.
                                        {% endif %}
                                    </td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        {# Right column - Quick add form (4/12) #}
        <div class="lg:col-span-4">
            <div class="card sticky top-24">
                <div class="card-header">
                    <h3 class="card-title"><i class="fas fa-plus-circle mr-2"></i> Hizli Etiket Ekle</h3>
                </div>
                <div class="card-body">
                    <form method="post" action="{{ path('admin_tag_create') }}" class="space-y-4">
                        <input type="hidden" name="_token" value="{{ csrf_token('tag_form') }}">
                        <div>
                            <label for="tag_name" class="form-label">Etiket Adi <span class="text-red-500">*</span></label>
                            <input type="text" id="tag_name" name="name" required
                                   class="form-input w-full"
                                   placeholder="Yeni etiket adi">
                            <p class="text-xs text-gray-500 mt-1">Slug otomatik olusturulur.</p>
                        </div>
                        <button type="submit" class="btn-primary w-full justify-center">
                            <i class="fas fa-plus mr-2"></i> Etiket Ekle
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
