<?php include 'common/header.php'; ?>

<div class="container-fluid">
    <div class="row">
        <!-- Sidebar (should already be in header.php) -->

        <!-- Main content area -->
        <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
            <div class="pt-3">
                <h4>Employee Attendance Records</h4>

                <div class="table-responsive mt-4">
                    <table class="table table-bordered table-striped">
                        <thead class="table-dark">
                            <tr>
                                <th>Employee ID</th>
                                <th>Name</th>
                                <th>Date</th>
                                <th>Login Time</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $sql = "SELECT id, fname, lname, register_at FROM register";
                            $result = $conn->query($sql);

                            if ($result->num_rows > 0) {
                                while ($row = $result->fetch_assoc()) {
                                    $date = date('Y-m-d', strtotime($row['register_at']));
                                    $time = date('H:i:s', strtotime($row['register_at']));
                                    echo "<tr>
                                            <td>{$row['id']}</td>
                                            <td>{$row['fname']} {$row['lname']}</td>
                                            <td>{$date}</td>
                                            <td>{$time}</td>
                                        </tr>";
                                }
                            } else {
                                echo "<tr><td colspan='4'>No records found</td></tr>";
                            }

                            $conn->close();
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </main>
    </div>
</div>

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