@extends('admin.layout')

@section('title', 'Sujets Forum')
@section('header', 'Sujets Forum')

@section('content')
<div class="overflow-x-auto">
    <table class="w-full">
        <thead>
            <tr class="border-b border-slate-200">
                <th class="text-left py-3 px-4 font-semibold text-slate-800">Sujet</th>
                <th class="text-left py-3 px-4 font-semibold text-slate-800">Catégorie</th>
                <th class="text-left py-3 px-4 font-semibold text-slate-800">Auteur</th>
                <th class="text-left py-3 px-4 font-semibold text-slate-800">Réponses</th>
                <th class="text-left py-3 px-4 font-semibold text-slate-800">Date</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach($threads ?? [] as $thread)
                <tr class="border-b border-slate-100 hover:bg-slate-50">
                    <td class="py-3 px-4">
                        <a href="{{ route('admin.forum.thread', $thread) }}" class="font-medium text-slate-900 hover:underline">{{ $thread->title }}</a>
                        @if($thread->is_pinned)<span class="text-amber-600 text-xs ml-1">Épinglé</span>@endif
                        @if(!$thread->is_approved)<span class="text-amber-700 text-xs ml-1 font-medium">· En attente</span>@endif
                    </td>
                    <td class="py-3 px-4 text-slate-600">{{ $thread->category->name ?? '-' }}</td>
                    <td class="py-3 px-4 text-slate-600">{{ $thread->author_name }}</td>
                    <td class="py-3 px-4">{{ $thread->replies_count }}</td>
                    <td class="py-3 px-4 text-slate-500 text-sm">{{ $thread->created_at->format('d/m/Y') }}</td>
                    <td class="py-3 px-4">
                        @if($thread->is_approved)
                            <a href="{{ route('forum.thread', [$thread->category->slug, $thread->slug]) }}" target="_blank" class="text-primary-600 text-sm hover:underline">Voir</a>
                        @else
                            <span class="text-slate-400 text-sm">—</span>
                        @endif
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
</div>

@if($threads->hasPages())
    <div class="mt-6">{{ $threads->links() }}</div>
@endif

<a href="{{ route('admin.forum.index') }}" class="inline-block mt-6 text-slate-600 hover:text-slate-900">← Retour au forum</a>
@endsection
