<?php
session_start();
if ($_SESSION['unohs'] == null) {
    header("location:index.php?msg=unauthorized");
}
date_default_timezone_set("Asia/Kolkata");
include("conn.php");
$curdate = date('Y-m-d h:i:s');
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=1200, initial-scale=0.1">
    <title>Admin Dashboard</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="shortcut icon" href="images/favicon.png" />
</head>

<body>
    <div class="container-scroller">
        
        <nav class="navbar">
            <div class="navbar-brand-wrapper">
                <button class="navbar-toggler d-lg-none" type="button" id="mobile-toggle">
                    <i class="fa-solid fa-bars"></i>
                </button>
                <a class="navbar-brand" href="dashboard.php" style="margin-left: 10px;">
                    <a href="https://t.me/anonymous_botz" target="_blank"
   style="
     display:inline-flex;
     align-items:center;
     gap:8px;
     height:40px;
     padding:0 14px;
     background:#0088cc;
     color:#ffffff;
     font-weight:600;
     text-decoration:none;
     border-radius:8px;
     box-shadow:0 0 12px rgba(0,136,204,0.7);
     font-family:Arial, sans-serif;
   ">
   
   <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="white" viewBox="0 0 24 24">
     <path d="M22.05 1.577L1.58 9.616c-1.4.545-1.392 1.303-.254 1.657l5.262 1.643 2.012 6.048c.258.712.146.996.987.996.648 0 1.008-.298 1.465-.746l2.56-2.488 5.32 3.93c.98.54 1.682.26 1.93-.91L23.98 3.52c.33-1.47-.56-2.09-1.93-1.943z"/>
   </svg>

   Contact Now
