<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Invoice <?php echo e($invoice->invoice_number); ?></title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 14px;
            line-height: 1.6;
            color: #333;
            margin: 0;
            padding: 20px;
        }
        .invoice-container {
            max-width: 800px;
            margin: 0 auto;
        }
        .invoice-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #D7A769;
        }
        .company-info {
            flex: 1;
        }
        .company-name {
            font-size: 24px;
            font-weight: bold;
            color: #D7A769;
            margin-bottom: 10px;
        }
        .invoice-info {
            text-align: right;
        }
        .invoice-title {
            font-size: 28px;
            font-weight: bold;
            color: #333;
            margin-bottom: 10px;
        }
        .invoice-details {
            display: flex;
            justify-content: space-between;
            margin-bottom: 30px;
        }
        .bill-to, .invoice-meta {
            flex: 1;
        }
        .section-title {
            font-weight: bold;
            font-size: 16px;
            margin-bottom: 10px;
            color: #555;
        }
        .invoice-table {
            width: 100%;
            border-collapse: collapse;
            margin: 30px 0;
            border: 1px solid #ddd;
        }
        .invoice-table th {
            background-color: #f5f5f5;
            padding: 12px;
            text-align: left;
            font-weight: bold;
            border-bottom: 2px solid #D7A769;
            color: #333;
        }
        .invoice-table td {
            padding: 12px;
            border-bottom: 1px solid #e0e0e0;
            vertical-align: top;
        }
        .invoice-table tbody tr:last-child td {
            border-bottom: 1px solid #ddd;
        }
        .amount-col {
            text-align: right;
            width: 15%;
        }
        .invoice-table th:first-child,
        .invoice-table td:first-child {
            width: 40%;
        }
        }
        .totals-section {
            margin-top: 30px;
            text-align: right;
        }
        .totals-table {
            display: inline-block;
            min-width: 350px;
            background-color: #f9f9f9;
            padding: 20px;
            border-radius: 5px;
            border: 1px solid #e0e0e0;
        }
        .totals-row {
            display: flex;
            justify-content: space-between;
            padding: 10px 0;
            border-bottom: 1px solid #e0e0e0;
        }
        .totals-row:last-child {
            border-bottom: none;
        }
        .totals-label {
            font-weight: 600;
            color: #555;
            font-size: 14px;
        }
        .totals-amount {
            text-align: right;
            font-weight: bold;
            color: #333;
            font-size: 14px;
        }
        .grand-total {
            border-top: 3px solid #D7A769;
            margin-top: 15px;
            padding-top: 15px;
            background-color: #fff;
            margin-left: -20px;
            margin-right: -20px;
            padding-left: 20px;
            padding-right: 20px;
            border-bottom: none;
        }
        .grand-total .totals-label {
            font-size: 16px;
            font-weight: bold;
            color: #D7A769;
        }
        .grand-total .totals-amount {
            font-size: 18px;
            font-weight: bold;
            color: #D7A769;
        }
            font-size: 18px;
            font-weight: bold;
        }
        .status-badge {
            display: inline-block;
            padding: 5px 15px;
            border-radius: 20px;
            font-weight: bold;
            font-size: 12px;
            text-transform: uppercase;
        }
        .status-paid {
            background-color: #d4edda;
            color: #155724;
        }
        .status-pending {
            background-color: #fff3cd;
            color: #856404;
        }
        .footer {
            margin-top: 50px;
            padding-top: 20px;
            border-top: 1px solid #ddd;
            text-align: center;
            font-size: 12px;
            color: #777;
        }
    </style>
