<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Veranstaltungen</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 40px 20px;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        .header {
            text-align: center;
            color: white;
            margin-bottom: 50px;
        }
        .header h1 {
            font-size: 3em;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }
        .header p {
            font-size: 1.2em;
            opacity: 0.9;
        }
        .filters {
            background: white;
            padding: 30px;
            border-radius: 10px;
            margin-bottom: 40px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        .filter-row {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }
        .filter-group {
            display: flex;
            flex-direction: column;
        }
        .filter-group label {
            font-weight: 600;
            margin-bottom: 8px;
            color: #333;
        }
        .filter-group input,
        .filter-group select {
            padding: 10px;
            border: 2px solid #e0e0e0;
            border-radius: 5px;
            font-size: 1em;
            transition: border-color 0.3s;
        }
        .filter-group input:focus,
        .filter-group select:focus {
            outline: none;
            border-color: #667eea;
        }
        .btn-filter {
            padding: 10px 30px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 1em;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
            align-self: flex-end;
        }
        .btn-filter:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        .events-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
            gap: 30px;
            margin-bottom: 40px;
        }
        .event-card {
            background: white;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
            transition: transform 0.3s, box-shadow 0.3s;
            display: flex;
            flex-direction: column;
        }
        .event-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 15px 40px rgba(0,0,0,0.2);
        }
        .event-image {
            width: 100%;
            height: 200px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 3em;
            position: relative;
            overflow: hidden;
        }
        .event-image img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .event-content {
            padding: 25px;
            flex-grow: 1;
            display: flex;
            flex-direction: column;
        }
        .event-category {
            display: inline-block;
            background: #f0f0f0;
            color: #667eea;
            padding: 5px 15px;
            border-radius: 20px;
            font-size: 0.8em;
            font-weight: 600;
            margin-bottom: 10px;
            width: fit-content;
        }
        .event-title {
            font-size: 1.5em;
            font-weight: 700;
            color: #333;
            margin-bottom: 12px;
            line-height: 1.3;
        }
        .event-description {
            color: #666;
            font-size: 0.95em;
            margin-bottom: 15px;
            line-height: 1.5;
            flex-grow: 1;
        }
        .event-meta {
            display: flex;
            flex-direction: column;
            gap: 10px;
            margin-bottom: 20px;
            padding-top: 15px;
            border-top: 1px solid #f0f0f0;
        }
        .meta-item {
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 0.9em;
            color: #666;
        }
        .meta-icon {
            font-size: 1.2em;
        }
        .event-link {
            display: inline-block;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 12px 25px;
            border-radius: 5px;
            text-decoration: none;
            font-weight: 600;
            text-align: center;
            transition: transform 0.2s, box-shadow 0.2s;
        }
        .event-link:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        .no-events {
            text-align: center;
            background: white;
            padding: 60px 20px;
            border-radius: 10px;
            color: #999;
        }
        .no-events h3 {
            font-size: 1.5em;
            margin-bottom: 10px;
        }
        .pagination {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin-top: 40px;
        }
        .pagination a {
            padding: 10px 15px;
            background: white;
            color: #667eea;
            border-radius: 5px;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s;
        }
        .pagination a:hover {
            background: #667eea;
            color: white;
        }
        .pagination .active {
            background: #667eea;
            color: white;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🎭 Veranstaltungen</h1>
            <p>Entdecke spannende Events in deiner Stadt</p>
        </div>

        <div class="filters">
            <form method="GET" action="/">
                <div class="filter-row">
                    <div class="filter-group">
                        <label for="from">Von:</label>
                        <input type="date" id="from" name="from" value="{{ request('from') }}">
                    </div>
                    <div class="filter-group">
                        <label for="to">Bis:</label>
                        <input type="date" id="to" name="to" value="{{ request('to') }}">
                    </div>
                    <div class="filter-group">
                        <label for="category">Kategorie:</label>
                        <select id="category" name="category">
                            <option value="">-- Alle Kategorien --</option>
                            @foreach($categories as $category)
                                <option value="{{ $category }}" {{ request('category') === $category ? 'selected' : '' }}>
                                    {{ $category }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="filter-group">
                        <label for="location">Ort:</label>
                        <select id="location" name="location">
                            <option value="">-- Alle Orte --</option>
                            @foreach($locations as $location)
                                <option value="{{ $location }}" {{ request('location') === $location ? 'selected' : '' }}>
                                    {{ $location }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="filter-group">
                        <button type="submit" class="btn-filter">🔍 Filtern</button>
                    </div>
                </div>
            </form>
        </div>

        @if($events->count() > 0)
            <div class="events-grid">
                @foreach($events as $event)
                    <div class="event-card">
                        <div class="event-image">
                            @if($event->image_url)
                                <img src="{{ $event->image_url }}" alt="{{ $event->title }}">
                            @else
                                <span>📅</span>
                            @endif
                        </div>
                        <div class="event-content">
                            @if($event->category)
                                <span class="event-category">{{ $event->category }}</span>
                            @endif
                            <h3 class="event-title">{{ $event->title }}</h3>
                            <p class="event-description">
                                {{ Str::limit($event->description, 120) }}
                            </p>
                            <div class="event-meta">
                                @if($event->occurrences->count() > 0)
                                    @php $firstOccurrence = $event->occurrences->first(); @endphp
                                    <div class="meta-item">
                                        <span class="meta-icon">📅</span>
                                        <span>{{ $firstOccurrence->start_datetime->format('d.m.Y H:i') }} Uhr</span>
                                    </div>
                                @endif
                                @if($event->location)
                                    <div class="meta-item">
                                        <span class="meta-icon">📍</span>
                                        <span>{{ $event->location }}</span>
                                    </div>
                                @endif
                                @if($event->occurrences->count() > 1)
                                    <div class="meta-item">
                                        <span class="meta-icon">🔔</span>
                                        <span>+{{ $event->occurrences->count() - 1 }} weitere Termin(e)</span>
                                    </div>
                                @endif
                            </div>
                            <a href="/events/{{ $event->id }}" class="event-link">Details anzeigen →</a>
                        </div>
                    </div>
                @endforeach
            </div>

            @if($events->hasPages())
                <div class="pagination">
                    {{ $events->render() }}
                </div>
            @endif
        @else
            <div class="no-events">
                <h3>😔 Keine Veranstaltungen gefunden</h3>
                <p>Versuchen Sie, Ihre Filter anzupassen.</p>
            </div>
        @endif
    </div>
</body>
</html>
