<?php
session_start();

// Redirect if not logged in
if (empty($_SESSION['user_id'])) {
    header('Location: index.php');
    exit;
}

$user_type = $_SESSION['user_type'] ?? 'user';
$username = $_SESSION['username'] ?? 'User';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Dashboard - Esa's Fashion</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
<?php include __DIR__ . '/header.php'; ?>
<main class="container">
    <h1>Welcome, <?php echo htmlspecialchars($username); ?></h1>

    <?php if ($user_type === 'admin'): ?>
        <section style="margin-top:20px;">
            <h2>Admin Tools</h2>
            <p><a href="admin_products.php" class="btn">Manage Products</a> <a href="admin_orders.php" class="btn">View Orders</a></p>
        </section>
    <?php else: ?>
        <section style="margin-top:20px;">
            <h2>User Dashboard</h2>
            <p><a href="shop.php" class="btn">Continue Shopping</a> <a href="cart.php" class="btn">My Cart</a> <a href="my_orders.php" class="btn">My Orders</a></p>
        </section>
    <?php endif; ?>

    <section style="margin-top:20px;">
        <h3>Account</h3>
        <p><a href="logout.php" class="btn" style="background:#999;">Logout</a></p>
    </section>
</main>
<?php include __DIR__ . '/footer.php'; ?>
</body>
</html>
