<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Savings Accounts Report</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 14px;
            line-height: 1.6;
            margin: 20px;
        }
        .header {
            text-align: center;
            margin-bottom: 30px;
            border-bottom: 2px solid #28a745;
            padding-bottom: 10px;
        }
        .header h1 {
            margin: 0;
            font-size: 24px;
            color: #28a745;
        }
        .header p {
            margin: 5px 0;
            color: #666;
        }
        .summary {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 20px;
            margin-bottom: 30px;
        }
        .summary-item {
            text-align: center;
            padding: 15px;
            border: 1px solid #28a745;
            background-color: #f9f9f9;
        }
        .summary-value {
            font-size: 18px;
            font-weight: bold;
            color: #28a745;
        }
        .summary-label {
            font-size: 12px;
            color: #666;
            margin-top: 5px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        th, td {
            border: 1px solid #28a745;
            padding: 10px;
            text-align: left;
            vertical-align: top;
        }
        th {
            background-color: #ffc107;
            font-weight: bold;
            color: #333;
        }
        .text-right {
            text-align: right;
        }
        .text-center {
            text-align: center;
        }
        .footer {
            margin-top: 30px;
            text-align: center;
            font-size: 10px;
            color: #666;
            border-top: 1px solid #28a745;
            padding-top: 10px;
        }
        @media print {
            body { margin: 0; }
            .no-print { display: none; }
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>Savings Accounts Report</h1>
        <p>All Savings Accounts</p>
        <p>Generated on {{ now()->format('F d, Y H:i') }}</p>
    </div>

    <div class="summary">
        <div class="summary-item">
            <div class="summary-value">{{ $savingsAccounts->count() }}</div>
            <div class="summary-label">Total Accounts</div>
        </div>
        <div class="summary-item">
            <div class="summary-value">USD {{ number_format($savingsAccounts->sum('current_balance'), 2) }}</div>
            <div class="summary-label">Total Balance</div>
        </div>
        <div class="summary-item">
            <div class="summary-value">{{ $savingsAccounts->where('status', 'active')->count() }}</div>
            <div class="summary-label">Active Accounts</div>
        </div>
        <div class="summary-item">
            <div class="summary-value">{{ $savingsAccounts->sum(function($account) { return $account->transactions->count(); }) }}</div>
            <div class="summary-label">Total Transactions</div>
        </div>
    </div>

    <h3>Savings Accounts</h3>
    <table>
        <thead>
            <tr>
                <th>ACCOUNT NO.</th>
                <th>CLIENT</th>
                <th>PRODUCT</th>
                <th>TYPE</th>
                <th>BALANCE</th>
                <th>INTEREST RATE</th>
                <th>STATUS</th>
                <th>CREATED</th>
            </tr>
        </thead>
        <tbody>
            @forelse($savingsAccounts as $account)
            <tr>
                <td>
                    <strong>{{ $account->account_number }}</strong>
                </td>
                <td>
                    @if ($account->client)
                        <div>{{ $account->client->full_name ?? 'N/A' }}</div>
                        <small>{{ $account->client->client_number ?? 'N/A' }}</small>
                    @else
                        <div class="text-danger">Client Missing</div>
                    @endif
                </td>
                <td>{{ $account->product_name }}</td>
                <td>
                    <span>{{ ucfirst($account->type) }}</span>
                </td>
                <td class="text-right">USD {{ number_format($account->current_balance, 2) }}</td>
                <td>{{ $account->interest_rate }}%</td>
                <td>
                    @if($account->status == 'active')
                        Active
                    @elseif($account->status == 'dormant')
                        Dormant
                    @elseif($account->status == 'closed')
                        Closed
                    @else
                        Frozen
                    @endif
                </td>
                <td>{{ $account->created_at->format('M d, Y') }}</td>
            </tr>
            @empty
            <tr>
                <td colspan="8" class="text-center">No savings accounts found.</td>
            </tr>
            @endforelse
        </tbody>
    </table>

    <div class="footer">
        <p>Report generated by Credora System</p>
        <p>© {{ date('Y') }} All rights reserved</p>
    </div>
</body>
</html>
