<h6 class="span" style="display: none;">Operate only for all currencies that have been checked</h6>
<div class="row">
<?php
 $id= $symbol;
      if(is_numeric($id))
    {
        $cls = 'col-lg-6';
    }
    else
    { 
    	$cls = 'col-lg-4';
      $display = "none";
    }
?>
<div class="<?php echo $cls;?>">
<div class="boxs" style="border :2px solid gray;">
<i class="bi bi-gear"></i>
  <a href="" data-bs-toggle="modal" data-bs-target="#TransactionModel" data-bs-whatever="@fat" ><h5>Transaction settings</h5></a>
</div>
</div>


<?php 
$pair = $get_active;

 $id= $symbol;

        if(!is_numeric($id))
    {

if(!empty($pair)) {
if($pair->trade_status != 1 || $pair->trade_status == 0) { 
?>
<div class="col-lg-4">
<div class="boxs" id="start_button" style="border :2px solid gray;cursor: pointer;">
<i class="bi bi-skip-start-circle-fill"></i>
<h5>Resume</h5>
</div>
<?php }
else 
{ ?>
<div class="col-lg-4">
<div class="boxs" id="pause_button"  style="border :2px solid gray;cursor: pointer;">
<i class="bi bi-skip-start-circle-fill"></i>
<h5>Pause</h5>
</div>
<?php } }
 else{ ?>
 <div class="col-lg-4">
 <div class="boxs" id="start_button" style="border :2px solid gray;cursor: pointer;">
<i class="bi bi-skip-start-circle-fill"></i>
<h5>Start</h5>
</div>
<?php
}
 ?>

</div>
<?php
}
?>
<div class="<?php echo $cls;?>" id="one" style="display:none;cursor: pointer;">
<div class="boxs"  id="Ostartegy"  style="border :2px solid gray;">
<i class="bi bi-file-earmark-bar-graph-fill"></i>
<h5 style="color: #0d6efd;"  id="Ostartegy_Name">One-shot strategy</h5>
</div>
</div>

<div class="<?php echo $cls;?>" id="cycle">
<div class="boxs" id="Cstartegy"  style="border :2px solid gray;cursor: pointer;">
<i class="bi bi-arrow-repeat"></i>
<h5 style="color: #0d6efd;" id="Cstartegy_Name">Cycle strategy</h5>
</div>
</div>


</div>

<div class="row" style="margin-top:10px;">



<div class="<?php echo $cls;?>">
<div class="boxs" style="border :2px solid gray;cursor: pointer;">
<i class="bi bi-pie-chart-fill"></i>
<a href="" data-bs-toggle="modal" data-bs-target="#staticBackdrop" data-bs-whatever="@fat"><h5>First Preset Start Price</h5></a>
</div>
</div>


<?php
        if(!is_numeric($id))
    {

?>
<div class="col-lg-4" id="Margin_Clk">
<div class="boxs" style="border :2px solid gray; cursor: pointer;">
<i class="bi bi-collection-play-fill"></i>
  <h5 class="smc"  id="mc" >Initiate margin call</h5>
</div>
</div>

<?php
}
?>
<div class="<?php echo $cls;?>">
<div class="boxs" style="border :2px solid gray;cursor: pointer;">
<a href="" href="" data-bs-toggle="modal" data-bs-target="#staticBackdrop1" data-bs-whatever="@fat"  >
                <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico5.png" class="img-fluid me-2"></div>
                <div>
                </div>
                 <h6 class="color-2 mb-0">Strategy mode</h6>
              </a>
</div>
</div>

</div>
<div class="row" style="margin-top:10px;">

</div>