</a>
                </a>
            </div>
            
            <div class="navbar-menu-wrapper">
                <a href="logout.php" class="btn-logout">
                    <i class="fa-solid fa-power-off"></i> Logout
                </a>
            </div>
        </nav>

        <div class="container-fluid page-body-wrapper">
            
            <nav class="sidebar sidebar-offcanvas" id="sidebar">
                <div class="user-profile">
                    <img src="images/faces/face28.png" alt="admin">
                    <div class="user-name">Made BY Anonymous_Botz</div>
                    <div class="user-designation">Super Admin</div>
                </div>
                <?php include 'compass.php'; ?>
            </nav>

            <div class="main-panel">
                <div class="content-wrapper">
                    
                    <div class="page-header">
                        <h3 class="page-title">Dashboard Overview</h3>
                        <span class="page-subtitle">Statistics for <?php echo date("F d, Y"); ?></span>
                    </div>

                    <?php
                    $chkserial = mysqli_query($conn, "select * from `nirvahaka_shonu` where `unohs`='" . $_SESSION['unohs'] . "'");
                    $salu = mysqli_fetch_array($chkserial);
                    if ($salu['dashboard'] == 1) {
                    ?>
                    
                    <h5 style="margin-bottom:15px; color:#555; font-weight:600;">🚀 Quick Actions</h5>
                    <div class="action-grid" style="margin-bottom:30px;">
                        <a href="abmain.php" class="action-card">
                            <div class="action-icon"><i class="fa-solid fa-screwdriver-wrench"></i></div>
                            <div class="action-title">Site Maintenance</div>
                        </a>
                        <a href="addgiftcode.php" class="action-card">
                            <div class="action-icon" style="color:#28c76f; background:rgba(40,199,111,0.1);"><i class="fa-solid fa-gift"></i></div>
                            <div class="action-title">Create Gift Code</div>
                        </a>
                        <a href="autobanuser.php" class="action-card">
                            <div class="action-icon" style="color:#ea5455; background:rgba(234,84,85,0.1);"><i class="fa-solid fa-ban"></i></div>
                            <div class="action-title">Check Same IP</div>
                        </a>
                        <a href="manage_salary.php" class="action-card">
                            <div class="action-icon" style="color:#ff9f43; background:rgba(255,159,67,0.1);"><i class="fa-solid fa-hand-holding-dollar"></i></div>
                            <div class="action-title">Manage Salary</div>
                        </a>
                    </div>

                    <h5 style="margin-bottom:15px; color:#555; font-weight:600;">📊 Live Statistics</h5>
                    <div class="dashboard-grid">

                        <div class="card-3d grad-blue">
                            <div class="card-body">
                                <i class="fa-solid fa-users card-icon"></i>
                                <h4 class="card-title">Total Users</h4>
                                <h2 class="card-amount">
                                    <?php
                                    $result = mysqli_query($conn, "SELECT count(*) as 'total_user' FROM shonu_subjects where id NOT IN (SELECT balakedara FROM `demo` WHERE `sthiti`='1') AND status = 1");
                                    $row = mysqli_fetch_array($result);
                                    echo number_format($row["total_user"]);
                                    ?>
                                </h2>
                                <a href="manage_user.php" class="card-link">View All Users</a>
                            </div>
                        </div>

                        <div class="card-3d grad-purple">
                            <div class="card-body">
                                <i class="fa-solid fa-sack-dollar card-icon"></i>
                                <h4 class="card-title">User Wallet</h4>
                                <h2 class="card-amount">
                                    ₹ <?php
                                    $result = mysqli_query($conn, "SELECT sum(motta) as 'wallt' FROM shonu_kaichila where balakedara NOT IN (SELECT balakedara FROM `demo` WHERE `sthiti`='1') AND motta > 0");
                                    $row = mysqli_fetch_array($result);
                                    echo number_format($row["wallt"] ?? 0, 2);
                                    ?>
                                </h2>
                                <a href="manage_user.php" class="card-link">Check Balances</a>
                            </div>
                        </div>

                        <div class="card-3d grad-green">
                            <div class="card-body">
                                <i class="fa-solid fa-bolt card-icon"></i>
                                <h4 class="card-title">Today's Recharge</h4>
                                <h2 class="card-amount">
                                    ₹ <?php
                                    $result = mysqli_query($conn, "SELECT sum(motta) as 'pending' FROM thevani WHERE sthiti = '1' AND balakedara NOT IN (SELECT balakedara FROM `demo` WHERE `sthiti`='1') AND DATE(dinankavannuracisi) = DATE('" . $curdate . "')");
                                    $row = mysqli_fetch_array($result);
                                    echo number_format($row["pending"] ?? 0);
                                    ?>
                                </h2>
                                <a href="deposit_update.php" class="card-link">View Report</a>
                            </div>
                        </div>

                        <div class="card-3d grad-red">
                            <div class="card-body">
                                <i class="fa-solid fa-money-bill-transfer card-icon"></i>
                                <h4 class="card-title">Today's Withdrawal</h4>
                                <h2 class="card-amount">
                                    ₹ <?php
                                    $result = mysqli_query($conn, "SELECT sum(motta) as 'succ_w' FROM hintegedukolli where sthiti = 1 AND balakedara NOT IN (SELECT balakedara FROM `demo` WHERE `sthiti`='1') AND DATE(dinankavannuracisi) = DATE('" . $curdate . "')");
                                    $row = mysqli_fetch_array($result);
                                    echo number_format($row["succ_w"] ?? 0);
                                    ?>
                                </h2>
                                <a href="withdraw_accept_list.php" class="card-link">View Report</a>
                            </div>
                        </div>

                        <div class="card-3d grad-orange">
                            <div class="card-body">
                                <i class="fa-solid fa-clock card-icon"></i>
                                <h4 class="card-title">Pending Recharge</h4>
                                <h2 class="card-amount">
                                    <?php
                                    $result = mysqli_query($conn, "SELECT sum(motta) as 'pending_amount' FROM thevani where balakedara NOT IN (SELECT balakedara FROM `demo` WHERE `sthiti`='1') AND sthiti = '0'");
                                    $row = mysqli_fetch_array($result);
                                    echo number_format($row["pending_amount"] ?? 0);
                                    ?>
                                </h2>
                                <a href="deposit_update.php" class="card-link">Approve Now</a>
                            </div>
                        </div>

                        <div class="card-3d grad-dark">
                            <div class="card-body">
                                <i class="fa-solid fa-chart-line card-icon"></i>
                                <h4 class="card-title">Today's Profit</h4>
                                <h2 class="card-amount">
                                    ₹ <?php
                                    $tables = ['bajikattuttate','bajikattuttate_drei','bajikattuttate_funf','bajikattuttate_zehn','bajikattuttate_kemuru','bajikattuttate_kemuru_drei','bajikattuttate_kemuru_funf','bajikattuttate_kemuru_zehn','bajikattuttate_aidudi','bajikattuttate_aidudi_drei','bajikattuttate_aidudi_funf','bajikattuttate_aidudi_zehn'];
                                    $total_bet = 0; $total_win = 0;
                                    foreach ($tables as $t) {
                                        $qb = mysqli_fetch_assoc(mysqli_query($conn, "SELECT sum(ketebida) as total FROM `$t` where byabaharkarta NOT IN (SELECT balakedara FROM `demo` WHERE `sthiti`='1') AND DATE(tiarikala) = DATE('" . $curdate . "')"));
                                        $total_bet += $qb['total'];
                                        
                                        $qw = mysqli_fetch_assoc(mysqli_query($conn, "SELECT sum(sesabida) as total FROM `$t` where `phalaphala` = 'gagner' AND byabaharkarta NOT IN (SELECT balakedara FROM `demo` WHERE `sthiti`='1') AND DATE(tiarikala) = DATE('" . $curdate . "')"));
                                        $total_win += $qw['total'];
                                    }
                                    echo number_format($total_bet - $total_win, 2);
                                    ?>
                                </h2>
                            </div>
                        </div>

                    </div>
                    <?php } ?>
                </div>
                
                <footer class="footer">
                    <span>Dev by Anonymous_botz</span>
                </footer>
            </div>
        </div>
    </div>

    <script src="vendors/base/vendor.bundle.base.js"></script>
    <script src="vendors/chart.js/Chart.min.js"></script>
    
    <script>
    (function($) {
      'use strict';
      $(document).ready(function() {
        
        // 1. MOBILE SIDEBAR TOGGLE FIX
        $('#mobile-toggle').on('click', function(e) {
            e.stopPropagation();
            $('.sidebar-offcanvas').toggleClass('active');
        });

        // 2. CLOSE SIDEBAR ON OUTSIDE CLICK
        $(document).on('click', function(e) {
            if (!$(e.target).closest('.sidebar-offcanvas').length && !$(e.target).closest('#mobile-toggle').length) {
                $('.sidebar-offcanvas').removeClass('active');
            }
        });

        // 3. DROPDOWN (ACCORDION STYLE)
        $('.nav-item > a[data-toggle="collapse"]').on("click", function(e) {
             e.preventDefault();
             var target = $(this).attr('href');
             $('.collapse').not(target).collapse('hide'); // Close others
             $(target).collapse('toggle'); // Open current
        });

      });
    })(jQuery);
    </script>
</body>
</html>