@extends('admin.layout')

@section('title', 'Noticias - Admin OnAPB')

@section('content')
<div class="mb-5 d-flex justify-content-between align-items-end">
    <div>
        <span class="text-primary fw-bold text-uppercase tracking-widest d-block mb-2">Comunicación Oficial</span>
        <h1 class="display-4 fw-bold font-header mb-0">Noticias<span class="text-primary">.</span></h1>
    </div>
    <a href="{{ route('admin.noticias.create') }}" class="btn-admin-primary">
        <i class="bi bi-plus-lg me-2"></i> NUEVA NOTICIA
    </a>
</div>

<div class="admin-card">
    @if($noticias->isEmpty())
        <div class="text-center py-5">
            <i class="bi bi-newspaper text-muted mb-3" style="font-size: 3rem;"></i>
            <p class="fs-5 text-muted">No hay noticias publicadas.</p>
        </div>
    @else
        <div class="table-responsive">
            <table class="kinetic-table">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Imagen</th>
                        <th>Título / Categoría</th>
                        <th>Publicación</th>
                        <th class="text-end">Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($noticias as $n)
                    <tr>
                        <td><span class="badge bg-light text-dark px-2 py-1">#{{ $n->id }}</span></td>
                        <td>
                            @if($n->imagen)
                                <img src="{{ asset($n->imagen) }}" alt="" class="rounded" style="width: 60px; height: 40px; object-fit: cover; border: 1px solid #eee;">
                            @else
                                <div class="bg-light rounded d-flex align-items-center justify-content-center text-muted" style="width: 60px; height: 40px; font-size: 0.8rem;">
                                    <i class="bi bi-image"></i>
                                </div>
                            @endif
                        </td>
                        <td>
                            @if($n->categoria)
                                <span class="badge bg-primary-subtle text-primary border-primary border-opacity-25 mb-1">{{ strtoupper($n->categoria) }}</span>
                            @endif
                            <span class="fw-bold fs-5 d-block">{{ $n->titulo }}</span>
                        </td>
                        <td>
                            <span class="fw-bold d-block text-muted text-uppercase" style="font-size: 0.8rem;">
                                <i class="bi bi-clock me-1"></i> {{ $n->fecha ? \Carbon\Carbon::parse($n->fecha)->format('d/m/Y H:i') : '—' }}
                            </span>
                        </td>
                        <td class="text-end">
                            <a href="{{ route('admin.noticias.edit', $n->id) }}" class="btn btn-sm btn-light border me-1">
                                <i class="bi bi-pencil"></i>
                            </a>
                            <form action="{{ route('admin.noticias.destroy', $n->id) }}" method="POST" class="d-inline delete-form confirm-submit" data-confirm-text="¿Eliminar esta noticia?">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="btn btn-sm btn-outline-danger">
                                    <i class="bi bi-trash"></i>
                                </button>
                            </form>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    @endif
</div>
@endsection
