<style>
	.select2-selection--single {
		background-color: #fff !important;
		border: 1px solid gray;
		border-radius: 4px;
		height: 42px !important;
	}
	.select2-selection--single .select2-selection__rendered  {
		color: gray !important;
		line-height: 40px !important;
	}
</style>
<div >

	<?php if($this->session->flashdata('message')!==null):?>
		<div class="alert alert-<?=$this->session->flashdata('type')?> alert-dismissible fade show" role="alert">
			<?=$this->session->flashdata('message')?>
			<button type="button" class="close" data-dismiss="alert" aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>
		</div>
	<?php endif?>
	<div class="card">
		<div class="card-body">
			<h4 class="card-title">Balance Transfer</h4>


			<form class="forms-sample" method="post" action="<?=base_url('FlexiloadCtrl/blance_transfer_store')?>">



				<div class="row">

					<div class="col-md-6">
						<div class="form-group">
							<label for="validity">Select Member</label>
							<select class="select2 form-control" name="receiver_id" required>
								<option disabled selected>Select Member</option>
								<?php foreach ($users as $user):?>
									<option value="<?=$user->user_id?>" <?=set_value('receiver_id')==$user->user_id ? 'selected' :''?>><?=$user->mobile_num?></option>
								<?php endforeach;?>
							</select>
							<span id="input-14-error" class="error"><?= form_error('receiver_id'); ?></span>
						</div>
					</div>

					<div class="col-md-6">
						<div class="form-group">
							<label for="exampleInputName1">Transfer Amount</label>
							<input type="number" value="<?=set_value('amount')?>" class="form-control" name="amount" id="transfer_amount" placeholder="Transfer Amount" required>
							<span id="input-14-error" class="error"><?= form_error('amount'); ?></span>
						</div>
					</div>

				</div>

				<div class="row">

					<div class="col-md-6">
						<div class="form-group">
							<label for="total_commission">Remaining Amount</label>
							<input type="number" value="<?=set_value('remaining_amount')?>" class="form-control" name="remaining_amount" id="remaining_amount" placeholder="Remaining Amount"  readonly >
						</div>
					</div>

					<div class="col-md-6">
						<div class="form-group">
							<label for="total_commission">Note</label>
							<textarea  class="form-control" name="note" id="note" placeholder="note"><?=set_value('note')?></textarea>
						</div>
					</div>

				</div>

				<div class="row">


					<div class="col-md-6">
						<div class="form-group">
							<label for="commission">Pin Code</label>
							<input type="password" value="<?=set_value('pin_code')?>" class="form-control"  name="pin_code" id="pin_code" placeholder="Pin Code" required>
							<a href="javascript:void()" id="resend_c" class="mr-5 btn btn-link">Resend code in mobile <i class="mdi mdi-sync mdi-spin loading"></i> </a>
						</div>
					</div>

				</div>
				<button  class="btn btn-primary mr-2">Send</button>

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

<script>
	let blance = "<?php echo blance_check()?>";

	let amountChange = document.getElementById("transfer_amount");
	 amountChange.addEventListener('keyup',function () {
		 document.getElementById("remaining_amount").value='';

		if(parseInt(blance)<parseInt(amountChange.value))
		{
			alert("Your Balance is Insufficient !!");
			amountChange.value='';
		}
		else{
			document.getElementById("remaining_amount").value=blance-amountChange.value;
		}
	});

	let resend = document.getElementById("resend_c");
	 resend.addEventListener('click',function () {

		 let id = '<?=$this->session->user_id?>';
		 $.ajax({
			 type: "post",
			 url: "<?=base_url('ActivateCtrl/resend_code')?>",
			 data: {id:id},
			 dataType: "json",
			 success: function (response) {
				 if(response.success == 1){
					 document.getElementById('resend_c').innerHTML += "<i class='mdi mdi-check'></i>";
					 $(".loading").hide();
				 }
			 }
		 });
	 });

</script>


