@extends('layouts.admin')

@section('title', 'Events Management')

@section('content')
<div class="dashboard-header" style="margin-bottom: 24px; display: flex; justify-content: space-between; align-items: center;">
    <div>
        <h1 style="font-family:'Oswald',sans-serif; font-size:2rem; color:var(--primary); margin:0;">Events Management</h1>
    </div>
    <a href="{{ route('admin.events.create') }}" class="btn btn-primary">
        <i class="fas fa-plus"></i> Create Event
    </a>
</div>

<div class="admin-card">
    <div class="admin-card-body" style="padding:0;">
        @if($events->count())
        <div class="table-responsive">
            <table class="admin-table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Title</th>
                        <th>Venue</th>
                        <th>Start Date</th>
                        <th>End Date</th>
                        <th>Registration</th>
                        <th style="text-align:right;">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($events as $event)
                    <tr>
                        <td>{{ $event->id }}</td>
                        <td>
                            <div style="font-weight:600; color:var(--primary);">{{ $event->title }}</div>
                            @if($event->description)
                            <div style="font-size:0.8rem; color:var(--text-muted); margin-top:2px;">{{ Str::limit($event->description, 60) }}</div>
                            @endif
                        </td>
                        <td>
                            <i class="fas fa-map-marker-alt" style="color:var(--text-muted); margin-right:4px;"></i>
                            {{ $event->venue }}
                        </td>
                        <td>{{ \Carbon\Carbon::parse($event->start_date)->format('M d, Y') }}</td>
                        <td>{{ \Carbon\Carbon::parse($event->end_date)->format('M d, Y') }}</td>
                        <td>
                            @if($event->registration_status === 'open')
                                <span class="badge badge-success">Open</span>
                            @else
                                <span class="badge badge-info" style="background:rgba(107,114,128,.1); color:#6b7280;">Closed</span>
                            @endif
                        </td>
                        <td style="text-align:right;">
                            <a href="{{ route('admin.events.edit', $event->id) }}" class="btn btn-primary btn-sm">
                                <i class="fas fa-edit"></i> Edit
                            </a>
                            <form action="{{ route('admin.events.destroy', $event->id) }}" method="POST" style="display:inline-block;" onsubmit="return confirm('Delete this event?');">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="btn btn-danger btn-sm">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </form>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div style="padding: 20px;">
            {{ $events->links() }}
        </div>
        @else
        <div style="padding: 60px; text-align: center; color: var(--text-muted);">
            <i class="fas fa-calendar-alt" style="font-size: 3rem; opacity: 0.5; margin-bottom: 16px; display:block;"></i>
            <p style="margin-bottom:16px;">No events found.</p>
            <a href="{{ route('admin.events.create') }}" class="btn btn-primary">
                <i class="fas fa-plus"></i> Create First Event
            </a>
        </div>
        @endif
    </div>
</div>
@endsection
