<?php
/**
 * PAYMENT CONFIRMATION EMAIL TEMPLATE
 * File: templates/email/payment-confirmation.php
 * Payment success confirmation template
 */

// Email content
ob_start();
?>

<p>Great news! Your payment has been successfully processed and your order is now confirmed.</p>

<div class="alert alert-success">
    <strong>Payment Successful!</strong> Your rental is confirmed and you can now enjoy your item.
</div>

<div class="order-summary">
    <h3>Payment Confirmation</h3>
    <p><strong>Transaction ID:</strong> <?= $transaction_id ?></p>
    <p><strong>Order Number:</strong> #<?= $order_number ?></p>
    <p><strong>Item:</strong> <?= htmlspecialchars($item_title) ?></p>
    <p><strong>Amount Paid:</strong> <span style="color: #28a745; font-weight: bold; font-size: 18px;">₦<?= number_format($amount_paid) ?></span></p>
    <p><strong>Payment Method:</strong> <?= ucwords(str_replace('_', ' ', $payment_method)) ?></p>
    <p><strong>Payment Date:</strong> <?= date('F j, Y \a\t g:i A', strtotime($payment_date)) ?></p>
</div>

<table class="table">
    <tr>
        <th colspan="2" style="background: #f8f9fa;">Payment Breakdown</th>
    </tr>
    <tr>
        <td>Item Rental</td>
        <td style="text-align: right;">₦<?= number_format($rental_amount) ?></td>
    </tr>
    <tr>
        <td>Platform Fee</td>
        <td style="text-align: right;">₦<?= number_format($platform_fee) ?></td>
    </tr>
    <tr>
        <td>Tax</td>
        <td style="text-align: right;">₦<?= number_format($tax_amount) ?></td>
    </tr>
    <tr>
        <td>Processing Fee</td>
        <td style="text-align: right;">₦<?= number_format($processing_fee) ?></td>
    </tr>
    <tr style="font-weight: bold; font-size: 16px;">
        <td>Total Paid</td>
        <td style="text-align: right; color: #28a745;">₦<?= number_format($total_paid) ?></td>
    </tr>
</table>

<?php if ($deposit_amount > 0): ?>
<div class="alert alert-info">
    <strong>Security Deposit:</strong> A security deposit of ₦<?= number_format($deposit_amount) ?> has been held and will be refunded within 3-5 business days after successful return of the item.
</div>
<?php endif; ?>

<div class="order-summary">
    <h3>Rental Details</h3>
    <p><strong>Pickup/Delivery:</strong> <?= date('M j, Y \a\t g:i A', strtotime($start_date)) ?></p>
    <p><strong>Return:</strong> <?= date('M j, Y \a\t g:i A', strtotime($end_date)) ?></p>
    <p><strong>Duration:</strong> <?= $total_days ?> days</p>
    <p><strong>Vendor Contact:</strong> <?= $vendor_contact ?></p>
</div>

<div class="alert alert-warning">
    <strong>Next Steps:</strong>
    <ul style="margin: 10px 0 0 20px;">
        <li>Contact the vendor to arrange pickup/delivery details</li>
        <li>Review the item carefully before accepting</li>
        <li>Keep all rental documentation for your records</li>
        <li>Return the item on time to avoid late fees</li>
    </ul>
</div>

<?php if (!empty($invoice_url)): ?>
<div class="text-center mt-4">
    <a href="<?= $invoice_url ?>" class="btn">Download Invoice</a>
</div>
<?php endif; ?>

<?php
$content = ob_get_clean();

// Prepare email data
$email_data = [
    'title' => 'Payment Confirmed - #' . $order_number,
    'greeting' => "Hello {$customer_name}!",
    'content' => $content,
    'action_url' => APP_URL . '/customer/order-details.php?id=' . $order_id,
    'action_text' => 'View Order Details',
    'secondary_action_url' => APP_URL . '/customer/orders.php',
    'secondary_action_text' => 'My Orders',
    'footer_note' => 'Thank you for choosing rentidium! We hope you have a great experience.',
    'signature' => "Best regards,<br>The rentidium Payments Team<br>payments@rentidium.com"
];

// Include layout
include 'layout.php';
?>