@extends('layouts.admin')

@section('title', 'Demandes de Retrait')

@section('content')
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 mb-0">Demandes de Retrait</h1>
        <a href="{{ route('admin.wallets.index') }}" class="btn btn-secondary">Retour aux Wallets</a>
    </div>

    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif
    @if(session('error'))
        <div class="alert alert-danger">{{ session('error') }}</div>
    @endif

    <div class="row mb-4">
        <div class="col-md-4">
            <div class="card bg-warning text-dark">
                <div class="card-body">
                    <h6>Demandes en attente</h6>
                    <h3>{{ $pendingCount }}</h3>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card bg-primary text-white">
                <div class="card-body">
                    <h6>Montant en attente</h6>
                    <h3>{{ number_format($pendingAmount, 0, ',', ' ') }} XOF</h3>
                </div>
            </div>
        </div>
    </div>

    <div class="card mb-4">
        <div class="card-body">
            <form action="{{ route('admin.wallets.withdrawals') }}" method="GET" class="row g-3">
                <div class="col-md-4">
                    <select name="status" class="form-select">
                        <option value="">Tous les statuts</option>
                        <option value="pending" {{ request('status') == 'pending' ? 'selected' : '' }}>En attente</option>
                        <option value="processing" {{ request('status') == 'processing' ? 'selected' : '' }}>En traitement</option>
                        <option value="completed" {{ request('status') == 'completed' ? 'selected' : '' }}>Complété</option>
                        <option value="rejected" {{ request('status') == 'rejected' ? 'selected' : '' }}>Rejeté</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">Filtrer</button>
                </div>
            </form>
        </div>
    </div>

    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Date</th>
                            <th>Référence</th>
                            <th>Utilisateur</th>
                            <th>Montant</th>
                            <th>Frais</th>
                            <th>Net</th>
                            <th>Méthode</th>
                            <th>Statut</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($withdrawals as $withdrawal)
                        <tr>
                            <td>{{ $withdrawal->created_at->format('d/m/Y H:i') }}</td>
                            <td><code>{{ $withdrawal->reference }}</code></td>
                            <td>{{ $withdrawal->user->name ?? 'N/A' }}</td>
                            <td>{{ number_format($withdrawal->amount, 0, ',', ' ') }}</td>
                            <td>{{ number_format($withdrawal->fee, 0, ',', ' ') }}</td>
                            <td><strong>{{ number_format($withdrawal->net_amount, 0, ',', ' ') }}</strong></td>
                            <td>{{ $withdrawal->payment_method }}</td>
                            <td>
                                @switch($withdrawal->status)
                                    @case('pending')
                                        <span class="badge bg-warning text-dark">En attente</span>
                                        @break
                                    @case('processing')
                                        <span class="badge bg-info">En traitement</span>
                                        @break
                                    @case('completed')
                                        <span class="badge bg-success">Complété</span>
                                        @break
                                    @case('rejected')
                                        <span class="badge bg-danger">Rejeté</span>
                                        @break
                                @endswitch
                            </td>
                            <td>
                                <button class="btn btn-sm btn-info" data-bs-toggle="modal" data-bs-target="#detailModal{{ $withdrawal->id }}">
                                    <i class="fas fa-eye"></i> Détails
                                </button>
                                @if($withdrawal->status === 'pending')
                                <form action="{{ route('admin.wallets.withdrawals.approve', $withdrawal) }}" method="POST" class="d-inline">
                                    @csrf
                                    <button type="submit" class="btn btn-sm btn-success" onclick="return confirm('Confirmer l\'approbation de ce retrait ?')">
                                        <i class="fas fa-check"></i> Approuver
                                    </button>
                                </form>
                                <button class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#rejectModal{{ $withdrawal->id }}">
                                    <i class="fas fa-times"></i> Rejeter
                                </button>
                                @endif
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="9" class="text-center">Aucune demande de retrait</td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            {{ $withdrawals->links() }}
        </div>
    </div>
</div>

