<?php

include_once('includes/app.php');
include_once('includes/functions.php');
include('includes/header.php');


// Handle search query
$searchQuery = isset($_GET['search']) ? $_GET['search'] : '';

// Fetch persons from the database
$persons = getPersons($searchQuery);


?>



		<div class="container mt-5">

			<!-- Search form -->
			<form method="GET" action="index.php" class="mb-4" autocomplete="off">
				<div class="input-group">
					<input type="text" name="search" class="form-control" placeholder="Search for persons" value="<?php echo htmlspecialchars($searchQuery); ?>">
					<button class="btn btn-primary" type="submit">
						<i class="bi bi-search"></i> Search
					</button>
				</div>
			</form>

			<!-- Display persons -->
			<div class="row">
				<?php if (empty($persons)): ?>
					<p class="text-center">No persons found.</p>
				<?php else: ?>
					<?php foreach ($persons as $person): ?>
						<div class="col-6 col-md-4 col-lg-3 mb-4">
							<div class="card">
								<div class="card-body">
									<img src="<?php echo $person['image']; ?>" class="card-img-top" alt="<?php echo $donut['name']; ?>">
									<h5 class="card-title"><?php echo $person['name']; ?></h5>
									<p class="card-text">Age: <?php echo $person['age']; ?></p>
									<p class="card-text">Image: <?php echo $person['image']; ?></p>

								</div>
							</div>
						</div>
					<?php endforeach; ?>
				<?php endif; ?>
			</div>
		</div>
		

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>