<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Pending Loans Report</title>
    <style>
        body {
            font-family: 'DejaVu Sans', sans-serif;
            font-size: 10px;
            line-height: 1.4;
            color: #333;
            margin: 20px;
        }
        .header {
            text-align: center;
            margin-bottom: 30px;
            border-bottom: 2px solid #007bff;
            padding-bottom: 10px;
        }
        .header h1 {
            color: #007bff;
            margin: 0;
            font-size: 18px;
        }
        .header p {
            margin: 5px 0;
            color: #666;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
            font-size: 8px;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 6px;
            text-align: left;
            vertical-align: top;
        }
        th {
            background-color: #f8f9fa;
            font-weight: bold;
            text-align: center;
        }
        .text-right {
            text-align: right;
        }
        .text-center {
            text-align: center;
        }
        .badge {
            display: inline-block;
            padding: 2px 6px;
            font-size: 7px;
            font-weight: bold;
            border-radius: 3px;
            text-transform: uppercase;
        }
        .badge-success {
            background-color: #28a745;
            color: white;
        }
        .badge-warning {
            background-color: #ffc107;
            color: black;
        }
        .badge-info {
            background-color: #17a2b8;
            color: white;
        }
        .total-row {
            background-color: #e9ecef;
            font-weight: bold;
        }
        .footer {
            margin-top: 30px;
            text-align: center;
            font-size: 8px;
            color: #666;
            border-top: 1px solid #ddd;
            padding-top: 10px;
        }
        .page-break {
            page-break-before: always;
        }
        @media print {
            body {
                margin: 0;
            }
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>Credora - Pending Loans Report</h1>
        <p>Generated on: {{ now()->format('F d, Y H:i:s') }}</p>
        <p>Total Pending Loans: {{ $loans->count() }}</p>
    </div>

    <table>
        <thead>
            <tr>
                <th width="8%">Loan Number</th>
                <th width="12%">Client Name</th>
                <th width="8%">Client Number</th>
                <th width="8%">Amount</th>
                <th width="6%">Rate</th>
                <th width="6%">Duration</th>
                <th width="8%">Monthly</th>
                <th width="8%">Total</th>
                <th width="10%">Purpose</th>
                <th width="6%">Type</th>
                <th width="8%">Applied</th>
                <th width="12%">Created By</th>
            </tr>
        </thead>
        <tbody>
            @foreach($loans as $loan)
            <tr>
                <td class="text-center"><strong>{{ $loan->loan_number }}</strong></td>
                <td>{{ $loan->client->first_name }} {{ $loan->client->last_name }}</td>
                <td>{{ $loan->client->client_number }}</td>
                <td class="text-right">${{ number_format($loan->amount, 2) }}</td>
                <td class="text-center">{{ number_format($loan->interest_rate, 2) }}%</td>
                <td class="text-center">{{ $loan->duration_months }}m</td>
                <td class="text-right">${{ number_format($loan->monthly_payment, 2) }}</td>
                <td class="text-right">${{ number_format($loan->total_repayment, 2) }}</td>
                <td>{{ $loan->purpose }}</td>
                <td class="text-center">
                    <span class="badge {{ $loan->loan_type === 'cash' ? 'badge-success' : 'badge-warning' }}">
                        {{ ucfirst($loan->loan_type) }}
                    </span>
                </td>
                <td class="text-center">{{ $loan->application_date->format('M d, Y') }}</td>
                <td>{{ $loan->creator->name ?? 'N/A' }}</td>
            </tr>
            @endforeach

            @if($loans->isEmpty())
            <tr>
                <td colspan="12" class="text-center" style="padding: 40px;">
                    <strong>No pending loan applications found</strong>
                </td>
            </tr>
            @endif
        </tbody>
        @if($loans->isNotEmpty())
        <tfoot>
            <tr class="total-row">
                <td colspan="3" class="text-right"><strong>Totals:</strong></td>
                <td class="text-right"><strong>${{ number_format($loans->sum('amount'), 2) }}</strong></td>
                <td colspan="3"></td>
                <td class="text-right"><strong>${{ number_format($loans->sum('total_repayment'), 2) }}</strong></td>
                <td colspan="4"></td>
            </tr>
        </tfoot>
        @endif
    </table>

    <div class="footer">
        <p>This report was generated automatically by the Credora system.</p>
        <p>&copy; {{ date('Y') }} Credora. All rights reserved.</p>
    </div>
</body>
</html>
