<?php
session_start();
require_once 'db.php';

// Hakikisha user amelogin
if (!isset($_SESSION['phone'])) {
  header('Location: login.php');
  exit();
}

$phone = $_SESSION['phone'];

// Fetch balance & income from DB
$stmt = $conn->prepare("SELECT balance, income FROM users WHERE phone = ?");
$stmt->bind_param("s", $phone);
$stmt->execute();
$stmt->bind_result($balance, $income);
$stmt->fetch();
$stmt->close();
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="manifest" href="manifest.json" />
  <meta name="theme-color" content="#0d47a1">
  <link rel="apple-touch-icon" href="icon-192.png">
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>BlackRock</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
  <style>
    body {
      margin: 0;
      font-family: Arial, sans-serif;
      background-color: #0a0a1a; /* dark navy background */
      color: #f1f1f1;
      padding-bottom: 80px;
    }
    .header {
      background-color: #0d47a1; /* dark blue */
      padding: 15px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: white;
    }
    .header h1 {
      font-size: 18px;
      margin: 0;
    }
    .profile-bar {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 15px;
    }
    .profile-left {
      font-size: 16px;
    }
    .profile-badge {
      background: #1e88e5; /* medium blue */
      color: #fff;
      padding: 4px 8px;
      display: inline-block;
      margin-top: 5px;
      border-radius: 12px;
      font-size: 12px;
      font-weight: bold;
    }
    .profile-pic {
      width: 55px;
      height: 55px;
      border-radius: 50%;
      overflow: hidden;
      border: 2px solid #64b5f6; /* light blue */
      box-shadow: 0 0 8px #64b5f6, 0 0 16px #1e88e5, 0 0 24px #0d47a1;
    }
    .profile-pic img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
    .balance-container {
      display: flex;
      justify-content: space-between;
      background-color: #1a1a2a;
      padding: 15px;
      margin: 15px;
      border-radius: 12px;
    }
    .balance-box {
      background: linear-gradient(45deg, #1e88e5, #64b5f6);
      color: black;
      padding: 12px 16px;
      border-radius: 10px;
      flex: 1;
      margin: 0 6px;
      font-weight: bold;
      text-align: center;
    }
    .balance-box strong {
      display: block;
      margin-top: 5px;
      font-size: 20px;
    }
    .menu {
      padding: 10px 15px;
    }
    .menu-item {
      background: #1a1a2a;
      margin-bottom: 10px;
      padding: 14px;
      border-radius: 10px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      box-shadow: 0 2px 5px rgba(30,136,229,0.25);
      cursor: pointer;
      transition: 0.2s;
    }
    .menu-item:hover {
      background: #2a2a3a;
    }
    .menu-item i {
      margin-right: 12px;
      font-size: 18px;
      width: 24px;
      color: #64b5f6;
    }
    .menu-item span {
      flex: 1;
      font-weight: 500;
      color: #f1f1f1;
    }
    .bottom-nav {
      position: fixed;
      bottom: 0;
      left: 0;
      width: 100%;
      background: #0a0a1a;
      display: flex;
      justify-content: space-around;
      padding: 10px 0;
      border-top: 1px solid #1e88e5;
    }
    .bottom-nav div {
      text-align: center;
      font-size: 13px;
      color: #ccc;
    }
    .bottom-nav div.active {
      color: #64b5f6;
      font-weight: bold;
    }
    .bottom-nav i {
      display: block;
      font-size: 18px;
      margin-bottom: 4px;
    }
    a {
      text-decoration: none;
      color: inherit;
    }
  </style>
</head>
<body>
  <div class="header">
    <h1>BlackRock</h1>
    <div>🌐 English</div>
  </div>

  <!-- Profile Info with Picture -->
  <div class="profile-bar">
    <div>
      <div class="profile-left">Hi, <?php echo htmlspecialchars($phone); ?></div>
      <div class="profile-badge">Stable income</div>
    </div>
    <div class="profile-pic">
      <img src="bo.jpg" alt="Profile Picture"/>
    </div>
  </div>

  <!-- Balance Boxes -->
  <div class="balance-container">
    <div class="balance-box">
      Total Balance (ZMW):
      <strong><?php echo number_format($balance, 2); ?></strong>
    </div>
    <div class="balance-box">
      Total Income (ZMW):
      <strong><?php echo number_format($income, 2); ?></strong>
    </div>
  </div>

  <div class="menu">
    <div class="menu-item" onclick="window.location.href='recharge_records.php'">
      <i class="fas fa-receipt"></i><span>Financial Records</span><i class="fas fa-chevron-right"></i>
    </div>
    <div class="menu-item" onclick="window.location.href='recharge.php'">
      <i class="fas fa-university"></i><span>Recharge</span><i class="fas fa-chevron-right"></i>
    </div>
    <div class="menu-item" onclick="window.location.href='withdraw.php'">
      <i class="fas fa-wallet"></i><span>Withdraw</span><i class="fas fa-chevron-right"></i>
    </div>
    <div class="menu-item" onclick="window.location.href='earnings_table.html'">
      <i class="fas fa-chart-line"></i><span>Earnings</span><i class="fas fa-chevron-right"></i>
    </div>
    <div class="menu-item" onclick="window.location.href='change.php'">
      <i class="fas fa-key"></i><span>Change Password</span><i class="fas fa-chevron-right"></i>
    </div>
    <div class="menu-item" onclick="window.location.href='login.php'">
      <i class="fas fa-sign-out-alt"></i><span>Sign out</span><i class="fas fa-chevron-right"></i>
    </div>
  </div>

  <div class="bottom-nav">
    <a href="home.php"><div><i class="fas fa-home"></i>Home</div></a>
    <a href="task.php"><div><i class="fas fa-tasks"></i>Task</div></a>
    <a href="team.php"><div><i class="fas fa-users"></i>Team</div></a>
    <a href="vip.php"><div><i class="fas fa-crown"></i>VIP</div></a>
    <a href="me.php"><div class="active"><i class="fas fa-user"></i>Me</div></a>
  </div>
  
  <script>
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('service-worker.js')
        .then(function(registration) {
          console.log('ServiceWorker registered:', registration);
        })
        .catch(function(error) {
          console.log('ServiceWorker failed:', error);
        });
    }
  </script>
</body>
</html>
