@extends('admin.layout')

@section('title', 'Contenus')

@section('content')
    <div style="display:flex;justify-content:space-between;align-items:flex-start;gap:16px;flex-wrap:wrap;margin-bottom:20px;">
        <div>
            <h1>Contenus</h1>
            <p class="muted">Blog, guides, actualites et secteurs geres depuis l'administration.</p>
        </div>
        <a class="btn" href="{{ route('admin.contents.create', ['type' => $filterType ?: 'blog']) }}">Nouveau contenu</a>
    </div>

    <div style="display:flex;gap:8px;flex-wrap:wrap;margin-bottom:18px;">
        <a href="{{ route('admin.contents.index') }}" class="pill" @if(!$filterType) style="outline:2px solid #f05a1a;" @endif>Tous</a>
        @foreach($types as $key => $label)
            <a href="{{ route('admin.contents.index', ['type' => $key]) }}" class="pill" @if($filterType === $key) style="outline:2px solid #f05a1a;" @endif>{{ $label }}</a>
        @endforeach
    </div>

    <div class="card" style="padding:0;overflow:hidden;">
        <table>
            <thead>
                <tr>
                    <th>Type</th>
                    <th>Titre</th>
                    <th>Publie</th>
                    <th>Maj</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @forelse($contents as $item)
                    <tr>
                        <td><span class="pill">{{ $types[$item->type] ?? $item->type }}</span></td>
                        <td>{{ $item->title }}</td>
                        <td>{{ $item->is_published ? 'Oui' : 'Non' }}</td>
                        <td>{{ $item->updated_at->format('d/m/Y') }}</td>
                        <td>
                            <a href="{{ route('admin.contents.edit', $item) }}">Modifier</a>
                            @if($item->isPubliclyVisible())
                                · <a href="{{ route('ressources.show', $item) }}" target="_blank" rel="noopener">Voir</a>
                            @endif
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="5" style="color:#5f6b76;">Aucun contenu. Creez-en un ou ajustez le filtre.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div style="margin-top:20px;">
        {{ $contents->links() }}
    </div>
@endsection
