<?php
/**
 * ORDER CONFIRMATION EMAIL - CUSTOMER
 * File: templates/email/order-confirmation.php
 *
 * Available variables (from Mailer::sendOrderConfirmation):
 * $customer_name, $order_number, $order_id, $item_title, $vendor_name,
 * $start_date, $end_date, $total_days, $quantity, $status,
 * $daily_rate, $subtotal, $platform_commission, $tax_amount,
 * $deposit_amount, $total_amount, $vendor_contact[], $vendor_location[],
 * $app_name, $app_url
 */

ob_start();
?>

<p>Hi <strong><?= htmlspecialchars($customer_name ?? '') ?></strong>,</p>
<p>Great news! Your booking has been confirmed and payment received successfully. Here is a summary of your order.</p>

<div class="order-summary">
    <h4>Order Details</h4>
    <p><strong>Order Number:</strong> <?= htmlspecialchars($order_number ?? '') ?></p>
    <p><strong>Item:</strong> <?= htmlspecialchars($item_title ?? '') ?></p>
    <p><strong>Rental Period:</strong> <?= date('M j, Y', strtotime($start_date)) ?> &ndash; <?= date('M j, Y', strtotime($end_date)) ?></p>
    <p><strong>Duration:</strong> <?= $total_days ?> day<?= $total_days > 1 ? 's' : '' ?></p>
    <p><strong>Quantity:</strong> <?= $quantity ?></p>
    <p><strong>Status:</strong> <span style="color:#27ae60; font-weight:bold;">&#10003; Confirmed</span></p>
</div>

<div class="order-summary">
    <h4>Payment Breakdown</h4>
    <p><strong>Daily Rate:</strong> &#8358;<?= number_format($daily_rate, 2) ?></p>
    <p><strong>Subtotal:</strong> &#8358;<?= number_format($subtotal, 2) ?></p>
    <p><strong>Security Deposit (Refundable):</strong> &#8358;<?= number_format($deposit_amount, 2) ?></p>
    <?php /* if ($platform_commission > 0): ?>
    <p><strong>Platform Fee:</strong> &#8358;<?= number_format($platform_commission, 2) ?></p>
    <?php endif; */ ?>
    <p style="font-size:16px; border-top:1px solid #ddd; padding-top:10px; margin-top:10px;">
        <strong>Total Paid:</strong>
        <span style="color:#27ae60; font-size:18px; font-weight:bold;"> &#8358;<?= number_format($total_amount, 2) ?></span>
    </p>
</div>

<div class="order-summary">
    <h4>Vendor Contact</h4>
    <p><strong>Business:</strong> <?= htmlspecialchars($vendor_name ?? '') ?></p>
    <?php if (!empty($vendor_contact['phone'])): ?>
    <p><strong>Phone:</strong> <?= htmlspecialchars($vendor_contact['phone']) ?></p>
    <?php endif; ?>
    <?php if (!empty($vendor_contact['email'])): ?>
    <p><strong>Email:</strong> <?= htmlspecialchars($vendor_contact['email']) ?></p>
    <?php endif; ?>
    <?php if (!empty($vendor_location['city'])): ?>
    <p><strong>Location:</strong> <?= htmlspecialchars($vendor_location['city']) ?><?= !empty($vendor_location['state']) ? ', ' . htmlspecialchars($vendor_location['state']) : '' ?></p>
    <?php endif; ?>
</div>

<div class="alert alert-info">
    <strong>What Happens Next?</strong>
    <ol style="margin:10px 0 0 20px; line-height:1.9;">
        <li>The vendor will contact you to arrange pickup or delivery</li>
        <li>Pick up the item on <strong><?= date('F j, Y', strtotime($start_date)) ?></strong></li>
        <li>Return the item by <strong><?= date('F j, Y', strtotime($end_date)) ?></strong></li>
        <li>Your security deposit of <strong>&#8358;<?= number_format($deposit_amount, 2) ?></strong> will be refunded to your wallet within 1 &ndash; 2 days after a successful return.</li>
    </ol>
</div>

<div class="alert alert-warning">
    <strong>Important:</strong><br>
    <ol>
        <li>Always collect and return the item in open places, possibly with witness(es). Secret place is not encouraged for security reasons.</li>
        <li>The Vendor Details shared are strictly meant for this order and transaction. Any further use aside this purpose is considered unathorised.</li>
        <li>Late returns may incur a penalty.</li>
        <li>Keep the item in good condition to ensure a full refund of your security deposit.</li>
        <li>If you have any issues during the rental period, please contact the vendor or our support team immediately.</li>
        <li>Please keep this email for your records. Your order number is <strong><?= htmlspecialchars($order_number ?? '') ?></strong>.</li>
    </ol>
    
</div>

<p>
    <a href="<?= $app_url ?>/customer/orders.php" class="btn" style="background:#27ae60; color:white; padding:10px 20px; text-decoration:none; border-radius:5px;">View Your Order</a>
</p>

<?php
$content = ob_get_clean();

$email_data = [
    'title'       => 'Booking Confirmed!',
    'greeting'    => "Booking Confirmed! &#127881;",
    'content'     => $content,
    'action_url'  => $app_url . '/customer/orders.php',
    'action_text' => 'View Your Order',
    'footer_note' => "You're receiving this email because you placed an order on " . $app_name . ". If this wasn't you, please contact support immediately.",
    'signature'   => "Thank you for choosing " . $app_name . "!<br>The " . $app_name . " Team"
];

include 'layout.php';
?>