<!doctype html>
<html lang="en"  class="w-[640px]">
   <head>
      <?php echo view('user/layout/head');?>
   </head>
   <style>
      .help-block 
      {
      color:red;
      font-size:12px;
      font-weight:bold;
      }
      .quantity {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}
.spin {
      animation: spin 1s infinite;
      }
      @keyframes spin {
      from { transform: rotate(0deg); }
      to { transform: rotate(360deg); }
      }

.quantity .minus,
.quantity .plus {
    width: 40px;
    height: 40px;
    border: none;
    background-color: #007bff;
    color: white;
    font-size: 20px;
    font-weight: bold;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.quantity .minus:hover,
.quantity .plus:hover {
    background-color: #0056b3;
}

.quantity .minus:disabled,
.quantity .plus:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

.quantity .input-box {
    /* width: 60px;
    height: 40px; */
    text-align: center;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

   </style>
   <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 team-wrap">
         <div class="container">
            <?php 
               $this->session = \Config\Services::session();
               $this->db = db_connect();
               $uusersid = $this->session->get('uusersid');
               
                  use App\Libraries\MyEncrypt;
                  use App\Helpers\site_helper;
                  use App\Helpers\form_helper;
               
                  $this->common_model = model('CommonModel');
                  $this->form_validation =  \Config\Services::validation();
                  $list = \Config\Services::validation()->listErrors();
                  
                  helper('form_helper');
                  //echo view('user/common_header');
                  $us_data = userMinPass();
                  ?>
            <div class="row">
               <div class="col-12">
                  <div class="quantify-header d-flex align-items-center text-white justify-content-between">
                     <div class="trade-content ms-2">
                        <h6 class="text-white fw-semibold aleo mb-0 align-items-center">USDT Balance</h6>
                     </div>
                     <div class="repeat-icon d-flex align-items-center">
                        <h5 class="text-white me-2 fw-bold "><span id="balanceVal"><?php echo number_format("0.00",2); ?></span><span id="deduct"><?php echo strtoupper('USDT');?></span>
                           <span id="ip-exist" style="display:none;color:#d84315;" class="error_msg"><?php echo "Insufficient Amount";?></span>  
                        </h5>
                        <a href="javascript:void(0);">
                           <iconify-icon icon="mage:reload-reverse" id="balance_load" class="fs-3"></iconify-icon>
                        </a>
                     </div>
                  </div>
               </div>
            </div>
            <div class="col-lg-12">
            <?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 
                              } 
                              ?>


               <?php 
                  // $this->uri = service('uri');
                  // $this->uri->getSegment('2');
                  
                          $user=$this->session->get('uusersid');
                          $coinid='1';
                          $buy_bal=curbalance($this->session->get('uusersid'),$coinid);
                          $bal=str_replace(",","", $buy_bal);
                  
                          $first_dat=$this->db->query("select * from coin_info where coid='".$coinid."'");  
                          $fir_d=$first_dat->getResult();
                          $coin_det=$fir_d[0];
                  
                          $withdraw_datas = $this->common_model->GetSettingall('withdraw');
                          foreach ($withdraw_datas as $key => $value) {
                              if($value->site_key == "trans_fee")
                                 $coin_dets = $value->site_value;
                              if($value->site_key == "trans_min_amt")
                                 $trans_min_amt = $value->site_value;
                              if($value->site_key == "trans_max_amt")
                                 $trans_max_amt = $value->site_value;   
                  
                          }
                          
                  
                          ?>
               </div>
               <div class="team-tab mt-4">
               <ul class="nav nav-pills d-flex justify-content-center ps-0" id="pills-tab" role="tablist">
                     <li class="nav-item" role="presentation">
                        <button class="nav-link active" id="pills-dep1-tab " data-bs-toggle="pill" data-bs-target="#pills-dep1"
                           type="button" role="tab" aria-controls="pills-dep1" aria-selected="true">
                           <div class="make-list">
                              <div class="process">
                                 <span>Transfer to others</span>
                              </div>
                           </div>
                        </button>
                     </li>
                     <li class="nav-item" role="presentation">
                        <button class="nav-link" id="pills-dep2-tab " data-bs-toggle="pill" data-bs-target="#pills-dep2"
                           type="button" role="tab" aria-controls="pills-dep2" aria-selected="true">
                           <div class="make-list">
                              <div class="process">
                                 <span>Transfer to gas wallet</span>
                              </div>
                           </div>
                        </button>
                     </li>
                  </ul>

                  <div class="tab-content" id="pills-tabContent">
                  <div class="tab-pane fade show active" id="pills-dep1" role="tabpanel" aria-labelledby="pills-dep1-tab">
                
                           <form class="steps-validation transfer" method="post"  id="pin" action="<?php echo $action;?>">
                           <div class="offset-sm-1 col-sm-10">
                           <div class=" team-profit-content" style="text-align:start !important">

                           <div class="row" >

                                 <div class="col-sm-12 <?php if($this->form_validation->getError('amount')) echo "has-error"; ?>">
                                 <div class="form-block form-group mb-3 user-box ">
                                    <div class="quantity">

                                    
                                    <button class="minus btn btn-secondary" aria-label="Decrease">&minus;</button>
                                    <input 
                                          name="amount" 
                                          class="form-control input-box" 
                                          type="text" 
                                          id="amount" 
                                          placeholder="Transfer Amount" 
                                          value="" 
                                    />
                                    <button class="plus btn btn-secondary" aria-label="Increase">&plus;</button>
                                    </div>
                                 
                                    <small id="amount_error" style="color:red"></small>
                                    <?php echo $this->form_validation->getError('amount', '<span class="help-block">', '</span>'); ?>
                                 </div>
                              </div>
                                 <div class="col-sm-12  <?php if($this->form_validation->getError('recv_id')) echo "has-error";?>">
                                    <div class="form-block  mb-3 user-box">
                                       <input name="recv_id" class="form-control"   type="text" id="recv_id"  placeholder="Receiver ID" value="" />
                                       <small id="name-error" style="color:red"></small>
                                       <?php echo $this->form_validation->getError('recv_id', '<span class="help-block">', '</span>'); ?>
                                    </div>
                                 </div>
                                 <!--<div class="col-sm-12  <?php if($this->form_validation->getError('sec_pin')) echo "has-error";?>">
                                    <div class="form-block position-relative login-ico form-group">
                                       <div class="form-ico password-toggle-icon" style="right:0px;"><i class="fa-regular fa-eye-slash"></i></div>
                                       <input name="sec_pin" class="form-control"   type="password" id="sec_pin"  placeholder="Security Pin" value="" />
                                       <span id="pin-error" style="color:red"></span>
                                       <?php echo $this->form_validation->getError('sec_pin', '<span class="help-block">', '</span>'); ?>
                                    </div>
                                    </div>-->
                                 <div class="col-sm-12">
                                    <div class=" form-block position-relative login-ico">
                                    <div class="form-ico">
                                       <iconify-icon icon="stash:eye-closed-solid" id="togglePasswordIcon1"></iconify-icon>
                                    </div>
                                       <input type="password" class="form-control " id="sec_pin" name="sec_pin" aria-describedby="" placeholder="Security Pin">
                                    </div>
                                 </div>
                              </div>
                              <div class="col-lg-12 mt-2">
                                 <div class="form-block  form-group mb-3 user-box">
                                    <div class="row text-white text-start">
                                       <div class="col-lg-5">
                                          <p>Transfer Fee </p>
                                       </div>
                                       <div class="col-lg-6">
                                          <strong><?php echo number_format($coin_dets,2); ?></strong>&nbsp;<small>Will be deducted</small>
                                       </div>
                                    </div>
                                    <div class="col-lg-12 mt-2">
                                       <div class="form-block  form-group mb-3 user-box">
                                          <div class="row text-white text-start">
                                             <div class="col-lg-5">
                                                <p>Received Amount </p>
                                             </div>
                                             <div class="col-lg-6">
                                                <strong  id="recv_amt">0</strong>&nbsp;<small>Will be transfer</small>
                                             </div>
                                          </div>
                                       </div>
                                    </div>
                                 </div>
                                 <br>
                                 <input type="hidden" id="transfee" name="trans_fee">
                                 <input type="hidden" id="org_amount" name="org_amt">
                                 <div class="form-btn my-4 text-center">
                                    <button type="submit" id="trans" name="trans" class="btn btn-primary mb-5" >Transfer</button>
                                 </div>
                              </div>
                              </div>
                              </div>
                           </form>
                        </div>
                     <!-- </div> -->
                     <div class="tab-pane fade " id="pills-dep2" role="tabpanel" aria-labelledby="pills-dep2-tab">

                           <form action="<?php echo base_url();?>/user/validategastransfer" id="transfer1" method="post">
                           <div class="offset-sm-1 col-sm-10">
                           <div class="team-profit-content" style="text-align:start !important">
                              <div class="row" >
                                 <div class="col-sm-12 <?php if($this->form_validation->getError('amount')) echo "has-error";?>">
                                    <div class="form-block form-group mb-3 user-box" >
                                       <input name="amount" class="form-control" type="text" id="amount" placeholder="Gas Amount" value="" />
                                       <small id="amount_error" style="color:red"></small>
                                       <?php echo $this->form_validation->getError('amount', '<span class="help-block">', '</span>'); ?>
                                    </div>
                                 </div>
                              </div>
                              <div class="form-btn my-4 text-center">
                                 <button type="submit" id="trans1" name="trans1" class="btn btn-primary mb-5" >Transfer</button>
                              </div>
                              </div>
                              </div>
                           </form>
                       
                     </div>
                  </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="http://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script type="text/javascript" src="<?php echo base_url();?>/assets/js/formValidation1.js"></script>
      <script type="text/javascript" src="<?php echo base_url();?>/assets/js/bootstrap.js"></script>
      <script>
(function () {
    const quantityContainer = document.querySelector(".quantity");
    const minusBtn = quantityContainer.querySelector(".minus");
    const plusBtn = quantityContainer.querySelector(".plus");
    const inputBox = quantityContainer.querySelector(".input-box");

    // Set dynamic min and max values
    const minValue = <?php echo $trans_min_amt;?>;
    const maxValue = <?php echo $trans_max_amt;?>;

    updateButtonStates();

    quantityContainer.addEventListener("click", handleButtonClick);
    inputBox.addEventListener("input", handleQuantityChange);

    function updateButtonStates() {
        const value = parseInt(inputBox.value);
        minusBtn.disabled = value <= minValue;
        plusBtn.disabled = value >= maxValue;
    }

    function handleButtonClick(event) {
        if (event.target.classList.contains("minus")) {
            decreaseValue();
        } else if (event.target.classList.contains("plus")) {
            increaseValue();
        }
    }

    function decreaseValue() {
        let value = parseInt(inputBox.value);
        value = isNaN(value) ? minValue : Math.max(value - 1, minValue);
        inputBox.value = value;
        updateButtonStates();
        handleQuantityChange();
    }

    function increaseValue() {
        let value = parseInt(inputBox.value);
        value = isNaN(value) ? minValue : Math.min(value + 1, maxValue);
        inputBox.value = value;
        updateButtonStates();
        handleQuantityChange();
    }

    function handleQuantityChange() {
        let value = parseInt(inputBox.value);
        value = isNaN(value) ? minValue : Math.min(Math.max(value, minValue), maxValue); // Clamp the value within range
        inputBox.value = value; // Update the input field in case of invalid input

        // Execute your code here based on the updated quantity value
        console.log("Quantity changed:", value);
    }
})();
</script>

      <script type="text/javascript">
         jQuery.noConflict();
         (function( $ ) {
             $(document).ready(function() {
             
          $('#amount').change(function(){
           var amount = $('#amount').val();
           var with_fee = <?php echo $coin_dets;?>;
           var trans_min_amt = <?php echo $trans_min_amt;?>;
           var trans_max_amt = <?php echo $trans_max_amt;?>;
           if(amount >= trans_min_amt && amount <= trans_max_amt) {
           $('#amount_error').css('display','none');
           $('#amount_error').html();
           $('#trans').removeClass('disabled');
           var remain = +amount - +with_fee;
           $('#recv_amt').html(remain);
           $('#transfee').val(with_fee);
           $('#org_amount').val(remain);
           }else {
                  $('#amount_error').css('display','inline');
                  $('#amount_error').html('Amount is not less than '+trans_min_amt+' and not more than '+trans_max_amt);
                  $('#btn').addClass('disabled');
           }
         });
         
         
         $.ajax({
           type: 'post',
           url : '<?php echo base_url();?>/checkbalance/<?php echo $coinid?>',
           success : function(msg)
           {
         
             if(msg) {
               $('#balanceVal').html(msg);
         
               if(msg=='<?php echo number_format('0',$currency_info->deimal_point, '.', ''); ?>' || msg < '0') {
         
                 $('#ip-exist').css('display','block');
                 $('#balanceVal').css('color','#d84315');
                 $('#deduct').css('color','#d84315');
                 $('.error_msg').parent().parent().addClass('has-error');
                 $('#trans').addClass('disabled');
         
               } else {
         
                 $('#ip-exist').css('display','none');
                 $('#balanceVal').css('color','#fff');
                 $('#deduct').css('color','#fff');
                 $('.error_msg').parent().parent().removeClass('has-error');
               }
             }
           }
         });
         
         
            $('#recv_id').change(function(){
                var name = $('#recv_id').val();
               
         
            $.ajax({
           type: 'post',
           url : '<?php echo base_url();?>/withdraw/name_verify',
           data : {"rec_name":name},
           success : function(msg)
           {
             
             if(msg == 1){
                   $('#name-error').css('display','none');
                   $('#name-error').html();
                   $('#trans').removeClass('disabled');
             }else if(msg == 2){
                  $('#name-error').html('Invalid Username');
                  $('#name-error').css('display','inline');
                  $('#trans').addClass('disabled');
             }else{
                  $('#name-error').css('display','inline');
                  $('#name-error').html('Inactive account');
                  $('#trans').addClass('disabled');
             }
           }
         });
         
          });
         
         
          $('.transfer').formValidation({
         
           
             framework: 'bootstrap',
             excluded: [':disabled'],
           
             fields: {
                     amount: {
                     validators: {
                         notEmpty: {
                             message: '<?php echo "Transfer amount is required";?>'
                         },
                         regexp: {
                   regexp: /^[0-9.]+$/,
                   message: '<?php echo "Transfer amount is Invalid"; ?>'
                 },
                 remote: {
                   url: function(validator, $field, value) {
                     return '<?php echo base_url();?>/checkfee/<?php echo $coinid?>';
                   },
                   type: 'POST',
                   delay: 1000,
                   
                 }
                     }
                 },
                 recv_id: {
                     validators: {
                         notEmpty: {
                             message: '<?php echo "Receiver Id is required";?>'
                         }
                     }
                 },
                 sec_pin: {
                     validators: {
                         notEmpty: {
                             message:  '<?php echo "Security pin is required";?>' 
                         },
                         remote: {
                                    url: function(validator, $field, value) {
                                        
                                        return '<?php echo base_url();?>/withdraw/validsecuritypin';
                                    },
                                    type: 'POST',
                                    delay: 1000,
                                    message: '<?php echo "Security pin invalid"; ?>'
                                }
                        
                     }
                 }
                 
             }
            });
         
            $('#transfer1').formValidation({
         
           
         framework: 'bootstrap',
         excluded: [':disabled'],
         
         fields: {
                 amount: {
                 validators: {
                     notEmpty: {
                         message: '<?php echo "Gas amount is required";?>'
                     },
                     regexp: {
               regexp: /^[0-9.]+$/,
               message: '<?php echo "Gas amount is Invalid"; ?>'
             },
             remote: {
               url: function(validator, $field, value) {
                 return '<?php echo base_url();?>/checkfee/<?php echo $coinid?>';
               },
               type: 'POST',
               delay: 1000,
               
             }
                 }
             },
            
             
         }
         });
         
         
         
         
         
          });
         
          
         })(jQuery);

         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
         });
         
      </script>
      <script>

         const passwordField = document.getElementById("sec_pin");
        const togglePasswordIcon = document.getElementById("togglePasswordIcon1");

        togglePasswordIcon.addEventListener("click", function () {
            if (passwordField.type === "password") {
                // Change to text
                passwordField.type = "text";
                togglePasswordIcon.setAttribute("icon", "mdi:eye-outline"); // Change icon
            } else {
                // Change to password
                passwordField.type = "password";
                togglePasswordIcon.setAttribute("icon", "stash:eye-closed-solid"); // Change icon
            }
        });
      </script>
      <script></script>
   </body>
</html>
