@extends('themes.classic.layouts.app')

@section('title', $category->name.' - Forum')

@section('content')
<div class="max-w-4xl mx-auto px-6 py-16">
    <nav class="mb-6">
        <a href="{{ route('forum.index') }}" class="text-slate-600 hover:text-slate-900 text-sm">← Forum</a>
    </nav>
    <div class="flex items-center justify-between mb-8">
        <div>
            <h1 class="text-3xl font-bold text-slate-900">{{ $category->name }}</h1>
            @if($category->description)
                <div class="text-slate-600 mt-1 prose prose-slate prose-sm max-w-none">{!! \App\Support\SafeHtml::richText($category->description) !!}</div>
            @endif
        </div>
        <a href="{{ route('forum.create-thread', $category->slug) }}" class="px-6 py-3 bg-slate-900 text-white rounded-xl font-medium hover:bg-slate-800 transition">
            Nouveau sujet
        </a>
    </div>

    <div class="space-y-2">
        @forelse($threads ?? [] as $thread)
            <a href="{{ route('forum.thread', [$category->slug, $thread->slug]) }}" class="block p-4 bg-white rounded-xl border border-slate-200 hover:border-slate-300 transition">
                <div class="flex items-center gap-4">
                    @if($thread->is_pinned)
                        <span class="px-2 py-0.5 bg-amber-100 text-amber-800 text-xs font-medium rounded">Épinglé</span>
                    @endif
                    <div class="flex-1 min-w-0">
                        <h3 class="font-semibold text-slate-900 truncate">{{ $thread->title }}</h3>
                        <p class="text-sm text-slate-500">par {{ $thread->author_name }} · {{ $thread->created_at->diffForHumans() }}</p>
                    </div>
                    <div class="text-right shrink-0">
                        <span class="font-semibold text-slate-900">{{ $thread->replies_count }}</span>
                        <span class="text-slate-500 text-sm">réponses</span>
                    </div>
                </div>
            </a>
        @empty
            <p class="text-slate-500 py-12 text-center">Aucun sujet. <a href="{{ route('forum.create-thread', $category->slug) }}" class="text-slate-900 font-medium underline">Créer le premier</a></p>
        @endforelse
    </div>

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