<?php
/**
 * CUSTOMER ORDER CANCELLATION WITH PENALTY EMAIL TEMPLATE
 * File: templates/email/order-cancellation-penalty.php
 * Used when: Customer cancels their own order (with penalty calculation)
 */

// Email content
ob_start();
?>

<div class="alert alert-warning">
    <strong>⚠️ Order Cancelled</strong><br>
    Your order has been cancelled. A cancellation penalty has been applied based on our cancellation policy.
</div>

<div class="order-summary">
    <h3>Cancellation Details</h3>
    <p><strong>Order Number:</strong> #<?= $order_number ?></p>
    <p><strong>Reason:</strong> <?= htmlspecialchars($reason) ?></p>
    <?php if (!empty($timing)): ?>
    <p><strong>Timing:</strong> <?= htmlspecialchars($timing) ?></p>
    <?php endif; ?>
</div>

<table class="table">
    <tr>
        <th colspan="2" style="background: #f8f9fa;">Payment Breakdown</th>
    </tr>
    <tr>
        <td>Rental Amount Paid</td>
        <td style="text-align: right;">₦<?= number_format($rental_amount, 2) ?></td>
    </tr>
    <tr>
        <td>Security Deposit</td>
        <td style="text-align: right;">₦<?= number_format($security_deposit, 2) ?></td>
    </tr>
    <tr style="color: #dc3545; font-weight: bold;">
        <td>Cancellation Penalty (<?= $penalty_percentage ?>%)</td>
        <td style="text-align: right;">-₦<?= number_format($penalty_amount, 2) ?></td>
    </tr>
    <tr style="border-top: 2px solid #dee2e6;">
        <th>Total Refund Amount</th>
        <th style="text-align: right; color: #28a745; font-size: 18px;">₦<?= number_format($refund_amount, 2) ?></th>
    </tr>
</table>

<div class="alert alert-success">
    <strong>✅ Refund Processed Successfully!</strong><br>
    The amount of <strong>₦<?= number_format($refund_amount, 2) ?></strong> has been credited to your wallet and is now available for:
    <ul style="margin: 10px 0 0 20px;">
        <li>Withdrawal to your bank account</li>
        <li>Use for future rentals on our platform</li>
    </ul>
</div>

<div class="alert alert-info">
    <strong>📋 About The Cancellation Penalty</strong>
    <p style="margin: 10px 0;">
        The <?= $penalty_percentage ?>% penalty is part of our fair cancellation policy to compensate vendors for:
    </p>
    <ul style="margin: 10px 0 0 20px;">
        <li>Item preparation and reservation time</li>
        <li>Lost opportunity to rent to other customers</li>
        <li>Administrative costs associated with the cancellation</li>
    </ul>
    <p style="margin: 10px 0 0 0;">
        <small><em>The earlier you cancel before the rental start date, the lower the penalty. Please review our cancellation policy for details.</em></small>
    </p>
</div>

<div class="alert alert-light" style="border-left: 4px solid #17a2b8;">
    <strong>🔄 What Happens Next?</strong>
    <ul style="margin: 10px 0 0 20px;">
        <li><strong>Your Refund:</strong> Now available in your wallet</li>
        <li><strong>Security Deposit:</strong> Fully refunded (no deductions)</li>
        <li><strong>Vendor Compensation:</strong> Penalty amount shared between vendor and platform</li>
        <li><strong>Your Account:</strong> No negative impact on your customer status</li>
    </ul>
</div>

<div style="background: #f8f9fa; padding: 15px; border-radius: 5px; margin-top: 20px;">
    <h4 style="margin: 0 0 10px 0; color: #495057;">💡 Tips for Future Bookings</h4>
    <ul style="margin: 5px 0 0 20px; color: #6c757d;">
        <li>Book only when you're certain about your rental dates</li>
        <li>Review cancellation policies before confirming orders</li>
        <li>Contact the vendor early if you need to make changes</li>
        <li>Consider flexible rental dates when planning</li>
    </ul>
</div>

<p style="margin-top: 20px;">We're sorry this booking didn't work out. We hope to serve you better on your next rental!</p>

<?php
$content = ob_get_clean();

// Prepare email data
$email_data = [
    'title' => 'Order Cancelled - Refund Processed',
    'greeting' => "Hello {$customer_name}!",
    'content' => $content,
    'action_url' => APP_URL . '/customer/wallet.php',
    'action_text' => 'View Wallet Balance',
    'secondary_action_url' => APP_URL . '/items.php',
    'secondary_action_text' => 'Browse Available Items',
    'footer_note' => 'Questions about your refund? Contact our support team anytime.',
    'signature' => "Best regards,<br>The " . APP_NAME . " Team<br>support@rentidium.com"
];

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