@extends('admin.layouts.app')

@section('content')
    <div class="flex items-center justify-between mb-8">
        <h1 class="text-3xl font-bold">Manajemen Galeri</h1>
        <a href="{{ route('admin.galleries.create') }}"
           class="bg-blue-900 hover:bg-blue-800 text-white px-5 py-3 rounded-xl font-semibold">
            + Tambah Foto
        </a>
    </div>

    <div class="bg-white rounded-2xl shadow p-6 overflow-x-auto">
        <table class="w-full text-left">
            <thead>
                <tr class="border-b">
                    <th class="py-3">Foto</th>
                    <th class="py-3">Judul</th>
                    <th class="py-3">Status</th>
                    <th class="py-3">Tanggal</th>
                    <th class="py-3">Aksi</th>
                </tr>
            </thead>
            <tbody>
                @forelse($galleries as $gallery)
                    <tr class="border-b align-top">
                        <td class="py-3">
                            <img src="{{ asset($gallery->image) }}" alt="{{ $gallery->title }}" class="w-24 h-16 object-cover rounded-lg">
                        </td>
                        <td class="py-3 font-medium">{{ $gallery->title }}</td>
                        <td class="py-3">
                            @if($gallery->is_published)
                                <span class="px-3 py-1 rounded-full bg-green-100 text-green-700 text-sm">Publish</span>
                            @else
                                <span class="px-3 py-1 rounded-full bg-yellow-100 text-yellow-700 text-sm">Draft</span>
                            @endif
                        </td>
                        <td class="py-3">{{ $gallery->created_at->format('d M Y') }}</td>
                        <td class="py-3">
                            <div class="flex gap-2">
                                <a href="{{ route('admin.galleries.edit', $gallery) }}"
                                   class="bg-amber-500 hover:bg-amber-600 text-white px-4 py-2 rounded-lg text-sm">
                                    Edit
                                </a>

                                <form action="{{ route('admin.galleries.destroy', $gallery) }}" method="POST"
                                      onsubmit="return confirm('Yakin hapus foto ini?')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit"
                                            class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg text-sm">
                                        Hapus
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="5" class="py-4 text-slate-500">Belum ada foto galeri.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>

        <div class="mt-6">
            {{ $galleries->links() }}
        </div>
    </div>
@endsection