@extends('layouts.app')

@section('title', 'Panel de administrador')

@section('content')
<h1 class="mb-4">Panel de administrador</h1>

<p class="text-muted">Bienvenido, {{ $user->name }} 👋</p>

<div class="alert alert-info">
  Puedes ver todos los eventos creados por los usuarios.
</div>

@if($events->isEmpty())
  <p class="text-muted">No hay eventos registrados.</p>
@else
  <table class="table table-dark table-striped">
    <thead>
      <tr>
        <th>Título</th>
        <th>Usuario</th>
        <th>Slug</th>
        <th>Creado</th>
        <th>Acciones</th>
      </tr>
    </thead>
    <tbody>
      @foreach($events as $event)
        <tr>
          <td>{{ $event->titulo }}</td>
          <td>{{ $event->user->name ?? 'N/A' }}</td>
          <td>{{ $event->slug }}</td>
          <td>{{ $event->created_at->format('d/m/Y') }}</td>
          <td>
            <a href="{{ route('preview.form', $event->slug) }}" class="btn btn-sm btn-outline-light">Preview</a>
            <a href="{{ route('events.edit', $event) }}" class="btn btn-sm btn-accent">Editar</a>
          </td>
        </tr>
      @endforeach
    </tbody>
  </table>
@endif
@endsection
