<x-app-layout>
    <div class="min-h-screen bg-gray-50 pt-20">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
            <!-- Header -->
            <div class="mb-8">
                <div class="flex items-center justify-between mb-4">
                    <div>
                        <h1 class="text-2xl font-bold text-gray-900" style="color: {{ $siteInfo['theme_color'] }};">
                            {{ $siteInfo['name'] }} - Items
                        </h1>
                        <p class="text-gray-600 mt-1">{{ $items->total() }} items found</p>
                    </div>
                    <a href="{{ route('sites.' . $siteGroup . '.index') }}" 
                       class="text-gray-600 hover:text-gray-900 flex items-center">
                        ← Back to {{ $siteInfo['name'] }}
                    </a>
                </div>
            </div>

            <!-- Search and Filters -->
            <div class="bg-white border border-gray-200 rounded-lg p-6 mb-8">
                <form method="GET" class="space-y-4">
                    <div class="flex flex-col lg:flex-row lg:items-end gap-4">
                        <!-- Search -->
                        <div class="flex-1">
                            <input type="text" 
                                   name="search" 
                                   value="{{ request('search') }}" 
                                   placeholder="Search items..." 
                                   class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-opacity-50"
                                   style="focus:ring-color: {{ $siteInfo['theme_color'] }};">
                        </div>

                        <!-- Category Filter -->
                        <div class="lg:w-48">
                            <select name="category" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-opacity-50"
                                    style="focus:ring-color: {{ $siteInfo['theme_color'] }};">
                                <option value="">All Categories</option>
                                @foreach($categories as $category)
                                    <option value="{{ $category->id }}" {{ request('category') == $category->id ? 'selected' : '' }}>
                                        {{ $category->name }}
                                    </option>
                                @endforeach
                            </select>
                        </div>

                        <!-- Type Filter -->
                        <div class="lg:w-40">
                            <select name="type" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-opacity-50"
                                    style="focus:ring-color: {{ $siteInfo['theme_color'] }};">
                                <option value="">All Types</option>
                                <option value="sale" {{ request('type') == 'sale' ? 'selected' : '' }}>For Sale</option>
                                <option value="pre-market" {{ request('type') == 'pre-market' ? 'selected' : '' }}>Pre-Market</option>
                            </select>
                        </div>

                        <!-- Sort -->
                        <div class="lg:w-40">
                            <select name="sort" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-opacity-50"
                                    style="focus:ring-color: {{ $siteInfo['theme_color'] }};">
                                <option value="newest" {{ request('sort') == 'newest' ? 'selected' : '' }}>Newest</option>
                                <option value="oldest" {{ request('sort') == 'oldest' ? 'selected' : '' }}>Oldest</option>
                                <option value="price_low" {{ request('sort') == 'price_low' ? 'selected' : '' }}>Price: Low</option>
                                <option value="price_high" {{ request('sort') == 'price_high' ? 'selected' : '' }}>Price: High</option>
                            </select>
                        </div>

                        <!-- Submit -->
                        <button type="submit" 
                                class="px-6 py-2 text-white font-medium rounded-lg transition-colors hover:opacity-90"
                                style="background-color: {{ $siteInfo['theme_color'] }};">
                            Filter
                        </button>
                    </div>

                    <!-- Price Range -->
                    <div class="flex gap-4 max-w-md">
                        <input type="number" 
                               name="min_price" 
                               value="{{ request('min_price') }}" 
                               placeholder="Min price" 
                               step="0.01" 
                               class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-opacity-50"
                               style="focus:ring-color: {{ $siteInfo['theme_color'] }};">
                        <input type="number" 
                               name="max_price" 
                               value="{{ request('max_price') }}" 
                               placeholder="Max price" 
                               step="0.01" 
                               class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-opacity-50"
                               style="focus:ring-color: {{ $siteInfo['theme_color'] }};">
                    </div>

                    <div class="flex gap-4">
                        <a href="{{ route('sites.' . $siteGroup . '.items') }}" 
                           class="text-gray-600 hover:text-gray-900 text-sm">
                            Clear Filters
                        </a>
                    </div>
                </form>
            </div>

            <!-- Items Grid -->
            @if($items->count() > 0)
                <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 mb-8">
                    @foreach($items as $item)
                        <div class="bg-white border border-gray-200 rounded-lg overflow-hidden hover:shadow-lg transition-shadow">
                            <div class="aspect-square bg-gray-100 flex items-center justify-center">
                                @if($item->photos->count() > 0)
                                    <img src="{{ $item->photos->first()->url }}" alt="{{ $item->title }}" 
                                         class="w-full h-full object-cover">
                                @else
                                    <div class="text-gray-400 text-4xl">{{ $item->category->icon ?? '📦' }}</div>
                                @endif
                            </div>
                            <div class="p-4">
                                <h3 class="font-medium text-gray-900 mb-1 line-clamp-2">{{ $item->title }}</h3>
                                <p class="text-gray-600 text-sm mb-2">{{ $item->category->name }}</p>
                                <p class="text-gray-500 text-xs mb-3">by {{ $item->user->name }}</p>
                                
                                <div class="flex items-center justify-between">
                                    @if($item->price)
                                        <p class="font-bold text-lg" style="color: {{ $siteInfo['theme_color'] }};">
                                            ${{ number_format($item->price, 2) }}
                                        </p>
                                    @else
                                        <p class="text-gray-500 text-sm font-medium">Make Offer</p>
                                    @endif

                                    <div class="text-right">
                                        @if($item->listing_type === 'pre-market')
                                            <span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full bg-purple-100 text-purple-800">
                                                Pre-Market
                                            </span>
                                        @elseif($item->listing_type === 'sale')
                                            <span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full bg-green-100 text-green-800">
                                                For Sale
                                            </span>
                                        @endif
                                    </div>
                                </div>

                                <div class="mt-3">
                                    <a href="{{ route('items.show', $item) }}" 
                                       class="block w-full text-center px-4 py-2 border border-gray-300 text-gray-700 hover:bg-gray-50 rounded-lg transition-colors">
                                        View Details
                                    </a>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>

                <!-- Pagination -->
                <div class="flex justify-center">
                    {{ $items->links() }}
                </div>
            @else
                <div class="bg-white border border-gray-200 rounded-lg p-12 text-center">
                    <div class="text-4xl mb-4">🔍</div>
                    <h3 class="text-lg font-medium text-gray-900 mb-2">No items found</h3>
                    <p class="text-gray-600 mb-6">Try adjusting your search criteria or browse categories</p>
                    <div class="flex gap-4 justify-center">
                        <a href="{{ route('sites.' . $siteGroup . '.items') }}" 
                           class="text-gray-600 hover:text-gray-900">Clear filters</a>
                        <a href="{{ route('sites.' . $siteGroup . '.index') }}" 
                           class="text-gray-600 hover:text-gray-900">Browse categories</a>
                    </div>
                </div>
            @endif
        </div>
    </div>
</x-app-layout>