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

{% block title %}Yonlendirmeler{% endblock %}
{% block page_title %}Yonlendirmeler{% endblock %}

{% block body %}
    {# Quick Add Form #}
    <div class="card mb-6">
        <div class="card-header">
            <h3 class="card-title"><i class="fas fa-plus-circle mr-2"></i> Yeni Yonlendirme</h3>
        </div>
        <div class="card-body">
            <form method="post" action="{{ path('admin_seo_redirect_create') }}">
                <input type="hidden" name="_token" value="{{ csrf_token('redirect_form') }}">
                <div class="grid grid-cols-1 md:grid-cols-12 gap-4 items-end">
                    <div class="md:col-span-4">
                        <label for="source_path" class="form-label">Kaynak URL <span class="text-red-500">*</span></label>
                        <input type="text" id="source_path" name="source_path" required
                               class="form-input w-full"
                               placeholder="/eski-sayfa">
                    </div>
                    <div class="md:col-span-4">
                        <label for="target_path" class="form-label">Hedef URL <span class="text-red-500">*</span></label>
                        <input type="text" id="target_path" name="target_path" required
                               class="form-input w-full"
                               placeholder="/yeni-sayfa">
                    </div>
                    <div class="md:col-span-2">
                        <label for="status_code" class="form-label">Kod</label>
                        <select id="status_code" name="status_code" class="form-input w-full">
                            <option value="301">301 - Kalici</option>
                            <option value="302">302 - Gecici</option>
                        </select>
                    </div>
                    <div class="md:col-span-2">
                        <button type="submit" class="btn-primary w-full justify-center">
                            <i class="fas fa-plus mr-2"></i> Ekle
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    {# Back to SEO Dashboard #}
    <div class="flex items-center justify-between mb-4">
        <a href="{{ path('admin_seo') }}" class="text-sm text-primary-600 hover:text-primary-800">
            <i class="fas fa-arrow-left mr-1"></i> SEO Paneline Don
        </a>
        <span class="text-sm text-gray-500">{{ redirects|length }} yonlendirme</span>
    </div>

    {# Redirects Table #}
    <div class="card overflow-hidden">
        <div class="overflow-x-auto">
            <table class="table">
                <thead>
                    <tr>
                        <th>Kaynak URL</th>
                        <th>Hedef URL</th>
                        <th>Kod</th>
                        <th>Tiklama</th>
                        <th>Durum</th>
                        <th class="w-24">Islem</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-200 bg-white">
                    {% for redirect in redirects %}
                        <tr>
                            <td>
                                <span class="text-sm font-mono text-gray-800">{{ redirect.sourcePath }}</span>
                            </td>
                            <td>
                                <span class="text-sm font-mono text-gray-600">{{ redirect.targetPath }}</span>
                            </td>
                            <td>
                                {% if redirect.statusCode == 301 %}
                                    <span class="inline-flex items-center rounded-full bg-blue-50 px-2 py-0.5 text-xs font-medium text-blue-700">
                                        301
                                    </span>
                                {% else %}
                                    <span class="inline-flex items-center rounded-full bg-yellow-50 px-2 py-0.5 text-xs font-medium text-yellow-700">
                                        302
                                    </span>
                                {% endif %}
                            </td>
                            <td>
                                <span class="text-sm text-gray-500">
                                    <i class="fas fa-mouse-pointer text-xs text-gray-400 mr-1"></i>
                                    {{ redirect.hitCount }}
                                </span>
                            </td>
                            <td>
                                {% if redirect.isActive %}
                                    <span class="badge-success">Aktif</span>
                                {% else %}
                                    <span class="badge-gray">Pasif</span>
                                {% endif %}
                            </td>
                            <td>
                                <form method="post" action="{{ path('admin_seo_redirect_delete', {id: redirect.id}) }}"
                                      onsubmit="return confirm('Bu yonlendirmeyi silmek istediginize emin misiniz?')">
                                    <input type="hidden" name="_token" value="{{ csrf_token('delete_redirect_' ~ redirect.id) }}">
                                    <button type="submit" class="text-red-600 hover:text-red-900" title="Sil">
                                        <i class="fas fa-trash-alt"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                    {% else %}
                        <tr>
                            <td colspan="6" class="text-center text-gray-500 py-12">
                                <i class="fas fa-directions text-4xl text-gray-300 mb-3 block"></i>
                                Henuz yonlendirme eklenmemis.
                                <br>
                                <span class="text-sm text-gray-400 mt-1 inline-block">Yukaridaki formu kullanarak yeni yonlendirme ekleyin.</span>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
