<!DOCTYPE html>
<html>
<head>
    <title>Payment Reminder</title>
    <style>
        body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
        .container { max-width: 600px; margin: 0 auto; padding: 20px; }
        .header { background-color: {{ $data['urgent'] ? '#dc3545' : '#007bff' }}; color: white; padding: 20px; text-align: center; }
        .content { padding: 20px; background: #f9f9f9; }
        .payment-table { width: 100%; border-collapse: collapse; margin: 15px 0; }
        .payment-table th, .payment-table td { border: 1px solid #ddd; padding: 10px; text-align: left; }
        .payment-table th { background-color: #f2f2f2; }
        .total { font-size: 18px; font-weight: bold; margin-top: 20px; padding-top: 10px; border-top: 2px solid #ddd; }
        .footer { margin-top: 30px; padding: 20px; text-align: center; font-size: 12px; color: #666; }
        .urgent-badge { background: #dc3545; color: white; padding: 5px 10px; border-radius: 3px; display: inline-block; }
        .button { display: inline-block; padding: 10px 20px; background: #28a745; color: white; text-decoration: none; border-radius: 5px; }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            @if($data['urgent'])
                <div class="urgent-badge">URGENT ACTION REQUIRED</div>
            @endif
            <h1>Payment Reminder</h1>
            <p>{{ ucfirst(str_replace('_', ' ', $data['reminder_type'])) }} Notice</p>
        </div>
        
        <div class="content">
            <p>Dear <strong>{{ $data['contact_person'] }}</strong>,</p>
            
            <p>This is a payment reminder for {{ $data['station_name'] }}. 
            You have <strong>{{ $data['total_payments'] }} payment(s)</strong> 
            @if($data['urgent'])
                requiring immediate attention
            @else
                coming due soon
            @endif
            as of {{ $data['reminder_date'] }}.</p>
            
            @if($data['internet_count'] > 0)
                <h3>Internet Payments ({{ $data['internet_count'] }})</h3>
                <table class="payment-table">
                    <thead>
                        <tr>
                            <th>Provider</th>
                            <th>Account Number</th>
                            <th>Amount (KES)</th>
                            <th>Due Date</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($data['internet_payments'] as $payment)
                            <tr>
                                <td>{{ $payment['provider'] }}</td>
                                <td>{{ $payment['account_number'] }}</td>
                                <td>{{ number_format($payment['amount'], 2) }}</td>
                                <td>{{ $payment['due_date'] }}</td>
                                <td>
                                    @if($payment['days_until_due'] < 0)
                                        <span style="color: #dc3545;">Overdue</span>
                                    @elseif($payment['days_until_due'] == 0)
                                        <span style="color: #ffc107;">Due Today</span>
                                    @else
                                        <span style="color: #28a745;">Due in {{ $payment['days_until_due'] }} days</span>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
                
                <p><strong>Payment Instructions:</strong><br>
                Paybill Number: {{ $data['internet_payments'][0]['paybill'] ?? 'XXXXXX' }}<br>
                Account Number: Your account number as listed above</p>
            @endif
            
            @if($data['airtime_count'] > 0)
                <h3>Airtime Top-ups ({{ $data['airtime_count'] }})</h3>
                <table class="payment-table">
                    <thead>
                        <tr>
                            <th>Mobile Number</th>
                            <th>Network</th>
                            <th>Amount (KES)</th>
                            <th>Expiry Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($data['airtime_payments'] as $payment)
                            <tr>
                                <td>{{ $payment['mobile_number'] }}</td>
                                <td>{{ $payment['network_provider'] }}</td>
                                <td>{{ number_format($payment['amount'], 2) }}</td>
                                <td>{{ $payment['expiry_date'] }}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            @endif
            
            <div class="total">
                <p>Total Amount Due: <strong>KES {{ number_format($data['total_due'], 2) }}</strong></p>
            </div>
            
            <p style="margin-top: 20px;">
                To make a payment or view details, please log into the payment portal.
            </p>
            
            @if($data['urgent'])
                <p style="color: #dc3545; font-weight: bold;">
                    Please take immediate action to avoid service interruption.
                </p>
            @endif
        </div>
        
        <div class="footer">
            <p>This is an automated reminder. Please do not reply to this email.</p>
            <p>&copy; {{ date('Y') }} Payment Management System. All rights reserved.</p>
        </div>
    </div>
</body>
</html>