<div class="modal fade" id="staticBackdrop1" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" style="display: none;" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content" style="border-radius:30px;padding: 11px;" >
<div class="modal-header" style="border-bottom: 0px;padding-top: 11px;margin-bottom:-15px;">
<p class="modal-title" id="staticBackdropLabel" style="padding-left:170px;"><b>Strategy mode</b></p>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<center>
<span class="span" style="border-bottom: 1px;">Please select a strategy mode</span>
</center>
<hr>
<div class="row col-lg-12 mt-3">
<div class="form-check form-check-right mb-3" style="font-size: 14px;">
<input type="radio" class="form-check-label" name="strategy_mode" id="strategy_mode" value="1" <?php if($pair->strategy_mode==='1'){ echo 'checked="checked"'; } ?>> Whole warehouse mode<br><br>
<input type="radio" class="form-check-label" name="strategy_mode" id="strategy_mode" value="2" <?php if($pair->strategy_mode==='2'){ echo 'checked="checked"'; } ?>> Sub-bin mode<br><br>
<input type="radio" class="form-check-label" name="strategy_mode" id="strategy_mode" value="3" <?php if($pair->strategy_mode==='3'){ echo 'checked="checked"'; } ?>> Sub-bin mode-real-time settlement

</div>
</div>

</div>
<div class="modal-footer" style="padding: 0px;">
  <table style="margin-bottom: -2px;">
    <tr>
      <button data-bs-dismiss="modal" class="btn btn-primary" style="border-right: 1px solid #dee2e6;text-align: center;">Cancel</button>
      <button style="text-align: center;" class="btn btn-secondary"  data-bs-dismiss="modal" name="sure_mode" id="sure_mode">Sure</button>
    </tr>
  </table>
</div>
</div>
</div>
</div>  



<!-- transaction model -->

<?php

    // $qury = $this->db->query("SELECT * FROM user_strategy WHERE uusersid='".$uusersid."'")->getResult();
    // $qry=$qury[0];
    $qry = $pair;

    $id= $symbol;

        if(!is_numeric($id))
    {
    	?>
<form class="modal fade" id="TransactionModel" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" method="post" action="<?php echo base_url().'/tradedetails/'.$id;?>" enctype="multipart/form-data">
    	<?
    }
    else
    {
    	?>
	<form class="modal fade" id="TransactionModel" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" method="post" action="<?php echo base_url().'/user/dashboard';?>" enctype="multipart/form-data">
    	<?
    }
?>

  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Transaction Setting</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <input type="hidden" value="<?php echo $qry->id?>;" name="uusersid" id="uusersid">
      <div class="modal-body">
        <div class="row">
          <div class="col-lg-3">
            <div class="modal-form mb-4">
              <label class="">First order amount</label>
              <input type="text" class="form-control mt-1" placeholder="" name="first_buy_amount" id="first_buy_amount" value="<?php echo $qry->first_buy_amount;?>">
            </div>
             <div class="modal-form mb-4">
              <label class="">Double open position</label>
            <div class="form-check form-switch form-switch-lg mb-3" dir="ltr">
            <input type="checkbox" class="form-check-input" data-on-text="<?php echo $on?>" data-off-text="<?php echo $off; ?>" data-on-color="primary" data-off-color="default" name="open_position_doubled" <?php if($qry->open_position_doubled==='on'){ echo 'checked="checked"'; } ?>>
            </div>
            </div>
            <div class="modal-form mb-4">
              <label class="">Replenishment times</label>
              <input type="text" class="form-control mt-1" id="replenishment_time" name="replenishment_time" placeholder="" value="<?php echo $qry->margin_column_limit;?>">
            </div>
            <div class="modal-form mb-4">
              <label class="">Whole position take profit ratio</label>
              <div class="input-group">
                <input type="text" class="form-control mt-1" placeholder="" name="whole_profit_ratio" value="<?php echo $qry->whole_profit_ratio;?>">
                <span class="input-group-text mt-1">% </span> </div>
            </div>
            <div class="modal-form mb-4">
              <label class="">Whole position take profit Callback</label>
              <div class="input-group">
                <input type="text" class="form-control mt-1" placeholder="" name="whole_profit_callback" value="<?php echo $qry->whole_profit_callback;?>">
                <span class="input-group-text mt-1">% </span> </div>
            </div>
            
                <div class="modal-form mb-4">
              <label class="">Buy in callback</label>
              <div class="input-group">
                <input type="text" class="form-control mt-1" placeholder="" name="buyin_callback" value="<?php echo $qry->buyin_callback;?>">
                <span class="input-group-text mt-1">% </span> </div>
            </div>
            <div class="modal-form mb-4" id="subposition">
              <label class="">Sub-Position take-profit callback</label>
              <div class="input-group">
                <input type="text" class="form-control mt-1" placeholder="" name="sub_position_callback" value="<?php echo $qry->sub_position_callback;?>">
                <span class="input-group-text mt-1">% </span> </div>
            </div>
          </div>
          <div class="col-lg-6">
            <div class="modal-head">
              <h6 class="mont">Margin Configuration</h6>
            </div>
            <div class="row">
              <div class="col-lg-6">
                <div class="modal-head">
                  <h5 class="text-black mont">Margin Call drop</h5>
                </div>

                  <span id="ex_demo1"></span>

              </div>
              <div class="col-lg-6">
                <div class="modal-head">
                  <h5 class="text-black mont">Multiply Buy in ratio</h5>
                </div>

                <span id="ex_demo2"></span>

              </div>
            </div>
          </div>
          <div class="col-lg-3">
            <div class="modal-head">
              <h6 class="mont">Distributed and take profit Allocation</h6>
              <h5 class="text-black mont">Percentage of spilt-to-profit</h5>
            </div>
            <span id="ex_demo"></span>
          </div>
        </div>
      </div>
      <div class="modal-footer" style="float:left;">

        <button type="submit" class="btn btn-primary" name="strategy" style="display: <?php echo $display;?>" value="strategy">Get a Suggested Strategy</button>

        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" id="submit_button" class="btn btn-primary" name="sub" value="sub">Submit</button>
      </div>
    </div>
  </div>
