@extends('layouts.public')

@section('title', 'Daftar Aset - IPA')

@section('content')
    <section class="bg-gradient-to-r from-slate-50 via-slate-50 to-white border-b">
        <div class="container-custom py-10">
            <div class="grid gap-6 lg:grid-cols-[1.5fr_0.7fr] items-center">
                <div>
                    <h1 class="text-3xl md:text-4xl font-bold text-slate-900">Daftar Aset</h1>
                    <p class="text-slate-600 mt-2 max-w-xl">Telusuri seluruh aset daerah yang tersedia, gunakan pencarian dan filter untuk menemukan aset yang paling sesuai.</p>
                </div>
                <div class="rounded-3xl bg-white border border-slate-200 p-5 shadow-sm">
                    <div class="text-sm text-slate-500">Jumlah aset tersedia</div>
                    <div class="mt-3 text-3xl font-bold text-primary-600">{{ number_format($assets->total()) }}</div>
                    <a href="{{ route('map') }}" class="btn-secondary mt-4 inline-flex">Lihat Peta Aset</a>
                </div>
            </div>
        </div>
    </section>

    <section class="container-custom py-8">
        <form method="GET" action="{{ route('assets.index') }}" class="card p-6 mb-6">
            <div class="grid grid-cols-1 md:grid-cols-4 gap-3">
                <input type="text" name="q" value="{{ request('q') }}" placeholder="Cari aset..."
                    class="md:col-span-2 px-4 py-2.5 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent text-sm">

                <select name="kategori" class="px-4 py-2.5 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent text-sm">
                    <option value="">Semua Kategori</option>
                    @foreach($categories as $category)
                        <option value="{{ $category->slug }}" @selected(request('kategori') === $category->slug)>{{ $category->name }}</option>
                    @endforeach
                </select>

                <select name="opd" class="px-4 py-2.5 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent text-sm">
                    <option value="">Semua OPD</option>
                    @foreach($opds as $opd)
                        <option value="{{ $opd->id }}" @selected(request('opd') == $opd->id)>{{ $opd->name }}</option>
                    @endforeach
                </select>
            </div>

            <div class="mt-3 flex flex-col sm:flex-row gap-3 items-stretch sm:items-center justify-between">
                <div class="flex items-center gap-2">
                    <label class="text-sm text-gray-600">Urutkan:</label>
                    <select name="sort" onchange="this.form.submit()" class="px-3 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent text-sm">
                        <option value="latest" @selected(request('sort') === 'latest' || ! request('sort'))>Terbaru</option>
                        <option value="name" @selected(request('sort') === 'name')>Nama A-Z</option>
                        <option value="price_asc" @selected(request('sort') === 'price_asc')>Harga Terendah</option>
                        <option value="price_desc" @selected(request('sort') === 'price_desc')>Harga Tertinggi</option>
                    </select>
                </div>
                <div class="flex gap-2">
                    <a href="{{ route('assets.index') }}" class="btn-secondary text-sm">Reset</a>
                    <button type="submit" class="btn-primary text-sm">Terapkan Filter</button>
                </div>
            </div>
        </form>

        <div class="flex items-center justify-between mb-4">
            <p class="text-sm text-gray-600">Menampilkan <strong>{{ $assets->count() }}</strong> dari <strong>{{ $assets->total() }}</strong> aset</p>
        </div>

        @if($assets->count())
            <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-5">
                @foreach($assets as $asset)
                    <x-asset-card :asset="$asset" />
                @endforeach
            </div>

            <div class="mt-8">
                {{ $assets->links() }}
            </div>
        @else
            <div class="card p-12 text-center">
                <svg class="w-16 h-16 mx-auto text-gray-300 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                </svg>
                <h3 class="font-semibold text-gray-900 mb-1">Aset tidak ditemukan</h3>
                <p class="text-sm text-gray-500">Coba ubah kata kunci atau filter pencarian Anda</p>
            </div>
        @endif
    </section>
@endsection