@extends('layouts.app')

@section('title','Daftar Event')

@section('content')

<div class="container">

    <h2 class="mb-4 fw-bold">
        🎵 Daftar Event
    </h2>

    @if(session('success'))
        <div class="alert alert-success">
            {{ session('success') }}
        </div>
    @endif

    @if(session('error'))
        <div class="alert alert-danger">
            {{ session('error') }}
        </div>
    @endif

    <div class="row g-3">
    <div class="card-dark mb-3 p-3">
        <form method="GET" action="{{ route('user.events') }}">
            <div class="d-flex gap-3 flex-wrap align-items-center">
                <div style="position:relative; flex:1; min-width:220px">
                    <i class="bi bi-search" style="position:absolute; left:12px; top:50%; transform:translateY(-50%); color:var(--text-muted); font-size:0.85rem"></i>
                    <input name="search" type="text" class="form-control-dark" placeholder="Cari event..." style="padding-left:36px" value="{{ request('search') }}">
                </div>

                <select name="kategori" class="form-control-dark" style="width:auto">
                    <option value="">Semua Kategori</option>
                    @foreach($kategori ?? [] as $k)
                        <option value="{{ $k->id }}" {{ request('kategori') == $k->id ? 'selected' : '' }}>{{ $k->nama_kategori }}</option>
                    @endforeach
                </select>

                <select name="lokasi" class="form-control-dark" style="width:auto">
                    <option value="">Semua Lokasi</option>
                    @foreach($lokasi ?? [] as $l)
                        <option value="{{ $l->id }}" {{ request('lokasi') == $l->id ? 'selected' : '' }}>{{ $l->nama_lokasi }}</option>
                    @endforeach
                </select>

                <select name="perpage" class="form-control-dark" style="width:auto">
                    <option value="9" {{ request('perpage', 9) == 9 ? 'selected' : '' }}>9</option>
                    <option value="12" {{ request('perpage') == 12 ? 'selected' : '' }}>12</option>
                    <option value="24" {{ request('perpage') == 24 ? 'selected' : '' }}>24</option>
                </select>

                <div class="ms-auto d-flex gap-2">
                    <button type="submit" class="btn-primary-glow">Cari</button>
                    <a href="{{ route('user.events') }}" class="btn btn-outline-light">Reset</a>
                </div>
            </div>
        </form>
    </div>

    @forelse($events as $event)
            <div class="col-lg-4 col-md-6">
                <div class="event-card">
                    <img src="{{ $event->gambar ? asset('storage/'.$event->gambar) : 'https://via.placeholder.com/500x250?text=Konser' }}" class="poster" alt="{{ $event->nama_event }}">
                    <div class="p-3">
                        <h4 class="fw-bold mb-1">{{ $event->nama_event }}</h4>
                        <div class="text-muted">{{ $event->kategori->nama_kategori ?? '-' }} • {{ $event->lokasi->nama_lokasi ?? '-' }}</div>
                        <div class="mt-2 text-muted-sm">{{ $event->tanggal ? \Carbon\Carbon::parse($event->tanggal)->format('d M Y') : '-' }}</div>
                        <div class="mt-3 d-flex gap-2">
                            <a href="{{ route('user.event.show',$event->id) }}" class="btn btn-primary-custom">Detail Event</a>
                        </div>
                    </div>
                </div>
            </div>
        @empty
            <div class="col-12">
                <div class="alert alert-warning">Belum ada event.</div>
            </div>
        @endforelse
        @if(method_exists($events, 'links'))
            <div class="d-flex justify-content-center mt-4">{{ $events->links() }}</div>
        @endif
    </div>

</div>

@endsection