</form>



  <div class="modal fade staticBackdrop" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" style="display: none;" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document" style="width:360px;height:200px;">
  <div class="modal-content" style="border-radius:30px;padding: 5px;" >
  <div class="modal-header"style="border-bottom: 0px;border-bottom:1px solid #dee2e6;font-size:15px;">
  <center><b><p class="modal-title" id="staticBackdropLabel" style="border-bottom: 0px;font-size:15px;line-height: 24px;">First Preset Start Price</p></b></center>
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  </div>
  <div class="modal-body" style="border-bottom:1px solid #dee2e6;font-size:15px;line-height: 24px;">
  <p style="font-size:14px;">
    <input type="text" name="first_preset_drop"  style="border-style: none;" id="first_preset_drop" placeholder="First Preset Start Price" value="<?php echo $qry->first_buy_amount;?>">
  </p>
  </div>
  <div class="modal-footer" >
  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal" style="border-right: 1px solid #dee2e6;text-align: center;" >Cancel</button>
  <button type="submit" class="btn btn-primary" name="sure_price" id="sure_price" value="sub" data-bs-dismiss="modal">Sure</button>

  </div>
  </div>
  </div>
  </div> 


<input type="hidden" value="<?php echo $pair->strategy_type;?>" id="find_mode">
<input type="hidden" value="<?php echo $pair->strategy_mode;?>" id="modes">


<script type="text/javascript">
     $(document).ready(function() {

    $('#subposition').css('display', 'none');

        var num = $('#replenishment_time').val();

      if(num >= 5)
        {

          $('#subposition').css('display', 'block');
        }
        else
        {
          $('#subposition').css('display', 'none');
        }

        });
</script>

<script type="text/javascript">

