<?php if($gatewayData['module'] == 'store'){ ?>
	<?php 
		$bank_names = [];

		if(isset($settingData['bank_names']) && ! empty($settingData['bank_names'])){
			$bank_names = (array)json_decode($settingData['bank_names'],1);
		} 
	?>
	<div class="form-group">
		<label class="control-label">Choose Bank</label>
		<select name="bank_method" class="form-control">
			<option value="0"><?= (isset($bank_names[0]) && !empty($bank_names[0])) ? $bank_names[0]  : substr($settingData['bank_details'],0,50)."..." ?></option>
			<?php
				if(isset($settingData['additional_bank_details'])){
					$additional_bank_details = (array)json_decode($settingData['additional_bank_details'],1);
					foreach ($additional_bank_details as $key => $value) {
						$Bname = (isset($bank_names[$key+1]) && !empty($bank_names[$key+1])) ? $bank_names[$key+1]  : substr($value,0,50)."...";
						echo '<option value="'. ($key+1) .'">'. $Bname .'</option>';
					}
				}
			?>
		</select>
	</div>

	<div class="checkout-bank-details">
		<?php $Bname = (isset($bank_names[0]) && !empty($bank_names[0])) ? $bank_names[0]."\r\n"  : ""; ?>
		<pre class="well d-none"><?= $Bname.$settingData['bank_details'] ?></pre>
		<?php
			if(isset($settingData['additional_bank_details'])){
				$additional_bank_details = (array)json_decode($settingData['additional_bank_details'],1);
				foreach ($additional_bank_details as $key => $value) {
					$Bname = (isset($bank_names[$key+1]) && !empty($bank_names[$key+1])) ? $bank_names[$key+1]."\r\n"  : "";
					$value = $Bname.$value;
					echo '<pre class="well d-none">'. $value .'</pre>';
				}
			}
		?>
	</div>

	<?php if($settingData['proof'] == 1){ ?>
		<div class="form-group">
			<label class="control-label"><?= __('user.payment_proof') ?></label>
			<input type="file" name="payment_proof" class="form-control">
		</div>
	<?php } ?>
	<?php if($settingData['proof'] == 2){ ?>
		<div class="form-group">
			<label class="control-label"><?= __('user.payment_proof') ?></label>
			<input type="file" name="payment_proof" class="form-control" required>
		</div>
	<?php } ?>

	<button type="button" class="btn btn-default" onclick='backCheckout()'><?= __('user.back') ?></button>
	<button id="button-confirm" class="btn btn-primary"><?= __('user.confirm') ?></button>

	<script type="text/javascript">
		$("select[name=bank_method]").change(function(){
			var val = $(this).val();
			$('.checkout-bank-details .well').addClass('d-none');
			$('.checkout-bank-details .well').eq(val).removeClass('d-none');
		});

		$("select[name=bank_method]").val('0').trigger("change");

		$("#button-confirm").click(function(){
			$this = $(this);
			
			let ajaxData = $('[name^="comment"]').serialize();
			<?php if($settingData['proof'] == 1){ ?>
				ajaxData += "&payment_proof=" + $('input[name="payment_proof"]').val();
			<?php } ?>

			<?php if($settingData['proof'] == 2){ ?>
				if($('input[name="payment_proof"]').val() == "") {
					alert('<?= __('user.payment_proof_required'); ?>');
					return false
				}

				ajaxData += "&payment_proof=" + $('input[name="payment_proof"]').val();
			<?php } ?>

			$.ajax({
				url:'<?= base_url("store/payment_confirmation") ?>',
				type:'POST',
				dataType:'json',
				data:ajaxData,
				beforeSend:function(){$("#button-confirm").btn("loading");},
				complete:function(){$("#button-confirm").btn("reset");},
				success:function(json){
					$container = $("#checkout-confirm");
					$container.find(".has-error").removeClass("has-error");
					$container.find("span.text-danger").remove();



					if(json['errors']){
						if(json['errors']['comment']){
							$.each(json['errors']['comment'], function(ii,jj){
							    $ele = $container.find('#comment_textarea'+ ii);
							    if($ele){
							        $ele.parents(".form-group").addClass("has-error");
							        $ele.after("<span class='text-danger'>"+ jj +"</span>");
							    }
							});
						}
						
						if(json['errors']['payment_proof']){
							$ele = $container.find('input[name="payment_proof"]');
							if($ele){
								$ele.parents(".form-group").addClass("has-error");
							    $ele.after("<span class='text-danger'>"+ json['errors']['payment_proof'] +"</span>");
							}
						}
					}

					if(json['success']){
						data = localStorage.getItem("selectedCookies");
						data = JSON.parse(data);
						var formData = new FormData();
						formData.append('bank_method', $('select[name="bank_method"]').val());
						
						if (data) {

							formData.append('cookies_consent',data.cookie1);
						}else{
							formData.append('cookies_consent','');
						}
						<?php if($settingData['proof']){ ?>
							formData.append('payment_proof', ($('input[type=file][name=payment_proof]')[0] ? $('input[type=file][name=payment_proof]')[0].files[0] : null)); 
						<?php } ?>

						$.ajax({
							url:'<?= base_url("store/confirm_payment") ?>',
							type:'POST',
							dataType:'json',
							data:formData,
							contentType: false,
				    		processData: false,
							beforeSend:function(){$this.btn("loading");},
							complete:function(){$this.btn("reset");},
							success:function(json){
								if(json['redirect']){
									window.location = json['redirect'];
								}
								if(json['warning']){
									alert(json['warning'])
								}

								$container = $("#checkout-confirm");
								$container.find(".has-error").removeClass("has-error");
								$container.find("span.text-danger").remove();
							

								if(json['errors']){
								    $.each(json['errors'], function(i,j){
								        $ele = $container.find('[name="'+ i +'"]');
								        if($ele){
								            $ele.parents(".form-group").addClass("has-error");
								            $ele.after("<span class='text-danger'>"+ j +"</span>");
								        }
								    });
								}
							},
						});
					}
				},
			});
		});
	</script>
<?php } else if($gatewayData['module'] == 'deposit'){ ?>
	<form id="formConfirmation">
		<?php 
			$bank_names = [];

			if(isset($settingData['bank_names']) && ! empty($settingData['bank_names'])){
				$bank_names = (array)json_decode($settingData['bank_names'],1);
			}
		?>

		<div class="form-group">
			<label class="control-label"><?= __('user.choose_bank') ?></label>
			<select name="bank_method" class="form-control">
				<option value="0"><?= (isset($bank_names[0]) && !empty($bank_names[0])) ? $bank_names[0]  : substr($settingData['bank_details'],0,50)."..." ?></option>
				<?php
					if(isset($settingData['additional_bank_details'])){
						$additional_bank_details = (array)json_decode($settingData['additional_bank_details'],1);
						foreach ($additional_bank_details as $key => $value) {
							$Bname = (isset($bank_names[$key+1]) && !empty($bank_names[$key+1])) ? $bank_names[$key+1]  : substr($value,0,50)."...";
							echo '<option value="'. ($key+1) .'">'. $Bname .'</option>';
						}
					}
				?>
			</select>
		</div>

		<div class="checkout-bank-details">
			<?php $Bname = (isset($bank_names[0]) && !empty($bank_names[0])) ? $bank_names[0]."\r\n"  : ""; ?>
			<pre class="well d-none"><?= $Bname.$settingData['bank_details'] ?></pre>
			<?php
				if(isset($settingData['additional_bank_details'])){
					$additional_bank_details = (array)json_decode($settingData['additional_bank_details'],1);
					foreach ($additional_bank_details as $key => $value) {
						$Bname = (isset($bank_names[$key+1]) && !empty($bank_names[$key+1])) ? $bank_names[$key+1]."\r\n"  : "";
						$value = $Bname.$value;
						echo '<pre class="well d-none">'. $value .'</pre>';
					}
				}
			?>
		</div>

		<?php $Bname = (isset($bank_names[0]) && !empty($bank_names[0])) ? $bank_names[0]."\r\n"  : ""; ?>
		<input type="hidden" name="bank_details[]" value="<?= $Bname.$settingData['bank_details'] ?>"/>
		<?php
			if(isset($settingData['additional_bank_details'])){
				$additional_bank_details = (array)json_decode($settingData['additional_bank_details'],1);
				foreach ($additional_bank_details as $key => $value) { 
					$Bname = (isset($bank_names[$key+1]) && !empty($bank_names[$key+1])) ? $bank_names[$key+1]."\r\n"  : "";
					$value = $Bname.$value;
					?>

					<input type="hidden" name="bank_details[]" value="<?= $value ?>"/>
					<?php
				}
			}
		?>

		<?php if($settingData['proof'] == 1){ ?>
			<div class="form-group">
				<label class="control-label"><?= __('user.payment_proof') ?></label>
				<input type="file" name="payment_proof" class="form-control">
			</div>
		<?php } ?>
		<?php if($settingData['proof'] == 2){ ?>
			<div class="form-group">
				<label class="control-label"><?= __('user.payment_proof') ?></label>
				<input type="file" name="payment_proof" class="form-control" required>
			</div>
		<?php } ?>
		</form>
		
		<div class="payment-button-group">
			<button type="button" class="btn btn-default" onclick='backCheckout()'><?= __('user.back') ?></button>
			<button id="button-confirm" class="btn btn-primary"><?= __('user.confirm') ?></button>
		</div>

		<script type="text/javascript">
			$("select[name=bank_method]").change(function(){
				var val = $(this).val();
				$('.checkout-bank-details .well').addClass('d-none');
				$('.checkout-bank-details .well').eq(val).removeClass('d-none');
			});

			$("select[name=bank_method]").val('0').trigger("change");

			$("#button-confirm").click(function(){
				<?php if($settingData['proof'] == 2){ ?>
					if($('input[name="payment_proof"]').val() == "") {
						alert('<?= __('user.payment_proof_required'); ?>');
						return false
					}
				<?php } ?>

				$this = $(this);
				
				$this.prop('disabled',true);
				
				$.ajax({
					url:'<?= base_url("usercontrol/payment_confirmation") ?>',
					type:'POST',
					dataType:'json',
					data:$('#formConfirmation').serialize(),
					beforeSend:function(){$("#button-confirm").btn("loading");},
					complete:function(){$("#button-confirm").btn("reset");},
					success:function(json){
						$container = $("#formConfirmation");
						$container.find(".has-error").removeClass("has-error");
						$container.find("span.text-danger").remove();

						if(json['errors']){
							$.each(json['errors']['comment'], function(ii,jj){
							    $ele = $container.find('#comment_textarea'+ ii);
							    if($ele){
							        $ele.parents(".form-group").addClass("has-error");
							        $ele.after("<span class='text-danger'>"+ jj +"</span>");
							    }
							});

							$.each(json['errors'], function(ii,jj){
							    $ele = $container.find('name['+ ii+']');
							    if($ele){
							        $ele.parents(".form-group").addClass("has-error");
							        $ele.after("<span class='text-danger'>"+ jj +"</span>");
							    }
							});
						}

						if(json['success']){
							var formData = new FormData();
							
							formData.append('bank_method', $('select[name="bank_method"]').val());
							
							<?php if($settingData['proof']){ ?>
								formData.append('payment_proof', ($('input[type=file][name=payment_proof]')[0] ? $('input[type=file][name=payment_proof]')[0].files[0] : null)); 
							<?php } ?>

							$.ajax({
								url:'<?= base_url("usercontrol/confirm_payment") ?>',
								type:'POST',
								dataType:'json',
								data:formData,
								contentType: false,
					    		processData: false,
								beforeSend:function(){$this.btn("loading");},
								complete:function(){$this.btn("reset");},
								success:function(json){
									if(json['redirect']){
										window.location = json['redirect'];
									}
									if(json['warning']){
										alert(json['warning'])
									}

									$container = $("#formConfirmation");
									$container.find(".has-error").removeClass("has-error");
									$container.find("span.text-danger").remove();
								

									if(json['errors']){
									    $.each(json['errors'], function(i,j){
									    	console.log(i);
									        $ele = $container.find('[name="'+ i +'"]');
									        console.log($ele.length)
									        if($ele){
									            $ele.parents(".form-group").addClass("has-error");
									            $ele.after("<span class='text-danger'>"+ j +"</span>");
									        }
									    });
									}
								},
							});
						}
					},
				});
			});
		</script>
<?php } else if($gatewayData['module'] == 'membership'){ ?>
	<form method="post" enctype="multipart/form-data">
		<div class="card border-0 shadow-sm">
			<div class="card-header bg-primary text-white py-2">
				<h6 class="mb-0">
					<i class="fas fa-university me-2"></i><?= __('user.bank_transfer_payment') ?>
				</h6>
			</div>
			<div class="card-body p-3">
				<?php 
				$bank_names = [];

				if(isset($settingData['bank_names']) && ! empty($settingData['bank_names'])){
					$bank_names = (array)json_decode($settingData['bank_names'],1);
				}
				?>

				<!-- Bank Selection -->
				<div class="mb-3">
					<label class="form-label fw-semibold small">
						<i class="fas fa-building me-1"></i><?= __('user.choose_bank') ?>
					</label>
					<select name="bank_method" class="form-select">
						<option value="0"><?= (isset($bank_names[0]) && !empty($bank_names[0])) ? $bank_names[0]  : substr($settingData['bank_details'],0,50)."..." ?></option>
						<?php
							if(isset($settingData['additional_bank_details'])){
								$additional_bank_details = (array)json_decode($settingData['additional_bank_details'],1);
								foreach ($additional_bank_details as $key => $value) {
									$Bname = (isset($bank_names[$key+1]) && !empty($bank_names[$key+1])) ? $bank_names[$key+1]  : substr($value,0,50)."...";
									echo '<option value="'. ($key+1) .'">'. $Bname .'</option>';
								}
							}
						?>
					</select>
				</div>

				<!-- Bank Details Display -->
				<div class="checkout-bank-details mb-3">
					<?php $Bname = (isset($bank_names[0]) && !empty($bank_names[0])) ? $bank_names[0]."\r\n"  : ""; ?>
					<div class="bank-details-card d-none">
						<div class="card border-primary">
							<div class="card-header bg-primary text-white py-2">
								<h6 class="mb-0 small">
									<i class="fas fa-info-circle me-1"></i><?= __('user.bank_account_details') ?>
								</h6>
							</div>
							<div class="card-body p-2">
								<pre class="mb-0 text-muted small"><?= $Bname.$settingData['bank_details'] ?></pre>
							</div>
						</div>
					</div>
					<?php
						if(isset($settingData['additional_bank_details'])){
							$additional_bank_details = (array)json_decode($settingData['additional_bank_details'],1);
							foreach ($additional_bank_details as $key => $value) {
								$Bname = (isset($bank_names[$key+1]) && !empty($bank_names[$key+1])) ? $bank_names[$key+1]."\r\n"  : "";
								$value = $Bname.$value;
								echo '<div class="bank-details-card d-none">
									<div class="card border-primary">
										<div class="card-header bg-primary text-white py-2">
											<h6 class="mb-0 small">
												<i class="fas fa-info-circle me-1"></i>'. __('user.bank_account_details') .'
											</h6>
										</div>
										<div class="card-body p-2">
											<pre class="mb-0 text-muted small">'. $value .'</pre>
										</div>
									</div>
								</div>';
							}
						}
					?>
				</div>

				<!-- Hidden Fields -->
				<?php $Bname = (isset($bank_names[0]) && !empty($bank_names[0])) ? $bank_names[0]."\r\n"  : ""; ?>
				<input type="hidden" name="bank_details[]" value="<?= $Bname.$settingData['bank_details'] ?>"/>
				<?php
					if(isset($settingData['additional_bank_details'])){
						$additional_bank_details = (array)json_decode($settingData['additional_bank_details'],1);
						foreach ($additional_bank_details as $key => $value) { 
							$Bname = (isset($bank_names[$key+1]) && !empty($bank_names[$key+1])) ? $bank_names[$key+1]."\r\n"  : "";
							$value = $Bname.$value;
							?>
							<input type="hidden" name="bank_details[]" value="<?= $value ?>"/>
							<?php
						}
					}
				?>

				<!-- Payment Proof Upload -->
				<?php if($settingData['proof'] == 1 || $settingData['proof'] == 2){ ?>
					<div class="mb-3">
						<label class="form-label fw-semibold small">
							<i class="fas fa-upload me-1"></i><?= __('user.payment_proof') ?>
							<?php if($settingData['proof'] == 2){ ?>
								<span class="text-danger">*</span>
							<?php } ?>
						</label>
						<input type="file" name="payment_proof" class="form-control" <?= ($settingData['proof'] == 2) ? 'required' : '' ?>>
						<div class="form-text small">
							<i class="fas fa-info-circle me-1"></i><?= __('user.upload_payment_receipt') ?>
						</div>
					</div>
				<?php } ?>

				<!-- Instructions -->
				<div class="alert alert-info border-0 py-2">
					<div class="d-flex align-items-start">
						<i class="fas fa-lightbulb me-2 mt-1 text-info"></i>
						<div>
							<h6 class="alert-heading mb-1 small"><?= __('user.payment_instructions') ?></h6>
							<p class="mb-0 small"><?= __('user.if_admin_asked_you_send_payment_proof') ?></p>
						</div>
					</div>
				</div>

				<!-- Action Buttons -->
				<div class="d-flex gap-2 justify-content-center">
					<button type="button" class="btn btn-outline-secondary btn-sm" onclick='backCheckout()'>
						<i class="fas fa-arrow-left me-1"></i><?= __('user.back') ?>
					</button>
					<button id="btn-confirm" type="button" class="btn btn-primary btn-sm">
						<i class="fas fa-check me-1"></i><?= __('user.buy_now') ?>
					</button>
				</div>
			</div>
		</div>
	</form>

	<script type="text/javascript">

		$("select[name=bank_method]").change(function(){
			var val = $(this).val();
			$('.checkout-bank-details .bank-details-card').addClass('d-none');
			$('.checkout-bank-details .bank-details-card').eq(val).removeClass('d-none');
		});

		$("select[name=bank_method]").val('0').trigger("change");

		$('#btn-confirm').on('click',function(){
			$this = $(this);

			<?php if($settingData['proof'] == 2){ ?>
				if($('input[name="payment_proof"]').val() == "") {
					alert('<?= __('user.payment_proof_required'); ?>');
					return false
				}
			<?php } ?>

			var formData = new FormData();
			formData.append('payment_proof', ($('input[type=file][name=payment_proof]')[0] ? $('input[type=file][name=payment_proof]')[0].files[0] : null));
 
			$.ajax({
				url:'<?= base_url("membership/confirm_plan") ?>',
				type:'POST',
				dataType:'json',
				data:formData,
				contentType: false,
	    		processData: false,
	    		beforeSend:function(){$this.btn("loading");$this.attr("disabled","disabled");},
				complete:function(){$this.btn("reset");$this.removeAttr("disabled");},
				success:function(json){
 					$this.removeAttr("disabled");
					if(json['redirect'])
						window.location = json['redirect'];

					if(json['warning'])
						alert(json['warning']);
				},
			});  
		})
	</script>
<?php } ?>