<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/css-file/u1.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css" />
    <link href='https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css' rel='stylesheet'>
    <title>Update Attendance</title>
</head>
<body id="body">
    <%- include('navbar') %>

    <main class="main-content">
        <div class="container">
            <h2>Update Attendance</h2>
            <form action="/submitAttendance" method="POST">
                <input type="hidden" name="date" value="<%= date %>">
                <input type="hidden" name="course_id" value="<%= course_id %>">
                <table class="table">
                    <thead>
                        <tr>
                            <th>Student ID</th>
                            <th>Student Name</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <% students.forEach(student => { %>
                            <tr>
                                <td><%= student.id %></td>
                                <td><%= student.name %></td>
                                <td>
                                    <input type="checkbox" name="attendance[<%= student.id %>][status]" value="present" 
                                    <%= attendance && attendance.attendance_list.some(att => att.student_id === student.id && att.status === 'present') ? 'checked' : '' %>>
                                    Present
                                    <input type="hidden" name="attendance[<%= student.id %>][student_id]" value="<%= student.id %>">
                                </td>
                            </tr>
                        <% }); %>
                    </tbody>
                </table>
                <button type="submit">Update Attendance</button>
            </form>
        </div>
    </main>
</body>
</html>
