@extends('layouts.admin')
@section('title', 'Galeri')
@section('page-title', 'Galeri Foto')

@section('content')
<div class="flex items-center justify-between mb-6">
    <p class="text-gray-500 text-sm">{{ $galleries->total() }} foto</p>
    <a href="{{ route('admin.galeri.create') }}" class="btn-primary">+ Upload Foto</a>
</div>

<div class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4">
    @forelse($galleries as $gallery)
    <div class="group relative rounded-xl overflow-hidden bg-gray-100 aspect-square">
        @if($gallery->foto_url)
            <img src="{{ $gallery->foto_url }}" alt="{{ $gallery->judul }}" class="w-full h-full object-cover" loading="lazy">
        @else
            <div class="w-full h-full flex items-center justify-center text-3xl">🖼️</div>
        @endif
        <div class="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2">
            <a href="{{ route('admin.galeri.edit', $gallery->id) }}" class="w-8 h-8 bg-white rounded-full flex items-center justify-center text-primary hover:bg-blue-50 transition-colors">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg>
            </a>
            <form method="POST" action="{{ route('admin.galeri.destroy', $gallery->id) }}" data-confirm-delete>
                @csrf @method('DELETE')
                <button type="submit" class="w-8 h-8 bg-red-500 rounded-full flex items-center justify-center text-white hover:bg-red-600 transition-colors">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
                </button>
            </form>
        </div>
        @if($gallery->judul)
        <div class="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/60 p-2">
            <p class="text-white text-xs line-clamp-1">{{ $gallery->judul }}</p>
        </div>
        @endif
    </div>
    @empty
    <div class="col-span-full text-center py-12 text-gray-400">Belum ada foto galeri.</div>
    @endforelse
</div>
<div class="mt-6">{{ $galleries->links() }}</div>
@endsection
