/* ================================================================== Overview → Staff Attendance ------------------------------------------------------------------ The heat-map from the reference design, driven by teacher_attendance. ONE THING TO UNDERSTAND BEFORE READING A NUMBER HERE: rows in teacher_attendance are written when a teacher checks in on the mobile app. A day with no row therefore means "nothing was recorded", which is NOT the same as "absent" — and the backend keeps the two apart ('unrecorded' vs 'leave'). This screen never colours an unrecorded day red, and it suppresses the headline average entirely when check-in coverage is too thin to average honestly. A confident 43% would be a lie about people's jobs. ================================================================== */ const StaffAttendanceScreen = ({ setScreen }) => { const CX = window.CX; const [period, setPeriod] = useState("monthly"); const state = CX.useCockpitData(`/admin/cockpit/staff-attendance?period=${period}`); const d = state.data; const exportCsv = () => { if (!d) return; const head = ["Name", "Role", "Subjects", "Days present", "Days on leave", "Holidays", "Working days in window", "Recorded %"]; const body = d.rows.map((r) => [ r.name, r.role, r.subjects || "", r.presentDays, r.leaveDays, r.holidayDays ?? 0, r.workDays, `${r.recordedPct}%`, ]); CX.exportCsv(`staff-attendance-${period}.csv`, [head, ...body]); }; const LEGEND = [ { label: "Present", cls: "present" }, { label: "On leave", cls: "leave" }, { label: "No record", cls: "unrecorded" }, { label: "Holiday", cls: "holiday" }, { label: "Weekend", cls: "weekend" }, ]; return (