<%- include('../partials/app-start') %>
<header class="topbar"><div><p class="kicker">Reporting</p><h1>Attendance reports</h1><p class="muted">Filter actual attendance data without fixed office-time rules.</p></div><a class="btn btn-primary" href="/admin/reports/export.csv?start=<%= start %>&end=<%= end %>">Export CSV</a></header>
<section class="panel filter-panel"><form class="filters" method="get"><label>From<input type="date" name="start" value="<%= start %>"></label><label>To<input type="date" name="end" value="<%= end %>"></label><label>Employee<select name="employee"><option value="">All employees</option><% employees.forEach(e=>{ %><option value="<%= e.id %>" <%= String(employeeId)===String(e.id)?'selected':'' %>><%= e.name %></option><% }) %></select></label><button class="btn btn-secondary">Apply filters</button></form></section>
<section class="metric-grid five"><article class="metric"><span>Sessions</span><strong><%= totals.sessions %></strong><small>Attendance days</small></article><article class="metric"><span>Session time</span><strong><%= fmtDuration(totals.session) %></strong><small>Total elapsed</small></article><article class="metric"><span>Effective work</span><strong><%= fmtDuration(totals.work) %></strong><small>Minus lunch + breaks</small></article><article class="metric"><span>Lunch</span><strong><%= fmtDuration(totals.lunch) %></strong><small>Total lunch time</small></article><article class="metric"><span>Breaks</span><strong><%= fmtDuration(totals.break) %></strong><small><%= totals.breakCount %> total breaks</small></article></section>
<section class="panel table-panel"><div class="table-wrap"><table><thead><tr><th>Date</th><th>Employee</th><th>Clock in</th><th>Clock out</th><th>Lunch</th><th>Breaks</th><th>Count</th><th>Effective work</th><th>Record</th></tr></thead><tbody>
<% if(!rows.length){ %><tr><td colspan="9"><div class="empty">No attendance records match these filters.</div></td></tr><% } %>
<% rows.forEach(r=>{ const work=Math.max(0,Number(r.session_seconds)-Number(r.lunch_seconds)-Number(r.break_seconds)); %><tr><td><strong><%= r.attendance_date %></strong></td><td><div class="person"><div class="avatar sm"><%= r.name.slice(0,1) %></div><div><strong><%= r.name %></strong><small><%= r.email %></small></div></div></td><td><%= fmtTime(r.clock_in) %></td><td><%= fmtTime(r.clock_out) %></td><td><%= fmtDuration(r.lunch_seconds) %></td><td><%= fmtDuration(r.break_seconds) %></td><td><%= r.break_count %></td><td><strong><%= fmtDuration(work) %></strong></td><td><span class="badge <%= !r.clock_out || r.open_activities ? 'warn':'good' %>"><%= !r.clock_out?'Open':'Complete' %></span></td></tr><% }) %>
</tbody></table></div></section>
<%- include('../partials/app-end') %>
