<?php

include '../../db_connect.php';

$sql = "SELECT * FROM appointments ORDER BY id DESC";
$result = $conn->query($sql);
?>

<?php include "../layout/header.php";?>

<h2 class="text-center mt-5">Appointments List</h2>
<table id="datatable" class="table table-bordered">
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Phone</th>
            <th>Message</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <?php while ($row = $result->fetch_assoc()) : ?>
        <tr>
            <td><?= $row['id'] ?></td>
            <td><?= $row['name'] ?></td>
            <td><?= $row['phone'] ?></td>
            <td><?= $row['message'] ?></td>
            <td>
                <a href="view.php?id=<?= $row['id'] ?>" class="btn btn-info btn-sm">View</a>
                <button class="btn btn-danger btn-sm delete-btn"
                    data-id="<?= htmlspecialchars($row['id']) ?>">Delete</button>
            </td>
        </tr>
        <?php endwhile; ?>
    </tbody>
</table>

<?php include "../layout/footer.php" ?>

<?php $conn->close();