</head>
<body>
    <div class="invoice-container">
        <!-- Header -->
        <div class="invoice-header">
            <div class="company-info">
                <div class="company-name"><?php echo e($company['name']); ?></div>
                <div><?php echo e($company['address']); ?></div>
                <div><?php echo e($company['city']); ?>, <?php echo e($company['postal_code']); ?></div>
                <div><?php echo e($company['country']); ?></div>
                <div>Phone: <?php echo e($company['phone']); ?></div>
                <div>Email: <?php echo e($company['email']); ?></div>
            </div>
            <div class="invoice-info">
                <div class="invoice-title">INVOICE</div>
                <div><strong>Invoice #:</strong> <?php echo e($invoice->invoice_number); ?></div>
                <div><strong>Date:</strong> <?php echo e($invoice->created_at->format('M d, Y')); ?></div>
                <?php if($invoice->paid_at): ?>
                    <div><strong>Paid:</strong> <?php echo e($invoice->paid_at->format('M d, Y')); ?></div>
                <?php endif; ?>
                <div style="margin-top: 10px;">
                    <span class="status-badge status-<?php echo e(strtolower($invoice->status)); ?>">
                        <?php echo e(ucfirst($invoice->status)); ?>

                    </span>
                </div>
            </div>
        </div>

        <!-- Bill To -->
        <div class="invoice-details">
            <div class="bill-to">
                <div class="section-title">Bill To:</div>
                <div><strong><?php echo e($user->first_name); ?> <?php echo e($user->last_name); ?></strong></div>
                <div><?php echo e($user->email); ?></div>
                <?php if($user->phone): ?>
                    <div><?php echo e($user->phone); ?></div>
                <?php endif; ?>
                <?php if($user->address): ?>
                    <div><?php echo e($user->address); ?></div>
                <?php endif; ?>
                <?php if(isset($metadata['billing_info'])): ?>
                    <?php
                        $billing = is_string($metadata['billing_info']) 
                            ? json_decode($metadata['billing_info'], true) 
                            : $metadata['billing_info'];
                    ?>
                    <?php if($billing): ?>
                        <div><?php echo e($billing['city'] ?? ''); ?><?php echo e(isset($billing['province']) ? ', ' . $billing['province'] : ''); ?></div>
                        <div><?php echo e($billing['postal_code'] ?? ''); ?></div>
                        <div><?php echo e($billing['country'] ?? ''); ?></div>
                    <?php endif; ?>
                <?php endif; ?>
            </div>
            <div class="invoice-meta">
                <?php if(isset($metadata['user'])): ?>
                    <div><strong>User Category:</strong> <?php echo e($metadata['user']['user_category_name'] ?? $metadata['user']['user_category'] ?? 'N/A'); ?></div>
                <?php endif; ?>
                <?php if(isset($metadata['payment_type'])): ?>
                    <div><strong>Payment Type:</strong> <?php echo e(ucwords(str_replace('_', ' ', $metadata['payment_type']))); ?></div>
                <?php endif; ?>
            </div>
        </div>

        <!-- Items Table -->
        <table class="invoice-table">
            <thead>
                <tr>
                    <th>Description</th>
                    <th class="amount-col">Quantity</th>
                    <th class="amount-col">Unit Price</th>
                    <th class="amount-col">Amount</th>
                </tr>
            </thead>
            <tbody>
                <?php if($payment_type === 'course_enrollment'): ?>
                    <tr>
                        <td>
                            <strong>Course Enrollment: <?php echo e($metadata['course']['title'] ?? $metadata['course_title'] ?? 'Course'); ?></strong>
                            <?php if(isset($metadata['course'])): ?>
                                <?php if(isset($metadata['course']['description'])): ?>
                                    <div style="font-size: 12px; color: #666; margin-top: 5px;">
                                        <?php echo e(Str::limit($metadata['course']['description'], 150)); ?>

                                    </div>
                                <?php endif; ?>
                                <?php if(isset($metadata['course']['duration']) || isset($metadata['course']['level'])): ?>
                                    <div style="font-size: 12px; color: #666; margin-top: 5px;">
                                        <?php if(isset($metadata['course']['duration'])): ?>
                                            Duration: <?php echo e($metadata['course']['duration']); ?>

                                        <?php endif; ?>
                                        <?php if(isset($metadata['course']['level'])): ?>
                                            | Level: <?php echo e(ucfirst($metadata['course']['level'])); ?>

                                        <?php endif; ?>
                                        <?php if(isset($metadata['course']['language'])): ?>
                                            | Language: <?php echo e($metadata['course']['language']); ?>

                                        <?php endif; ?>
                                    </div>
                                <?php endif; ?>
                            <?php endif; ?>
                        </td>
                        <td class="amount-col">1</td>
                        <td class="amount-col"><?php echo e(number_format($metadata['amount'] ?? $invoice->amount, 2)); ?></td>
                        <td class="amount-col">
                            <?php echo e(number_format($metadata['amount'] ?? $invoice->amount, 2)); ?> <?php echo e(strtoupper($invoice->currency)); ?>

                        </td>
                    </tr>
                <?php elseif(isset($metadata['type']) && $metadata['type'] === 'immigopro_package'): ?>
                    <tr>
                        <td>
                            <strong>ImmigoPro Package: <?php echo e($metadata['package_name'] ?? 'Package'); ?></strong>
                            <?php if(isset($metadata['payment_plan'])): ?>
                                <div style="font-size: 12px; color: #666; margin-top: 5px;">
                                    Payment Plan: <?php echo e($metadata['payment_plan'] === 'full' ? 'Full Payment' : 
                                        ($metadata['payment_plan'] === '3month' ? '3-Month Plan' :
                                        ($metadata['payment_plan'] === '6month' ? '6-Month Plan' :
                                        ($metadata['payment_plan'] === '12month' ? '12-Month Plan' : ucfirst($metadata['payment_plan']))))); ?>

                                </div>
                            <?php endif; ?>
                            <?php if(isset($metadata['description'])): ?>
                                <div style="font-size: 12px; color: #666; margin-top: 5px;">
                                    <?php echo e($metadata['description']); ?>

                                </div>
                            <?php endif; ?>
                        </td>
                        <td class="amount-col">1</td>
                        <td class="amount-col"><?php echo e(number_format($metadata['amount'] ?? $invoice->amount, 2)); ?></td>
                        <td class="amount-col">
                            <?php echo e(number_format($metadata['amount'] ?? $invoice->amount, 2)); ?> <?php echo e(strtoupper($invoice->currency)); ?>

                        </td>
                    </tr>
                <?php else: ?>
                    <tr>
                        <td>
                            <strong><?php echo e($metadata['product_name'] ?? $metadata['plan_name'] ?? 'Service'); ?></strong>
                            <?php if(isset($metadata['description'])): ?>
                                <div style="font-size: 12px; color: #666; margin-top: 5px;">
                                    <?php echo e($metadata['description']); ?>

                                </div>
                            <?php endif; ?>
                        </td>
                        <td class="amount-col">1</td>
                        <td class="amount-col"><?php echo e(number_format($invoice->amount, 2)); ?></td>
                        <td class="amount-col">
                            <?php echo e(number_format($invoice->amount, 2)); ?> <?php echo e(strtoupper($invoice->currency)); ?>

                        </td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>

        <!-- Totals -->
        <div class="totals-section">
            <div class="totals-table">
                <?php
                    $subtotal = isset($metadata['amount']) ? floatval($metadata['amount']) : floatval($invoice->amount);
                    $taxAmount = isset($metadata['tax_amount']) ? floatval($metadata['tax_amount']) : 0;
                    $total = floatval($invoice->amount);
                    
                    // Calculate tax rate if we have both subtotal and tax
                    $taxRate = 0;
                    if ($subtotal > 0 && $taxAmount > 0) {
                        $taxRate = ($taxAmount / $subtotal) * 100;
                    }
                ?>
                
                <div class="totals-row">
                    <div class="totals-label">Subtotal:</div>
                    <div class="totals-amount"><?php echo e(number_format($subtotal, 2)); ?> <?php echo e(strtoupper($invoice->currency)); ?></div>
                </div>
                
                <?php if($taxAmount > 0): ?>
                    <div class="totals-row">
                        <div class="totals-label">
                            Tax <?php if($taxRate > 0): ?>(<?php echo e(number_format($taxRate, 2)); ?>%)<?php endif; ?>:
                        </div>
                        <div class="totals-amount"><?php echo e(number_format($taxAmount, 2)); ?> <?php echo e(strtoupper($invoice->currency)); ?></div>
                    </div>
                <?php else: ?>
                    <div class="totals-row" style="color: #888;">
                        <div class="totals-label">Tax:</div>
                        <div class="totals-amount">0.00 <?php echo e(strtoupper($invoice->currency)); ?></div>
                    </div>
                <?php endif; ?>
                
                <div class="totals-row grand-total">
                    <div class="totals-label">Total Amount:</div>
                    <div class="totals-amount"><?php echo e(number_format($total, 2)); ?> <?php echo e(strtoupper($invoice->currency)); ?></div>
                </div>
                
                <?php if($invoice->status === 'paid' && $invoice->paid_at): ?>
                    <div class="totals-row" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid #ddd;">
                        <div class="totals-label">Amount Paid:</div>
                        <div class="totals-amount" style="color: #155724;"><?php echo e(number_format($total, 2)); ?> <?php echo e(strtoupper($invoice->currency)); ?></div>
                    </div>
                    <div class="totals-row">
                        <div class="totals-label">Balance Due:</div>
                        <div class="totals-amount" style="color: #155724;">0.00 <?php echo e(strtoupper($invoice->currency)); ?></div>
                    </div>
                <?php endif; ?>
            </div>
        </div>

        <!-- Payment Information -->
        <?php if(isset($metadata['user_details']) || isset($metadata['billing_info'])): ?>
            <div style="margin-top: 30px; padding: 15px; background-color: #f9f9f9; border-left: 4px solid #D7A769;">
                <div style="font-weight: bold; margin-bottom: 10px;">Payment Information</div>
                
                <?php if(isset($metadata['user_details'])): ?>
                    <div style="font-size: 12px; margin-bottom: 5px;">
                        <strong>Customer:</strong> <?php echo e($metadata['user_details']['full_name'] ?? 'N/A'); ?>

                    </div>
                    <?php if(isset($metadata['user_details']['user_category'])): ?>
                        <div style="font-size: 12px; margin-bottom: 5px;">
                            <strong>Category:</strong> <?php echo e($metadata['user_details']['user_category']); ?>

                        </div>
                    <?php endif; ?>
                <?php endif; ?>
                
                <?php if($invoice->status === 'paid'): ?>
                    <div style="font-size: 12px; margin-top: 10px; color: #155724;">
                        <strong>✓ Payment Completed</strong> on <?php echo e($invoice->paid_at->format('M d, Y \a\t h:i A')); ?>

                    </div>
                <?php endif; ?>
                
                <?php if(isset($metadata['user_details']['email'])): ?>
                    <div style="font-size: 12px; margin-top: 5px;">
                        <strong>Email:</strong> <?php echo e($metadata['user_details']['email']); ?>

                    </div>
                <?php endif; ?>
            </div>
        <?php endif; ?>

        <!-- Footer -->
        <div class="footer">
            <p>Thank you for your business!</p>
            <p>If you have any questions about this invoice, please contact us at <?php echo e($company['email']); ?></p>
            <p style="margin-top: 20px; font-size: 11px;">
                This is a computer-generated invoice. No signature is required.
            </p>
        </div>
    </div>
</body>
</html>
<?php /**PATH /home/jurislocator/public_html/api.jurislocator.ca/resources/views/invoices/invoice-pdf.blade.php ENDPATH**/ ?>