<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
  	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Admin Log in</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="icon" href="<?php echo base_url(); ?>assets/platformthreequarters/dist/img/favicon.ico">

	<!-- Font Awesome -->
	<link rel="stylesheet" href="<?php echo $this->config->item('admin_assets_folder'); ?>plugins/fontawesome-free/css/all.min.css">
	<!-- Ionicons -->
	<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
	<!-- icheck bootstrap -->
	<link rel="stylesheet" href="<?php echo $this->config->item('admin_assets_folder'); ?>plugins/icheck-bootstrap/icheck-bootstrap.min.css">
	<!-- Theme style -->
	<link rel="stylesheet" href="<?php echo $this->config->item('admin_assets_folder'); ?>dist/css/adminlte.min.css">
	<link rel="stylesheet" href="<?php echo $this->config->item('admin_assets_folder'); ?>dist/css/style.css">
	<!-- Google Font: Source Sans Pro -->
	<!-- <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet"> -->

	<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
	<link href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500;700&display=swap" rel="stylesheet">
</head>
<body class="hold-transition login-page">

	<div class="login-box">
		<div class="login-logo">
			<a href="<?php echo base_url().$this->config->item('admin_folder'); ?>"><b>TFI Lead Generation </b></a>
		</div>


		<div class="card">
			<div class="card-body login-card-body">
				<p class="login-box-msg">Sign in to start your session</p>

				<div class="error">
					<span id="login_error"></span>
				</div>

				<form name="form_submit" action="javascript:;"  method="POST" id="form_submit" data-parsley-validate="">
					<div class="input-group">
						<input type="text" class="form-control" placeholder="OTP" name="email_otp" autocomplete="off" required="" data-parsley-trigger="keyup" data-parsley-errors-container="#email_otp_error" />
					</div>
					<div class="error mb-3">
						<span id="email_otp_error"></span>
					</div>
					<div class="row">
						<div class="col-8">
						
						</div>
						<!-- /.col -->
						<div class="col-4">
							<button type="submit" class="btn btn-primary btn-block">Verify</button>
						</div>
						<!-- /.col -->
					</div>
				</form>
			</div>
		</div>
	</div>

	<script src="<?php echo $this->config->item('admin_assets_folder'); ?>plugins/jquery/jquery.min.js"></script>
	<!-- Bootstrap 4 -->
	<script src="<?php echo $this->config->item('admin_assets_folder'); ?>plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
	<script src="<?php echo $this->config->item('admin_assets_folder'); ?>dist/js/parsley.js"></script>

	<script type="text/javascript">
		$('#form_submit').parsley().on('field:validated', function() {
	        var ok = $('.parsley-error').length === 0;
	        $('.bs-callout-info').toggleClass('hidden', !ok);
	        $('.bs-callout-warning').toggleClass('hidden', ok);
	    })
	    .on('form:submit', function() {
	        var formData = new FormData($("#form_submit")[0]);
	        var base_url = '<?php echo base_url().$this->config->item('admin_folder'); ?>';
	        var id = $("#id").val();
	        var url = base_url+"/verify-email?token=<?php echo $_GET['token']; ?>";

	        $("#login_error").html("");

	        $.ajax({
	            type: "POST",
	            dataType: "json",
	            url: url,
	            data: formData,
	            //async: false,
	            global : false,
	            cache: false,
	            contentType: false,
	            processData: false,
	            success: function(result) {
	            	if(result["status"] === false){

	            		if(result["errors"]){
	            			$.each(result["errors"], function(i, v) {
		                        $("#"+i+"_error").html(v);
		                    });
	            		}else{
	           				$("#login_error").html(result["message"]);
	           			}
	            	}else{
	                    location.href = result["redirect_url"];
	                }
	            },
	            error: function() {
	            	$("#login_error").html("Failed to perfom this action");
	            }
	        });
	    });
	</script>
</body>
</html>