<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Reçu de paiement - #{{ $payment->id }}</title>
    <style>
        body {
            font-family: 'DejaVu Sans', sans-serif;
            font-size: 12px;
            line-height: 1.6;
            color: #333;
        }
        .header {
            border-bottom: 3px solid #3498db;
            padding-bottom: 20px;
            margin-bottom: 30px;
        }
        .header h1 {
            color: #3498db;
            margin: 0;
            font-size: 24px;
        }
        .invoice-info {
            margin: 20px 0;
        }
        .section {
            margin-bottom: 30px;
        }
        .section-title {
            background-color: #f8f9fa;
            padding: 10px;
            font-weight: bold;
            border-left: 4px solid #3498db;
            margin-bottom: 15px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        table th, table td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        table th {
            background-color: #f8f9fa;
            font-weight: bold;
        }
        .badge {
            display: inline-block;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 11px;
            font-weight: bold;
        }
        .badge.status-validated {
            background-color: #d4edda;
            color: #155724;
        }
        .badge.status-pending {
            background-color: #fff3cd;
            color: #856404;
        }
        .badge.status-rejected {
            background-color: #f8d7da;
            color: #721c24;
        }
        .footer {
            margin-top: 50px;
            padding-top: 20px;
            border-top: 2px solid #eee;
            text-align: center;
            color: #666;
            font-size: 11px;
        }
        .company-info {
            background-color: #f8f9fa;
            padding: 15px;
            border-left: 4px solid #3498db;
            margin-bottom: 20px;
        }
        .company-info h2 {
            margin: 0 0 10px 0;
            color: #3498db;
            font-size: 18px;
        }
        .company-info p {
            margin: 5px 0;
            color: #666;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>Reçu de paiement #{{ $payment->id }}</h1>
        <p style="margin-top: 5px; color: #666;">Date: {{ $payment->created_at->format('d/m/Y H:i') }}</p>
    </div>

    <div class="company-info">
        <h2>Informations de l'Entreprise</h2>
        <p><strong>Nom de l'entreprise:</strong> SM Bayar</p>
        <p><strong>Adresse:</strong> Ksar Hellal</p>
        <p><strong>Email:</strong> contact@smbayer.com</p>
        <p><strong>Téléphone:</strong> 53 338 869</p>
    </div>

    <div class="section">
        <div class="section-title">Informations Client</div>
        <table>
            <tr>
                <th>Nom</th>
                <td>{{ $payment->client->firstname }} {{ $payment->client->lastname }}</td>
            </tr>
            <tr>
                <th>Téléphone</th>
                <td>{{ $payment->client->phone_number }}</td>
            </tr>
            @if($payment->client->adress)
            <tr>
                <th>Adresse</th>
                <td>{{ $payment->client->adress }}</td>
            </tr>
            @endif
            @if($payment->client->taxNumber)
            <tr>
                <th>Matricule fiscale</th>
                <td>{{ $payment->client->taxNumber }}</td>
            </tr>
            @endif
        </table>
    </div>

    <div class="section">
        <div class="section-title">Détails du Paiement</div>
        <table>
            <tr>
                <th>Montant</th>
                <td>{{ number_format($payment->amount, 2) }} DT</td>
            </tr>
            <tr>
                <th>Mode de paiement</th>
                <td>{{ ucfirst(str_replace('_', ' ', $payment->payment_mode)) }}</td>
            </tr>
            <tr>
                <th>Date du paiement</th>
                <td>{{ $payment->creation_date ? $payment->creation_date->format('d/m/Y') : '-' }}</td>
            </tr>
            <tr>
                <th>Statut</th>
                <td>
                    @php
                        $statusClass = 'badge status-' . ($payment->status ?? 'pending');
                    @endphp
                    <span class="{{ $statusClass }}">
                        {{ $payment->status ? ucfirst($payment->status) : 'Pending' }}
                    </span>
                </td>
            </tr>
            <tr>
                <th>Propriétaire de l'instrument</th>
                <td>{{ $payment->instrument_owner ?? '-' }}</td>
            </tr>
            <tr>
                <th>Numéro de l'instrument</th>
                <td>{{ $payment->instrument_number ?? '-' }}</td>
            </tr>
            <tr>
                <th>Date d'enregistrement</th>
                <td>{{ optional($payment->date_entree)->format('d/m/Y') ?? $payment->created_at->format('d/m/Y') }}</td>
            </tr>
            <tr>
                <th>Date d'échéance</th>
                <td>{{ optional($payment->date_activation)->format('d/m/Y') ?? '-' }}</td>
            </tr>
        </table>
    </div>

    <div class="section">
        <div class="section-title">Crédit du Client</div>
        <table>
            <tr>
                <th>Total des commandes</th>
                <td>{{ number_format($payment->client->total_orders, 3) }} DT</td>
            </tr>
            <tr>
                <th>Total des paiements</th>
                <td>{{ number_format($payment->client->total_payments, 3) }} DT</td>
            </tr>
            <tr>
                <th>Crédit restant</th>
                <td>{{ number_format($payment->client->remaining_credit, 3) }} DT</td>
            </tr>
        </table>
    </div>

    <div class="footer">
        <p>Reçu généré automatiquement. Aucune signature requise.</p>
        <p>Généré le {{ now()->format('d/m/Y à H:i') }}</p>
    </div>
</body>
</html>

