<div class="container">
	<div class="card">
		<div class="card-header">
			<h3 class=""> <?= $user->name ?> hired jobs </h3>
		</div>
	</div>
</div>

<div class="container">

	<div class="table-responsive">
		<table class="table table-hover">
			<thead>
				<tr>
					<th>SL</th>
					<th>Job Title</th>
					<th>Freelancer</th>
					<th>Budget</th>
					<th>Bid Amount</th>
					<th>Status</th>
					<th>Manage</th>
				</tr>
			</thead>

			<tbody>
				<?php
				if ($jobs) {
					$encodedJob = json_decode($jobs);

					foreach ($encodedJob as $key => $job) : ?>
						<tr>
							<td> <?= ($key + 1) ?></td>
							<td><?= $job->title; ?></td>
							<td><?= $job->bidder_name ?></td>
							<td><?= number_format($job->budget)  ?> Tk</td>
							<td><?= number_format($job->amount) ?> Tk</td>
							<td>
								<?php
								if ($job->isClosed == 0) {
									echo ' <p class="bg-primary form-control payNow"
											style="padding: 5px 10px; border-radius: 10px; text-align: center"> Progressing </p> ';
								} else {
									echo ' <p class="bg-success form-control payNow"
											style="padding: 5px 10px; border-radius: 10px; text-align: center"> Complete </p> ';
								}
								?>
							</td>
							<td>
								<?php
								if ($job->isClosed == 0) {
									echo '
											<button type="button"
												class="bg-success form-control payNow"
												style="padding: 5px 10px; border-radius: 10px; text-align: center"
												data-id="' . $job->job_bid_id . '"
												data-url="https://myadmin.mali-mart.com/api/job/payNow/' . $job->job_bid_id . '"
											>
												Pay Now
											</button>
											<a href="' . base_url() . 'FreelanceController/JobChat/' . $job->job_bid_id . '" 
											class="bg-warning" 
											style="padding: 5px 10px; border-radius: 5px; margin: 2px;display: inline-block"
											target="_blank"
											 > Chat </a>
										';
								}
								?>

							</td>
						</tr>
				<?php
					endforeach;
				}
				?>
			</tbody>

		</table>
	</div>

</div>

<script>
	$(".payNow").click(function() {
		var url = $(this).attr("data-url");
		var id = $(this).attr("data-id");

		$.ajax({
			method: "post",
			url: url,
			data: {
				id: id
			},
			dataType: 'json',
			success: function(res) {

				location.reload();

			},
			error: function(err) {
				console.log(err);
			}
		});

	});
</script>