<?php

@include 'config.php';

session_start();

$admin_id = $_SESSION['admin_id'];

if (!isset($admin_id)) {
   header('location:login.php');
};

?>

<!DOCTYPE html>
<html lang="en">

<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>dashboard</title>

   <!-- font awesome cdn link  -->
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">

   <!-- custom admin css file link  -->
   <link rel="stylesheet" href="css/admin_style.css">

</head>

<body style="background-color: pink;">

   <?php @include 'admin_header.php'; ?>

   <section style="background-color: pink;" class="dashboard">

      <h1 class="title">BERANDA</h1>

      <div class="box-container">

         <div class="box">
            <?php
            $total_pendings = 0;

            $ongkirList = [
               1 => 10000,
               2 => 20000,
            ];

            $select_pendings = mysqli_query($conn, "SELECT * FROM `orders` WHERE payment_status = 'pending'") or die(mysqli_error($conn));

            while ($fetch_pendings = mysqli_fetch_assoc($select_pendings)) {
               $ongkir = $ongkirList[$fetch_pendings['pilihan_ongkir_id']] ? $ongkirList[$fetch_pendings['pilihan_ongkir_id']] :   0;
               $total_pendings += $fetch_pendings['total_price'] + $ongkir;
            }
            ?>
            <h3>Rp.<?php echo number_format($total_pendings, 0, ',', '.'); ?></h3>
            <p>
               <a href="admin_orders.php" style="background-color: pink; display: block; padding: 10px; border: 1px solid black; border-radius: 5px; text-align: center; color: #333; text-decoration: none; font-weight: 500;">Uang Tertunda</a>
            </p>
         </div>
         <div class="box">
            <?php
            $total_pendings = 0;

            $ongkirList = [
               1 => 10000,
               2 => 20000,
            ];

            $select_pendings = mysqli_query($conn, "SELECT * FROM `orders` WHERE payment_status = 'completed'") or die(mysqli_error($conn));

            while ($fetch_pendings = mysqli_fetch_assoc($select_pendings)) {
               $ongkir = $ongkirList[$fetch_pendings['pilihan_ongkir_id']] ? $ongkirList[$fetch_pendings['pilihan_ongkir_id']] : 0;
               $total_pendings += $fetch_pendings['total_price'] + $ongkir;
            }
            ?>
            <h3>Rp.<?php echo number_format($total_pendings, 0, ',', '.'); ?></h3>
           <p>
               <a href="admin_orders.php" style="background-color: pink; display: block; padding: 10px; border: 1px solid black; border-radius: 5px; text-align: center; color: #333; text-decoration: none; font-weight: 500;">Uang Masuk</a>
            </p>
         </div>

         <div class="box">
            <?php
            $select_orders = mysqli_query($conn, "SELECT * FROM `orders`") or die('query failed');
            $number_of_orders = mysqli_num_rows($select_orders);
            ?>
            <h3><?php echo $number_of_orders; ?></h3>
            <p>
               <a href="admin_orders.php" style="background-color: pink; display: block; padding: 10px; border: 1px solid black; border-radius: 5px; text-align: center; color: #333; text-decoration: none; font-weight: 500;">Permintaan Pembeli</a>
            </p>
         </div>

         <div class="box">
            <?php
            $select_products = mysqli_query($conn, "SELECT * FROM `products`") or die('query failed');
            $number_of_products = mysqli_num_rows($select_products);
            ?>
            <h3><?php echo $number_of_products; ?></h3>
           <p>
               <a href="admin_products.php" style="background-color: pink; display: block; padding: 10px; border: 1px solid black; border-radius: 5px; text-align: center; color: #333; text-decoration: none; font-weight: 500;">Produk Ditambahkan</a>
            </p>
         </div>

         <div class="box">
            <?php
            $select_users = mysqli_query($conn, "SELECT * FROM `users` WHERE user_type = 'user'") or die('query failed');
            $number_of_users = mysqli_num_rows($select_users);
            ?>
            <h3><?php echo $number_of_users; ?></h3>
           <p>
               <a href="admin_users.php" style="background-color: pink; display: block; padding: 10px; border: 1px solid black; border-radius: 5px; text-align: center; color: #333; text-decoration: none; font-weight: 500;">Akun Pengguna</a>
            </p>
         </div>

         <div class="box">
            <?php
            $select_admin = mysqli_query($conn, "SELECT * FROM `users` WHERE user_type = 'admin'") or die('query failed');
            $number_of_admin = mysqli_num_rows($select_admin);
            ?>
            <h3><?php echo $number_of_admin; ?></h3>
            <p>
               <a href="admin_users.php" style="background-color: pink; display: block; padding: 10px; border: 1px solid black; border-radius: 5px; text-align: center; color: #333; text-decoration: none; font-weight: 500;">Akun Admin</a>
            </p>
         </div>

         <div class="box">
            <?php
            $select_messages = mysqli_query($conn, "SELECT * FROM `message`") or die('query failed');
            $number_of_messages = mysqli_num_rows($select_messages);
            ?>
            <h3><?php echo $number_of_messages; ?></h3>
            <p>
               <a href="admin_contacts.php" style="background-color: pink; display: block; padding: 10px; border: 1px solid black; border-radius: 5px; text-align: center; color: #333; text-decoration: none; font-weight: 500;">Diskusi Masuk</a>
            </p>
      </div>

   </section>













   <script src="js/admin_script.js"></script>

</body>

</html>