
<?php $__env->startSection('title', 'Daftar Events'); ?>
<?php $__env->startSection('page-title', 'Events'); ?>

<?php $__env->startSection('content'); ?>
<div class="page-header d-flex flex-column flex-md-row align-items-start align-items-md-center justify-content-between gap-3 mb-4">
    <div>
        <div class="breadcrumb-dark">
            <a href="<?php echo e(route('dashboard')); ?>">Dashboard</a>
            <i class="bi bi-chevron-right" style="font-size:0.6rem"></i>
            <span class="current">Events</span>
        </div>
        <div class="page-header-title">Daftar Events 🎤</div>
        <div class="page-header-sub">Kelola semua event konser yang terdaftar di sistem</div>
    </div>
    <a href="<?php echo e(route('events.create')); ?>" class="btn-primary-glow">
        <i class="bi bi-plus-lg"></i> Tambah Event
    </a>
</div>

<div class="card-dark mb-4">
    <div class="card-body p-3">
        <form method="GET" action="<?php echo e(route('events.index')); ?>">
            <div class="d-flex gap-3 flex-wrap align-items-center">
                <div class="position-relative flex-fill" style="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.95rem"></i>
                    <input name="search" type="text" class="form-control-dark" placeholder="Cari event, kategori, lokasi..." value="<?php echo e(request('search')); ?>" style="padding-left:36px; width:100%;">
                </div>

                <select name="kategori" class="form-control-dark" style="min-width:180px;">
                    <option value="">Semua Kategori</option>
                    <?php $__currentLoopData = $kategoris ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($k->id); ?>" <?php echo e(request('kategori') == $k->id ? 'selected' : ''); ?>><?php echo e($k->nama_kategori); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>

                <select name="lokasi" class="form-control-dark" style="min-width:180px;">
                    <option value="">Semua Lokasi</option>
                    <?php $__currentLoopData = $lokasis ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $l): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($l->id); ?>" <?php echo e(request('lokasi') == $l->id ? 'selected' : ''); ?>><?php echo e($l->nama_lokasi); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>

                <select name="date_filter" class="form-control-dark" style="min-width:180px;">
                    <option value="">Semua Tanggal</option>
                    <option value="today" <?php echo e(request('date_filter') == 'today' ? 'selected' : ''); ?>>Hari Ini</option>
                    <option value="this_week" <?php echo e(request('date_filter') == 'this_week' ? 'selected' : ''); ?>>Minggu Ini</option>
                    <option value="this_month" <?php echo e(request('date_filter') == 'this_month' ? 'selected' : ''); ?>>Bulan Ini</option>
                    <option value="custom" <?php echo e(request('date_filter') == 'custom' ? 'selected' : ''); ?>>Rentang Tanggal</option>
                </select>

                <?php if(request('date_filter') == 'custom'): ?>
                    <input type="date" name="date_from" class="form-control-dark" value="<?php echo e(request('date_from')); ?>" style="min-width:170px;">
                    <input type="date" name="date_to" class="form-control-dark" value="<?php echo e(request('date_to')); ?>" style="min-width:170px;">
                <?php endif; ?>

                <select name="sort" class="form-control-dark" style="min-width:180px;">
                    <option value="">Urutkan: Terbaru</option>
                    <option value="oldest" <?php echo e(request('sort') == 'oldest' ? 'selected' : ''); ?>>Tanggal (Terlama)</option>
                    <option value="name_asc" <?php echo e(request('sort') == 'name_asc' ? 'selected' : ''); ?>>Nama A-Z</option>
                    <option value="name_desc" <?php echo e(request('sort') == 'name_desc' ? 'selected' : ''); ?>>Nama Z-A</option>
                    <option value="price_asc" <?php echo e(request('sort') == 'price_asc' ? 'selected' : ''); ?>>Harga (Termurah)</option>
                    <option value="price_desc" <?php echo e(request('sort') == 'price_desc' ? 'selected' : ''); ?>>Harga (Termahal)</option>
                </select>

                <select name="perpage" class="form-control-dark" style="min-width:110px;">
                    <option value="9" <?php echo e(request('perpage', 9) == 9 ? 'selected' : ''); ?>>9</option>
                    <option value="12" <?php echo e(request('perpage') == 12 ? 'selected' : ''); ?>>12</option>
                    <option value="24" <?php echo e(request('perpage') == 24 ? 'selected' : ''); ?>>24</option>
                </select>

                <div class="ms-auto d-flex gap-2 flex-wrap">
                    <button type="submit" class="btn-primary-glow">Filter</button>
                    <a href="<?php echo e(route('events.index')); ?>" class="btn btn-outline-soft">Reset</a>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="card-dark overflow-auto">
    <div class="table-responsive">
        <table class="table-dark-custom mb-0" style="min-width:900px;">
            <thead>
                <tr>
                    <th>Nama Event</th>
                    <th>Kategori</th>
                    <th>Lokasi</th>
                    <th>Tanggal</th>
                    <th>Stok</th>
                    <th>Status</th>
                    <th>Aksi</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $events; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $event): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <?php
                        $totalStock = $event->tikets->sum('stok');
                        $eventDate = $event->tanggal ? \Carbon\Carbon::parse($event->tanggal) : null;
                        $statusText = 'Aktif';
                        $statusClass = 'badge-success';
                        if ($eventDate && $eventDate->isPast()) {
                            $statusText = 'Selesai';
                            $statusClass = 'badge-danger';
                        } elseif ($totalStock === 0) {
                            $statusText = 'Habis';
                            $statusClass = 'badge-danger';
                        } elseif ($totalStock <= 10) {
                            $statusText = 'Terbatas';
                            $statusClass = 'badge-warning';
                        }
                    ?>
                    <tr>
                        <td style="font-weight:600;">
                            <?php echo e($event->nama_event); ?>

                            <div style="font-size:0.82rem; color:var(--text-muted); margin-top:6px;"><?php echo e(Str::limit($event->deskripsi, 80)); ?></div>
                        </td>
                        <td><?php echo e($event->kategori->nama_kategori ?? '-'); ?></td>
                        <td><?php echo e($event->lokasi->nama_lokasi ?? '-'); ?></td>
                        <td><?php echo e($event->tanggal ? \Carbon\Carbon::parse($event->tanggal)->format('d M Y') : '-'); ?></td>
                        <td><?php echo e($totalStock); ?></td>
                        <td><span class="badge-status <?php echo e($statusClass); ?>"><?php echo e($statusText); ?></span></td>
                        <td>
                            <div class="d-flex flex-wrap gap-2">
                                <a href="<?php echo e(route('events.edit', $event->id)); ?>" class="btn-edit-soft"><i class="bi bi-pencil-fill"></i> Edit</a>
                                <form action="<?php echo e(route('events.destroy', $event->id)); ?>" method="POST" onsubmit="return confirm('Hapus event ini?')">
                                    <?php echo csrf_field(); ?>
                                    <?php echo method_field('DELETE'); ?>
                                    <button type="submit" class="btn-danger-soft"><i class="bi bi-trash-fill"></i> Hapus</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="7" class="text-center py-5">
                            <div class="empty-state" style="background:rgba(15,23,36,0.9);color:#fff;">
                                <i class="bi bi-calendar-event" style="font-size:2rem;margin-bottom:.75rem"></i>
                                <p class="mb-0">Belum ada event. <a href="<?php echo e(route('events.create')); ?>">Tambah sekarang</a></p>
                            </div>
                        </td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<div class="d-flex justify-content-center mt-4">
    <?php echo e($events->links()); ?>

</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\tugas pa asur\konser-ticket\resources\views/events/index.blade.php ENDPATH**/ ?>