<!doctype html>
<html lang="en"  class="w-[640px]">
   <head>
      <?php echo view('user/layout/head');?>
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10.6.0/dist/sweetalert2.min.css">
   </head>
   <style>
      .img
      {
      width : 50px;
      height:50px;
      border:none;
      border-radius:23px;
      }
      .notify-top-right,
      .notify-bottom-right {
      left: auto;
      right: 10px;
      }
      .notify-top-center,
      .notify-bottom-center {
      left: 50%;
      margin-left: -175px;
      }
      .notify-bottom-left,
      .notify-bottom-right,
      .notify-bottom-center {
      top: auto;
      bottom: 10px;
      }
      .notify button {
      -webkit-appearance: none;
      padding: 0;
      cursor: pointer;
      background: 0 0;
      border: 0;
      display: none;
      }
      /* Responsiveness
      ========================================================================== */
      /* Phones portrait and smaller */
      @media (max-width: 479px) {
      /*
      * Fit in small screen
      */
      .notify {
      left: 10px;
      right: 10px;
      width: auto;
      margin: 0;
      }
      }
      /* Sub-object: `notify-message`
      ========================================================================== */
      .notify-message {
      position: relative;
      cursor: pointer;
      }
      .notify .alert-default {
      background: #fff;
      border: 1px solid #e5e5e5;
      }
      .swal2-popup {
      font-size: 12px !important;
      font-weight:bold;
      }
      .circle
      {
      border :1px solid green;
      border-radius:20px;
      background:green;
      color:#fff;
      padding:5px;
      margin-left:5px;
      }
      .circle1
      {
      border :1px solid red;
      border-radius:20px;
      background:red;
      color:#fff;
      padding:5px;
      margin-left:5px;
      }
   </style>
   <?php 
      use App\Libraries\MyEncrypt;
      use App\Helpers\site_helper;
      
      $session =  \Config\Services::session();
      $validation =  \Config\Services::validation();
      $this->db = db_connect();
      $userid = $session->get('uusersid');
      $confirm = $this->db->table('history')->where('uusersid',$userid)->where('type','activation')->where('status',1)->get()->getRow();
      ?> 
   <body class="section-overflow">
      <!--banner start -->
      <section class="banner-bg overall-bg ">
         <div class="container">
            <?php echo view('user/layout/header');?>
         </div>
         <section class="dash-wrap coin-wrap">
            <div class="container">
               <div class="row">
                  <div class="col-12">
                     <div class="table-responsive trans asset-trans position-relative mb-5">
                        <?php 
                           $session = \Config\Services::session();
                           if($session->getFlashData('success_message')) 
                           {
                           ?>
                        <div class="success-msg input-msg">
                           <img src="<?php echo base_url();?>/assets/images/success.png">
                           <p class="text-white fw-medium ms-2 mb-0"><?php echo $session->getFlashData('success_message');?></p>
                        </div>
                        <?php 
                           } 
                           else if($session->getFlashData('error_message')) 
                           { 
                           ?>
                        <div class="error-msg input-msg">
                           <img src="<?php echo base_url();?>/assets/images/error.png">
                           <p class="text-white fw-medium ms-2 mb-0"><?php echo $session->getFlashData('error_message');?></p>
                        </div>
                        <?php 
                           } 
                           ?>
                        <table class="payment-info"  id="example1" style="width:100%">
                           <thead style="display:none">
                              <td></td>
                              <td></td>
                           </thead>
                           <tbody>
                              <?php 
                                 $i=0;
                                 foreach($apikey as $row)
                                 {
                                    
                                    $i++
                                 
                                 ?>
                              <?php 
                                 $this->session = session();
                                 $uusersid = $this->session->get('uusersid');
                                 $referral1=$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$uusersid."' and type= '".$row->id."'");
                                 $ref=$referral1->getRow();
                                 if($ref=='')
                                 {
                                     
                                 ?>
                              <tr>
                                 <td>
                                    <div class="asset-trans-content d-flex align-items-center justify-content-between">
                                       <div class="asset-trans-left text-start">
                                          <div class="d-flex align-items-center">
                                             <img src="<?php echo base_url();?>/styles/new_style/images/<?php echo $row->image;?>"  class="img">&nbsp;&nbsp; 
                                             <h6 class="aleo text-white"><?php echo $row->coin;?></h6>
                                          </div>
                                          <small class="text-primary fs-6 py-2 fw-bold lato"><?php echo $row->coin;?> is a cryptocurrency exchange</small>
                                       </div>
                                    </div>
                                 </td>
                                 <?php if($confirm) { ?>  
                                 <td>
                                    <a href="<?php echo base_url();?>/binding/<?php echo $row->url;?>">
                                    bound &nbsp;&nbsp;&nbsp;<i class="fa-solid fa-greater-than"></i>
                                    </a>
                                 </td>
                                 <?php } else { ?>
                                 <td > 
                                    <span id="inactive_bind<?php echo $i;?>"><strong style="font-size:19px">Unbound</strong>&nbsp;&nbsp;</span>
                                    <i class="fa-solid fa-greater-than"></i>
                                 </td>
                                 <?php } ?>
                              </tr>
                              <?php 
                                 }
                                 else
                                 {
                                 ?>
                              <tr>
                                 <td>
                                    <div class="asset-trans-content d-flex align-items-center justify-content-between">
                                       <div class="asset-trans-left text-start">
                                          <div class="d-flex align-items-center">
                                             <img src="<?php echo base_url();?>/styles/new_style/images/<?php echo $row->image;?>"  class="img">&nbsp;&nbsp;
                                             <h6 class="aleo text-white mb-0"><?php echo $row->coin;?></h6>
                                             <span class="circle" id="remove" style="background:red;" onclick="remove_api('<?php echo $row->id;?>')">Unbind</span>
                                          </div>
                                          <small class="text-primary fs-6 py-2 fw-bold lato"><?php echo $row->coin;?> is a cryptocurrency exchange</small>
                                       </div>
                                    </div>
                                 </td>
                                 <?php if($confirm) { ?>  
                                 <td>
                                    <a href="<?php echo base_url();?>/binding/<?php echo $row->url;?>">
                                    Bound &nbsp;&nbsp;&nbsp;<i class="fa-solid fa-greater-than"></i>
                                    </a>
                                 </td>
                                 <?php } else { ?>
                                 <td > 
                                    <span id="inactive_bind<?php echo $i;?>"><strong style="font-size:19px">Bound</strong>&nbsp;&nbsp;</span>
                                    <i class="fa-solid fa-greater-than"></i>
                                 </td>
                                 <?php } ?>
                              </tr>
                              <?php }  } ?>
                           </tbody>
                        </table>
                     </div>
                  </div>
               </div>
            </div>
         </section>
         <!--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@10.6.0/dist/sweetalert2.all.min.js"></script>
      <script src="<?php echo base_url()?>/styles/new_style/js/notify.js"></script>
      <script>
         $(document).ready(function(){
         
         <?php 
            $i=0;
            
            foreach($apikey as $row)
            { 
               
               $i++;?>
          
           $('#inactive_bind<?php echo $i;?>').on('click',function(){         
           $.notify(' <i class="fas fa-exclamation-triangle"></i>&nbsp;&nbsp;  Please activate the bot first. ', 'danger');
         });
         
         <?php    }  ?>
         
         });
         
         function remove_api(str)
         {
          
                 
            Swal.fire({
                            title: 'Confirm',
                            text: "Are You sure you want to unbind Api?",
                            icon: 'warning',
                            showCancelButton: true,
                            confirmButtonColor: '#3085d6',
                            cancelButtonColor: '#d33',
                            confirmButtonText: 'Yes, confirm it!'
                        }).then((result) => {
                            // Check if user confirmed
                            if (result.isConfirmed) {
                  
                      $.ajax({
                        'method': 'POST',
                        'url': '<?php echo base_url("/removeapi");?>',
                         data:{'id':str,'uusersid':"<?php echo $this->session->get('uusersid');?>"},
                        success:function(msg)
                        {
                          //$.notify(' <i class="fas fa-check-circle"></i>  Trade stopped successfully', 'success'); 
                          // console.log(msg);
                          var msg=msg.trim();
                          if(msg=='yes')
                          {
                              $.notify(' <i class="fas fa-times-circle"></i> Currently Active trade available. Please close and try again', 'danger'); 
                          }
                            
                           else if(msg=='no')
                           {
                               $.notify(' <i class="fas fa-check-circle"></i> API successfully unbind', 'success'); 
                               setInterval(nextpage, 1000);
                           }
                           //window.location.reload();
                        }
                      })
              
                }
            }); 
             
         }
         
         function nextpage()
         {
            window.location.reload();
         }
      </script>
   </body>
</html>
