<?php
session_start();
include "db.php";

if(!isset($_SESSION['user_id']) || $_SESSION['role'] != 'admin'){
    header("Location: login.php");
    exit();
}

// Total products
$result = mysqli_query($conn, "SELECT COUNT(*) as total_products FROM products");
$row = mysqli_fetch_assoc($result);
$total_products = $row['total_products'];

// Total orders
$order_result = mysqli_query($conn, "SELECT COUNT(*) as total_orders FROM orders");
$order_row = mysqli_fetch_assoc($order_result);
$total_orders = $order_row['total_orders'];

// Total users
$user_result = mysqli_query($conn, "SELECT COUNT(*) as total_users FROM users");
$user_row = mysqli_fetch_assoc($user_result);
$total_users = $user_row['total_users'];
?>

<!DOCTYPE html>
<html>
<head>
    <title>Admin Dashboard - ApexUniversalMart</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body{
            margin:0;
            font-family:Segoe UI;
            background:#f4f4f4;
        }
        header{
            background:rgb(242,139,0);
            color:white;
            padding:15px;
            text-align:center;
            font-size:22px;
        }
        .container{
            display:flex;
            flex-wrap:wrap;
            justify-content:center;
            gap:20px;
            padding:20px;
        }
        .card{
            background:white;
            flex: 1 1 200px;
            min-width: 200px;
            max-width: 250px;
            padding:20px;
            border-radius:10px;
            box-shadow:0 5px 15px rgba(0,0,0,0.1);
            text-align:center;
            cursor:pointer;
            transition: transform 0.2s;
            color:#333;
            text-decoration:none;
        }
        .card:hover{
            transform: scale(1.05);
            box-shadow:0 10px 25px rgba(0,0,0,0.2);
        }
        .card h3{
            margin-bottom:15px;
            color:rgb(242,139,0);
        }
        .card p{
            font-size:24px;
            margin:0;
        }
        @media(max-width:600px){
            .container{
                flex-direction:column;
                align-items:center;
            }
        }
    </style>
</head>
<body>
    <!-- FLOATING BACK BUTTON -->
<a href="javascript:history.back()" class="floating-back">
    ←
</a>

<style>
.floating-back {
    position: fixed;
    bottom: 30px;
    left: 30px;
    background: #5d1b01;
    color: #fff;
    font-size: 22px;
    text-decoration: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    transition: 0.3s;
    z-index: 999;
}

.floating-back:hover {
    background: #8b2e0c;
    transform: scale(1.1);
}
</style>

<header>Admin Dashboard ðŸ‘‘ <?php echo $_SESSION['fullname']; ?></header>

<div class="container">

    <a href="products.php" class="card">
        <h3>Total Products</h3>
        <p><?php echo $total_products; ?></p>
    </a>

    <a href="products_upload.php" class="card">
        <h3>Upload Product</h3>
        <p>+</p>
    </a>

    <a href="orders.php" class="card">
        <h3>Total Orders</h3>
        <p><?php echo $total_orders; ?></p>
    </a>

   

    <a href="" class="card">
        <h3>Total Users</h3>
        <p><?php echo $total_users; ?></p>
    </a>

    <a href="logout.php" class="card">
        <h3>Logout</h3>
        <p>Exit</p>
    </a>

</div>

</body>
</html>