<?php
require_once __DIR__ . '/../app/bootstrap.php';
use App\Core\Database;
$id=(int)($_GET['order_id']??($_SESSION['last_order_id']??0));
$order=$id?Database::safeFetchOne('SELECT * FROM orders WHERE id=? LIMIT 1',[$id]):null;
$pageTitle='Thank You | '.BRAND_NAME; require ROOT_PATH.'/app/Layouts/frontend_header.php';
?>
<section class="container py-5"><?php if($msg=flash('error')): ?><div class="alert alert-danger"><?= e($msg) ?></div><?php endif; ?><div class="row justify-content-center"><div class="col-lg-7"><div class="card border-0 shadow-sm text-center"><div class="card-body p-5"><div class="display-3 text-success">✓</div><h1>Thank you for your order</h1><?php if($order): ?><p class="lead">Order <strong><?= e($order['order_no']) ?></strong> has been placed.</p><p>Total: <strong><?= money($order['total_amount']) ?></strong> · Payment: <?= e(ucwords($order['payment_status'])) ?></p><div class="d-flex justify-content-center gap-2 flex-wrap"><?php if(($order['payment_status']??'')!=='paid' && in_array($order['payment_method']??'', ['sslcommerz','bkash','nagad','partial'], true)): ?><a class="btn btn-success" href="<?= url('payment/'.rawurlencode($order['payment_method']).'.php?order_id='.(int)$order['id']) ?>">Pay Now</a><?php endif; ?><a class="btn btn-primary" href="<?= url('public/track-order.php') ?>">Track Order</a><?php if(current_user()): ?><a class="btn btn-outline-primary" href="<?= url('customer/orders.php') ?>">My Orders</a><?php endif; ?></div><?php else: ?><p class="lead">Your order has been submitted.</p><a class="btn btn-primary" href="<?= url('public/products.php') ?>">Continue Shopping</a><?php endif; ?></div></div></div></div></section><?php require ROOT_PATH.'/app/Layouts/frontend_footer.php'; ?>
