@extends('admin.layout')

@section('title', 'Carrusel Principal - 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">Visual Merchandising</span>
        <h1 class="display-4 fw-bold font-header mb-0">Carrusel Principal<span class="text-primary">.</span></h1>
    </div>
    <a href="{{ route('admin.carousel.create') }}" class="btn-admin-primary">
        <i class="bi bi-plus-lg me-2"></i> AGREGAR SLIDE
    </a>
</div>

<div class="admin-card">
    @if($items->isEmpty())
        <div class="text-center py-5">
            <i class="bi bi-images text-muted mb-3" style="font-size: 3rem;"></i>
            <p class="fs-5 text-muted">No hay slides en el carrusel.</p>
        </div>
    @else
        <div class="table-responsive">
            <table class="kinetic-table">
                <thead>
                    <tr>
                        <th style="width: 80px;">Orden</th>
                        <th>Imagen</th>
                        <th>Título / Subtítulo</th>
                        <th>Botón de Acción</th>
                        <th>Estado</th>
                        <th class="text-end">Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($items as $item)
                    <tr>
                        <td><span class="badge bg-light text-dark fw-bold border p-2">{{ $item->orden }}</span></td>
                        <td>
                            <div class="bg-dark" style="width: 120px; height: 60px; overflow: hidden; border: 1px solid var(--admin-outline);">
                                <img src="{{ Str::startsWith($item->imagen, 'http') ? $item->imagen : asset($item->imagen) }}" 
                                     alt="Slide" style="width: 100%; height: 100%; object-fit: cover;">
                            </div>
                        </td>
                        <td>
                            <span class="fw-bold d-block text-uppercase">{{ $item->titulo ?: '(SIN TÍTULO)' }}</span>
                            <small class="text-muted text-uppercase tracking-tighter">{{ $item->subtitulo }}</small>
                        </td>
                        <td>
                            @if($item->boton_texto)
                                <div class="small fw-bold text-primary">{{ $item->boton_texto }}</div>
                                <div class="small text-muted font-monospace" style="font-size: 0.75rem;">{{ Str::limit($item->boton_enlace, 20) }}</div>
                            @else
                                <span class="text-muted small">—</span>
                            @endif
                        </td>
                        <td>
                            @if($item->activo)
                                <span class="badge bg-success text-white text-uppercase px-2 py-1">ACTIVO</span>
                            @else
                                <span class="badge bg-light text-muted border text-uppercase px-2 py-1">OCULTO</span>
                            @endif
                        </td>
                        <td class="text-end">
                            <a href="{{ route('admin.carousel.edit', $item->id) }}" class="btn btn-sm btn-light border me-1">
                                <i class="bi bi-pencil"></i>
                            </a>
                            <form action="{{ route('admin.carousel.destroy', $item->id) }}" method="POST" class="d-inline delete-form confirm-submit" data-confirm-text="¿Eliminar este slide?">
                                @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
