<?php
session_start();
@$userKey = $_SESSION['loginKey'];

if($userKey == "")
{
    echo "<script>window.open('login.php','_self')</script>";
}


include "control/activity.php";
$dd = new activity();


$table = "userdetails";
$condition = " where userKey='$userKey'";
$getuserdetails = $dd->single($table,$condition);
$myRefral = $getuserdetails['my_refral_id'];
$refAmount = $getuserdetails['refAmount'];


$condition = " where refral_from='$myRefral'";
$getRefraldetails = $dd->fetch_multi($table,$condition);
$totalRefer = count($getRefraldetails);
foreach($getRefraldetails as $key)
{
    @$teamtotalRecharge += $key->tdeposit;
    
    @$teamTotalBey += $key->totalBet;
}

if(@$teamTotalBey == "")
{
    $teamTotalBey = 0;
}

if(@$teamtotalRecharge == "")
{
    $teamtotalRecharge = 0;
}


$table = "account_history";
$condition = " where userKey='$userKey' AND game_name like '%bet%'";
$getAcHistory = $dd->fetch_multi($table,$condition);
foreach($getAcHistory as $key)
{
        @$totalBetCommission += $key->amount;
}

 $table= "admin_calculation";
 $condition = null;
 $getAdminDetails = $dd->single($table,$condition);
 $telegram = $getAdminDetails['telegram'];
 $fevicon = $getAdminDetails['favicon'];

if(@$totalBetCommission == "")
{
    $totalBetCommission = 0;
}


if(@$totalRechargeCommission == "")
{
    $totalRechargeCommission = 0;
}


?>



<!DOCTYPE html>
<html lang="en" translate="no">
<head>
    <meta charset="UTF-8">
    <link rel="icon" type="image/svg+xml" href="temp_img/<?= $fevicon; ?>">
    <meta name="google" content="notranslate">
    <meta name="robots" content="noindex,nofollow">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title><?= $getAdminDetails['title'];?></title>
    <link rel="stylesheet" href="css/slick.css" />
    <link rel="stylesheet" href="css/modules.css" />
    <link rel="stylesheet" href="css/style.css" />
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="js/slick.min.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
</head>
<body>
    <div id="app">
        <!--NavBar-->
        <div class="navbar">
            <div class="navbar-fixed" style="background: linear-gradient(90deg, rgb(207, 3, 5) 0%, rgb(242, 63, 58) 100%);">
                <div class="navbar__content">
                    <div data-v-905dfe8c="" class="navbar__content-left" onclick="clicktoBack()"><div data-v-905dfe8c="" class="backIcon"></div></div>
                    <div data-v-905dfe8c="" class="navbar__content-center"><div data-v-905dfe8c="" class="navbar__content-title"> Overview </div></div>
                    <div class="navbar__content-right">
                        <div data-v-7c8bbbf4="" data-v-106b99c8="" class="c-row">
                            <i data-v-7c8bbbf4="" data-v-106b99c8="" class="van-icon van-icon-notes-o" style="font-size: 25px;"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--NavBar-->

        <!--promotion-->
        <div class="promotion">
            <div class="tab">
                <ul class="c-row c-row-between">
                <li data-v-7c8bbbf4="" onclick="location.href='promotion.php'" class="action block-click">Overview</li>
                    <li data-v-7c8bbbf4="" onclick="location.href='myTeam.php'">My Team</li>
                    <!--<li data-v-7c8bbbf4="" onclick="location.href='promotionDes.php'">Receipt history</li>-->
                    <li data-v-7c8bbbf4="" onclick="location.href='tutorial.php'">Tutorial</li>
                </ul>
            </div>
            <div class="box">
                <div data-v-7c8bbbf4="" class="tit">Guide</div>
                <div class="info">
                    <div class="info-data c-row c-row-between m-b-20">
                        <div class="left">
                            <h5 class="all">Total Team Members</h5>
                            <p data-v-7c8bbbf4="" class="num" id="total_sub"><?= $totalRefer; ?></p>
                            <p data-v-7c8bbbf4="" class="txt" id="total_rech">Team total recharge: <?= round($teamtotalRecharge,2); ?></p>
                            <p data-v-7c8bbbf4="" class="txt" id="today_rech">Team Recharge commision: <?= round($refAmount,2); ?></p>
                        </div>
                        <div class="right" style="height: 60%;">
                            <p data-v-7c8bbbf4="" class="txt">Team total Betting:<br><span data-v-7c8bbbf4="" class="num" id="total_with"><?= round($teamTotalBey,2); ?></span></p>
                            <br><br>
                            <p data-v-7c8bbbf4="" class="txt" roses_f="">Team Betting Commision:<br><span data-v-7c8bbbf4="" class="num" id="today_with"><?= round($totalBetCommission,2); ?></span></p>
                        </div>
                    </div>
<?php
 $server = $_SERVER['SERVER_NAME'];
?>
                    <div class="info-img c-row c-row-between">
                        <div class="img">
                            <div id="qrcode">
                                <img alt="Scan me!" src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=<?= urlencode("https://$server/register.php?refral=$myRefral"); ?>" style="display: block;">
                            </div>
                            <div data-v-7c8bbbf4="" class="c-tc">Long press to save QR code</div>
                        </div>
                        <div class="btn-list c-row c-row-middle-center">
                            <div class="btn-box">
<?php
  $refralLink = "https://$server/register.php?refral=$myRefral";
?>
                            <div class="copy_btn myRefralt">
                                <input type="text" class="myRefral-text" value="<?= $myRefral; ?>" />
                                <button>Copy Referral Code</button>
                            </div>
                            <div class="copy_btn refralLink">
                                <input type="text" class="refralLink-text" value="<?= $refralLink; ?>" />
                                <button>Copy Link</button>
                            </div>
                                <!--div data-v-7c8bbbf4="" onclick="getTolinkCopy('<?= $myRefral; ?>')" class="btn m-b-10 c-row c-row-middle-center tag-read" data-clipboard-text="6fGGw42409">Copy Referral Code</div>
                                <div data-v-7c8bbbf4="" onclick="getToCopyLink('<?= $refralLink; ?>')" data-clipboard-text="demodamann.up.railway.app/register?r_code=6fGGw42409 " class="btn m-b-10 c-row c-row-middle-center tag-read">Copy Link</div-->
                           
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <!--promotion-->
             <?php include "footer.php"; ?>
    </div>
</body>

</html>

<script>
  function getTolinkCopy(a)
  {
    navigator.clipboard.writeText(a);
    alert("Copied the text: " + a);
  }



  function getToCopyLink(a)
  {
    navigator.clipboard.writeText(a);
    alert("Copied the text: " + a);
  }



// myRefralt
let myRefralt = document.querySelector(".myRefralt");
myRefralt.querySelector("button").addEventListener("click", function () {
	let input = myRefralt.querySelector(".myRefral-text");
	input.select();
	document.execCommand("copy");
	myRefralt.classList.add("active");
	window.getSelection().removeAllRanges();
	setTimeout(function () {
		myRefralt.classList.remove("active");
	}, 2500);
});

// Copy Link
let refralLink = document.querySelector(".refralLink");
refralLink.querySelector("button").addEventListener("click", function () {
	let input = refralLink.querySelector(".refralLink-text");
	input.select();
	document.execCommand("copy");
	refralLink.classList.add("active");
	window.getSelection().removeAllRanges();
	setTimeout(function () {
		refralLink.classList.remove("active");
	}, 2500);
});
</script>