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

{% block title %}Yorumlar{% endblock %}
{% block page_title %}Yorum Yönetimi{% endblock %}

{% block body %}
    {# Status filters #}
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between mb-6 gap-4">
        <div class="flex gap-2">
            <a href="{{ path('admin_comments') }}"
               class="{{ not currentStatus ? 'btn-primary btn-sm' : 'btn-outline btn-sm' }}">
                Tümü
            </a>
            <a href="{{ path('admin_comments', {status: 'pending'}) }}"
               class="{{ currentStatus == 'pending' ? 'btn-primary btn-sm' : 'btn-outline btn-sm' }}">
                Beklemede
            </a>
            <a href="{{ path('admin_comments', {status: 'approved'}) }}"
               class="{{ currentStatus == 'approved' ? 'btn-primary btn-sm' : 'btn-outline btn-sm' }}">
                Onaylı
            </a>
            <a href="{{ path('admin_comments', {status: 'rejected'}) }}"
               class="{{ currentStatus == 'rejected' ? 'btn-primary btn-sm' : 'btn-outline btn-sm' }}">
                Reddedildi
            </a>
            <a href="{{ path('admin_comments', {status: 'spam'}) }}"
               class="{{ currentStatus == 'spam' ? 'btn-primary btn-sm' : 'btn-outline btn-sm' }}">
                Spam
            </a>
        </div>
    </div>

    {# Comments table #}
    <div class="card overflow-hidden">
        <div class="overflow-x-auto">
            <table class="table">
                <thead>
                    <tr>
                        <th>Yazar</th>
                        <th>Yorum</th>
                        <th>Haber</th>
                        <th>Durum</th>
                        <th>Tarih</th>
                        <th class="w-36">İşlem</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-200 bg-white">
                    {% for comment in comments %}
                        <tr>
                            <td>
                                <div>
                                    <div class="font-medium text-gray-900">{{ comment.authorName }}</div>
                                    {% if comment.authorEmail %}
                                        <div class="text-xs text-gray-500">{{ comment.authorEmail }}</div>
                                    {% endif %}
                                    {% if comment.ipAddress %}
                                        <div class="text-xs text-gray-400">{{ comment.ipAddress }}</div>
                                    {% endif %}
                                </div>
                            </td>
                            <td>
                                <div class="max-w-xs text-sm text-gray-700 truncate" title="{{ comment.content }}">
                                    {{ comment.content|length > 100 ? comment.content|slice(0, 100) ~ '...' : comment.content }}
                                </div>
                            </td>
                            <td>
                                <a href="{{ path('admin_news_edit', {id: comment.news.id}) }}"
                                   class="text-primary-600 hover:text-primary-900 text-sm">
                                    {{ comment.news.title|length > 50 ? comment.news.title|slice(0, 50) ~ '...' : comment.news.title }}
                                </a>
                            </td>
                            <td>
                                {% if comment.status == 'approved' %}
                                    <span class="badge-success">Onaylı</span>
                                {% elseif comment.status == 'pending' %}
                                    <span class="badge-warning">Beklemede</span>
                                {% elseif comment.status == 'rejected' %}
                                    <span class="badge-gray">Reddedildi</span>
                                {% elseif comment.status == 'spam' %}
                                    <span class="badge-danger">Spam</span>
                                {% endif %}
                            </td>
                            <td class="text-gray-500 text-sm">
                                {{ comment.createdAt|date('d.m.Y H:i') }}
                            </td>
                            <td>
                                <div class="flex items-center gap-2">
                                    {% if comment.status != 'approved' %}
                                        <form method="post" action="{{ path('admin_comment_approve', {id: comment.id}) }}">
                                            <input type="hidden" name="_token" value="{{ csrf_token('comment_action_' ~ comment.id) }}">
                                            <button type="submit" class="text-green-600 hover:text-green-900" title="Onayla">
                                                <i class="fas fa-check"></i>
                                            </button>
                                        </form>
                                    {% endif %}
                                    {% if comment.status != 'rejected' %}
                                        <form method="post" action="{{ path('admin_comment_reject', {id: comment.id}) }}">
                                            <input type="hidden" name="_token" value="{{ csrf_token('comment_action_' ~ comment.id) }}">
                                            <button type="submit" class="text-yellow-600 hover:text-yellow-900" title="Reddet">
                                                <i class="fas fa-ban"></i>
                                            </button>
                                        </form>
                                    {% endif %}
                                    <form method="post" action="{{ path('admin_comment_delete', {id: comment.id}) }}"
                                          onsubmit="return confirm('Bu yorumu silmek istediğinize emin misiniz?')">
                                        <input type="hidden" name="_token" value="{{ csrf_token('delete_comment_' ~ comment.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="6" class="text-center text-gray-500 py-12">
                                <i class="fas fa-comments text-4xl text-gray-300 mb-3 block"></i>
                                Henüz yorum bulunmuyor.
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
