<!doctype html>
<html lang="en"  class="w-[640px]">
   <head>
   <?php echo view('user/layout/head');?>
   </head>
   <style>
       .swal2-title {
         font-size: 15px; 
         }
         .swal2-html-container p {
         font-size: 13px !important; /* Adjust the font size for the content text */
         white-space: pre-line; /* Display text content line by line */
         line-height:15px !important;
         }
         .custom-list-item {
         position: relative;
         list-style: none;
         }
         .custom-list-item::before {
         content: '•';
         font-weight: bold;
         position: absolute;
         left: -20px; /* Adjust as needed */
         top: 50%; /* Adjust as needed */
         transform: translateY(-50%);
         font-size: 1.5em; /* Adjust as needed */
         }
         .icon-top-notify {
         position: absolute;
         left: -40px; /* Adjust as needed */
         top: 0;
         font-size: 1.5em; /* Adjust as needed */
         }
         .statistic-link
         {
            height:auto !important;
            padding:20px 3px !important;
            background: rgb(3,2,57) !important;
            background: linear-gradient(151deg, rgba(3,2,57,1) 0%, rgba(54,53,96,1) 35%) !important;
         }
         .statistic-link li {

	margin: 13px 32px;
	/* width: 85px; */
}
@media only screen and (max-width:432px) {
    .statistic-link
    {
        margin-bottom:25px !important;
        margin-top:10px !important;
        

    }
    .statistic-link li {
	margin: 12px 31px;
	width: 95px;
}
    .hidden
    {
        display:none !important;
    }
    .icon_width
    {
        width:40px !important;
    }
    .stastic-icon {

	padding: 16px 0px;

	width: 75px;
	height: 75px;
	text-align: center;
}
.dash-bg
{
    height:78vh !important;
}
      }
/*@media only screen and (max-width:424px) {*/
/*    .statistic-link*/
/*    {*/
/*        margin-bottom:25px !important;*/
/*        margin-top:10px !important;*/
        

/*    }*/
/*    .hidden*/
/*    {*/
/*        display:none !important;*/
/*    }*/

