@php use App\Enums\NotificationStatus; @endphp
<div class="max-w-full sm:max-w-4xl mx-auto p-4 sm:p-6 bg-white shadow rounded">
  <h2 class="text-xl font-semibold mb-6 text-center sm:text-left">
    Détails de {{ $donateur->nom }} {{ $donateur->prenom }} <br> {{ $donateur->fonction }}
  </h2>

  {{-- Statistiques --}}
  <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
    <div class="p-4 bg-blue-50 rounded text-center">
      <h3 class="text-sm text-gray-500 uppercase">Total Liens</h3>
      <p class="text-2xl font-bold">{{ $donateur->links->count() }}</p>
    </div>
    <div class="p-4 bg-green-50 rounded text-center">
      <h3 class="text-sm text-gray-500 uppercase">Payés</h3>
      <p class="text-2xl font-bold">{{ $donateur->payments->count() }}</p>
    </div>
    <div class="p-4 bg-yellow-50 rounded text-center">
      <h3 class="text-sm text-gray-500 uppercase">En attente</h3>
      <p class="text-2xl font-bold">{{ $donateur->links->where('status','pending')->count() }}</p>
    </div>
    <div class="p-4 bg-indigo-50 rounded text-center">
      <h3 class="text-sm text-gray-500 uppercase">Montant Total Payé</h3>
      <p class="text-2xl font-bold">{{ number_format($donateur->payments->sum('amount'), 0, ',', ' ') }} XOF</p>
    </div>
  </div>

  {{-- Table des liens --}}
  <div class="overflow-x-auto">
    <table class="min-w-full table-auto divide-y divide-gray-200 datatable">
      <thead class="bg-gray-50">
        <tr>
          <th class="px-4 py-2 text-left text-sm font-medium text-gray-500 uppercase">Campagne</th>
          <th class="px-4 py-2 text-left text-sm font-medium text-gray-500 uppercase">Lien</th>
          <th class="px-4 py-2 text-left text-sm font-medium text-gray-500 uppercase">Email</th>
          <th class="px-4 py-2 text-left text-sm font-medium text-gray-500 uppercase">WhatsApp</th>
          <th class="px-4 py-2 text-left text-sm font-medium text-gray-500 uppercase">Statut Paiement</th>
          <th class="px-4 py-2 text-right text-sm font-medium text-gray-500 uppercase">Montant</th>
        </tr>
      </thead>
      <tbody class="bg-white divide-y divide-gray-200">
        @foreach($donateur->links as $link)
        <tr class="hover:bg-gray-50">
          <td class="px-4 py-2 whitespace-nowrap">{{ $link->campaign->name }}</td>
          <td class="px-4 py-2 whitespace-nowrap">
            <button
              type="button"
              onclick="window.location='{{ url('/don/'.$link->campaign->slug.'/'.$link->token) }}'"
              class="px-3 py-1 bg-blue-600 text-white rounded hover:bg-blue-700 transition"
            >
              Voir
            </button>

            <button
              type="button"
              onclick="window.location='{{ route('links.details', $link) }}'"
              class="px-3 py-1 bg-indigo-600 text-white rounded hover:bg-indigo-700 transition"
            >
              Détails
            </button>
          </td>
          <td class="px-4 py-2 whitespace-nowrap">
            @if($link->email_status === NotificationStatus::Sent)
              <span class="text-green-600 font-semibold">Envoyé</span>
            @else
              <span class="text-red-600 font-semibold">Non envoyé</span>
            @endif
          </td>
          <td class="px-4 py-2 whitespace-nowrap">
            @if($link->whatsapp_status === NotificationStatus::Sent)
              <span class="text-green-600 font-semibold">Envoyé</span>
            @else
              <span class="text-red-600 font-semibold">Non envoyé</span>
            @endif
          </td>
          <td class="px-4 py-2 whitespace-nowrap">
            @switch($link->status)
              @case('paid')<span class="text-green-600 font-semibold">Payé</span>@break
              @case('pending')<span class="text-yellow-600 font-semibold">En attente</span>@break
              @case('failed')<span class="text-red-600 font-semibold">Échoué</span>@break
              @case('canceled')<span class="text-gray-600 font-semibold">Annulé</span>@break
              @default{{ ucfirst($link->status->value) }}
            @endswitch
          </td>
          <td class="px-4 py-2 text-right whitespace-nowrap">{{ number_format($link->payments->sum('amount'), 0, ',', ' ') }} XOF</td>
        </tr>
        @endforeach
      </tbody>
    </table>
  </div>

  <div class="mt-6 text-center">
    <a href="{{ route('donateurs.index') }}" class="inline-block px-4 py-2 bg-gray-200 rounded hover:bg-gray-300">Retour</a>
  </div>
</div>
