<div class="page-header" id="page">
	<h3 class="page-title center">
		<span class="page-title-icon bg-gradient-primary text-white mr-2">
			<i class="mdi mdi-worker"></i>
		</span>
		Paid Task
	</h3>

</div>

<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">
			<div class="row ">

				<div class="col-md-12 ">
					<h3 class="text-center">Paid Task</h3>
					<div class="p-4 border20 bg-gradient-gray card-img-holder shadow">
						<p class="p-1" style="line-height: 22px"><?= $setting->rule_one ?></p>
					</div>

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

				<div class="row ">
					<div class="col-md-8 offset-2 ">
						<iframe width="560" " height=" 315" src="<?= $setting->video_link ?>" frameborder="0" allow="accelerometer; autoplay;
					encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
					</div>
				</div>
				<br><br>

				<div class="row">
					<div class="col-md-8 offset-2">
						<h3 class="text-center"><img src="https://admin.work.mali-mart.com/uploads/social/<?= $task->logo ?>" width="45px" height="40px"> <?= $task->category_name ?>
						</h3>
					</div>
					<div class="col-md-12">
						<div class="p-4 border20 bg-gradient-gray card-img-holder shadow">

							<p class="p-1" style="line-height: 22px"><?= $task->note ?></p>
						</div>

					</div>
				</div>


				<div class="row ">

					<?php foreach ($tasks as $key => $task) : ?>
						<?php $key++ ?>
						<div class="col-md-6 mt-5">
							<h2>Task <?= $key ?></h2>


							<textarea class="border20 bg-gradient-gray card-img-holder shadow " id="task_<?= $task->id ?>" cols="60" rows="7" readonly><?= $task->task ?></textarea><br>
							<button id="copy_<?= $task->id ?>" onclick="copy_to_text(<?= $task->id ?>)" class="btn btn-outline-info btn-rounded">Copy
							</button>

						</div>
					<?php endforeach; ?>
				</div>
				<br><br>
				<div class="row">

					<div class="col-md-6 offset-3 justify-content-center">
						<h4 class="text-center">প্রমান সাবমিট করুন </h4><br>
						<?php foreach ($tasks as $key => $task) : ?>
							<?php $key++; ?>
							<label class="radio-inline"><input class="task" type="radio" id="task" name="task" value="<?= $task->id ?>">&nbsp;
								Task <?= $key ?> &nbsp;&nbsp;
							</label>
						<?php endforeach; ?>
					</div>
					<div class="col-md-6 offset-3 ">
						<input type="text" class="form-control shadow border-5" id="u" placeholder="Enter The Url"><br>
					</div>
					<div class="col-md-6 offset-3">
						<button onclick="taskSubmit()" class="btn btn-outline-info">Submit</button>
					</div>

				</div>

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

<script>
	function copy_to_text(id) {
		document.getElementById('task_' + id).select();
		document.execCommand('copy');

		document.getElementById('copy_' + id).innerHTML = 'Copied !';
		setTimeout(() => {
			document.getElementById('copy_' + id).innerHTML = 'Copy'
		}, 2000);
	}

	function taskSubmit() {
		let base_url = "<?= base_url() ?>";
		let task_id = document.querySelector("input[name=task]:checked");
		var url = document.getElementById("u").value;
		if (confirm('Are Sure to submit task?')) {
			let urlCheck = is_url(url);
			if (task_id == null) {
				alert("Select Your Task ");
				return false;
			} else if (urlCheck !== true) {
				alert("Your url is invalid !!");
				return false;
			} else {
				$.ajax({
					type: "post",
					url: "<?= base_url('MarketingTaskCtrl/task_store') ?>",
					data: {
						task_id: task_id.value,
						url: url
					},
					dataType: "json",
					success: function(response) {

						if (response.success == 1) {

							location.reload();
							window.location.href = base_url + '/MarketingTaskCtrl/task_view#page';
						} else if (response.success == 2) {
							location.reload();
							window.location.href = base_url + '/MarketingTaskCtrl/task_view#page';
						} else {
							alert("sometimes server error please reoad page and try again");
						}

					}
				});
			}

		}

	}

	function is_url(str) {
		regexp = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/;
		if (regexp.test(str)) {
			return true;
		} else {
			return false;
		}
	}
</script>