<?php
// --- rider_list.php ---
include 'db.php';
include 'layout.php';
?>
<body>
<div class="main-wrapper">
	<div class="page-wrapper">
		<div class="content">
			<div class="page-header">
				<div class="page-title">
					<h4>Rider List</h4>
					<h6>Manage your delivery riders</h6>
				</div>
				<div class="page-btn">
					<a href="#" class="btn btn-added" data-bs-toggle="modal" data-bs-target="#addRiderModal">
						<i class="fa fa-plus me-2"></i>Add Rider
					</a>
				</div>
			</div>

			<div class="card">
				<div class="card-body">
					<table class="table datatable table-bordered">
						<thead>
							<tr>
								<th>Name</th>
								<th>Phone</th>
								<th>Email</th>
								<th>Vehicle</th>
								<th>Status</th>
								<th>Actions</th>
							</tr>
						</thead>
						<tbody>
						<?php
						$res = $conn->query("SELECT * FROM delivery_riders ORDER BY id DESC");
						while ($row = $res->fetch_assoc()) {
							echo "<tr>
								<td>{$row['name']}</td>
								<td>{$row['phone']}</td>
								<td>{$row['email']}</td>
								<td>{$row['vehicle_number']}</td>
								<td>" . ($row['is_active'] ? 'Active' : 'Inactive') . "</td>
								<td>
									<a href='edit_rider.php?id={$row['id']}' class='btn btn-sm btn-primary'>
										<i class='fas fa-edit'></i> Edit
									</a>
								</td>
							</tr>";
						}
						?>
						</tbody>
					</table>
				</div>
			</div>

			<!-- Add Rider Modal -->
			<div class="modal fade" id="addRiderModal" tabindex="-1">
				<div class="modal-dialog">
					<form method="POST" action="add_rider.php" class="modal-content">
						<div class="modal-header">
							<h5 class="modal-title">Add Rider</h5>
							<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
						</div>
						<div class="modal-body">
							<div class="mb-2"><label>Name</label><input type="text" name="name" class="form-control" required></div>
							<div class="mb-2"><label>Phone</label><input type="text" name="phone" class="form-control"></div>
							<div class="mb-2"><label>Email</label><input type="email" name="email" class="form-control"></div>
							<div class="mb-2"><label>Vehicle Number</label><input type="text" name="vehicle_number" class="form-control"></div>
							<div class="form-check mb-2">
								<input class="form-check-input" type="checkbox" name="is_active" id="active" checked>
								<label class="form-check-label" for="active">Active</label>
							</div>
						</div>
						<div class="modal-footer"><button type="submit" class="btn btn-primary">Save Rider</button></div>
					</form>
				</div>
			</div>

		</div>
	</div>
</div>
</body>
</html>