<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <title>Reçu Commission #{{ $commission->id }}</title>
    <link rel="icon" type="image/svg+xml" href="{{ asset('favicon.svg') }}">
    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}">
    <style>
        body { font-family: Arial, sans-serif; max-width: 720px; margin: 32px auto; padding: 24px; color: #1f2937; }
        .header { text-align: center; padding-bottom: 16px; margin-bottom: 24px; border-bottom: 2px solid #e5e7eb; }
        .brand { font-size: 26px; font-weight: 700; color: #2563eb; margin: 0; }
        .subtitle { margin: 4px 0 0; color: #6b7280; font-size: 13px; }
        .amount { background: #f0f9ff; border: 1px solid #e5f2ff; border-radius: 10px; padding: 18px; text-align: center; margin: 18px 0; }
        .amount .label { margin: 0; color: #6b7280; font-size: 13px; }
        .amount .value { margin: 6px 0 0; font-size: 26px; font-weight: 700; color: #16a34a; }
        .details table { width: 100%; border-collapse: collapse; }
        .details td { padding: 10px 8px; border-bottom: 1px solid #e5e7eb; font-size: 14px; }
        .details td:first-child { font-weight: 700; width: 42%; color: #374151; }
        .footer { text-align: center; font-size: 12px; color: #9ca3af; margin-top: 28px; padding-top: 16px; border-top: 1px solid #e5e7eb; }
        .qr { text-align: center; margin-top: 16px; }
        .qr img { width: 120px; height: 120px; }
        .badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
        .badge-success { background: #ecfdf3; color: #16a34a; }
        .badge-warning { background: #fffbeb; color: #d97706; }
        .badge-info { background: #eef2ff; color: #4338ca; }
        .badge-danger { background: #fef2f2; color: #b91c1c; }
        @media print { .no-print { display: none; } body { margin: 0; } }
    </style>
</head>
<body>
    <div class="header">
        <p class="brand">{{ config('app.name', 'ATARA') }}</p>
        <p class="subtitle">Reçu de commission</p>
    </div>

    <div class="amount">
        <p class="label">Montant</p>
        <p class="value">{{ number_format($commission->amount, 0, ',', ' ') }} XOF</p>
    </div>

    <div class="details">
        <table>
            <tr><td>Numéro de reçu</td><td>#COM-{{ str_pad($commission->id, 6, '0', STR_PAD_LEFT) }}</td></tr>
            <tr><td>Bénéficiaire</td><td>{{ $user->name }}</td></tr>
            <tr><td>Email</td><td>{{ $user->email }}</td></tr>
            <tr><td>Type</td><td>{{ $commission->type == 'sale' ? 'Commission sur vente' : 'Bonus' }}</td></tr>
            <tr><td>Niveau MLM</td><td>{{ $commission->level ? 'Niveau ' . $commission->level : '-' }}</td></tr>
            <tr><td>Statut</td><td>
                @php
                    $status = $commission->status;
                    $map = [
                        'paid' => ['badge-success','Payée'],
                        'approved' => ['badge-info','Approuvée'],
                        'pending' => ['badge-warning','En attente'],
                        'rejected' => ['badge-danger','Rejetée']
                    ];
                    $badge = $map[$status] ?? ['badge-info', ucfirst($status)];
                @endphp
                <span class="badge {{ $badge[0] }}">{{ $badge[1] }}</span>
            </td></tr>
            <tr><td>Date</td><td>{{ $commission->created_at->format('d/m/Y à H:i') }}</td></tr>
            <tr><td>Référence source</td><td>{{ $commission->reference ?? '—' }}</td></tr>
        </table>
    </div>

    <div class="footer">
        <p>Ce reçu est généré automatiquement par {{ config('app.name', 'ATARA') }}.</p>
        <p>Date d'impression: {{ now()->format('d/m/Y H:i') }}</p>
        <div class="no-print" style="margin-top:12px;">
            <button onclick="window.print()" style="padding:10px 30px;background:#2563eb;color:white;border:none;border-radius:6px;cursor:pointer;">Imprimer</button>
        </div>
    </div>
</body>
</html>
