@extends('admin.layout')

@section('title', 'Biens')

@section('content')
    <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
        <h1 class="text-2xl font-semibold text-slate-900">Biens immobiliers</h1>
        <a href="{{ route('admin.biens.create') }}" class="inline-flex justify-center rounded-lg bg-sky-600 px-4 py-2 text-sm font-semibold text-white hover:bg-sky-700">Ajouter un bien</a>
    </div>

    <div class="mt-8 overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm">
        <table class="min-w-full divide-y divide-slate-200 text-sm">
            <thead class="bg-slate-50">
                <tr>
                    <th class="px-4 py-3 text-left font-semibold text-slate-700">Image</th>
                    <th class="px-4 py-3 text-left font-semibold text-slate-700">Nom</th>
                    <th class="px-4 py-3 text-left font-semibold text-slate-700">Lieu</th>
                    <th class="hidden px-4 py-3 text-left font-semibold text-slate-700 md:table-cell">Superficie</th>
                    <th class="hidden px-4 py-3 text-left font-semibold text-slate-700 lg:table-cell">Prix</th>
                    <th class="px-4 py-3 text-right font-semibold text-slate-700">Actions</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-slate-100">
                @forelse ($biens as $bien)
                    <tr class="hover:bg-slate-50/80">
                        <td class="px-4 py-3">
                            <img src="{{ $bien->imageUrl() }}" alt="" class="h-12 w-16 rounded object-cover">
                        </td>
                        <td class="px-4 py-3 font-medium text-slate-900">{{ $bien->nom }}</td>
                        <td class="px-4 py-3 text-slate-600">{{ $bien->lieu }}</td>
                        <td class="hidden px-4 py-3 text-slate-600 md:table-cell">{{ number_format((float) $bien->superficie, 0, ',', ' ') }} m²</td>
                        <td class="hidden px-4 py-3 text-slate-600 lg:table-cell">
                            @if ($bien->prix !== null)
                                {{ number_format((float) $bien->prix, 0, ',', ' ') }} F CFA
                            @else
                                —
                            @endif
                        </td>
                        <td class="px-4 py-3 text-right">
                            <a href="{{ route('admin.biens.edit', $bien) }}" class="text-sky-600 hover:text-sky-800">Modifier</a>
                            <form action="{{ route('admin.biens.destroy', $bien) }}" method="post" class="ml-3 inline" onsubmit="return confirm('Supprimer ce bien ?');">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="text-red-600 hover:text-red-800">Supprimer</button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="6" class="px-4 py-12 text-center text-slate-500">Aucun bien pour le moment. <a href="{{ route('admin.biens.create') }}" class="font-medium text-sky-600 hover:underline">Ajouter le premier</a>.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    @if ($biens->hasPages())
        <div class="mt-6">{{ $biens->links() }}</div>
    @endif
@endsection
