<!doctype html>
<html lang="en" translate="no" class="w-[640px] mx-auto md:w-full">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>API binding</title>
      <?php echo view('user/layout/head');?>
   </head>
   <style>
      .img
      {
      width : 50px;
      height:50px;
      border:none;
      border-radius:23px;
      }
      p.frgtpwd1 {
      background:#8DC540 !important
      }
      p.frgtpwd1 i {
      background:#8DC540 !important;
      color:#fff !important
      }
      p.frgtpwd {
      font-size: 13px;
      color: #fff;
      text-align: left;
      line-height: 24px;
      margin: 0 0 1em 0;
      background: #22313F;
      border-radius: 2px;
      padding:10px 39px 10px 10px;
      font-weight: 600;
      position: relative;
      }
      p.frgtpwd i {
      position: absolute;
      top: 0;
      right: 0;
      padding:15px 8px 8px 8px;
      font-size: 14px;
      background: #F5AB35;
      color: #22313F;
      height: 100%;
      }
      p.frgtpwdred {
      background:#EB5055 !important;
      }
      p.frgtpwdred i {
      background:#EB5055 !important
      }
      .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;
      }
      .trans_info tbody tr td:nth-child(2) {
      word-wrap: break-word;
      }
      .preca-btn {
      margin-top: 10px;
      position: relative;
      z-index: 1;
      }
      .notify {
      position: fixed;
      top: 10px;
      left: 10px;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      width: 350px;
      font-size: 14px;
      text-align: center;
      }
      /* Positions
      ========================================================================== */
      .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;
 
}
   </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="reg-overflow">
      <section class="dash-banner-bg banner-bg">
         <div class="container">
            <!---header start---->
            <?php echo view('user/layout/header');?>
            <!---header end---->
            <!---banner start---->
            <div class="row">
               <div class="col-lg-12">
                  <div class="dash-wrap">
                     <div class="title text-center py-1">
                        <h2 class="text-primary ">API Binding</h2>
                     </div>
                     <?php 
                        $session = \Config\Services::session();
                        if($session->getFlashData('success_message')) 
                        {
                        ?>
                     <p class="frgtpwd frgtpwd1 mt-5"><i class="fa fa-thumbs-up"></i><?php echo $session->getFlashData('success_message');?></p>
                     <?php 
                        } 
                        else if($session->getFlashData('error_message')) 
                        { 
                        ?>
                     <p class="frgtpwd frgtpwd1 frgtpwdred mt-5"><i class="fa fa-thumbs-down"></i><?php echo $session->getFlashData('error_message');?></p>
                     <?php 
                        } 
                        ?>
                         <div class="table-responsive trans position-relative">
                     <table class="trans_info mt-4 reward-info" id="" 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 >
                                 <p><img src="<?php echo base_url();?>/styles/new_style/images/<?php echo $row->image;?>"  class="img">&nbsp;&nbsp;<span class="mb-0" style="text-transform:uppercase;font-size:19px"><?php echo $row->coin;?></span> <span class="circle1" style="background:red;">Unbound</span></p>
                                 <p class="text-white-50 mb-0" style="width:50% important"> <?php echo $row->coin;?> is a cryptocurrency exchange</p>
                              </td>
                              <?php if($confirm) { ?>  
                              <td > 
                                 <a href="<?php echo base_url();?>/binding/<?php echo $row->url;?>">
                                 <span><strong style="font-size:19px">Bind</strong>&nbsp;&nbsp;</span>
                                 <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">Bind</strong>&nbsp;&nbsp;</span>
                                 <i class="fa-solid fa-greater-than"></i>
                              </td>
                           
                              <?php } ?>
                           </tr>
                           <?php 
                              }
                              else
                              {
                              ?>
                           <tr>
                              <td >
                                 <p><img src="<?php echo base_url();?>/styles/new_style/images/<?php echo $row->image;?>"  class="img">&nbsp;&nbsp;
                                 <span class="mb-0" style="text-transform:uppercase;font-size:19px"><?php echo $row->coin;?></span> <span class="circle">Bound</span>  <span class="circle" id="remove" style="background:red;" onclick="remove_api('<?php echo $row->id;?>')">Unbind</span></p>
                                 <p class="text-white-50 mb-0">  <?php echo $row->coin;?> is a cryptocurrency exchange. </p>
                              </td>
                              <?php if($confirm) { ?>  
                              <td > 
                                 <a href="<?php echo base_url();?>/binding/<?php echo $row->url;?>">
                                 <span><strong style="font-size:19px">Updated</strong>&nbsp;&nbsp;</span>
                                 <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">Updated</strong>&nbsp;&nbsp;</span>
                                 <i class="fa-solid fa-greater-than"></i>
                              </td>
                              <?php } ?>
                           </tr>
                           <?php } 
                           }
                           ?>


                           
                        </tbody>
                        <tfoot style="display:none"></tfoot>
                     </table>
                  </div>
                  </div>
                  <!---banner end---->
               </div>
            </div>
         </div>
         <?php echo view('user/layout/footer');?>
         </div>
      </section>
      <?php echo view('user/layout/footer-script');?>
      
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10.6.0/dist/sweetalert2.min.css">
<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>