@extends('layouts.dashboard')

@section('title', 'Contacts')

@section('content')
<h1 class="text-2xl font-bold text-slate-800 mb-8">Messages de contact</h1>

@if($contacts->isEmpty())
<div class="bg-white rounded-xl p-12 text-center border border-slate-100">
    <p class="text-slate-500">Aucun message reçu.</p>
</div>
@else
<div class="bg-white rounded-xl shadow-sm border border-slate-100 overflow-hidden">
    <table class="w-full">
        <thead class="bg-slate-50 border-b border-slate-200">
            <tr>
                <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Nom</th>
                <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Email</th>
                <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Sujet</th>
                <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Date</th>
                <th class="text-right px-6 py-4 text-sm font-semibold text-slate-700">Actions</th>
            </tr>
        </thead>
        <tbody>
            @foreach($contacts as $contact)
            <tr class="border-b border-slate-100 hover:bg-slate-50/50 {{ !$contact->lu ? 'bg-amber-50/30' : '' }}">
                <td class="px-6 py-4">
                    <a href="{{ route('dashboard.contacts.show', $contact) }}" class="font-medium text-slate-800 hover:text-amber-600 {{ !$contact->lu ? 'font-semibold' : '' }}">
                        {{ $contact->nom }}
                        @if(!$contact->lu)
                        <span class="text-amber-500 text-xs">(nouveau)</span>
                        @endif
                    </a>
                </td>
                <td class="px-6 py-4 text-slate-600">{{ $contact->email }}</td>
                <td class="px-6 py-4 text-slate-600">{{ $contact->sujet ?? '-' }}</td>
                <td class="px-6 py-4 text-slate-500 text-sm">{{ $contact->created_at->format('d/m/Y H:i') }}</td>
                <td class="px-6 py-4 text-right">
                    <a href="{{ route('dashboard.contacts.show', $contact) }}" class="text-amber-600 hover:text-amber-700 text-sm font-medium">Voir</a>
                    <form action="{{ route('dashboard.contacts.destroy', $contact) }}" method="POST" class="inline ml-2" onsubmit="return confirm('Supprimer ce message ?')">
                        @csrf
                        @method('DELETE')

                        <button type="submit" class="text-red-600 hover:text-red-700 text-sm font-medium"> <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>
                            Supprimer</button>
                    </form>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>

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