<?php
require_once __DIR__ . '/../config.php';
$order_no = trim($_GET['order'] ?? '');
$order = null;
if ($order_no) {
    $db = getDB();
    $stmt = $db->prepare("SELECT * FROM orders WHERE order_no=?");
    $stmt->execute([$order_no]);
    $order = $stmt->fetch();
}
$page_title = 'Order Placed! | Balimeen Private Limited';
include __DIR__ . '/../includes/header.php';
?>
<section class="section-pad">
  <div class="container">
    <div class="success-page">
      <div class="success-icon">✅</div>
      <h2>Order Placed Successfully!</h2>
      <?php if ($order): ?>
      <div class="success-order-no">Order #<?= h($order['order_no']) ?></div>
      <p>Thank you, <strong><?= h($order['name']) ?></strong>! Your order has been received and will be processed shortly. Our team will contact you on <strong><?= h($order['phone']) ?></strong> to confirm.</p>
      <div style="background:var(--bg-light);border-radius:14px;padding:24px;max-width:480px;margin:0 auto 28px;text-align:left;">
        <h4 style="font-family:'Outfit',sans-serif;font-weight:700;color:var(--blue-dark);margin-bottom:14px;">Order Details</h4>
        <div style="display:flex;justify-content:space-between;font-size:.88rem;padding:6px 0;border-bottom:1px solid #e2e8f0;">
          <span style="color:var(--text-mid);font-weight:600;">Order No</span>
          <span style="color:var(--blue-main);font-weight:700;"><?= h($order['order_no']) ?></span>
        </div>
        <div style="display:flex;justify-content:space-between;font-size:.88rem;padding:6px 0;border-bottom:1px solid #e2e8f0;">
          <span style="color:var(--text-mid);font-weight:600;">Payment Method</span>
          <span><?= ucwords(str_replace('_',' ',$order['payment_method'])) ?></span>
        </div>
        <div style="display:flex;justify-content:space-between;font-size:.88rem;padding:6px 0;border-bottom:1px solid #e2e8f0;">
          <span style="color:var(--text-mid);font-weight:600;">Deliver To</span>
          <span><?= h($order['city'].', '.$order['state']) ?></span>
        </div>
        <div style="display:flex;justify-content:space-between;font-size:.88rem;padding:8px 0;">
          <span style="color:var(--text-mid);font-weight:700;">Order Total</span>
          <span style="font-family:'Outfit',sans-serif;font-size:1.1rem;font-weight:800;color:var(--blue-main);"><?= rupee($order['total']) ?></span>
        </div>
      </div>
      <?php if ($order['payment_method'] === 'bank_transfer'): ?>
      <div style="background:#eff6ff;border:1px solid #bfdbfe;border-radius:12px;padding:20px;max-width:480px;margin:0 auto 24px;text-align:left;">
        <h4 style="color:#1e40af;font-weight:700;margin-bottom:10px;">🏦 Bank Transfer Details</h4>
        <p style="font-size:.88rem;color:#1e40af;line-height:1.8;">
          <strong>Account Name:</strong> Balimeen Private Limited<br>
          <strong>Bank:</strong> State Bank of India<br>
          <strong>Account No:</strong> XXXXXXXXXX<br>
          <strong>IFSC:</strong> SBIN0XXXXXX<br>
          <strong>Reference:</strong> <?= h($order['order_no']) ?>
        </p>
      </div>
      <?php elseif ($order['payment_method'] === 'upi'): ?>
      <div style="background:#f0fdf4;border:1px solid #86efac;border-radius:12px;padding:20px;max-width:480px;margin:0 auto 24px;text-align:left;">
        <h4 style="color:#166534;font-weight:700;margin-bottom:8px;">📱 UPI Payment</h4>
        <p style="font-size:.88rem;color:#166534;">Send payment to UPI ID: <strong>balimeen@upi</strong><br>Reference: <strong><?= h($order['order_no']) ?></strong></p>
      </div>
      <?php endif; ?>
      <?php else: ?>
      <p>Your order has been placed. Our team will contact you to confirm the details shortly.</p>
      <?php endif; ?>
      <div style="display:flex;gap:14px;justify-content:center;flex-wrap:wrap;">
        <a href="<?= SITE_URL ?>/pages/account.php#orders" class="btn btn-primary">📦 View My Orders</a>
        <a href="<?= SITE_URL ?>/pages/products.php" class="btn btn-outline" style="color:var(--blue-main);border-color:var(--blue-main);">Continue Shopping</a>
      </div>
    </div>
  </div>
</section>
<?php include __DIR__ . '/../includes/footer.php'; ?>
