<?php
session_start();
require("config.php");
require("db.php");

$user_id = $_SESSION['SESS_USERID'];
$query = mysqli_query($db, "SELECT * FROM logins WHERE id='$user_id'");
$user = mysqli_fetch_assoc($query);

// Restrict access
if ($user['top_investor'] != 2) {
    header("Location: trade.php");
    exit;
}

// Variables
$firstname  = $user['firstname'];
$lastname   = $user['lastname'];
$balance    = $user['balance'];

$available_tax = $user['available_tax'] ?? null;



$invest_amt = $user['invest_amt'];
$currency   = $user['currency'] ?? 'USD';
$acc_verified=$user['acc_verified'];
$userImage = $user['user_image'];
$ver_b=$user['ver_badge'];

$investor_tier = $user['investor_tier'] ?? 'Gold';
$hashrate_power  = $user['hashrate_power'] ?? '0.00 TH/s';
$hashrate_growth = $user['hashrate_growth'] ?? '0.00%';
$priority_withdrawals = $user['priority_withdrawals'] ?? 0;

$active_bonus_amount = $user['active_bonus_amount'] ?? 0;
$bonus_expiry = $user['bonus_expiry'] ?? 'No Active Bonus';
$total_claimed = $user['total_bonus_claimed'] ?? 0;
$lost_bonus = $user['lost_bonus'] ?? 0;

$upcoming_meeting_text = $user['upcoming_meeting_text'] ?? '';
$mining_tour_text = $user['mining_tour_text'] ?? '';
$withdrawal_privilege_text = $user['withdrawal_privilege_text'] ?? '';
$hashrate_strategy_text = $user['hashrate_strategy_text'] ?? '';
$zoom_access_code = $user['zoom_access_code'] ?? '';
?>

<!DOCTYPE html>
<html lang="en">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<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>Alpha Chequersâ„¢ - Top Investors Panel</title>
  <link rel="shortcut icon" href="assets/img/myfavicon.png" type="image/x-icon">
  <link rel="stylesheet" href="assets/css/bootstrap_custom.css">
  <link rel="stylesheet"
  href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200">
  <link rel="stylesheet" href="assets/css/nice-select.css">
  <link rel="stylesheet" href="assets/css/styles.css">
  
  <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  
  <script src='https://kit.fontawesome.com/a076d05399.js' crossorigin='anonymous'></script>
   <link rel="stylesheet" href="assets1/css/style.css">

