<!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>Withdraw</title>
      <?php echo view('user/layout/head');?>
   </head>
   <style>
      .para
      {
      text-align:justify;
      color:#fff;
      }
      .help-block {
      color: red;
      margin: 0em 0em 0em !important;
      }
      .alert-success {
      color: #0f5132;
      background-color: #d1e7dd;
      border-color: #badbcc;
      font-size: 12px;
      }
      .span
      {
      font-size: 12px;
      color: #9395a1;
      margin-top: 14px;
      font-weight: 900;
      }
      #getcode {
      background: #b18720;
      box-shadow: 0px 0px 39px 0px rgba(255,227,172,0.27);
      border: none;
      padding: 8px 22px;
      margin-top:-20px;
      margin-left:20px;
      /* position: absolute; */
      border-top-right-radius: 10px;
      display: flex;
      align-items: end;
      border-bottom-right-radius: 10px;
      }
      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
         }
   </style>
   <body class="reg-overflow">
      <section class=" dash-banner-bg banner-bg referral profile">
         <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-2">
               <h2 class="text-primary">Withdraw</h2>
            </div>
            <div class="row">
               <div class="col-lg-12">
                  <div class="income-sec">
                     <div class="total-income d-flex align-items-center">
                        <div class="ref-content text-start">
                           <h5 class="text-white">
                              USDT Balance : <span id="balanceVal"><?php echo number_format("0.00",2); ?></span>&nbsp;<span id="deduct"><?php echo strtoupper('USDT');?></span>
                              <div id="ip-exist" style="display:none;color:#d84315;" class="error_msg"><?php echo "Insufficient Amount";?></div>
                           </h5>
                        </div>
                     </div>
                  </div>
                  <center>
                  <?php
                     use App\Libraries\MyEncrypt;
                     use App\Helpers\site_helper;
                     use App\Helpers\form_helper;
                     $this->db = db_connect();
                     $this->session = session();
                     $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="col-lg-12">
                     <?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 
                        } 
                        ?>
                     <?php 
                        $id = 'NyYmemh5aXA=';
                        
                        $myencrypt = new MyEncrypt;
                        $coinid = $myencrypt->decode($id);
                        $user=$this->session->get('uusersid');
                        $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 == "with_fee")
                        $coin_dets = $value->site_value;
                        if($value->site_key == "with_min_amt")
                        $trans_min_amt = $value->site_value;
                        if($value->site_key == "with_max_amt")
                        $trans_max_amt = $value->site_value; 
                        if($value->site_key == "with_instant")
                        $trans_instant = $value->site_value; 
                        }
                        
                        ?> 
                     <div class="reg-page mt-5 ">
                      
                        <form class="steps-validation withdraw" method="post"  id="pin" action="<?php echo $action;?>">
                           <div class="row" style="margin-top:20px ">
                              <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="Withdraw Amount" value="" />
                                    <span id="amount_error" style="color:red"></span>
                                    <?php echo $this->form_validation->getError('amount', '<span class="help-block">', '</span>'); ?>
                                 </div>
                              </div>
                              <div class="col-sm-12">
                                 <div id="otpmsg" ></div>
                              </div>
                              <!--<div class="col-sm-12   <?php if($this->form_validation->getError('code1')) echo "has-error";?>" >
                                 <div class="form-block form-group mb-3 user-box position-relative" >
                                    <input name="code1" class="form-control" type="text" id="code1" placeholder="Enter Code" value="" />
                                    <button type="button" id="getcode" name="getcode">GETCODE</button>
                                 </div>
                                
                              </div>-->
                              
                                <div class="col-sm-12">
                           <div class="form-block form-group  position-relative">
          
                              <div class="input-group">
                                 <input type="text" class="form-control" name="code1" id="code1"  maxLength="6"  placeholder="Verfication Code">
                                 <span class="input-group-btn"> &nbsp;
                                 <button type="button" name="getcode" id="getcode"  class="btn btn-primary">SEND</button>
                                 </span>
                              </div>
                              <?php echo $this->form_validation->getError('code1', '<span class="help-block">', '</span>'); ?>
                           </div>
                           </div>
                              <div class="col-sm-12 <?php if($this->form_validation->getError('address')) echo "has-error";?>">
                                 <div class="form-block form-group mb-3 user-box">
                                    <textarea class="form-control" name="address" id="address" placeholder="USDT address"></textarea>
                                    <!-- <input name="recv_id" class="form-control"   type="text" id="recv_id"  placeholder="Receiver ID" value="" /> -->
                                    <span id="name-error" style="color:red"></span>
                                    <?php echo $this->form_validation->getError('address', '<span class="help-block">', '</span>'); ?>
                                 </div>
                              </div>
                
                           </div>
                           <div class="col-sm-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">
                                       <label>Withdraw Fee </label>
                                    </div>
                                    <div class="col-lg-6">
                                       <strong><?php echo number_format($coin_dets,2); ?></strong>&nbsp;<span>Will be deducted</span>
                                    </div>
                                 </div>
                                 <div class="col-sm-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">
                                             <label>Received Amount </label>
                                          </div>
                                          <div class="col-lg-6">
                                             <strong  id="recv_amt">0</strong>&nbsp;<span>Will be withdrawn</span>
                                          </div>
                                       </div>
                                    </div>
                                 </div>
                              </div>
                              <input type="hidden" id="transfee" name="trans_fee">
                              <input type="hidden" id="org_amount" name="org_amt">
                              <button type="submit" id="trans" name="trans" class="btn btn-primary mb-5" >Withdraw</button>
                        </form>
                          <hr>
                        <div class="title para" style="margin-top:20px;padding:10px;">
                             <p> <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon> Kindly provide a valid USDT wallet address (TRC20) for withdrawal to prevent any potential loss of funds. </p>
                             <p> <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon> Withdrawals are processed within +3 days, with a fee deducted from the withdrawn amount. </p>
                             <p> <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon>The withdrawal fee is a fixed amount of 2 USDT.</p>
                             <p style="color:orange;"> <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon> Important note: Please choose the network carefully and make sure it matches the network of the platform you're withdrawing funds to. If you select the wrong network, your funds might be lost and cannot be recovered.</p>
                             </div>
                       
                        </div>
                     </div>
               </center>
              </div>
            </div>
            </div>
         </div>
      </section>
      <?php echo view('user/layout/footer');?>
      <?php echo view('user/layout/footer-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>
jQuery.noConflict();
(function ($) {
   $(document).ready(function () {

      $('#getcode').on("click", function () {
         $.ajax({
            type: 'post',
            url: '<?php echo base_url();?>/withdraw/verifyregcode',
            data: {
               'sub': 1
            },
            dataType: 'json',
            success: function (msg) {
               if (msg !== '') {
               
                 $("#otpmsg").html('<div class="alert alert-success">' + msg + '</div>');
                  setTimeout(otphide,3000);
               }
            }
         })

      });

        function otphide()
        {
        $('#otpmsg').html("");
        }
   


      $('#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');
               }
            }
         }
      });


  

      $('.withdraw').formValidation({


         framework: 'bootstrap',
         excluded: [':disabled'],

         fields: {
            amount: {
               validators: {
                  notEmpty: {
                     message: '<?php echo "Withdraw amount is required";?>'
                  },
                  regexp: {
                     regexp: /^[0-9.]+$/,
                     message: '<?php echo "Withdraw amount is Invalid"; ?>'
                  },
                  remote: {
                     url: function (validator, $field, value) {
                        return '<?php echo base_url();?>/checkfee/<?php echo $coinid?>';
                     },
                     type: 'POST',
                     delay: 1000,
                   
                  }
               }
            },
            code1: {
               validators: {
                  notEmpty: {
                     message: 'Please Enter the verification code'
                  },
                  remote: {
                     url: function (validator, $field, value) {
                        return '<?php echo base_url();?>/withdraw/verifyotp'
                     },
                     type: 'POST',
                     delay: 500,
                     message: '<?php echo "Invalid Code, Try again "; ?>'
                  }
               }
            },
            address: {
               validators: {
                  notEmpty: {
                     message: '<?php echo "Address is required";?>'
                  }
               }
            },

         }
      });


   });
})(jQuery);
</script> 


 </body>
</html>