@extends('admin.layouts.app')

@section('title', 'Events')

@section('content')
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
    <div>
        <h2 class="text-xl font-bold text-gray-800">All Events</h2>
        <p class="text-sm text-gray-500 mt-0.5">{{ $events->total() }} total</p>
    </div>
    <a href="{{ route('admin.events.create') }}" class="inline-flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white text-sm font-semibold px-4 py-2.5 rounded-lg transition">
        <span>+</span> Add Event
    </a>
</div>

<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-4 mb-4">
    <form method="GET" action="{{ route('admin.events.index') }}" class="flex gap-3">
        <input type="text" name="search" value="{{ request('search') }}" placeholder="Search by event title..." class="flex-1 px-4 py-2 border border-gray-300 rounded-lg text-sm">
        <button type="submit" class="px-4 py-2 bg-blue-600 text-white text-sm rounded-lg">Search</button>
    </form>
</div>

<div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
    @if($events->isEmpty())
        <div class="text-center py-16 text-sm text-gray-500">No events found.</div>
    @else
        <table class="min-w-full divide-y divide-gray-100">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-5 py-3 text-left text-xs font-semibold text-gray-500 uppercase">Event</th>
                    <th class="px-5 py-3 text-left text-xs font-semibold text-gray-500 uppercase hidden md:table-cell">Date</th>
                    <th class="px-5 py-3 text-left text-xs font-semibold text-gray-500 uppercase hidden md:table-cell">Status</th>
                    <th class="px-5 py-3 text-right text-xs font-semibold text-gray-500 uppercase">Actions</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100">
                @foreach($events as $event)
                    <tr>
                        <td class="px-5 py-4">
                            <p class="text-sm font-semibold text-gray-800">{{ $event->title }}</p>
                            <p class="text-xs text-gray-400">{{ $event->slug }}</p>
                        </td>
                        <td class="px-5 py-4 hidden md:table-cell text-sm text-gray-600">
                            {{ $event->starts_at ? $event->starts_at->format('d M Y h:i A') : '-' }}
                        </td>
                        <td class="px-5 py-4 hidden md:table-cell">
                            <span class="text-xs px-2 py-1 rounded-full {{ $event->is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-600' }}">
                                {{ $event->is_active ? 'Active' : 'Inactive' }}
                            </span>
                        </td>
                        <td class="px-5 py-4">
                            <div class="flex justify-end gap-2">
                                <a href="{{ route('events.show', $event->slug) }}" target="_blank" class="px-2 py-1 text-xs bg-gray-100 rounded">View</a>
                                <a href="{{ route('admin.events.edit', $event) }}" class="px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded">Edit</a>
                                <form method="POST" action="{{ route('admin.events.destroy', $event) }}" onsubmit="return confirm('Delete this event?')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="px-2 py-1 text-xs bg-red-100 text-red-700 rounded">Delete</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                @endforeach
            </tbody>
        </table>
        <div class="px-5 py-4 border-t border-gray-100">
            {{ $events->links() }}
        </div>
    @endif
</div>
@endsection

