<?php

require_once '../includes/config.php';

$db = getDB();

$totalLawyers = $db->query("
SELECT COUNT(*) FROM lawyers
")->fetchColumn();

$totalAppointments = $db->query("
SELECT COUNT(*) FROM appointments
")->fetchColumn();

$pendingAppointments = $db->query("
SELECT COUNT(*) 
FROM appointments
WHERE status='pending'
")->fetchColumn();

$recentLawyers = $db->query("
SELECT *
FROM lawyers
ORDER BY id DESC
LIMIT 5
")->fetchAll();

require_once '../includes/header.php';

?>

<section class="section-light py-5">

<div class="container">

<h2 class="fw-bold mb-5">
Admin Dashboard
</h2>

<div class="row">

<div class="col-md-4 mb-4">

<div class="card border-0 shadow">

<div class="card-body">

<h5>Total Lawyers</h5>

<h2>
<?= $totalLawyers ?>
</h2>

</div>

</div>

</div>

<div class="col-md-4 mb-4">

<div class="card border-0 shadow">

<div class="card-body">

<h5>Total Appointments</h5>

<h2>
<?= $totalAppointments ?>
</h2>

</div>

</div>

</div>

<div class="col-md-4 mb-4">

<div class="card border-0 shadow">

<div class="card-body">

<h5>Pending Appointments</h5>

<h2>
<?= $pendingAppointments ?>
</h2>

</div>

</div>

</div>

</div>

<div class="card border-0 shadow mt-4">

<div class="card-body">

<h4 class="mb-4">
Recent Lawyers
</h4>

<div class="table-responsive">

<table class="table table-bordered">

<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Experience</th>
</tr>

<?php foreach($recentLawyers as $lawyer): ?>

<tr>

<td>
<?= htmlspecialchars($lawyer['name']) ?>
</td>

<td>
<?= htmlspecialchars($lawyer['email']) ?>
</td>

<td>
<?= htmlspecialchars($lawyer['mobile']) ?>
</td>

<td>
<?= htmlspecialchars($lawyer['experience_years']) ?>
</td>

</tr>

<?php endforeach; ?>

</table>

</div>

</div>

</div>

</div>

</section>

<?php require_once '../includes/footer.php'; ?>