$(document).ready(function(){

      $('#submit_button').click(function(){
      var first_buy_amount =  $("[name=first_buy_amount]").val();
      var whole_profit_ratio =  $("[name=whole_profit_ratio]").val();
      var whole_profit_callback =  $("[name=whole_profit_callback]").val();
      var sub_position_callback = $("[name=sub_position_callback]").val();
      var limit = $("[name=replenishment_time]").val();
      var buyin_callback =  $("[name=buyin_callback]").val();
      var flag = 1;
      if(!(whole_profit_ratio > 0)){
          $.notify(' <i class="fas fa-exclamation-triangle"></i> Please enter a value greater than 1', 'danger');
          flag = 0;
      }
      if(whole_profit_ratio < whole_profit_callback && flag == 1){
          $.notify(' <i class="fas fa-exclamation-triangle"></i> Take profit ratio will be greater than take profit callback', 'danger');
          flag = 0;
        }

        if(!(first_buy_amount >= 11 && flag == 1)){
          $.notify(' <i class="fas fa-exclamation-triangle"></i> Minimum first buy amount is 11 USDT', 'danger');
          flag = 0;
      }

        if(limit >= 5){
        var j=0;
        var i;
           for(i=5; limit >= i; i++){
            var var_name = "rep_time"+j;
            if($("[name="+var_name+"]").val() < sub_position_callback && flag == 1){
            $.notify(' <i class="fas fa-exclamation-triangle"></i> Subbin Take profit ratio will be greater than subbin take profit callback', 'danger');
            flag = 0;
            }
            j++;
           }
        }
        
        if(!(buyin_callback >= 0) && flag == 1){
          $.notify(' <i class="fas fa-exclamation-triangle"></i> Please enter a positive value', 'danger');
          flag = 0;
        }
          
       var empty = true;

      $('#TransactionModel input[type="text"]').each(function() {
      if($(this).val() == ''){
      $flag = 0;
      empty = false;
      }
      });

      if(empty == false){
      $.notify(' <i class="fas fa-exclamation-triangle"></i> Some fields are empty', 'danger');
      }

        if(flag == 1 && empty == true){
          $('#TransactionModel').submit();
          $.notify('<i class="fas fa-check"></i>  Set Successfully', 'success');
        }


          
    });  



    $('#sure_price').click(function(){
    var uusersid = $('#uusersid').val();
    var first_preset_drop = $('#first_preset_drop').val();
    $.ajax({
    type: 'post',
    url : '<?php echo base_url("/dashboard/first_preset_drop");?>',
    data : {'first_preset_drop':first_preset_drop,'uusersid':uusersid,'pair':'<?php echo $symbol; ?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
       window.location.reload();
    }
    }
    });
    });


var num = $('#replenishment_time').val();
var uusersid = $('#uusersid').val();
  $.ajax({
  type: 'post',
  dataType:'html',
  url : '<?php echo base_url("/replenishment_time1");?>',
  data : {'number1':num,'uusersid':uusersid,'pair':'<?php echo $symbol; ?>'},
  headers: {'X-Requested-With': 'XMLHttpRequest'},
  success : function(msg)
  {
  if(msg)
  {
  $('#ex_demo1').html(msg);
  }
  }
  });

  $.ajax({
  type: 'post',
  dataType:'html',
  url : '<?php echo base_url("/replenishment_time2");?>',
  data : {'number2':num,'uusersid':uusersid,'pair':'<?php echo $symbol; ?>'},
  headers: {'X-Requested-With': 'XMLHttpRequest'},
  success : function(msg)
  {
    if(msg)
    {
    $('#ex_demo2').html(msg);
    }
  }
  });

  $.ajax({
  type: 'post',
  dataType:'html',
  url : '<?php echo base_url("/replenishment_time");?>',
  data : {'number':num,'uusersid':uusersid,'pair':'<?php echo $symbol; ?>'},
  headers: {'X-Requested-With': 'XMLHttpRequest'},
  success : function(msg)
    {
      if(msg)
      {
      $('#ex_demo').html(msg);
      }
    }
  });


});


$('#replenishment_time').keyup(function(){

  var num = $('#replenishment_time').val();
  var uusersid = $('#uusersid').val();

  if(num >= 5)
    {
      $('#subposition').css('display', 'block');
    }
    else
      {
        $('#subposition').css('display', 'none');
      }

  if(num>=5)
  {
    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/replenishment_time");?>',
    data : {'number':num,'uusersid':uusersid},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
        if(msg)
        {
        $('#ex_demo').html(msg);
        }
      }
    });
  }
  else
  {
     $('#ex_demo').html("");
  }

  if(num>0)
  {
    $.ajax({
      type: 'post',
      dataType:'html',
      url : '<?php echo base_url("/replenishment_time1");?>',
      data : {'number1':num,'uusersid':uusersid},
      headers: {'X-Requested-With': 'XMLHttpRequest'},
      success : function(msg)
      {
        if(msg)
        {
        $('#ex_demo1').html(msg);
        }
      }
    });

  }