{{-- STYLES MODERNES HARMONISÉS AVEC LE BACK-OFFICE ADMIN --}}
<style>
    :root {
        --admin-primary: #4f46e5;
        --admin-primary-light: #6366f1;
        --admin-primary-dark: #4338ca;
        --admin-secondary: #64748b;
        --admin-success: #10b981;
        --admin-success-light: #34d399;
        --admin-warning: #f59e0b;
        --admin-danger: #ef4444;
        --admin-info: #0ea5e9;
        --admin-bg: #f8fafc;
        --admin-card-bg: #ffffff;
        --admin-border: #e2e8f0;
        --admin-text: #1e293b;
        --admin-text-muted: #64748b;
    }

    .withdrawal-modal .modal-content {
        border: none;
        border-radius: 16px;
        overflow: hidden;
        box-shadow: 0 20px 40px rgba(79, 70, 229, 0.15), 0 0 0 1px rgba(79, 70, 229, 0.05);
    }
    
    .withdrawal-modal .modal-header {
        background: linear-gradient(135deg, var(--admin-primary) 0%, var(--admin-primary-dark) 100%);
        border: none;
        padding: 1.25rem 1.5rem;
    }
    
    .withdrawal-modal .modal-header.bg-reject {
        background: linear-gradient(135deg, var(--admin-danger) 0%, #dc2626 100%);
    }
    
    .withdrawal-modal .modal-body {
        padding: 1.5rem;
        background: var(--admin-bg);
    }
    
    .withdrawal-modal .modal-footer {
        border: none;
        padding: 1rem 1.5rem;
        background: var(--admin-card-bg);
        border-top: 1px solid var(--admin-border);
    }
    
    .info-card {
        background: var(--admin-card-bg);
        border-radius: 12px;
        padding: 1rem;
        border: 1px solid var(--admin-border);
        transition: all 0.2s ease;
    }
    
    .info-card:hover {
        border-color: var(--admin-primary-light);
        box-shadow: 0 4px 12px rgba(79, 70, 229, 0.1);
    }
    
    .info-card .icon {
        width: 44px;
        height: 44px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.125rem;
    }
    
    .info-card.user .icon { 
        background: linear-gradient(135deg, var(--admin-primary) 0%, var(--admin-primary-light) 100%); 
        color: white; 
    }
    .info-card.amount .icon { 
        background: linear-gradient(135deg, var(--admin-info) 0%, #38bdf8 100%); 
        color: white; 
    }
    .info-card.fee .icon { 
        background: linear-gradient(135deg, var(--admin-warning) 0%, #fbbf24 100%); 
        color: white; 
    }
    .info-card.net .icon { 
        background: linear-gradient(135deg, var(--admin-success) 0%, var(--admin-success-light) 100%); 
        color: white; 
    }
    
    .payment-box {
        background: var(--admin-card-bg);
        border: 2px solid var(--admin-primary);
        border-radius: 12px;
        padding: 1.25rem;
        position: relative;
    }
    
    .payment-box::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 4px;
        background: linear-gradient(90deg, var(--admin-primary), var(--admin-primary-light));
        border-radius: 12px 12px 0 0;
    }
    
    .payment-number {
        font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
        font-size: 1.5rem;
        font-weight: 700;
        color: var(--admin-primary-dark);
        background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
        padding: 0.75rem 1.25rem;
        border-radius: 10px;
        border: 2px solid var(--admin-primary-light);
        display: inline-block;
        letter-spacing: 1px;
    }
    
    .copy-btn {
        background: var(--admin-primary);
        border: none;
        color: white;
        padding: 0.625rem 1rem;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s ease;
        font-weight: 500;
        font-size: 0.875rem;
    }
    
    .copy-btn:hover {
        background: var(--admin-primary-dark);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    }
    
    .status-badge {
        padding: 0.5rem 1rem;
        border-radius: 8px;
        font-weight: 600;
        font-size: 0.8125rem;
        display: inline-flex;
        align-items: center;
        gap: 0.375rem;
    }
    
    .status-pending { 
        background: #fef3c7; 
        color: #b45309;
        border: 1px solid #fcd34d;
    }
    .status-approved { 
        background: #dbeafe; 
        color: #1d4ed8;
        border: 1px solid #93c5fd;
    }
    .status-completed { 
        background: #d1fae5; 
        color: #047857;
        border: 1px solid #6ee7b7;
    }
    .status-rejected { 
        background: #fee2e2; 
        color: #b91c1c;
        border: 1px solid #fca5a5;
    }
    
    .method-badge {
        padding: 0.5rem 0.875rem;
        border-radius: 8px;
        font-weight: 600;
        font-size: 0.8125rem;
        display: inline-flex;
        align-items: center;
        gap: 0.375rem;
    }
    
    .method-mobile { 
        background: linear-gradient(135deg, var(--admin-success) 0%, var(--admin-success-light) 100%); 
        color: white; 
    }
    .method-bank { 
        background: linear-gradient(135deg, var(--admin-primary) 0%, var(--admin-primary-light) 100%); 
        color: white; 
    }
    .method-wave { 
        background: linear-gradient(135deg, #0ea5e9 0%, #38bdf8 100%); 
        color: white; 
    }
    .method-orange { 
        background: linear-gradient(135deg, #f97316 0%, #fb923c 100%); 
        color: white; 
    }
    
    .btn-modern {
        border: none;
        padding: 0.625rem 1.25rem;
        border-radius: 8px;
        font-weight: 600;
        font-size: 0.875rem;
        transition: all 0.2s ease;
        display: inline-flex;
        align-items: center;
        gap: 0.375rem;
    }
    
    .btn-modern:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    
    .btn-approve {
        background: var(--admin-success);
        color: white;
    }
    .btn-approve:hover {
        background: #059669;
        color: white;
    }
    
    .btn-reject {
        background: var(--admin-danger);
        color: white;
    }
    .btn-reject:hover {
        background: #dc2626;
        color: white;
    }
    
    .btn-close-modern {
        background: var(--admin-border);
        color: var(--admin-text);
    }
    .btn-close-modern:hover {
        background: #cbd5e1;
        color: var(--admin-text);
    }
    
    .section-title {
        font-size: 0.75rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--admin-text-muted);
        margin-bottom: 0.75rem;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    .section-title i {
        color: var(--admin-primary);
    }
    
    .section-title::after {
        content: '';
        flex: 1;
        height: 1px;
        background: var(--admin-border);
        margin-left: 0.5rem;
    }
    
    /* Amélioration du tableau */
    .table thead th {
        background: var(--admin-bg);
        border-bottom: 2px solid var(--admin-border);
        color: var(--admin-text-muted);
        font-weight: 600;
        font-size: 0.8125rem;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        padding: 0.875rem;
    }
    
    .table tbody td {
        padding: 0.875rem;
        vertical-align: middle;
        border-bottom: 1px solid var(--admin-border);
    }
    
    .table tbody tr:hover {
        background: #f8fafc;
    }
</style>

<!-- Modals de détails ULTRA MODERNES -->
@foreach($withdrawals as $withdrawal)
<div class="modal fade withdrawal-modal" id="detailModal{{ $withdrawal->id }}" tabindex="-1" aria-labelledby="detailModalLabel{{ $withdrawal->id }}" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
    <div class="modal-dialog modal-lg modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header">
                <div>
                    <h5 class="modal-title text-white mb-1" id="detailModalLabel{{ $withdrawal->id }}">
                        <i class="bi bi-receipt me-2"></i>Détails du Retrait
                    </h5>
                    <span class="text-white-50 small">{{ $withdrawal->reference }}</span>
                </div>
                <button type="button" class="btn btn-light btn-sm rounded-circle" data-bs-dismiss="modal" aria-label="Fermer" style="width: 36px; height: 36px;">
                    <i class="bi bi-x-lg"></i>
                </button>
            </div>
            <div class="modal-body">
                {{-- ROW 1: Informations utilisateur et statut --}}
                <div class="row g-3 mb-4">
                    <div class="col-md-8">
                        <div class="info-card user h-100">
                            <div class="d-flex align-items-center gap-3">
                                <div class="icon">
                                    <i class="bi bi-person-fill"></i>
                                </div>
                                <div>
                                    <div class="text-muted small">Demandeur</div>
                                    <div class="fw-bold fs-5">{{ $withdrawal->user->name ?? 'N/A' }}</div>
                                    <div class="text-muted small">{{ $withdrawal->user->email ?? '' }} • {{ $withdrawal->user->phone ?? '' }}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="info-card h-100 text-center">
                            <div class="text-muted small mb-2">Statut</div>
                            @switch($withdrawal->status)
                                @case('pending')
                                    <span class="status-badge status-pending">⏳ En attente</span>
                                    @break
                                @case('processing')
                                    <span class="status-badge status-approved">🔄 En cours</span>
                                    @break
                                @case('approved')
                                @case('completed')
                                    <span class="status-badge status-completed">✅ Complété</span>
                                    @break
                                @case('rejected')
                                    <span class="status-badge status-rejected">❌ Rejeté</span>
                                    @break
                            @endswitch
                            <div class="text-muted small mt-2">{{ $withdrawal->created_at->format('d/m/Y H:i') }}</div>
                        </div>
                    </div>
                </div>

                {{-- ROW 2: Montants --}}
                <div class="section-title">
                    <i class="bi bi-cash-stack"></i> Informations Financières
                </div>
                <div class="row g-3 mb-4">
                    <div class="col-md-4">
                        <div class="info-card amount">
                            <div class="d-flex align-items-center gap-3">
                                <div class="icon">
                                    <i class="bi bi-wallet2"></i>
                                </div>
                                <div>
                                    <div class="text-muted small">Montant demandé</div>
                                    <div class="fw-bold fs-5 text-primary">{{ number_format($withdrawal->amount, 0, ',', ' ') }} <small>XOF</small></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="info-card fee">
                            <div class="d-flex align-items-center gap-3">
                                <div class="icon">
                                    <i class="bi bi-dash-circle"></i>
                                </div>
                                <div>
                                    <div class="text-muted small">Frais</div>
                                    <div class="fw-bold fs-5 text-warning">-{{ number_format($withdrawal->fee ?? 0, 0, ',', ' ') }} <small>XOF</small></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="info-card net">
                            <div class="d-flex align-items-center gap-3">
                                <div class="icon">
                                    <i class="bi bi-check-circle-fill"></i>
                                </div>
                                <div>
                                    <div class="text-muted small">Net à payer</div>
                                    <div class="fw-bold fs-4 text-success">{{ number_format($withdrawal->net_amount ?? $withdrawal->amount, 0, ',', ' ') }} <small>XOF</small></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                {{-- ROW 3: Coordonnées de paiement --}}
                <div class="section-title">
                    <i class="bi bi-credit-card-2-front"></i> Coordonnées de Paiement
                    <span class="badge bg-danger ms-2 rounded-pill">IMPORTANT</span>
                </div>
                
                <div class="payment-box mb-4">
                    <div class="d-flex align-items-center gap-3 mb-3">
                        @switch($withdrawal->payment_method)
                            @case('bank_transfer')
                                <span class="method-badge method-bank"><i class="bi bi-bank"></i> Virement Bancaire</span>
                                @break
                            @case('mobile_money')
                                <span class="method-badge method-mobile"><i class="bi bi-phone"></i> Mobile Money</span>
                                @break
                            @case('wave')
                                <span class="method-badge method-wave"><i class="bi bi-phone"></i> Wave</span>
                                @break
                            @case('orange_money')
                                <span class="method-badge method-orange"><i class="bi bi-phone"></i> Orange Money</span>
                                @break
                            @default
                                <span class="method-badge method-mobile"><i class="bi bi-credit-card"></i> {{ ucfirst($withdrawal->payment_method) }}</span>
                        @endswitch
                    </div>
                    
                    @if($withdrawal->payment_details && is_array($withdrawal->payment_details) && count($withdrawal->payment_details) > 0)
                        {{-- Mobile Money / Wave / Orange Money --}}
                        @if(isset($withdrawal->payment_details['phone']))
                            <div class="mb-3">
                                <div class="text-muted small mb-2"><i class="bi bi-telephone me-1"></i> Numéro de téléphone pour le paiement:</div>
                                <div class="d-flex align-items-center gap-3 flex-wrap">
                                    <span class="payment-number" id="phone-{{ $withdrawal->id }}">{{ $withdrawal->payment_details['phone'] }}</span>
                                    <button type="button" class="copy-btn" onclick="copyToClipboard('{{ $withdrawal->payment_details['phone'] }}', this)">
                                        <i class="bi bi-clipboard me-1"></i> Copier
                                    </button>
                                </div>
                            </div>
                        @endif
                        
                        {{-- Virement Bancaire --}}
                        @if(isset($withdrawal->payment_details['bank_info']))
                            <div class="mb-3">
                                <div class="text-muted small mb-2"><i class="bi bi-bank me-1"></i> Informations bancaires (RIB/IBAN):</div>
                                <div class="d-flex align-items-start gap-3 flex-wrap">
                                    <span class="payment-number" style="font-size: 1.25rem; white-space: pre-wrap;" id="bank-{{ $withdrawal->id }}">{{ $withdrawal->payment_details['bank_info'] }}</span>
                                    <button type="button" class="copy-btn" onclick="copyToClipboard('{{ addslashes($withdrawal->payment_details['bank_info']) }}', this)">
                                        <i class="bi bi-clipboard me-1"></i> Copier
                                    </button>
                                </div>
                            </div>
                        @endif
                        
                        {{-- Ancien format --}}
                        @if(isset($withdrawal->payment_details['account_holder_name']))
                            <div class="mb-2"><strong>Bénéficiaire:</strong> {{ $withdrawal->payment_details['account_holder_name'] }}</div>
                        @endif
                        @if(isset($withdrawal->payment_details['bank_name']))
                            <div class="mb-2"><strong>Banque:</strong> {{ $withdrawal->payment_details['bank_name'] }}</div>
                        @endif
                        @if(isset($withdrawal->payment_details['bank_account_number']))
                            <div class="d-flex align-items-center gap-3">
                                <span class="payment-number">{{ $withdrawal->payment_details['bank_account_number'] }}</span>
                                <button type="button" class="copy-btn" onclick="copyToClipboard('{{ $withdrawal->payment_details['bank_account_number'] }}', this)">
                                    <i class="bi bi-clipboard me-1"></i> Copier
                                </button>
                            </div>
                        @endif
                        
                        {{-- Autres champs --}}
                        @foreach($withdrawal->payment_details as $key => $value)
                            @if(!in_array($key, ['phone', 'bank_info', 'account_holder_name', 'bank_name', 'bank_account_number']))
                                <div class="mb-2"><strong>{{ ucfirst(str_replace('_', ' ', $key)) }}:</strong> {{ $value }}</div>
                            @endif
                        @endforeach
                    @else
                        <div class="alert alert-danger mb-0">
                            <i class="bi bi-exclamation-triangle-fill me-2"></i>
                            <strong>Attention:</strong> Aucune coordonnée de paiement fournie. Contactez l'utilisateur.
                        </div>
                    @endif
                </div>

                {{-- Informations supplémentaires --}}
                @if($withdrawal->rejection_reason)
                    <div class="alert alert-danger">
                        <i class="bi bi-x-circle-fill me-2"></i>
                        <strong>Raison du rejet:</strong> {{ $withdrawal->rejection_reason }}
                    </div>
                @endif
                
                @if($withdrawal->approved_at)
                    <div class="text-muted small">
                        <i class="bi bi-check-circle me-1"></i> Approuvé le {{ $withdrawal->approved_at->format('d/m/Y à H:i') }}
                        @if($withdrawal->approvedByUser) par {{ $withdrawal->approvedByUser->name }} @endif
                    </div>
                @endif
            </div>
            <div class="modal-footer">
                @if($withdrawal->status === 'pending')
                    <form action="{{ route('admin.wallets.withdrawals.approve', $withdrawal) }}" method="POST" class="d-inline">
                        @csrf
                        <button type="submit" class="btn btn-modern btn-approve" onclick="return confirm('✅ Confirmer l\'approbation et le paiement de {{ number_format($withdrawal->net_amount ?? $withdrawal->amount, 0, ',', ' ') }} XOF ?')">
                            <i class="bi bi-check-lg me-2"></i>Approuver le retrait
                        </button>
                    </form>
                    <button type="button" class="btn btn-modern btn-reject" onclick="openRejectModal({{ $withdrawal->id }})">
                        <i class="bi bi-x-lg me-2"></i>Rejeter
                    </button>
                @endif
                <button type="button" class="btn btn-modern btn-close-modern" data-bs-dismiss="modal">
                    <i class="bi bi-x me-1"></i>Fermer
                </button>
            </div>
        </div>
    </div>
</div>
@endforeach

<!-- Modals de rejet -->
@foreach($withdrawals->where('status', 'pending') as $withdrawal)
<div class="modal fade withdrawal-modal" id="rejectModal{{ $withdrawal->id }}" tabindex="-1" aria-hidden="true" data-bs-backdrop="static">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <form action="{{ route('admin.wallets.withdrawals.reject', $withdrawal) }}" method="POST">
                @csrf
                <div class="modal-header bg-reject">
                    <div>
                        <h5 class="modal-title text-white mb-1">
                            <i class="bi bi-x-circle me-2"></i>Rejeter le retrait
                        </h5>
                        <span class="text-white-50 small">{{ $withdrawal->reference }}</span>
                    </div>
                    <button type="button" class="btn btn-light btn-sm rounded-circle" data-bs-dismiss="modal" style="width: 36px; height: 36px;">
                        <i class="bi bi-x-lg"></i>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="info-card user mb-4">
                        <div class="d-flex align-items-center gap-3">
                            <div class="icon">
                                <i class="bi bi-person-fill"></i>
                            </div>
                            <div>
                                <div class="fw-bold">{{ $withdrawal->user->name ?? 'N/A' }}</div>
                                <div class="text-muted small">Montant: <strong class="text-danger">{{ number_format($withdrawal->amount, 0, ',', ' ') }} XOF</strong></div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label fw-bold">
                            <i class="bi bi-chat-left-text me-1"></i> Raison du rejet <span class="text-danger">*</span>
                        </label>
                        <textarea name="rejection_reason" class="form-control" rows="3" required 
                            style="border-radius: 12px; border: 2px solid #e2e8f0;"
                            placeholder="Ex: Informations bancaires incorrectes, vérification KYC échouée..."></textarea>
                    </div>
                    
                    <div class="alert alert-info" style="border-radius: 12px; border: none; background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);">
                        <i class="bi bi-info-circle-fill me-2"></i>
                        Le montant de <strong>{{ number_format($withdrawal->amount, 0, ',', ' ') }} XOF</strong> sera automatiquement remboursé au portefeuille.
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-modern btn-close-modern" data-bs-dismiss="modal">Annuler</button>
                    <button type="submit" class="btn btn-modern btn-reject">
                        <i class="bi bi-x-lg me-2"></i>Confirmer le rejet
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
@endforeach

<script>
// Fonction pour copier dans le presse-papier avec feedback visuel
function copyToClipboard(text, button) {
    navigator.clipboard.writeText(text).then(function() {
        const originalHTML = button.innerHTML;
        button.innerHTML = '<i class="bi bi-check-lg me-1"></i> Copié !';
        button.style.background = 'linear-gradient(135deg, #11998e 0%, #38ef7d 100%)';
        setTimeout(function() {
            button.innerHTML = originalHTML;
            button.style.background = 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)';
        }, 2000);
    }).catch(function(err) {
        alert('Erreur lors de la copie: ' + err);
    });
}

// Fonction pour ouvrir le modal de rejet depuis le modal de détails
function openRejectModal(withdrawalId) {
    // Fermer le modal de détails
    var detailModal = bootstrap.Modal.getInstance(document.getElementById('detailModal' + withdrawalId));
    if (detailModal) {
        detailModal.hide();
    }
    // Attendre que le premier modal soit fermé puis ouvrir le second
    setTimeout(function() {
        var rejectModal = new bootstrap.Modal(document.getElementById('rejectModal' + withdrawalId));
        rejectModal.show();
    }, 300);
}
</script>
@endsection
