root = Card([header, controls, kpis, engagementCard, coursesCard, riskCard], "card", "column", "l")
header = CardHeader("Training Analytics", "Live overview · Fall 2025 cohort")
controls = Card([cohortForm, messageDrawer], "clear", "row", "m", "end", "between")
cohortForm = Form("cohort_filter", filterButtons, [cohortField])
filterButtons = Buttons([applyBtn])
applyBtn = Button("Apply filter", null, "primary")
cohortField = FormControl("Cohort", cohortSelect, "Narrow all analytics to one cohort")
cohortSelect = Select("cohort", [cohAll, cohSpring, cohSummer, cohFall], "Choose a cohort", null, "all")
cohAll = SelectItem("all", "All cohorts")
cohSpring = SelectItem("spring-2025", "Spring 2025")
cohSummer = SelectItem("summer-2025", "Summer 2025")
cohFall = SelectItem("fall-2025", "Fall 2025")
messageDrawer = DrawerBlock("Message cohort", "Message the current cohort", "Send an announcement or an early-intervention nudge to the learners in the active cohort filter.", [messageForm])
messageForm = Form("cohort_message", messageButtons, [subjectField, messageField])
messageButtons = Buttons([sendBtn, cancelMsgBtn])
sendBtn = Button("Send to cohort", null, "primary")
cancelMsgBtn = Button("Cancel", null, "tertiary")
subjectField = FormControl("Subject", subjectInput)
subjectInput = Input("subject", "e.g., Week 4 quiz closes Friday")
messageField = FormControl("Message", messageTextarea, "Delivered to 1,284 learners in the current cohort")
messageTextarea = TextArea("message", "Write your message…", 6)
kpis = Card([activeKpi, completionKpi, quizKpi], "clear", "row", "m")
activeKpi = Card([activeValue, activeLabel], "sunk")
activeValue = TextContent("1,284", "large-heavy")
activeLabel = TextContent("Active learners this week", "small")
completionKpi = Card([completionValue, completionLabel], "sunk")
completionValue = TextContent("86%", "large-heavy")
completionLabel = TextContent("Course completion rate", "small")
quizKpi = Card([quizValue, quizLabel], "sunk")
quizValue = TextContent("78%", "large-heavy")
quizLabel = TextContent("Average quiz score", "small")
engagementCard = Card([engagementHeader, engagementChart], "sunk")
engagementHeader = CardHeader("Engagement over the past 8 weeks", "Active learners and quiz attempts per week")
engagementChart = AreaChart(["W1", "W2", "W3", "W4", "W5", "W6", "W7", "W8"], [activeSeries, quizSeries], "linear", "Week", "Learners")
activeSeries = Series("Active learners", [980, 1040, 1100, 1210, 1180, 1250, 1300, 1284])
quizSeries = Series("Quiz attempts", [310, 360, 410, 480, 520, 560, 610, 645])
coursesCard = Card([coursesHeader, enrollmentChart], "sunk")
coursesHeader = CardHeader("Courses ranked by enrollment", "Headcount per course, highest first")
enrollmentChart = HorizontalBarChart(["Data Science with Python", "UX Research Fundamentals", "AWS Cloud Practitioner Prep", "Agile Project Management", "Financial Modeling in Excel", "Digital Marketing Essentials"], [enrollmentSeries])
enrollmentSeries = Series("Enrolled learners", [412, 356, 298, 251, 204, 167])
riskCard = Card([riskHeader, riskAlert, riskTable], "sunk")
riskHeader = CardHeader("Learners at risk of dropping out", "Top 5 flagged learners in the current cohort")
riskAlert = Callout("warning", "12 learners at risk", "7 have been inactive for 10+ days and 5 scored below 60% on the latest quiz.")
riskTable = Table([riskLearner, riskCourse, riskScore, riskDays])
riskLearner = Col("Learner", ["Aisha Patel", "Marcus Chen", "Sofia Reyes", "Dmitri Volkov", "Emma Thompson"])
riskCourse = Col("Course", ["Data Science with Python", "AWS Cloud Practitioner Prep", "UX Research Fundamentals", "Financial Modeling in Excel", "Digital Marketing Essentials"])
riskScore = Col("Risk score", [92, 87, 81, 79, 74], "number")
riskDays = Col("Days inactive", [12, 9, 6, 5, 3], "number")