if(num>0)
{
  $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/replenishment_time2");?>',
    data : {'number2':num,'uusersid':uusersid},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
      if(msg)
      {
      $('#ex_demo2').html(msg);
      }
    }
  });
}

});




  $('#start_button').on('click',function()
    {
      
      $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url("/tradingprocess");?>',
         data:{'id':"<?php echo $symbol?>",'uri':"<?php echo $symbol?>",'pair':"<?php echo $symbol?>" },
        success:function(msg)
        {
           window.location.reload();
        }
      })
    });

   $('#sure_mode').on('click',function(){
   
   var num = $('input[name="strategy_mode"]:checked').val();

    var pairs = "<?php echo $pair->trade_status;?>";
    var pair_id  = "<?php echo $symbol;?>";

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/Cstartegy_mode");?>',
    data : {'number2':num,'pair':pairs,'pair_id':pair_id},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
       window.location.reload();
    }
    }
    });
 
  });


 $('#pause_button').on('click',function()
    {
      
      $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url("/tradingprocess1");?>',
         data:{'id':"<?php echo $symbol?>",'uri':"<?php echo $symbol?>" },
        success:function(msg)
        {
           window.location.reload();
        }
      })
    });


	 var find_mode = $('#find_mode').val();

     var mode = $('#modes').val();
     var margin_call = '<?php echo $pair->margin_call;?>';

     if(mode==1)
     {
      mode =  "Whole warehouse mode";
     }
      if(mode==2)
     {
      mode =  "Sub-bin mode";
     }
      if(mode==3)
     {
      mode =  "Sub-bin mode-real-time settlement";
     }

     if(margin_call==1)
     {
          $('#mc').html("Stop margin call");
     }
     else
     {
     	  $('#mc').html("Initiate margin call");
     }

     if(find_mode=="One-shot strategy")
     {
        $('#Ostartegy_Name').html("One-shot strategy");
        $('#cycle').css('display','none');
        $('#one').css('display','inline-block');
     }
     else
     {
        $('#Cstartegy_Name').html(find_mode);
        $('#one').css('display','none');
        $('#cycle').css('display','inline-block');
     }


    $('#Margin_Clk').on('click',function(){
    
      var mci = $('.smc').html();

     if(mci == "Stop margin call")
     {
         $('#mc').html("Initiate margin call");
         var value = 1;
     }
     if(mci != "Stop margin call")
     {
        $('#mc').html("Stop margin call");
        var value = 0;
     }
   
    var pairs  = "<?php echo $symbol;?>";

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/call_margin");?>',
    data : {'margin_id':value,'pair':pairs},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
    }
    }
    });
   
    });

 $('#Cstartegy_Name').on('click',function(){
    
    var num="Cycle Strategy";
    var pairs = "<?php echo $pair->trade_status;?>";
    var pair_id  = "<?php echo $symbol;?>";

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/Cstartegy");?>',
    data : {'number2':num,'pair':pairs,'pair_id':pair_id},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
		$('#Ostartegy_Name').html("One-shot strategy");
		$('#cycle').css('display','none');
		$('#one').css('display','inline-block');
    }
    }
    });
  });

 function doalerts(obj) {
        $('#Cstartegy').css('display','none');
        $('#Ostartegy').css('display','inline-block');
        var a = $('#Ostartegy_Name').text();
        $('#crypto-strategy').html(a);
    }

     function Ooalerts(obj) {
        $('#Cstartegy').css('display','inline-block');
        $('#Ostartegy').css('display','none');
        var b = $('#Cstartegy_Name').text();
        $('#crypto-strategy').html(b);
    }

  

    $('#Ostartegy').on('click',function(){
    
    var num="Ostartegy";
    
    var pairs = "<?php echo $pair->trade_status;?>";
    var pair_id  = "<?php echo $symbol;?>";

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/Ostartegy");?>',
    data : {'number2':num,'pair':pairs,'pair_id':pair_id},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
			$('#Cstartegy_Name').html('Cycle Strategy');
			$('#one').css('display','none');
			$('#cycle').css('display','inline-block');
    }
    }
    });
  });

</script>