/*      }*/
   </style>
   <body class="section-overflow">
   <?php 
         $this->db = db_connect();
         $this->session = session();
         $this->common_model = model('CommonModel');
         $uusersid = $this->session->get('uusersid');
         $exchange_id = $this->session->get('exchange');
         
         
         if($exchange_id=='')
         {
            $array = array(
               "exchange" => '1'
            );
            $this->session->set($array);
         }
         function formatTradingPair($pair) 
         {
            $base = substr($pair, 0, -4);  // Extract the base currency (all but the last 4 characters)
            $quote = substr($pair, -4);    // Extract the quote currency (last 4 characters)
            return strtoupper($base) . '/' . strtoupper($quote); // Combine and convert to lowercase
          }

         $users_details = $this->db->query("SELECT * FROM uusers WHERE uusersid='".$uusersid."'")->getRow();

         $condition = array (
            'uusersid' => $uusersid,
            'type' => 'activation',
            'status' => '1',
            );
            $time = $this->db->table('history')->where($condition)->orderby('historyid','desc')->get()->getRow();
            
            if($time)
            {
               $datee = $time->expiry_date;
            }
            else
            {
               $datee = '';
            }

            function formatName($name) {
               $length = strlen($name);
               if ($length <= 4) {
                   // If the string is too short, return as is or handle as per your needs
                   return str_repeat('*', $length);
               }
               
               // Extract the first 2 characters and the last 2 characters
               $firstTwo = substr($name, 0, 2);
               $lastTwo = substr($name, -2);
               
               // Replace the middle part with asterisks
               $middleAsterisks = str_repeat('*', $length - 4);
           
               // Combine and return the formatted string
               return $firstTwo . $middleAsterisks . $lastTwo;
           }
         ?>
      <!--banner start -->
      <section class="banner-bg  dash-bg position-relative">
         <div class="added-dash-bg">
            <img src="<?php echo base_url();?>/assets/images/banner-number.png" alt="">
         </div>
         <div class="container">
            <!-- common-header start-->
            <header class="pt-3 pb-3">
               <div class="row">
                  <div class="col-6">
                     <div class="user-name">
                        <a href="" class="text-decoration-none" >
                           <h5 class="aleo text-white">Welcome <?php echo $users_details->username;?></h5>
                        </a>
                     </div>
                  </div>
                  <div class="col-6">
                     <div class="common-icon d-flex align-items-center justify-content-end">
                     <!-- <div class="dropdown">
                              <button onclick="myFunction()" class="dropbtn dropdown-toggle">
                                 <?php
                                 $image='';
                                 if($exchange_id=='1')
                                    $image="binance.svg";
                                 else if($exchange_id=='7')
                                    $image="kucoin.png"; 
                                 else if($exchange_id=='5')
                                 $image="bybit.svg"; 
                                 ?>
                                <img src="<?php echo base_url();?>/styles/web_style/images/<?php echo $image;?>" class="api_logo">
                              </button>
                              <div id="myDropdown" class="dropdown-content">

                              <?php 
                              foreach($exchange_list as $row)
                              { ?>
                                 <a href="javascript:void(0);" onclick="change(<?php echo $row->id;?>)"><img src="<?php echo base_url();?>/styles/web_style/images/<?php echo $row->image;?>" width="50px"> &nbsp;<?php echo $row->coin;?></a>

                                 <?php } ?>
                                
                              </div>
                           </div> -->
                           <!-- <div class=" form-block position-relative mb-3 mt-3">
                           <label for="" class="form-label text-white"></label> -->
                           <!--<select class="form-control ps-2 form-arrow" style="margin-right:10px !important;width:40% !important;height:40px !important" onchange="change(<?php echo $row->id;?>)">
                           <?php 
                              foreach($exchange_list as $row)
                              { ?>

                                 <option value=""><?php echo $row->coin;?></option>

                                

                                 <?php } ?>
                           </select>
                        <!-- </div> -->
                        <div class="wallet-icon header-icon me-2">
                           <a href="<?php echo base_url();?>/user/asset" class="text-decoration-none ">
                              <iconify-icon icon="ph:wallet-bold"></iconify-icon>
                           </a>
                        </div>
                       
                        <div class="header-icon">
                           <a href="<?php echo base_url();?>/news" class="text-decoration-none">
                              <iconify-icon icon="mdi:notifications-none"></iconify-icon>
                           </a>
                        </div>
                     </div>
                  </div>
               </div>
            </header>
         </div>
         <!-- wrapper-content start -->
         <section class="dash-wrap account-wrap">
            <div class="container">
               <div class="row">
                  <div class="col-12">
                     <div class="dash-heading mt-3 mb-4">
                        <div class="news d-flex align-items-center">
                           <div class="news-ico me-1">
                              <iconify-icon icon="mdi:announcement"></iconify-icon>
                           </div>
                           <div class="news-content">
                              <marquee behavior="" direction="" class="text-white">Trade Pilot automates trades seamlessly, capitalizing on market uptrends for consistent profit opportunities.</marquee>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
               <div class="dash-banner">
                  <div class="row">
                     <div class="col-6">
                        <div class="dash-banner-content pt-4">
                           <h3 class="fw-bold text-white">Hello,</h3>
                           <h5 class="text-white"> Welcome</h5>
                           <h3 class="text-white aleo main-name">Trade Pilot (Binance)</h3>
                        </div>
                     </div>
                     <div class="col-6">
                        <div class="dash-img">
                           <img src="<?php echo base_url();?>/assets/images/dash-img.png" alt="">
                        </div>
                     </div>
                     
                  </div>
                  
               </div>
               <!--banner end -->
               <!--statistic start -->
               <div class="row">
                   
                  <div class="col-12">
                     <ul class="statistic-link mb-0 list-unstyled">
                         
                        <a href="<?php echo base_url();?>/apikeylist" class="hidden">
                           <li>
                              <div class="stastic-icon">
                                 <img src="<?php echo base_url();?>/assets/images/static-ico1.png" alt="">
                              </div>
                              <div class="static-content">
                                 <h6 class="mb-0 mt-2 text-white fw-semibold">API Binding</h6>
                              </div>
                           </li>
                        </a>

                        <a href="<?php echo base_url();?>/revenue">
                        <li>
                           <div class="stastic-icon">
                              <img src="<?php echo base_url();?>/assets/images/static-ico2.png" alt="">
                           </div>
                           <div class="static-content">
                              <h6 class="mb-0 mt-2 text-white fw-semibold">Billing Details</h6>
                           </div>
                        </li>
                        </a>
                        
                        <a href="<?php echo base_url();?>/trade_orders">
                        <li>
                           <div class="stastic-icon">
                              <iconify-icon width="33" height="33"  icon="gravity-ui:files"></iconify-icon> 
                           </div>
                           <div class="static-content">
                              <h6 class="mb-0 mt-2 text-white fw-semibold">Trading Records</h6>
                           </div>
                        </li>
                      </a>

                        <a href="<?php echo base_url();?>/revenue?tab=revenue_details">
                        <li>
                           <div class="stastic-icon">
                              <img src="<?php echo base_url();?>/assets/images/static-ico4.png" alt="">
                           </div>
                           <div class="static-content">
                              <h6 class="mb-0 mt-2 text-white fw-semibold">Revenue Details</h6>
                           </div>
                        </li>
                      </a>

                        <a href="<?php echo base_url();?>/user/asset" class="hidden">
                           <li>
                              <div class="stastic-icon">
                                 <img src="<?php echo base_url();?>/assets/images/static-ico3.png" alt="">
                              </div>
                              <div class="static-content">
                                 <h6 class="mb-0 mt-2 text-white fw-semibold">Assets</h6>
                              </div>
                           </li>
                        </a>
                        

                      <a href="<?php echo base_url();?>/rewardhistory" class="hidden">
                        <li>
                           <div class="stastic-icon">
                           <iconify-icon icon="fluent:notepad-edit-16-regular" width="36" height="33"></iconify-icon>
                           </div>
                           <div class="static-content">
                              <h6 class="mb-0 mt-2 text-white fw-semibold">Reward details</h6>
                           </div>
                        </li>
                      </a>
                    
                      <a href="<?php echo base_url();?>/revenue?tab=alltransaction">
                        <li>
                           <div class="stastic-icon">
                           <iconify-icon  height="33" width="33" icon="hugeicons:mentoring"></iconify-icon>
                              <!--<img src="<?php echo base_url();?>/assets/images/static-ico6.png" alt="">-->
                           </div>
                           <div class="static-content">
                              <h6 class="mb-0 mt-2 text-white fw-semibold">All Transactions</h6>
                           </div>
                        </li>
                      </a>
                      <a href="<?php echo base_url();?>/user/profile" class="hidden">
                        <li>
                           <div class="stastic-icon">
                           <iconify-icon icon="hugeicons:menu-square"  width="36" height="33"></iconify-icon>
                           </div>
                           <div class="static-content">
                              <h6 class="mb-0 mt-2 text-white fw-semibold">More details</h6>
                           </div>
                        </li>
                      </a>
                     </ul>
                     
                  </div>
                  
               </div>
               <!--statistic end -->

               <?php 
               $today_profit='0';
               $total_profit='0';
               $total_asset=0;
               $CommonModel = model('CommonModel');
               $gas_wallet=gas_wallet_bal($uusersid);
               
                
               
               
               if($exchange_id=='1')
               {
                   $exchange_name='Binance';
                 $get_api_bind=$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$uusersid."' and type='1'")->getRow();
                   if($get_api_bind)
                   {
                      
                      $key = $get_api_bind->api_key;
                      $secret = $get_api_bind->secret_key;
                      /*$api = new Binance\API($key,$secret);
                      
                      $ticker='';
                      $balances = $api->balances($ticker);*/
                      $balances=binance_balance($key,$secret);
                     if($balances)
                     {
                         $total_asset = $balances;
                     }
                     else
                        $total_asset='0';
               
                   }
                   else
                   {
                      //$key = "XgTJQ5j5IwABkQvRJdxYYLubL5fqo4wt12VCnLBBhQC9MmnfQs8XqXpun7ECmfzH";
                      //$secret = "VdVMJL6yfIgvrh8hOBojfV2E5NQpCQw3SvsptvZzayZKeRzrhzokhgLycRHPJD0S";
               
                      //$api = new Binance\API($key,$secret);
                      $total_asset=0;
                   }
               }
               else if($exchange_id=="5")
               {
                 $exchange_name="Bybit";
                 $total_asset=0;
                 $get_api_bind=$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$uusersid."' and type='5'")->getRow();
                 if($get_api_bind)
                 {
                   $key = $get_api_bind->api_key;
                   $secret = $get_api_bind->secret_key;
                   $account = $get_api_bind->account;
                   $acc_type = $account == 1 ? 'CONTRACT' : 'UNIFIED';
                   $bybitApi = new App\Libraries\BybitApi($key, $secret);
                  
                   $total_asset = $bybitApi->getBalance('USDT',$acc_type);
                   
                 }
               
               }
                $buy_bal=curbalance($uusersid);
                  $profit=$CommonModel->total_profit($uusersid,$exchange_id);
                  $bal=str_replace(",","", $buy_bal);
                  $today_earnings=$CommonModel->today_profit($uusersid,$exchange_id);
               ?>

               
               <!--trade start -->
               <div class="row">
                  <div class="col-12">
                     <div class="trade-scroller">
                        <ul class="mb-0 list-unstyled trading text-center  overflow-auto">
                        <?php 
                           $get_pairs=$this->db->query("select * from tradepair_list where status='1'")->getResult();
                           
                           $required_pairs=array();
                           if($get_pairs)
                           {
                              foreach($get_pairs as $get_pairs)
                              {
                                 $required_pairs[]=$get_pairs->pair_name;
                              }
                           }
                           
                           if($exchange_id=='1')
                           {
                                 $i=0;
                                 //$data_binance = json_decode(@file_get_contents('https://trade.apfm.io/trading_pairs.json'), true);
                                 $data_binance=getpairs($exchange_id);
                                 
                                 if($data_binance) 
                                 {
                                       foreach($required_pairs as $pair) 
                                       {
                                             $symbol_find = $pair . 'USDT';
                                             foreach($data_binance as $data) 
                                             {
                                                if($data['symbol'] == $symbol_find) 
                                                {
                                                         $output[$i]['symbol'] = $data['symbol'];
                                                      $output[$i]['price'] = $data['lastPrice'];
                                                      $output[$i]['change'] = $data['priceChangePercentage'];
                                                   $i++;        
                                                }
                                                
                                                
                                             }
                                       }
                                 }
                           }
                           else
                           {
                                 $get_api_bind=$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$uusersid."' and type='5'")->getRow();
                                 if($get_api_bind)
                                 {
                                 $key = $get_api_bind->api_key;
                                    $secret = $get_api_bind->secret_key;
                                 }
                                 else
                                 {
                                    $key='of3MneVy7FCSAvxAXl';
                                    $secret='VpcyfXxVZyBwQZqJ3D3SNonEoPGDgLaav8vN';
                                 }
                           
                                 $bybitApi = new App\Libraries\BybitApi($key, $secret);
                                 $lists = $bybitApi->ticker(['category' => 'linear', 'baseCoin' => 'USDT']); 
                                 $output=[];
                                 $b=0;
                                 if($lists){
                                    foreach ($lists as  $value) {
                                    if(substr($value['symbol'], -4) == "USDT"){
                                       if(in_array(substr_replace($value['symbol'] ,"",-4), $required_pairs)){
                                          $output[$b]['symbol'] = $value['symbol'];
                                          $output[$b]['price'] = $value['lastPrice'];
                                          $output[$b]['change'] = $value['price24hPcnt'];
                           
                                          $b++; 
                                       } 
                                    
                                    }
                                 }
                              }
                                 
                           }
                           
                           
                           $k = 0;
                           if($output)
                           {
                           foreach ($output as $key => $value) {
                              $output[$k] = $value;
                              $k++;
                           }
                           $output =  array_unique($output,SORT_REGULAR);
                           }
                           
                           $sno=0;
                           if($output)
                           {
                           foreach ($output as $key => $value) 
                           {
                              $symbol = formatTradingPair($value['symbol']);
                           
                              if($value['change'] > 0)
                              {
                                 $class = "change-success";
                                 $change = $value['change'];
                                 $arrow='fa fa-plus';
                              }
                              else
                              {
                                 $class = 'change-danger';
                                 $change = $value['change'];
                                 $arrow='fa fa-minus';
                           
                              }
                              $price_class='';
                              $sno++;
                           
                           ?>  <a href="<?php echo base_url('tradedetails/'.$value['symbol']);?>">    
                              <li>
                                 <div class="earning d-flex align-items-center text-white">
                                    <div class="earn-icon">
                                       <img style="width:48px;height:51px" src="<?php echo base_url('styles/images/tradingpair_images/'.$value['symbol'].'.png');?>" alt="">
                                    </div>
                                    <div class="earn-content earn-content-one ms-2">
                                       <h6 class="text-white fw-semibold mb-0 fs-5"><?php echo $symbol;?></h6>
                                       <span class="text-primary fs-5 fw-bold"><?php echo $change;?> </span>
                                    </div>
                                 </div>
                                 <div class="added-earning">
                                    <h5 class="text-white mb-0 fw-semibold lato "> <?php echo number_format($value['price'],6);?></h5>
                                    <!--<small class=" fw-bold">//MYR 3597,596.09</small>-->
                                 </div>
                              </li>
                           </a>
                           <?php 
                           }
                           }
                           ?>
                           <!-- <li>
                              <div class="earning d-flex align-items-center text-white">
                                 <div class="earn-icon">
                                    <img src="<?php echo base_url();?>/assets/images/trade-coin2.png" alt="">
                                 </div>
                                 <div class="earn-content earn-content-one ms-2">
                                    <h6 class="text-white fw-semibold mb-0 fs-5">BTC/USDT</h6>
                                    <span class="text-primary fs-5 fw-bold"> +0.30% </span>
                                 </div>
                              </div>
                              <div class="added-earning">
                                 <h5 class="text-white mb-0 fw-semibold lato "> 81,956.32</h5>
                                 <small class=" fw-bold">//MYR 3597,596.09</small>
                              </div>
                           </li>
                           <li>
                              <div class="earning d-flex align-items-center text-white">
                                 <div class="earn-icon">
                                    <img src="<?php echo base_url();?>/assets/images/trade-coin1.png" alt="">
                                 </div>
                                 <div class="earn-content earn-content-one ms-2">
                                    <h6 class="text-white fw-semibold mb-0 fs-5">BTC/USDT</h6>
                                    <span class="text-primary fs-5 fw-bold"> +0.30% </span>
                                 </div>
                              </div>
                              <div class="added-earning">
                                 <h5 class="text-white mb-0 fw-semibold lato "> 81,956.32</h5>
                                 <small class=" fw-bold">//MYR 3597,596.09</small>
                              </div>
                           </li>
                           <li>
                              <div class="earning d-flex align-items-center text-white">
                                 <div class="earn-icon">
                                    <img src="<?php echo base_url();?>/assets/images/trade-coin2.png" alt="">
                                 </div>
                                 <div class="earn-content earn-content-one ms-2">
                                    <h6 class="text-white fw-semibold mb-0 fs-5">BTC/USDT</h6>
                                    <span class="text-primary fs-5 fw-bold"> +0.30% </span>
                                 </div>
                              </div>
                              <div class="added-earning">
                                 <h5 class="text-white mb-0 fw-semibold lato "> 81,956.32</h5>
                                 <small class=" fw-bold">//MYR 3597,596.09</small>
                              </div>
                           </li> -->
                        </ul>
                     </div>
                  </div>
               </div>
               <!--trade end -->
               <!--profit start -->
               <div class="row">
                  <div class="col-12">
                     <div class="profit text-center my-4">
                        <small class="mb-0 text-white fs-5"> Total Profit (USDT)</small>
                        <h2 class="my-2 text-primary fw-bold"><?php echo number_format($profit,2);?></h2>
                        <p class="text-white mb-0 fs-5">Today’s Profit (USDT) <b><?php echo number_format($today_earnings,2);?></b></p>
                     </div>
                  </div>
               </div>
               <!--profit end -->
               <!--balance start -->
               <div class="balance-sec-list mt-3 text-center">
                  <div class="row">
                     <div class="col-6">
                        <div class="added-balance">
                           <div class="balance ">
                              <div class="bal-ico text-primary">
                                 <img src="<?php echo base_url();?>/assets/images/balance-ico1.png" alt="">
                              </div>
                              <h6 class="text-white mb-0 fs-5"><?php echo $exchange_name;?> Exchange (USDT)</h6>
                              <h4 class="text-primary mb-2 lato fw-semibold"><?php echo number_format($total_asset,2);?></h4>
                              <br>
                              <!--<div class="balance-button">
                                 <a href="<?php echo base_url();?>/asset/recharge" class="btn btn-outline-primary">Recharge</a>
                              </div>-->
                           </div>
                        </div>
                     </div>
                     <div class="col-6">
                        <div class="added-balance">
                           <div class="balance ">
                              <div class="bal-ico text-primary">
                                 <img src="<?php echo base_url();?>/assets/images/balance-ico1.png" alt="">
                              </div>
                              <h6 class="text-white mb-0 fs-5">Trade Pilot Income</h6>
                              <h4 class="text-primary mb-2 lato fw-semibold"><?php echo number_format($bal,2);?></h4>
                              <br>
                              <!--<div class="balance-button">
                                 <a href="<?php echo base_url();?>/activate/account" class="btn btn-outline-primary">extend now</a>
                              </div>-->
                           </div>
                        </div>
                     </div>
                  </div>
               </div>

               <div class="balance-sec-list mt-3 text-center" style="margin-top:50px !important">
                  <div class="row">
                     <div class="col-6">
                        <div class="added-balance">
                           <div class="balance ">
                              <div class="bal-ico text-primary">
                                 <img src="<?php echo base_url();?>/assets/images/balance-ico1.png" alt="">
                              </div>
                              <h6 class="text-white mb-0 fs-5">Gas Wallet Balance (USDT) </h6>
                              <h4 class="text-primary mb-2 lato fw-semibold"><?php echo number_format($gas_wallet,2);?></h4>
                              <br>
                              <!-- <div class="balance-button">
                                 <a href="<?php echo base_url();?>/activate/account" class="btn btn-outline-primary">extend now</a>
                              </div> -->
                           </div>
                        </div>
                     </div>
                     <div class="col-6">
                        <div class="added-balance">
                           <div class="balance ">
                              <div class="bal-ico text-primary">
                                 <img src="<?php echo base_url();?>/assets/images/balance-ico1.png" alt="">
                              </div>
                              <h6 class="text-white mb-0 fs-5">Profit Performance Ranking (Group)</h6>
                              <h4 class="text-primary mb-2 lato fw-semibold"><?php echo number_format($bal,2);?></h4>
                              <br>
                              <!-- <div class="balance-button">
                                 <a href="<?php echo base_url();?>/asset/recharge" class="btn btn-outline-primary">Recharge</a>
                              </div> -->
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
               <!--balance end -->
               <!--trans table start -->
               <div class="row">
                  <div class=" col-12">
                     <div class="table-responsive dash-trans trans table-bg mt-4 position-relative">
                        <div class="head_trans ms-3 mb-4">
                           <h4 class="fw-semibold text-primary lato text-uppercase">Referral Link</h4>
                        </div>
                        <?php 
                        
                  $referral_code=base_url().'/register/'.$users_details->invitation_code;
                  $referral_info = $this->db->table("uusers")->where('uusersid',$users_details->referral_id)->get()->getRow();
                  if($referral_info)
                  {
                     $upline_code=$referral_info->username;
                     $upline_url=base_url().'/register/'.$referral_info->invitation_code;
                  }
                  else
                  {
                     $upline_code='-- NIL --';
                     $upline_url='-- NIL--';
                  }
                  
                  ?>
                  <div class="col-lg-12">
                     <div class="qr-code text-center">
                     <img src="https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=<?php echo $referral_code;?>" alt="referral" style="border:1px solid;margin-bottom:10px;">
                     </div>
                  </div>
                  <div class="ref-form-list">
                           <div class="ref-form d-flex align-items-center mt-4">
                              <div class="ref-content text-start">
                                 <p class="text-white mb-0">My Referral Code</p>
                                 <h5 class="text-white" style="word-break:break-all;"><?php echo base_url();?>/register/<?php echo $users_details->invitation_code;?></h5>
                                 <span id="link" style="display:none"><?php echo base_url();?>/register/<?php echo $users_details->invitation_code;?></span>
                              </div>
                              <div class="ref-sec-copy">
                              <a href="javascript:void(0);" class="text-decoration-none" onclick="javascript:copyToClipboard('#link')"><i class="fa-regular fa-copy "></i></a>
                              </div>
                           </div>
                        </div>
                    </div>
                  </div>
                </div>
               <!--<div class="row">
                  <div class=" col-12">
                     <div class="table-responsive dash-trans trans table-bg mt-4 position-relative">
                        <div class="head_trans ms-3 mb-4">
                           <h4 class="fw-semibold text-primary lato text-uppercase"> Top 5 Performer </h4>
                        </div>
                        <?php 
                        $builder = $this->db->table('history');
                        $builder->select('uusersid, SUM(amount) as total_amount');
                        $builder->groupBy('uusersid');
                        $builder->orderBy('total_amount', 'DESC');
                        $builder->limit(5);

                        // Execute the query and get the results
                        $query = $builder->get();
                        $resultt = $query->getResult();

                       // print_r($result);

                        ?>

                        <table class="trans_info">
                           <thead>
                              <tr>
                                 <th> Place</th>
                                 <th> User</th>
                                 <th> Profit (USDT)</th>
                              </tr>
                           </thead>
                           <tbody>

                             <?php
                               foreach($resultt as $rest)
                               {

                                 $users_details1 = $this->db->query("SELECT * FROM uusers WHERE uusersid='".$rest->uusersid."'")->getRow();
                                 
                                 if(!empty($users_details1->rankid))
                                 {
                                  

                                    $rank_details = $this->db->query("SELECT * FROM rewardsettings WHERE id='".$users_details1->rankid."'")->getRow();
                                    $rankimg = 'assets/images/rank/'.$rank_details->image;
                                    //$rankimg = 'assets/images/grade-1.png';
                                 }
                                 else
                                 {
                                    
                                    $rankimg = 'assets/images/grade-1.png';
                                 }
                             ?> 
                              <tr>
                                 <td><img style="width:36px;height:28px" src="<?php echo base_url();?>/<?php echo $rankimg;?>" alt=""></td>
                                 <td> <img src="<?php echo base_url();?>/assets/images/crypto-img.png" alt=""> <span><?php echo formatName($users_details1->username) ;?></span></td>
                                 <td><?php echo number_format($rest->total_amount,2);?></td>
                              </tr>

                              <?php } ?>
                             
                           </tbody>
                        </table>
                     </div>
                  </div>-->
                  <div class=" col-12">
                     <div class="table-responsive trans table-bg mt-4 position-relative">
                        <div class="head_trans ms-3 mb-4">
                           <h4 class="fw-semibold text-primary lato text-uppercase"> Top 5 Profitable Coins </h4>
                        </div>
                        <table class="trans_info">
                           <thead>
                              <tr>
                                 <th> Coin</th>
                                 <th> Symbol</th>
                                 <th> Profit (USDT)</th>
                              </tr>
                           </thead>
                           <tbody>
                              <?php

                                 $builder1 = $this->db->table('api_trade_history');
                                 $builder1->select('pair, SUM(comm_price) as total_comm_price');
                                 $builder1->where('type', 2);
                                 $builder1->groupBy('pair');
                                 $builder1->orderBy('total_comm_price', 'DESC');
                                 $builder1->limit(5);

                                 // Execute the query and fetch the results
                                 $query1 = $builder1->get();
                                 $resultss = $query1->getResult();
                              
                                  foreach($resultss as $ress)
                                  {
                              ?>
                              <tr>
                                 <td><img style="width:36px;height:28px"  src="<?php echo base_url('styles/images/tradingpair_images/'.$ress->pair.'.png');?>" alt=""></td>
                                 <td><?php echo $ress->pair;?></td>
                                 <td> <?php echo number_format($ress->total_comm_price,2);?></td>
                              </tr>

                              <?php } ?>
                           
                           </tbody>
                        </table>
                     </div>
                  </div>
               </div>
               <!--trans table end -->
            </div>
         </section>
         <!-- wrapper-content end-->
         <!--footer start -->
         <?php echo view('user/layout/footer');?>
         <!--footer end -->
      </section>
    
      <?php echo view('user/layout/footer-script');?>
      <script>
         AOS.init({
         });
      </script>
       <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
      <?php       
         if (session()->get('isLoggedIn') == 1) {
             unset($_SESSION['isLoggedIn']);
         
         ?>
      <!--<script>
         Swal.fire({
         title: " <i class='fa fa-bell text-secondary'></i> Announcement: Update new IP address for binding API ",
         html: `
         <div style="text-align: left;">
         <p>Dear Valued Customers,</p>
         <p><strong>If you have already binded your API, please go to the API page to check for the latest IP address to be updated in your API authorisation. </strong></p>
         <p>During this time, we kindly ask for your cooperation and understanding. If you encounter any problems or issues, please share your feedback with us so we can enhance our system.</p>
         <p>Your feedback is crucial for us to improve and provide you with a better experience. We are committed to making Trade Pilot the best it can be and appreciate your support in this process.</p>
         <p>Thank you for your support and cooperation.</p>
         <p>Best regards,<br>The Trade Pilot Team <?php echo $this->session->get('isLoggedIn');?></p>
         </div>
         `,
         
         showCancelButton: true,
         cancelButtonText: 'Close',
         cancelButtonColor: '#d33',
         showConfirmButton: false
         
         });
      </script>-->
      <?php } ?>
       <script>
         var timeString = "<?php echo $datee;?>";
         var date5 = new Date(timeString);
         var target_date = date5.getTime();
         
         
         
         var days, hours, minutes, seconds; // variables for time units
         
         var countdown = document.getElementById("tiles"); // get tag element
         
         getCountdown();
         
         setInterval(function () { getCountdown(); }, 1000);
         
         function getCountdown(){
         
         // find the amount of "seconds" between now and target
         var current_date = new Date().getTime();
         var seconds_left = (target_date - current_date) / 1000;
         
         days = pad( parseInt(seconds_left / 86400) );
         seconds_left = seconds_left % 86400;
         
         hours = pad( parseInt(seconds_left / 3600) );
         seconds_left = seconds_left % 3600;
         
         minutes = pad( parseInt(seconds_left / 60) );
         seconds = pad( parseInt( seconds_left % 60 ) );
         
         // format countdown string + set tag value
         countdown.innerHTML = "<span>" + days + " : </span><span>" + hours + " : </span><span>" + minutes + " : </span><span>" + seconds + "</span>"; 
         }
         
         function pad(n) {
         return (n < 10 ? '0' : '') + n;
         }

         function updateText() {
             const spanElement = document.getElementById('retrive');
             spanElement.classList.add('blink'); // Add the blink class to trigger the animation
             const randomIndex = Math.floor(Math.random() * texts.length);
             spanElement.textContent = texts[randomIndex];
         
             // Remove the blink class after the animation completes
             setTimeout(() => {
                 spanElement.classList.remove('blink');
             }, 500); // 0.5s matches the duration of the blink animation
         }
         
         // Set interval to update text every 5 seconds (5000 milliseconds)
         setInterval(updateText, 5000);
         
         // Initial call to display text immediately on load
         updateText();
         
         
      </script>
      
    
      <script type="text/javascript">
         document.getElementById('balance_load').addEventListener('click', function() {
         
            
               this.classList.add('spin');
               read_function();
               setTimeout(() => {
               
                 this.classList.remove('spin');
               }, 1000); // Duration of the animation in milliseconds
             });
         
             function read_function()
             {
               var uusersid='<?php echo $this->session->get('uusersid');?>';
               var exchange='<?php echo $exchange_id;?>';
               $.ajax({
                 'method': 'POST',
                 'url': '<?php echo base_url("/balance_update");?>',
                  data:{'exchange':exchange,'uusersid':uusersid},
                 success:function(msg)
                 {
                  $("#balance_update").html(msg);
                 }
               })
             }
             
                 function change(value) {
             var baseUrl = "<?php echo base_url(); ?>";
             var redirectUrl = baseUrl + '/user/dashboard/changeSession/' + value;
         
             console.log('Redirect URL:', redirectUrl);
         
             // Redirect to the constructed URL
             window.location.href = redirectUrl;
            }
           
      </script>
    <script>

      function copyToClipboard(element) {
      var $temp = $("<input>");
      $("body").append($temp);
      $temp.val($(element).html()).select(); //Note the use of html() rather than text()
      document.execCommand("copy");
      $temp.remove();
      
      }
      

      function copyToClipboard1(element) {
      var $temp = $("<input>");
      $("body").append($temp);
      $temp.val($(element).html()).select(); //Note the use of html() rather than text()
      document.execCommand("copy");
      $temp.remove();
      }
      </script>
      
   </body>
</html>
