<?php
/**
 * ORDER NOTIFICATION EMAIL - VENDOR
 * File: templates/email/order-notification-vendor.php
 *
 * Available variables (from Mailer::sendVendorOrderNotification):
 * $vendor_name, $order_number, $order_id, $item_title,
 * $customer_name, $customer_email, $customer_phone,
 * $start_date, $end_date, $total_days, $quantity, $status,
 * $total_amount (= subtotal), $commission_rate, $commission_amount,
 * $vendor_earnings, $customer_message, $app_name, $app_url
 */

ob_start();
?>

<p>Hi <strong><?= htmlspecialchars($vendor_name ?? '') ?></strong>,</p>
<p>Great news! You have received a new booking on <strong><?= $app_name ?></strong>. Please review the details below and contact the customer as soon as possible.</p>

<div class="alert alert-warning">
    <strong>&#9888; Action Required:</strong> Please contact the customer within <strong>12 hours</strong> to confirm pickup or delivery arrangements.
</div>

<div class="order-summary">
    <h4>Booking 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 & Paid</span></p>
</div>

<div class="order-summary">
    <h4>Customer Details</h4>
    <p><strong>Name:</strong> <?= htmlspecialchars($customer_name ?? '') ?></p>
    <p><strong>Phone:</strong> <strong style="font-size:15px;"><?= htmlspecialchars($customer_phone ?? 'Not provided') ?></strong></p>
    <p><strong>Email:</strong> <strong><?= htmlspecialchars($customer_email ?? '') ?></strong></p>
    <?php if (!empty($customer_message)): ?>
    <p><strong>Special Instructions:</strong> <?= htmlspecialchars($customer_message) ?></p>
    <?php endif; ?>
</div>

<div class="order-summary">
    <h4>Your Earnings</h4>
    <p><strong>Rental Amount:</strong> &#8358;<?= number_format($total_amount, 2) ?></p>
    <p><strong>Platform Commission (<?= $commission_rate ?>%):</strong> &minus;&#8358;<?= number_format($commission_amount, 2) ?></p>
    <p style="font-size:16px; border-top:1px solid #ddd; padding-top:10px; margin-top:10px;">
        <strong>Your Net Earnings:</strong>
        <span style="color:#27ae60; font-size:18px; font-weight:bold;"> &#8358;<?= number_format($vendor_earnings, 2) ?></span>
    </p>
    <p style="color:#888; font-size:13px;">Note: Security deposit is held in escrow and released after the customer returns the item.</p>
</div>

<div class="alert alert-info">
    <strong>Next Steps:</strong>
    <ol style="margin:10px 0 0 20px; line-height:1.9;">
        <li>Contact the customer at <strong><?= htmlspecialchars($customer_phone ?? '') ?></strong> or <strong><?= htmlspecialchars($customer_email ?? '') ?></strong></li>
        <li>Arrange pickup or delivery for <strong><?= date('F j, Y', strtotime($start_date)) ?></strong></li>
        <li>Ensure the item is clean and in good working condition</li>
        <li>Confirm the return via your dashboard by <strong><?= date('F j, Y', strtotime($end_date)) ?></strong></li>
        <li>Your earnings will be credited to your wallet after return confirmation</li>
    </ol>
</div>

<div class="alert alert-warning">
    <strong>Important:</strong><br>
    <ol>
        <li>Always deliver and collect-back the item in open places, possibly with witness(es). Secret places is not encouraged for security reasons.</li>
        <li>The Customer Details shared are strictly meant for this order and transaction. Any further use aside this purpose is considered unathorised.</li>
        <li>Late delivery may incur a penalty.</li>
        <li>Always delivery the item in good condition as advertised to ensure a full payment and continuos use of our platform.</li>
        <li>If you have any issues during the rental period, please contact the customer 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 ?>/vendor/orders.php" class="btn" style="background:#27ae60; color:white; padding:10px 20px; text-decoration:none; border-radius:5px;">View Order in Dashboard</a>
</p>

<?php
$content = ob_get_clean();

$email_data = [
    'title'       => 'New Booking Received!',
    'greeting'    => "New Booking Received! &#128276;",
    'content'     => $content,
    'action_url'  => $app_url . '/vendor/orders.php',
    'action_text' => 'View Order in Dashboard',
    'footer_note' => "You're receiving this because a customer booked one of your items on " . $app_name . ".",
    'signature'   => "Thank you for being a valued vendor!<br>The " . $app_name . " Team"
];

include 'layout.php';
?>