@extends('admin.layout')

@section('title', 'Messages contact')

@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">Messages reçus</h1>
    {{-- <a href="{{ route('admin.biens.index') }}" class="text-sm font-medium text-sky-600 hover:text-sky-800">← Biens</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">Date</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">Téléphone</th>
                <th class="px-4 py-3 text-left font-semibold text-slate-700">Message</th>
                <th class="px-4 py-3 text-right font-semibold text-slate-700"></th>
            </tr>
        </thead>
        <tbody class="divide-y divide-slate-100">
            @forelse ($messages as $msg)
            <tr class="align-top hover:bg-slate-50/80">
                <td class="whitespace-nowrap px-4 py-3 text-slate-500">{{ $msg->created_at->format('d/m/Y H:i') }}</td>
                <td class="px-4 py-3 font-medium text-slate-900">{{ $msg->nom_complet }}</td>
                <td class="whitespace-nowrap px-4 py-3 text-slate-600">{{ $msg->telephone }}</td>
                <td class="max-w-md px-4 py-3 text-slate-700">
                    <p class="whitespace-pre-wrap break-words">{{ $msg->message }}</p>
                </td>
                <td class="px-4 py-3 text-right">
                    <form action="{{ route('admin.messages.destroy', $msg) }}" method="post" class="inline" onsubmit="return confirm('Supprimer ce message ?');">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="text-red-600 hover:text-red-800">Supprimer</button>
                    </form>
                </td>
            </tr>
            @empty
            <tr>
                <td colspan="5" class="px-4 py-12 text-center text-slate-500">Aucun message pour le moment.</td>
            </tr>
            @endforelse
        </tbody>
    </table>
</div>

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