<style>
.top-investors-panel h2 { font-weight: 600; font-size: 24px; color: #007bff; border-left: 4px solid orange; padding-left: 12px; margin-bottom: 25px; }
.top-investors-card { background: #1D2330; border-radius: 12px; padding: 20px; color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,0.4); margin-bottom: 20px; transition: transform 0.3s ease;z-index: 0; }
.top-investors-card:hover { transform: translateY(-4px); box-shadow: 0 8px 20px rgba(0,0,0,0.5); }
.top-investors-card h5 { color: orange; font-size: 18px; margin-bottom: 12px; }
.top-investors-card p { color: #ccc; font-size: 14px; line-height: 1.6; margin-bottom: 0; }
.btn-primary { background: orange; border: none; color: #fff; padding: 8px 18px; border-radius: 6px; margin-top: 12px; display: inline-block; }
.btn-primary:hover { background: #ffb84d; }
.btn-disabled { background: gray; color: #ddd; cursor: not-allowed; }

/* --- Live status bar --- */
.live-status-header {
  position: fixed;
  top: 60px;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap; /* allow wrapping for smaller screens */
  gap: 60px;
  background: #1D2330;
  padding: 12px 10px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.live-status-header .status-item {
  text-align: center;
  color: #fff;
  flex: 1 1 auto;
  min-width: 100px;
}

.live-status-header h2 {
  color: #ffffff;
  font-size: 20px;
  margin-bottom: 2px;
  font-weight: 600;
}

.live-status-header h6 {
  font-size: 15px;
  color: #ffcc66;
  margin-bottom: 4px;
}

.live-status-header p {
  font-size: 14px;
  color: #ddd;
  margin: 0;
  line-height: 1.4;
}

.blinking-text {
  color: #00ffcc;
  font-size: 16px;
  text-shadow: 0 0 8px #00ffcc;
  font-weight: bold;
  animation: blink 1s infinite;
}

@keyframes blink {
  50% { opacity: 0.4; }
}

/* 📱 Responsive tweaks for tablets */
@media (max-width: 992px) {
  .live-status-header {
    gap: 30px;
    padding: 10px 6px;
  }
  .live-status-header h2 {
    font-size: 18px;
  }
  .live-status-header h6 {
    font-size: 14px;
  }
  .blinking-text {
    font-size: 15px;
  }
}

/* 📱 Responsive tweaks for mobile devices */
@media (max-width: 600px) {
  .live-status-header {
    gap: 15px;
    flex-wrap: wrap;
    padding: 8px 5px;
  }

  .live-status-header .status-item {
    flex: 1 1 30%;
    min-width: 90px;
  }

  .live-status-header h2 {
    font-size: 16px;
  }
  .live-status-header h6 {
    font-size: 13px;
  }
  .live-status-header p,
  .blinking-text {
    font-size: 13px;
  }
}


/* adjust main content margin */
.main-content { margin-top: 120px; }



/* ✅ Two-column layout for Mining Cycle Card */
.mining-cycle-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 20px;
}

/* Left & Right Columns */
.mining-cycle-left,
.mining-cycle-right {
  flex: 1;
  min-width: 280px; /* forces stacking on small screens */
}

/* Right column styling */
.mining-cycle-right {
  background: #141a28;
  padding: 16px;
  border-radius: 10px;
  border: 1px solid #2a3246;
}

/* Inputs inside the form */
.mining-cycle-right input[type="number"],
.mining-cycle-right input[type="datetime-local"],
.mining-cycle-right input[type="text"] {
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #1d2330;
  color: #fff;
}

/* Save button */
.mining-cycle-right .btn-primary {
  background: orange;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  margin-top: 10px;
}
.mining-cycle-right .btn-primary:hover {
  background: #ffb84d;
}

/* ✅ Responsive stacking on mobile */
@media (max-width: 768px) {
  .mining-cycle-container {
    flex-direction: column;
  }
  .mining-cycle-right {
    margin-top: 15px;
    border-top: 1px solid #333;
    padding-top: 18px;
  }
}

/* Responsive top margin adjustments for mining cycle section */
@media (max-width: 767px) {
  #top-investors {
    margin-top: 30px !important;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
   #top-investors {
    margin-top: 20px !important;
  }
}

/* Investment & Balance row styling */
.invest-balance-row {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.invest-balance-row .top-investors-card {
  flex: 1 1 48%;
  margin-bottom: 2px;
}

/* Responsive: stack vertically on mobile */
@media (max-width: 768px) {
  .invest-balance-row {
    flex-direction: column;
  }
  .invest-balance-row .top-investors-card {
    width: 100%;
  }
}

.btn-disabled {
  background: gray;
  color: #ddd;
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0.6;
}
</style>

</head>
<body style="background: var(--bg-body)">

<div class="d-flex wrapper" id="wrapper">

     <!-- Sidebar -->
    <div id="sidebar-wrapper" class="sidebar-wrapper" style="padding-top: 0px !important">
      <div class="sidebar-heading" style="padding-top: 0px !important">
        <a href="../index.html" style="margin-top: 8px !important">
          <img id="logo" src="assets/img/crypto/logo.png" style="height: 25px; width: 25px" alt="">
          <span style="font-weight: bold; color: #007bff; font-size: 14px !important"> ALPHA <span style="color: orange !important; font-size: 14px !important">CHEQUERS</span>
</span></a>
      </div>
      <nav class="sidebar mb-4" style="margin-top: 100px !important;">
        <ul class="nav flex-column" id="nav_accordion">
          <li class="nav-item">
            <a class="nav-link active d-flex gap-2 align-items-center" href="trade.php">
              <img src="assets/img/dashboard_icon.png" alt="">
              <span class="fw-semibold">Dashboard</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link d-flex gap-2 align-items-center" href="deposit.php">
              <span class="material-symbols-outlined fw-lighter">
                sync
              </span>
              <span class="fw-semibold">Deposit</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link d-flex gap-2 align-items-center" href="withdraw.php">
              <span class="material-symbols-outlined fw-lighter">
                payments
              </span>
              <span class="fw-semibold">Withdraw</span>
            </a>
          </li>
         
          <li class="nav-item">
            <a class="nav-link d-flex gap-2 align-items-center" href="pending.php">
              <span class="material-symbols-outlined fw-lighter">
                percent
              </span>
              <span class="fw-semibold">Pending</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link d-flex gap-2 align-items-center" href="verify.php">
              <span class="material-symbols-outlined fw-lighter">
                insights
              </span>
              <span class="fw-semibold">Verify</span>
            </a>
          </li>
		  
         
		  
          <li class="nav-item">
            <a class="nav-link d-flex gap-2 align-items-center" href="account-details.php">
              <span class="material-symbols-outlined fw-lighter">
                settings
              </span>
              <span class="fw-semibold">Settings</span>
            </a>
          </li>
          
  
    

         <li class="nav-item">
            <a class="nav-link d-flex gap-2 align-items-center" href="logout.php">
              <span class="material-symbols-outlined fw-lighter">
                logout
              </span>
              <span class="fw-semibold">Logout</span>
            </a>
          </li>
         
        </ul>
        
      </nav>
    </div>




<div id="page-content-wrapper" class="page-content-wrapper">
    
    
     <nav class="navbar navbar-expand-lg py-lg-3 px-2 px-lg-4 d-flex fixed-top justify-content-between" style="padding-top: 0px !important; padding-bottom: 0px !important; height: 60px !important;">
        
		<div class="d-flex align-items-center" style="margin-top: 0px !important">
          <div class="d-flex align-items-center d-lg-none">
            <span class="material-symbols-outlined menu-toggle" id="menu-toggle">
              menu
            </span>
          </div>
          <div class="d-none d-xl-block"> 
 		  
            
                <a class="dropdown-item d-flex align-items-center gap-2" href="#" style="color: #fff !important">
                  <span class="material-symbols-outlined fw-light" style="color: orange !important">
                    email
                  </span>
                  info@alphachequers.com</a>
               
          </div>
        </div>

        <div class="d-flex gap-3 p-lg-2 p-lg-0 align-items-center justify-content-end" style="">           
          <div class="nav-item dropdown">
            <a class="d-flex gap-2 align-items-center" href="#" id="navbarDropdown4" role="button"
              data-bs-toggle="dropdown" aria-expanded="false">
              <?php if(!empty($userImage)) {
                             ?>                            
              <img height="35" width="35" class="img-fluid" src="userImages/<?php echo $userImage; ?>" alt="" style="border-radius: 50%">
              <?php
              }else{
                ?>
                <img src="assets/img/avatarnow.png" alt="" height="35" width="35" style="border-radius: 50%">
                <?php
              }
        
            ?>
              <div class="d-flex flex-column d-none d-xl-block">
                 <script src="https://code.iconify.design/iconify-icon/1.0.7/iconify-icon.min.js"></script>
           
                 <p class="mb-0 text-white fw-semibold" style="font-size: 15px">
		   <?php echo $firstname; ?> <?php echo $lastname; if($ver_b == 2){
                  echo "<iconify-icon icon='material-symbols:verified' style='color: #ccc; font-size: 12px'></iconify-icon>";
                 } ?>		  		      
		   </p>
		
                <span class="small text-white">Investor</span>


				
			<?php
                        function display_currency($currency){

                            foreach($currency as $currence){
                                echo $currence;
                            }
                        }
                        $username = $_SESSION['SESS_USERNAME'];
                        $currency = array();
                        $query = mysqli_query($db,"SELECT * FROM logins WHERE username='$username'");
                        $user_data = mysqli_fetch_array($query);
                        if($user_data['currency']==mysqli_real_escape_string($db,'USD')){
                            $currency[]='$';
                        }
                        else if($user_data['currency']==mysqli_real_escape_string($db,'GBP')){
                            $currency[]='£';
                        }
                        else if($user_data['currency']==mysqli_real_escape_string($db,'EUR')){
                            $currency[]='€';
                        }
                        else if($user_data['currency']==mysqli_real_escape_string($db,'AUD')){
                            $currency[]='$';
                        }
                        else if($user_data['currency']==mysqli_real_escape_string($db,'CAD')){
                            $currency[]='$';
                        }
                        $seller= $_SESSION['SESS_USERID']; 
                        $sql = mysqli_query($db,"SELECT * FROM logins WHERE id='$seller'");

                        $numrow=mysqli_fetch_assoc($sql);
                        $balc=$numrow['balance'];
                        ?>
              </div>
            </a>
            <ul class="dropdown-menu dropdown-menu-end user shadow border-0" aria-labelledby="navbarDropdown4"
              onclick="event.stopPropagation()">
              <li><span class="px-3 d-inline-block">Welcome <?php echo $surname; ?></span></li>
              <li>
                <a class="dropdown-item d-flex align-items-center gap-2" href="account-details.php">
                  <span class="material-symbols-outlined fw-light">
                    account_circle
                  </span>
                  Profile Settings</a>
              </li>
             
            
            
              <li>
                <a class="dropdown-item d-flex align-items-center gap-2" href="deposit.php">
                  <span class="material-symbols-outlined fw-light"> sync </span>
                  Deposit</a>
              </li>
              <li>
                <a class="dropdown-item d-flex align-items-center gap-1" href="logout.php">
                  <span class="material-symbols-outlined fw-light"> logout </span>
                  Log Out</a>
              </li>
            </ul>
          </div>
        </div>
        <!-- For pc -->
      </nav> 
    
    
    
    

    
    
    


<div class="container-fluid main-content px-2 px-lg-4">
  <div class="top-investors-panel" style="margin-top: 190px !important">
    
    
    
        <!-- ðŸ”¹ Fixed top live status bar -->
<div class="live-status-header">
    <div class="status-item">
    <h2>Top Investors Panel</h2>
    <p><span style="color:#D4D381; line-height: 1px !important">(<?php echo $investor_tier; ?> Member)</span></p>
  </div>
    
    

  <div class="status-item">
    <h6>Hashrate Power</h6>
    <p class="blinking-text"><?php echo $hashrate_power; ?></p>
  </div>
  <div class="status-item">
    <h6>Growth Rate</h6>
    <p class="blinking-text"><?php echo $hashrate_growth; ?></p>
  </div>
</div>
    
    
    

   
   
   
   
   
   
   
   
   <!-- Investment + Balance Row -->
<div class="invest-balance-row" id="top-investors">
  <div class="top-investors-card">
    <h5>INVESTMENT</h5>
    <p><?php display_currency($currency); echo '' . $invest_amt; ?>.00</p>
  </div>

  <div class="top-investors-card">
  <h5>BALANCE</h5>
  <p>
    <?php display_currency($currency); echo '' . $balance; ?>.00
    <?php if (!empty($available_tax)): ?>
      <span style="color:red; font-size:13px;">
        (<?php echo htmlspecialchars($available_tax); ?> to be paid)
      </span>
    <?php endif; ?>
  </p>
</div>

</div>

   
   
   
   
   
   
   
   
   
   
   
   
    
    
    
    
    
    
    
    
    
    
<!-- MINING CYCLE CARD -->
<div class="top-investors-card">
  <h5>MINING CYCLE INFORMATION</h5>

  <div class="mining-cycle-container">
    <!-- LEFT COLUMN -->
    <div class="mining-cycle-left">
      <p><strong>Current Period:</strong>
        <?php echo intval($user['mining_period_months'] ?? 0) . ' month(s)'; ?>
      </p>
      <p><strong>Cycle End Date:</strong>
        <?php
          echo !empty($user['mining_end_date']) ? htmlspecialchars($user['mining_end_date']) : 'Not set';
        ?>
      </p>
      <p><strong>Expected ROI at end:</strong>
        <?php display_currency($currency); echo '' . number_format(floatval($user['expected_roi'] ?? 0), 2); ?>
      </p>
    </div>

    <!-- RIGHT COLUMN (editable form) -->
    <?php if (intval($user['top_investor']) === 2): ?>
    <div class="mining-cycle-right">
      <form id="miningForm" action="update_mining.php" method="POST">
        <div style="margin-bottom:8px;">
          <label>Change mining period (months):</label><br>
          <input type="number" id="mining_period_months" name="mining_period_months"
                 value="<?php echo intval($user['mining_period_months'] ?: 0); ?>"
                 min="1" max="120">
        </div>

        <div style="margin-bottom:8px;">
          <label>Change cycle end date (optional):</label><br>
          <input type="datetime-local" id="mining_end_date" name="mining_end_date"
                 value="<?php
                   if (!empty($user['mining_end_date'])) {
                     echo date('Y-m-d\TH:i', strtotime($user['mining_end_date']));
                   }
                 ?>">
        </div>

        <div style="margin-bottom:8px;">
          <label>New expected ROI (preview):</label><br>
          <input type="text" id="preview_expected_roi" readonly>
        </div>

        <button type="submit" class="btn-primary">Save Mining Cycle</button>
      </form>
    </div>
    <?php endif; ?>
  </div>

  <script>
    (function(){
      const storedMonths = <?php echo intval($user['mining_period_months'] ?: 1); ?>;
      const storedExpected = <?php echo floatval($user['expected_roi'] ?: 0); ?>;
      const currencySymbol = '<?php
          $sym=''; if($currency=='USD') $sym='$'; else if($currency=='GBP') $sym='£'; else if($currency=='EUR') $sym='€'; else $sym='$'; echo $sym;
      ?>';

      function updatePreview() {
        let newMonths = parseInt(document.getElementById('mining_period_months').value) || storedMonths;
        let newExpected = storedExpected > 0 ? (storedExpected * (newMonths / storedMonths)) : 0;
        document.getElementById('preview_expected_roi').value = currencySymbol + ' ' + Number(newExpected).toFixed(2);
      }
      document.getElementById('mining_period_months').addEventListener('input', updatePreview);
      updatePreview();
    })();
  </script>
</div>


    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    <div class="top-investors-card">
      <h5>ACTIVE BONUS</h5>
      <p><?php display_currency($currency); echo '' . $active_bonus_amount; ?></p>
      <p><strong>Bonus Expiry:</strong> <?php echo htmlspecialchars($bonus_expiry); ?></p>
      <?php if ($active_bonus_amount > 0): ?>
        <form action="claim_bonus.php" method="POST">
          <button type="submit" name="claim_bonus" class="btn-primary">Claim Bonus</button>
        </form>
      <?php else: ?>
        <button class="btn-disabled" disabled>Claim Bonus</button>
      <?php endif; ?>
    </div>

    <div class="top-investors-card">
      <h5>TOTAL BONUS CLAIMED</h5>
      <p><?php display_currency($currency); echo '' . $total_claimed; ?></p>
    </div>

    <div class="top-investors-card">
      <h5>LOST BONUS</h5>
      <p><?php display_currency($currency); echo '' . $lost_bonus; ?></p>
    </div>

   <div class="top-investors-card">
  <h5>BALANCE</h5>
  <p>
    <?php display_currency($currency); echo '' . $balance; ?>.00
    <?php if (!empty($available_tax)): ?>
      <span style="color:red; font-size:13px;">
        (<?php echo htmlspecialchars($available_tax); ?> to be paid)
      </span>
    <?php endif; ?>
  </p>
</div>


    <div class="top-investors-card">
      <h5>Upcoming Investors Meeting</h5>
      <p><?php echo htmlspecialchars($upcoming_meeting_text); ?></p>
      <?php if (!empty($zoom_access_code)): ?>
        <p><strong>Zoom Access Code:</strong> <?php echo htmlspecialchars($zoom_access_code); ?></p>
      <?php endif; ?>
    </div>

    <div class="top-investors-card">
  <h5>Mining Farm Tour</h5>
  <p><?php echo $mining_tour_text; ?></p>
  <a href="#" class="btn-primary btn-disabled" onclick="return false;">Accept Tour Invitation</a>
</div>



    <div class="top-investors-card">
  <h5>Withdrawal Privilege</h5>
  <p><?php echo $withdrawal_privilege_text; ?></p>
  <p><strong>Priority Withdrawals Remaining:</strong> <?php echo $priority_withdrawals; ?></p>
</div>

    <div class="top-investors-card">
  <h5>Exclusive Hashrate Strategy</h5>
  <p><?php echo $hashrate_strategy_text; ?></p>
  <?php if (!empty($hashrate_power)): ?>
    <p><strong>Hashrate Power:</strong> <?php echo $hashrate_power; ?></p>
  <?php endif; ?>
  <?php if (!empty($hashrate_growth)): ?>
    <p><strong>Growth Rate:</strong> <?php echo $hashrate_growth; ?></p>
  <?php endif; ?>
</div>


  </div>
</div>







<div class="row py-2 g-3 g-lg-4 top-border footer">
          <div class="col-lg-6">
            <span class="text-center text-lg-start d-block w-100">©2024. All Rights Reserved By <a href="#" class="primary" style="color: orange !important">Alpha Chequers.</a></span>
          </div>
         
        </div>

</div>
</div>








<script src="../cdn.jsdelivr.net/npm/bootstrap%405.0.0-beta3/dist/js/bootstrap.bundle.min.js"></script>
  <script src="../cdn.jsdelivr.net/npm/chart.js"></script>
  <script src="../code.jquery.com/jquery-3.5.1.min.js"></script>
  <script src="assets/js/jquery.nice-select.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  <script src="assets/js/main.js"></script>
  <script src="assets/js/chart.js"></script>

  <script src="../cdn.jsdelivr.net/npm/bootstrap%405.0.0-beta3/dist/js/bootstrap.bundle.min.js"></script>
  <script src="assets/js/main.js"></script>
</body>
</html>
