root = Card([header, cohortFilter, kpiRow, enrollmentChart, engagementChart, atRiskSection, messageCohortDialog])
header = CardHeader("Training Platform Analytics", "Weekly cohort performance overview")
cohortFilter = Form("cohort-filter", filterButtons, [cohortField])
cohortField = FormControl("Select Cohort", cohortSelect, "Filter all metrics by cohort")
cohortSelect = Select("cohort", cohortOptions, "All cohorts")
cohortOptions = [optAll, optNewHires, optEngineering, optSales, optMarketing]
optAll = SelectItem("all", "All Cohorts")
optNewHires = SelectItem("new-hires", "New Hires Q1")
optEngineering = SelectItem("eng", "Engineering")
optSales = SelectItem("sales", "Sales Team")
optMarketing = SelectItem("marketing", "Marketing")
filterButtons = Buttons([applyFilterBtn])
applyFilterBtn = Button("Apply", null, "primary")
kpiRow = Card([activeLearnersCard, completionRateCard, avgQuizCard], "clear", "row", "m")
activeLearnersCard = Card([activeLearnersLabel, activeLearnersValue], "sunk", "column", "s")
activeLearnersLabel = TextContent("Active Learners This Week", "small")
activeLearnersValue = TextContent("1,247", "large-heavy")
completionRateCard = Card([completionRateLabel, completionRateValue], "sunk", "column", "s")
completionRateLabel = TextContent("Course Completion Rate", "small")
completionRateValue = TextContent("78%", "large-heavy")
avgQuizCard = Card([avgQuizLabel, avgQuizValue], "sunk", "column", "s")
avgQuizLabel = TextContent("Average Quiz Score", "small")
avgQuizValue = TextContent("84.2", "large-heavy")
enrollmentChart = Card([enrollmentHeading, enrollmentBarChart], "sunk")
enrollmentHeading = Heading("Courses Ranked by Enrollment", "h3")
enrollmentBarChart = HorizontalBarChart(enrollmentLabels, [enrollmentSeries], "grouped", "Enrollments", "Course")
enrollmentLabels = ["Python Fundamentals", "Data Analysis", "Web Dev Bootcamp", "ML Intro", "DevOps Basics", "Cloud Architecture", "React Advanced"]
enrollmentSeries = Series("Enrollments", [342, 287, 256, 198, 167, 134, 98])
engagementChart = Card([engagementHeading, engagementAreaChart], "sunk")
engagementHeading = Heading("Engagement Across Past 8 Weeks", "h3")
engagementAreaChart = AreaChart(engagementLabels, [engagementSessions, engagementCompletions], "natural", "Week", "Count")
engagementLabels = ["W1", "W2", "W3", "W4", "W5", "W6", "W7", "W8"]
engagementSessions = Series("Sessions", [1240, 1380, 1450, 1520, 1480, 1610, 1590, 1720])
engagementCompletions = Series("Completions", [320, 380, 410, 450, 430, 490, 470, 520])
atRiskSection = Card([atRiskHeading, atRiskTable], "sunk")
atRiskHeading = Heading("Learners at Risk of Dropping Out", "h3")
atRiskTable = Table([atRiskName, atRiskCohort, atRiskLastActive, atRiskCourses, atRiskScore, atRiskAction])
atRiskName = Col("Learner", ["Sarah Chen", "Marcus Johnson", "Priya Patel", "James Wilson", "Lisa Zhang", "David Kim", "Emma Brown", "Alex Rivera"])
atRiskCohort = Col("Cohort", ["Engineering", "Sales", "New Hires Q1", "Marketing", "Engineering", "Sales", "New Hires Q1", "Marketing"])
atRiskLastActive = Col("Days Inactive", [14, 11, 18, 9, 16, 12, 20, 10])
atRiskCourses = Col("Courses Started", [3, 2, 4, 1, 3, 2, 5, 2])
atRiskScore = Col("Avg Quiz Score", [52, 58, 45, 61, 49, 55, 42, 57])
atRiskAction = Col("Action", ["Message", "Message", "Message", "Message", "Message", "Message", "Message", "Message"], "action")
messageCohortDialog = DialogBlock("Message Cohort", "Send Message to Cohort", "Compose and send a message to all learners in the selected cohort", messageDialogContent, "primary")
messageDialogContent = [messageForm]
messageForm = Form("message-cohort", messageButtons, [messageSubjectField, messageBodyField])
messageSubjectField = FormControl("Subject", messageSubjectInput, "Subject line for the message")
messageSubjectInput = Input("subject", "Enter subject")
messageBodyField = FormControl("Message", messageBodyTextarea, "Markdown supported")
messageBodyTextarea = TextArea("body", "Type your message here...", 6)
messageButtons = Buttons([sendMessageBtn, cancelMessageBtn])
sendMessageBtn = Button("Send Message", null, "primary")
cancelMessageBtn = Button("Cancel", null, "tertiary")