<?php
/* ============================================================
   me.php
   EARNING DETAILS + BACKEND
============================================================ */

error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

session_start();

date_default_timezone_set('Africa/Nairobi');

require_once 'db.php';


/* ============================================================
   LOGIN CHECK
============================================================ */

$user_id = (int)($_SESSION['user_id'] ?? 0);

if ($user_id <= 0) {
    header("Location: login.php");
    exit;
}


/* ============================================================
   HELPER
============================================================ */

function money($amount)
{
    return 'TSH' . number_format((float)$amount, 3);
}


/* ============================================================
   GET USER
============================================================ */

$stmt = $conn->prepare("
    SELECT
        id,
        phone,
        password,
        balance,
        referral_code,
        referred_by,
        created_at
    FROM users
    WHERE id = ?
    LIMIT 1
");

$stmt->bind_param("i", $user_id);

$stmt->execute();

$result = $stmt->get_result();

$user = $result->fetch_assoc();

$stmt->close();


if (!$user) {

    session_destroy();

    header("Location: login.php");

    exit;
}


/* ============================================================
   BASIC USER DATA
============================================================ */

$phone = htmlspecialchars(
    $user['phone'] ?? '',
    ENT_QUOTES,
    'UTF-8'
);

$referral_code = htmlspecialchars(
    $user['referral_code'] ?? '',
    ENT_QUOTES,
    'UTF-8'
);

$balance = (float)($user['balance'] ?? 0);

$user_created_at =
    $user['created_at']
    ?? date('Y-m-d H:i:s');


/* ============================================================
   INVESTMENT / BADGE / VALIDITY
============================================================ */

$investment_level = 0;

$investment_created_at = null;

$has_investment = false;


$stmt = $conn->prepare("
    SELECT
        level,
        created_at
    FROM investments
    WHERE user_id = ?
    ORDER BY level DESC, created_at DESC
    LIMIT 1
");

$stmt->bind_param(
    "i",
    $user_id
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $investment_level =
        (int)$row['level'];

    $investment_created_at =
        $row['created_at'];

    $has_investment = true;
}

$stmt->close();


/* ============================================================
   BADGE
============================================================ */

if ($investment_level == 1) {

    $badge = 's1.png';

} elseif ($investment_level == 2) {

    $badge = 's2.png';

} elseif ($investment_level == 3) {

    $badge = 's3.png';

} else {

    $badge = 'badges0.png';
}


/* ============================================================
   VALIDITY
============================================================ */

if (
    $has_investment &&
    !empty($investment_created_at)
) {

    $validity_start = date(
        'Y-m-d',
        strtotime($investment_created_at)
    );

    $validity_end = date(
        'Y-m-d',
        strtotime(
            $investment_created_at . ' +360 days'
        )
    );

} else {

    $validity_start = date(
        'Y-m-d',
        strtotime($user_created_at)
    );

    $validity_end = date(
        'Y-m-d',
        strtotime(
            $user_created_at . ' +3 days'
        )
    );
}


$validity =
    $validity_start . '~' . $validity_end;


/* ============================================================
   TEAM SIZE
============================================================ */

$team_size = 0;

$stmt = $conn->prepare("
    SELECT COUNT(*) AS total
    FROM users
    WHERE referred_by = ?
       OR referred_by = ?
");

$user_id_string = (string)$user_id;

$stmt->bind_param(
    "ss",
    $referral_code,
    $user_id_string
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $team_size =
        (int)$row['total'];
}

$stmt->close();


/* ============================================================
   TODAY
============================================================ */

$today = date('Y-m-d');


/* ============================================================
   TODAY - TASK RECORDS
============================================================ */

$today_task_earnings = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(reward), 0) AS total
    FROM task_records
    WHERE user_id = ?
      AND LOWER(TRIM(status)) = 'completed'
      AND DATE(created_date) = ?
");

$stmt->bind_param(
    "is",
    $user_id,
    $today
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $today_task_earnings =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   TODAY - REFERRAL BONUSES
============================================================ */

$today_referral = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(bonus_amount), 0) AS total
    FROM referral_bonuses
    WHERE user_id = ?
      AND DATE(created_at) = ?
");

$stmt->bind_param(
    "is",
    $user_id,
    $today
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $today_referral =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   TODAY - TASK BONUSES
============================================================ */

$today_task_bonus = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(amount), 0) AS total
    FROM task_bonuses
    WHERE user_id = ?
      AND DATE(created_at) = ?
");

$stmt->bind_param(
    "is",
    $user_id,
    $today
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $today_task_bonus =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   TODAY - SPINS
============================================================ */

$today_spin = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(prize), 0) AS total
    FROM spins
    WHERE user_id = ?
      AND DATE(spin_time) = ?
");

$stmt->bind_param(
    "is",
    $user_id,
    $today
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $today_spin =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   TODAY TOTAL
============================================================ */

$today_earnings =
      $today_task_earnings
    + $today_referral
    + $today_task_bonus
    + $today_spin;


/* ============================================================
   TOTAL TASK REVENUE
============================================================ */

$total_task_revenue = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(reward), 0) AS total
    FROM task_records
    WHERE user_id = ?
      AND LOWER(TRIM(status)) = 'completed'
");

$stmt->bind_param(
    "i",
    $user_id
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $total_task_revenue =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   TOTAL REFERRAL REVENUE
============================================================ */

$total_referral_revenue = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(bonus_amount), 0) AS total
    FROM referral_bonuses
    WHERE user_id = ?
");

$stmt->bind_param(
    "i",
    $user_id
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $total_referral_revenue =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   TOTAL TASK BONUS REVENUE
============================================================ */

$total_task_bonus = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(amount), 0) AS total
    FROM task_bonuses
    WHERE user_id = ?
");

$stmt->bind_param(
    "i",
    $user_id
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $total_task_bonus =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   TOTAL SPIN REVENUE
============================================================ */

$total_spin_revenue = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(prize), 0) AS total
    FROM spins
    WHERE user_id = ?
");

$stmt->bind_param(
    "i",
    $user_id
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $total_spin_revenue =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   TOTAL REVENUE
============================================================ */

$total_revenue =
      $total_task_revenue
    + $total_referral_revenue
    + $total_task_bonus
    + $total_spin_revenue;


/* ============================================================
   ACCUMULATED DEPOSITS
============================================================ */

$accumulated_deposits = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(amount), 0) AS total
    FROM recharges
    WHERE user_id = ?
      AND LOWER(TRIM(status)) = 'success'
");

$stmt->bind_param(
    "i",
    $user_id
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $accumulated_deposits =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   CUMULATIVE WITHDRAWALS
============================================================ */

$cumulative_withdrawals = 0;

$stmt = $conn->prepare("
    SELECT
        COALESCE(SUM(amount), 0) AS total
    FROM withdrawals
    WHERE user_id = ?
      AND LOWER(TRIM(status)) = 'paid'
");

$stmt->bind_param(
    "i",
    $user_id
);

$stmt->execute();

$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {

    $cumulative_withdrawals =
        (float)$row['total'];
}

$stmt->close();


/* ============================================================
   DISPLAY DATA
============================================================ */

$display_balance =
    money($balance);

$display_today =
    money($today_earnings);

$display_total_revenue =
    money($total_revenue);

$display_deposits =
    money($accumulated_deposits);

$display_withdrawals =
    money($cumulative_withdrawals);

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

<meta charset="UTF-8">

<meta name="viewport"
      content="width=device-width,initial-scale=1">

<title>Earning Details</title>

<style>

*{
box-sizing:border-box;
margin:0;
padding:0
}

html,
body{
width:100%;
min-height:100%;
overflow-x:hidden
}

body{
font-family:Arial,sans-serif;
background:#fff;
color:#292929;
padding-bottom:75px
}


/* HEADER */

.hero{
height:235px;
color:#fff;
position:relative;
overflow:hidden;
background:linear-gradient(145deg,#11723b,#4f8e7f);
border-radius:0 0 45px 0
}

.hero:after{
content:"";
position:absolute;
bottom:0;
width:100%;
height:45px;
background:#fff;
clip-path:polygon(
0 15%,
72% 75%,
89% 100%,
0 100%
)
}

.account{
padding:35px 14px 0;
position:relative;
z-index:1
}

.profile{
display:grid;
grid-template-columns:65px minmax(0,1fr) 58px;
gap:8px
}

.avatar{
width:55px;
height:55px;
border:3px solid #fff;
border-radius:50%;
object-fit:cover
}

.info{
min-width:0
}

.phone{
font-size:22px;
font-weight:bold;
margin-bottom:8px
}

.line{
font-size:11px;
line-height:1.5;
white-space:nowrap;
overflow:hidden
}

.copy{
display:inline-block;
width:11px;
height:13px;
border:1px solid #fff;
margin-left:3px;
position:relative;
cursor:pointer
}

.copy:after{
content:"";
position:absolute;
width:8px;
height:10px;
border:1px solid #fff;
left:-4px;
top:-3px
}

.right{
text-align:center;
overflow:hidden
}

.icons{
display:flex;
justify-content:center;
gap:6px
}

.icon{
width:22px;
height:22px
}

.icon-link{
display:flex;
align-items:center;
justify-content:center;
text-decoration:none
}

.badge{
width:52px;
height:52px;
object-fit:contain;
margin:4px auto
}

.balances{
display:grid;
grid-template-columns:1fr 1fr;
text-align:center;
margin-top:27px
}

.amount{
font-size:20px;
font-weight:bold;
margin-bottom:7px
}

.label{
font-size:11px;
white-space:nowrap
}


/* CONTENT */

.content{
padding:20px 12px 35px
}

h1{
font-size:25px;
font-weight:500;
margin:0 0 20px 3px
}


/* EARNING GRID */

.grid{
display:grid;
grid-template-columns:1fr 1fr;
grid-template-rows:135px 72px 72px;
grid-template-areas:
"team today"
"team revenue"
"deposit withdraw";
gap:8px
}

.card{
position:relative;
min-width:0;
overflow:hidden;
background:#f8f8f8;
border-radius:13px;
color:#888
}

.team-card{
grid-area:team
}

.today-card{
grid-area:today
}

.revenue-card{
grid-area:revenue
}

.deposit-card{
grid-area:deposit
}

.withdraw-card{
grid-area:withdraw
}

.title{
position:relative;
z-index:2;
font-size:14px;
padding:14px 13px 0;
white-space:nowrap
}

.value{
position:relative;
z-index:2;
font-size:21px;
color:#11723b;
font-weight:bold;
padding:13px
}

.art{
position:absolute;
right:0;
bottom:0;
width:52%;
height:75%;
opacity:.7
}

.coin{
width:38px;
height:38px;
border-radius:50%;
background:#e8c96f;
position:absolute;
display:flex;
align-items:center;
justify-content:center;
color:#c89e43;
font-weight:bold
}


/* TEAM ART */

.team-art{
width:75%;
left:12%;
right:auto
}

.team-art .coin{
left:50%;
top:5%;
transform:translateX(-50%)
}

.people{
position:absolute;
left:8%;
right:8%;
bottom:8%;
height:45px;
border-bottom:5px solid #7eaaa0
}

.people:before,
.people:after{
content:"";
position:absolute;
bottom:0;
width:27px;
height:40px;
background:#e5a9c1;
border-radius:14px 14px 5px 5px
}

.people:before{
left:0
}

.people:after{
right:0
}

.people i{
position:absolute;
left:50%;
bottom:0;
transform:translateX(-50%);
width:31px;
height:32px;
background:#86c5dc;
border-radius:7px
}


/* OTHER ART */

.money .coin{
right:20%;
bottom:18%
}

.money:before,
.money:after{
content:"";
position:absolute;
width:22px;
height:65px;
border-radius:14px;
bottom:13%;
right:8%;
background:#8ed0df;
transform:rotate(25deg)
}

.money:after{
right:28%;
height:57px;
background:#e8b5c6
}

.revenue:before{
content:"";
position:absolute;
right:5%;
top:8%;
width:65px;
height:38px;
background:#c5e6e7
}

.revenue .coin{
right:15%;
bottom:13%
}

.deposit:before{
content:"";
position:absolute;
right:8%;
bottom:13%;
width:85px;
height:47px;
background:#b5d8e0;
border-radius:13px;
transform:rotate(-18deg)
}

.deposit .coin{
right:10%;
top:5%
}

.withdraw .coin{
right:20%;
bottom:18%
}

.withdraw:before{
content:"⌛";
position:absolute;
right:8%;
bottom:3%;
font-size:47px;
opacity:.5
}


/* BANNER */

.banner{
margin:25px auto 28px;
width:92%;
border-radius:25px;
overflow:hidden;
background:#eaf7fa
}

.banner img{
display:block;
width:100%;
height:auto
}


/* MENU */

.menu{
padding:0 7%;
margin-bottom:28px
}

.menu-item{
height:55px;
display:flex;
align-items:center;
position:relative;
text-decoration:none;
color:#292929
}

.menu-icon{
width:40px;
height:40px;
border-radius:20px;
display:flex;
align-items:center;
justify-content:center;
font-size:19px;
flex:none
}

.menu-text{
font-size:16px;
margin-left:32px
}

.arrow{
position:absolute;
right:0;
font-size:25px;
font-weight:200;
color:#999
}

.help{
background:#e9f7f5;
color:#66827f
}

.bill{
background:#fff4e9;
color:#dda47b
}

.tax{
background:#eaf4fb;
color:#7795aa
}

.credit{
background:#ecf9ed;
color:#79a57d
}

.share{
background:#fbeded;
color:#ad8c8c
}


/* DOWNLOAD */

.download{
height:60px;
margin:0 5% 80px;
border:1px solid #ddd;
border-radius:55px;
display:flex;
align-items:center;
justify-content:center;
font-size:20px;
font-weight:bold;
color:#3d9788;
text-decoration:none
}


/* BOTTOM NAV */

.bottom-nav{
position:fixed;
left:0;
right:0;
bottom:0;
height:64px;
background:#fff;
border-top:1px solid #eee;
display:grid;
grid-template-columns:repeat(5,1fr);
z-index:100
}

.nav{
display:flex;
flex-direction:column;
align-items:center;
justify-content:center;
gap:3px;
font-size:14px;
color:#333;
text-decoration:none;
position:relative
}

.nav svg{
width:30px;
height:30px
}

.nav.active{
color:#258fc5
}

.vip{
position:relative
}

.vip-circle{
position:absolute;
top:-40px;
width:68px;
height:68px;
border-radius:50%;
background:#087b63;
border:5px solid #fff;
display:flex;
align-items:center;
justify-content:center
}

.vip-diamond{
width:35px;
height:28px;
border:3px solid #fff;
clip-path:polygon(
15% 0,
85% 0,
100% 35%,
50% 100%,
0 35%
);
background:transparent
}

.vip span{
margin-top:30px
}


/* SMALL SCREEN */

@media(max-width:380px){

.hero{
height:315px;
border-radius:0 0 45px 0
}

.hero:after{
height:48px
}

.account{
padding:38px 11px 0
}

.profile{
grid-template-columns:65px minmax(0,1fr) 55px;
gap:8px
}

.avatar{
width:65px;
height:65px
}

.phone{
font-size:21px;
margin-bottom:8px
}

.line{
font-size:10px
}

.right{
width:55px
}

.icons{
gap:6px
}

.icon{
width:21px;
height:21px
}

.badge{
width:50px;
height:50px
}

.balances{
margin-top:28px
}

.amount{
font-size:20px;
margin-bottom:8px
}

.label{
font-size:11px
}

.content{
padding:21px 11px 30px
}

h1{
font-size:25px;
margin-bottom:22px
}

.grid{
grid-template-rows:185px 90px 90px;
gap:9px 8px
}

.title{
font-size:12px;
padding:12px 10px 0
}

.value{
font-size:21px;
padding:11px 10px
}

.coin{
width:34px;
height:34px
}

.people{
height:38px
}

.people:before,
.people:after{
width:23px;
height:34px
}

.people i{
width:27px;
height:28px
}

.withdraw:before{
font-size:40px
}


/* MOBILE MENU */

.banner{
width:90%;
margin:22px auto 20px;
border-radius:22px
}

.menu{
padding:0 8%;
margin-bottom:22px
}

.menu-item{
height:92px
}

.menu-icon{
width:72px;
height:72px;
border-radius:22px;
font-size:32px
}

.menu-text{
font-size:20px;
margin-left:24px
}

.arrow{
font-size:36px
}

.download{
height:82px;
margin:0 5% 75px;
font-size:22px
}

.bottom-nav{
height:65px
}

.nav{
font-size:10px
}

.nav svg{
width:25px;
height:25px
}

.vip-circle{
width:60px;
height:60px;
top:-38px
}

.vip-diamond{
width:31px;
height:25px
}

.vip span{
margin-top:25px
}

}

</style>

</head>

<body>


<!-- =========================================================
     ACCOUNT
========================================================= -->

<section class="hero">

<div class="account">

<div class="profile">


<img
    src="avatar.jpeg"
    class="avatar"
    alt="Avatar"
>


<div class="info">

<div class="phone">
<?= $phone ?>
</div>


<div class="line">

Invitation code:

<?= $referral_code ?>

<span
    class="copy"
    onclick="copyReferral()"
    title="Copy"
></span>

</div>


<div class="line">

Validity:

<?= htmlspecialchars(
    $validity,
    ENT_QUOTES,
    'UTF-8'
) ?>

</div>

</div>


<div class="right">

<div class="icons">


<!-- NOTIFICATION -->

<div class="icon-link">

<svg
    class="icon"
    viewBox="0 0 64 64"
    fill="none"
>

<path
    d="M16 48h32M21 43V29c0-9 5-15 11-15s11 6 11 15v14M15 43h34M28 53c1 3 7 3 8 0M32 8v5"
    stroke="white"
    stroke-width="5"
    stroke-linecap="round"
/>

</svg>

</div>


<!-- SETTINGS -->

<a
    href="settings.php"
    class="icon-link"
    aria-label="Settings"
>

<svg
    class="icon"
    viewBox="0 0 64 64"
    fill="none"
>

<path
    d="M26 7h12l3 8c2 1 3 2 5 3l7-3 6 10-5 6a22 22 0 0 1 0 7l5 6-6 10-7-3c-2 1-3 2-5 3l-3 8H26l-3-8c-2-1-3-2-5-3l-7 3-6-10 5-6a22 22 0 0 1 0-7l-5-6 6-10 7 3c2-1 3-2 5-3l3-8z"
    stroke="white"
    stroke-width="4"
/>

<circle
    cx="32"
    cy="34"
    r="8"
    stroke="white"
    stroke-width="4"
/>

</svg>

</a>

</div>


<!-- BADGE -->

<img
    src="<?= htmlspecialchars(
        $badge,
        ENT_QUOTES,
        'UTF-8'
    ) ?>"
    class="badge"
    alt="S<?= $investment_level ?> Badge"
>

</div>

</div>


<!-- BALANCES -->

<div class="balances">


<div>

<div class="amount">

<?= $display_balance ?>

</div>

<div class="label">

Account Balance

</div>

</div>


<div>

<div class="amount">

<?= $display_total_revenue ?>

</div>

<div class="label">

Total fund performance

</div>

</div>


</div>

</div>

</section>


<!-- =========================================================
     EARNING DETAILS
========================================================= -->

<main class="content">

<h1>
Earning Details
</h1>


<div class="grid">


<!-- TEAM -->

<div class="card team-card">

<div class="title">
Team size
</div>

<div class="value">
<?= number_format($team_size) ?>
</div>

<div class="art team-art">

<div class="coin">
₤
</div>

<div class="people">
<i></i>
</div>

</div>

</div>


<!-- TODAY -->

<div class="card today-card">

<div class="title">
Today earnings
</div>

<div class="value">
<?= $display_today ?>
</div>

<div class="art money">

<div class="coin"></div>

</div>

</div>


<!-- REVENUE -->

<div class="card revenue-card">

<div class="title">
Total Revenue
</div>

<div class="value">
<?= $display_total_revenue ?>
</div>

<div class="art revenue">

<div class="coin"></div>

</div>

</div>


<!-- DEPOSITS -->

<div class="card deposit-card">

<div class="title">
Accumulated deposits
</div>

<div class="value">
<?= $display_deposits ?>
</div>

<div class="art deposit">

<div class="coin"></div>

</div>

</div>


<!-- WITHDRAWALS -->

<div class="card withdraw-card">

<div class="title">
Cumulative withdrawals
</div>

<div class="value">
<?= $display_withdrawals ?>
</div>

<div class="art withdraw">

<div class="coin"></div>

</div>

</div>

</div>


<!-- =========================================================
     BANNER
========================================================= -->

<div class="banner">

<img
    src="bannern.jpeg"
    alt="Banner"
>

</div>


<!-- =========================================================
     MENU
========================================================= -->

<div class="menu">


<a
    href="help.php"
    class="menu-item"
>

<div class="menu-icon help">
?
</div>

<div class="menu-text">
Help Manual
</div>

<div class="arrow">
›
</div>

</a>


<a
    href="daily.php"
    class="menu-item"
>

<div class="menu-icon bill">
▤
</div>

<div class="menu-text">
Daily bills
</div>

<div class="arrow">
›
</div>

</a>


<a
    href="#"
    class="menu-item"
>

<div class="menu-icon tax">
$
</div>

<div class="menu-text">
Tax records
</div>

<div class="arrow">
›
</div>

</a>


<a
    href="points.php"
    class="menu-item"
>

<div class="menu-icon credit">
☆
</div>

<div class="menu-text">
Credit score
</div>

<div class="arrow">
›
</div>

</a>


<a
    href="invite.php"
    class="menu-item"
>

<div class="menu-icon share">
♧
</div>

<div class="menu-text">
Share with friends
</div>

<div class="arrow">
›
</div>

</a>


</div>


<!-- =========================================================
     DOWNLOAD
========================================================= -->

<a
    href="#"
    class="download"
>
Download the App
</a>


</main>


<!-- =========================================================
     BOTTOM NAVIGATION
========================================================= -->

<nav class="bottom-nav">


<a
    href="home.php"
    class="nav"
>

<svg
    viewBox="0 0 40 40"
    fill="none"
>

<path
    d="M5 19L20 5l15 14"
    stroke="currentColor"
    stroke-width="2.5"
/>

<path
    d="M9 18v15h8V23h6v10h8V18"
    stroke="currentColor"
    stroke-width="2.5"
/>

</svg>

<span>
Home
</span>

</a>


<a
    href="promotion.php"
    class="nav"
>

<svg
    viewBox="0 0 40 40"
    fill="none"
>

<circle
    cx="20"
    cy="20"
    r="14"
    stroke="currentColor"
    stroke-width="2.5"
/>

<path
    d="M20 17v9M20 12h.01"
    stroke="currentColor"
    stroke-width="3"
    stroke-linecap="round"
/>

</svg>

<span>
Promotion
</span>

</a>


<a
    href="vip.php"
    class="nav vip"
>

<div class="vip-circle">

<div class="vip-diamond"></div>

</div>

<span>
VIP
</span>

</a>


<a
    href="invite.php"
    class="nav"
>

<svg
    viewBox="0 0 40 40"
    fill="none"
>

<circle
    cx="20"
    cy="11"
    r="4"
    stroke="currentColor"
    stroke-width="2"
/>

<circle
    cx="10"
    cy="25"
    r="4"
    stroke="currentColor"
    stroke-width="2"
/>

<circle
    cx="30"
    cy="25"
    r="4"
    stroke="currentColor"
    stroke-width="2"
/>

<path
    d="M17 13l-5 8M23 13l5 8M14 25h12"
    stroke="currentColor"
    stroke-width="2"
/>

</svg>

<span>
Invite
</span>

</a>


<a
    href="me.php"
    class="nav active"
>

<svg
    viewBox="0 0 40 40"
    fill="none"
>

<circle
    cx="20"
    cy="11"
    r="5"
    stroke="currentColor"
    stroke-width="2.5"
/>

<path
    d="M9 34c1-7 5-11 11-11s10 4 11 11"
    stroke="currentColor"
    stroke-width="2.5"
/>

</svg>

<span>
My
</span>

</a>


</nav>


<!-- =========================================================
     COPY REFERRAL CODE
========================================================= -->

<script>

function copyReferral(){

    const code =
        <?= json_encode(
            $user['referral_code'] ?? ''
        ) ?>;


    if(!code){

        return;

    }


    if(navigator.clipboard){

        navigator.clipboard
            .writeText(code)
            .catch(function(){});

    }else{

        const input =
            document.createElement("input");

        input.value = code;

        document.body.appendChild(input);

        input.select();

        try{

            document.execCommand("copy");

        }catch(e){}

        document.body.removeChild(input);

    }

}

</script>


</body>
</html>