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

{% block title %}Anketler{% endblock %}
{% block page_title %}Anket Yönetimi{% 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_poll_create') }}" class="btn-primary">
                <i class="fas fa-plus mr-2"></i> Yeni Anket
            </a>
        </div>
    </div>

    {# Polls table #}
    <div class="card overflow-hidden">
        <div class="overflow-x-auto">
            <table class="table">
                <thead>
                    <tr>
                        <th>Soru</th>
                        <th>Durum</th>
                        <th>Toplam Oy</th>
                        <th>Tarih</th>
                        <th class="w-24">İşlem</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-200 bg-white">
                    {% for poll in polls %}
                        <tr>
                            <td>
                                <a href="{{ path('admin_poll_edit', {id: poll.id}) }}"
                                   class="font-medium text-gray-900 hover:text-primary-600">
                                    {{ poll.question }}
                                </a>
                                <div class="text-xs text-gray-500 mt-1">
                                    {{ poll.options|length }} seçenek
                                    {% if poll.multipleChoice %}
                                        <span class="ml-2 text-blue-600"><i class="fas fa-check-double"></i> Çoklu seçim</span>
                                    {% endif %}
                                </div>
                            </td>
                            <td>
                                {% if poll.status == 'active' %}
                                    <span class="badge-success">Aktif</span>
                                {% elseif poll.status == 'closed' %}
                                    <span class="badge-gray">Kapalı</span>
                                {% elseif poll.status == 'draft' %}
                                    <span class="badge-warning">Taslak</span>
                                {% endif %}
                            </td>
                            <td class="text-gray-500">
                                {{ poll.totalVotes|number_format(0, ',', '.') }}
                            </td>
                            <td class="text-gray-500 text-sm">
                                {{ poll.createdAt|date('d.m.Y H:i') }}
                                {% if poll.startsAt %}
                                    <div class="text-xs text-gray-400">
                                        Başlangıç: {{ poll.startsAt|date('d.m.Y') }}
                                    </div>
                                {% endif %}
                                {% if poll.endsAt %}
                                    <div class="text-xs text-gray-400">
                                        Bitiş: {{ poll.endsAt|date('d.m.Y') }}
                                    </div>
                                {% endif %}
                            </td>
                            <td>
                                <div class="flex items-center gap-2">
                                    <a href="{{ path('admin_poll_edit', {id: poll.id}) }}"
                                       class="text-primary-600 hover:text-primary-900" title="Düzenle">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    <form method="post" action="{{ path('admin_poll_delete', {id: poll.id}) }}"
                                          onsubmit="return confirm('Bu anketi silmek istediğinize emin misiniz?')">
                                        <input type="hidden" name="_token" value="{{ csrf_token('delete_poll_' ~ poll.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="5" class="text-center text-gray-500 py-12">
                                <i class="fas fa-poll text-4xl text-gray-300 mb-3 block"></i>
                                Henüz anket eklenmemiş.
                                <br>
                                <a href="{{ path('admin_poll_create') }}" class="text-primary-600 hover:text-primary-500 mt-2 inline-block">
                                    İlk anketi ekleyin
                                </a>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
