<?php
require_once __DIR__ . '/includes/auth.php';
requireLogin();

$conn = getDBConnection();
$result = $conn->query("SELECT * FROM services WHERE active = 1 ORDER BY category, name");

$services = [];
while ($row = $result->fetch_assoc()) {
    $services[$row['category']][] = $row;
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Book Services - Oldage Home</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <?php include 'includes/header.php'; ?>

    <section class="py-5">
        <div class="container">
            <div class="row">
                <div class="col">
                    <h1 class="mb-4">Book Our Services</h1>
                    <p class="lead mb-5">Select from our range of professional care services</p>
                </div>
            </div>

            <?php foreach ($services as $category => $categoryServices): ?>
            <div class="row mb-5">
                <div class="col">
                    <h3 class="mb-4"><?php echo htmlspecialchars($category); ?> Services</h3>
                    <div class="row g-4">
                        <?php foreach ($categoryServices as $service): ?>
                        <div class="col-lg-4 col-md-6">
                            <div class="card h-100 border-0 shadow-sm">
                                <div class="card-body d-flex flex-column">
                                    <h5 class="card-title"><?php echo htmlspecialchars($service['name']); ?></h5>
                                    <p class="card-text flex-grow-1"><?php echo htmlspecialchars($service['description']); ?></p>
                                    <div class="mt-auto">
                                        <div class="d-flex justify-content-between align-items-center mb-3">
                                            <span class="h5 text-primary mb-0">$<?php echo number_format($service['price'], 2); ?></span>
                                            <small class="text-muted"><?php echo htmlspecialchars($service['duration']); ?></small>
                                        </div>
                                        <a href="book-service.php?id=<?php echo $service['id']; ?>" class="btn btn-primary w-100">Book Now</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
    </section>

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

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

