<?php
require __DIR__ . '/includes/functions.php';
customer_require_login();
$currentPage = 'account';
$pageTitle = 'My Orders | Furnify';
$customer = customer_current();
$rows = array();
$pdo = db();
if ($pdo) {
    try {
        $stmt = $pdo->prepare('SELECT * FROM orders WHERE customer_id = ? OR customer_email = ? ORDER BY created_at DESC');
        $stmt->execute(array((int) $customer['id'], $customer['email']));
        $rows = $stmt->fetchAll();
    } catch (Exception $e) {}
}
require __DIR__ . '/includes/header.php';
?>
<section class="page-section"><div class="container"><div class="section-heading split-heading"><div><p class="eyebrow">My account</p><h1>My Orders</h1><p class="lead">View payment and order status for your ready-made sofa inquiries.</p></div><a class="btn btn-outline-primary" href="customer-dashboard.php">Dashboard</a></div><div class="premium-panel p-4"><div class="table-responsive"><table class="table align-middle"><thead><tr><th>Order</th><th>Total</th><th>Payment</th><th>Balance</th><th>Status</th><th>Date</th></tr></thead><tbody><?php foreach ($rows as $row): ?><tr><td><?= e($row['order_number']) ?></td><td><?= money($row['total']) ?></td><td><?= e($row['payment_status']) ?></td><td><?= money($row['balance_due']) ?></td><td><span class="badge text-bg-light"><?= e($row['status']) ?></span></td><td><?= e(date('M d, Y h:i A', strtotime($row['created_at']))) ?></td></tr><?php endforeach; ?><?php if (!$rows): ?><tr><td colspan="6" class="text-center text-muted py-5">No orders yet.</td></tr><?php endif; ?></tbody></table></div></div></div></section>
<?php require __DIR__ . '/includes/footer.php'; ?>
