root = Card([header, live, topTitles, watchTrend, churn, genrePerf, buffering, regionHealth, releases, licenses, recClicks, deadEnds, revenueSplit, deviceSplit, regionFocus, featureFlags, promote], "card", "column", "xl")

header = CardHeader("Streaming Operations", "Live overview of the streaming platform")

live = Card([liveHeader, liveKpis], "sunk")
liveHeader = CardHeader("Now Watching", "Real-time audience")
liveKpis = Table([liveMetric, liveValue])
liveMetric = Col("Metric", ["Viewers now", "Peak today", "Avg session (min)"])
liveValue = Col("Value", ["1,284,392", "1,542,018", "47.3"])

topTitles = Card([topHeader, topChart], "sunk")
topHeader = CardHeader("Most-Watched Titles", "Hours streamed today")
topChart = HorizontalBarChart(["Stranger Nights", "The Crown of Ash", "Neon Harbor", "True Crime Files", "Cosmic Drift"], [topSeries], "grouped", "Hours", "Title")
topSeries = Series("Hours", [41200, 38800, 35400, 29100, 24600])

watchTrend = Card([watchHeader, watchChart], "sunk")
watchHeader = CardHeader("Watch Time", "Past month (millions of hours)")
watchChart = AreaChart(["Aug 1", "Aug 8", "Aug 15", "Aug 22", "Aug 29", "Sep 5"], [watchSeries], "natural", "Date", "M hours")
watchSeries = Series("Watch time", [18.2, 19.4, 21.1, 20.5, 22.8, 24.3])

churn = Card([churnHeader, churnChart], "sunk")
churnHeader = CardHeader("Subscriber Flow", "New vs. cancelled this month")
churnChart = LineChart(["Aug 1", "Aug 8", "Aug 15", "Aug 22", "Aug 29", "Sep 5"], [newSeries, cancelSeries], "linear", "Date", "Subscribers")
newSeries = Series("New", [8200, 9100, 8800, 10400, 11200, 12300])
cancelSeries = Series("Cancellations", [4100, 3900, 4300, 3800, 4200, 3700])

genrePerf = Card([genreHeader, genreChart], "sunk")
genreHeader = CardHeader("Performance by Genre", "Hours watched per genre")
genreChart = BarChart(["Drama", "Comedy", "Sci-Fi", "Documentary", "Kids", "Thriller"], [genreSeries], "grouped", "Genre", "Hours (thousands)")
genreSeries = Series("Hours", [58, 42, 51, 29, 37, 46])

buffering = Card([bufferHeader, bufferKpi], "sunk")
bufferHeader = CardHeader("Buffering Rate", "Global average")
bufferKpi = Table([bufferMetric, bufferValue])
bufferMetric = Col("Metric", ["Buffering rate", "Target", "Rebuffering events / 1k plays"])
bufferValue = Col("Value", ["1.8%", "≤ 2.0%", "14.2"])

regionHealth = Card([regionHeader, regionTable], "sunk")
regionHeader = CardHeader("Delivery Health by Region", "Error rate and latency")
regionTable = Table([regionName, regionErrors, regionLatency])
regionName = Col("Region", ["North America", "Europe", "Asia-Pacific", "Latin America", "Africa", "Middle East"])
regionErrors = Col("Error rate", ["0.4%", "0.6%", "1.1%", "1.9%", "3.2%", "2.4%"])
regionLatency = Col("Latency (ms)", ["82", "96", "134", "178", "241", "205"])

releases = Card([releaseHeader, releaseList], "sunk")
releaseHeader = CardHeader("Releases This Month", "Upcoming premieres")
releaseList = ListBlock([release1, release2, release3, release4], "number")
release1 = ListItem("Echoes of Tomorrow", "Sep 12 · Sci-Fi series", null, "View details")
release2 = ListItem("The Last Lighthouse", "Sep 18 · Drama film", null, "View details")
release3 = ListItem("Kitchen Legends", "Sep 24 · Docuseries", null, "View details")
release4 = ListItem("Midnight Circuit", "Sep 30 · Thriller series", null, "View details")

licenses = Card([licenseHeader, licenseTable], "sunk")
licenseHeader = CardHeader("Licenses Expiring Soon", "Next 60 days")
licenseTable = Table([licenseTitle, licenseRegion, licenseDate])
licenseTitle = Col("Title", ["Neon Harbor", "Cosmic Drift", "The Cartographer", "Wild Frontier"])
licenseRegion = Col("Region", ["Global", "Europe", "Asia-Pacific", "North America"])
licenseDate = Col("Expires", ["Sep 21", "Oct 5", "Oct 12", "Oct 28"])

recClicks = Card([recHeader, recChart], "sunk")
recHeader = CardHeader("Recommendation Clicks", "Click-through rate over time")
recChart = LineChart(["Aug 1", "Aug 8", "Aug 15", "Aug 22", "Aug 29", "Sep 5"], [recSeries], "linear", "Date", "CTR %")
recSeries = Series("CTR", [4.1, 4.4, 4.2, 4.7, 4.9, 5.2])

deadEnds = Card([deadHeader, deadChart], "sunk")
deadHeader = CardHeader("Searches Without Playback", "Top dead-end queries")
deadChart = HorizontalBarChart(["'space movie'", "'90s comedy'", "'anime dubs'", "'true crime uk'", "'holiday films'"], [deadSeries], "grouped", "Searches", "Query")
deadSeries = Series("Searches", [12400, 9800, 8700, 6500, 5400])

revenueSplit = Card([revHeader, revPie], "sunk")
revHeader = CardHeader("Revenue Split by Plan", "Share of MRR")
revPie = PieChart(["Premium", "Standard", "Basic", "Ad-supported"], [48, 31, 14, 7], "donut")

deviceSplit = Card([deviceHeader, devicePie], "sunk")
deviceHeader = CardHeader("Viewing Split by Device", "Share of watch time")
devicePie = PieChart(["Smart TV", "Mobile", "Tablet", "Web", "Console"], [41, 28, 14, 11, 6], "pie")

regionFocus = Card([focusHeader, focusForm], "sunk")
focusHeader = CardHeader("Focus on One Region", "Drill into a single region's metrics")
focusForm = Form("region-focus", focusButtons, [regionField])
regionField = FormControl("Region", regionSelect)
regionSelect = Select("region", [regionNA, regionEU, regionAP, regionLA, regionAF, regionME], "Select a region")
regionNA = SelectItem("NA", "North America")
regionEU = SelectItem("EU", "Europe")
regionAP = SelectItem("AP", "Asia-Pacific")
regionLA = SelectItem("LA", "Latin America")
regionAF = SelectItem("AF", "Africa")
regionME = SelectItem("ME", "Middle East")
focusButtons = Buttons([focusBtn])
focusBtn = Button("Apply region filter", null, "primary")

featureFlags = Card([flagHeader, flagList], "sunk")
flagHeader = CardHeader("Feature Flags", "Current state of each flag")
flagList = Table([flagName, flagState])
flagName = Col("Flag", ["4K HDR", "Download offline", "Kids profile", "Live sports", "AI subtitles", "Group watch"])
flagState = Col("State", ["On", "On", "On", "Beta", "Off", "Off"])

promote = Card([promoteHeader, promoteForm], "sunk")
promoteHeader = CardHeader("Promote a Title", "Feature on the home screen")
promoteForm = Form("promote-title", promoteButtons, [promoteField, promoteSlot])
promoteField = FormControl("Title", promoteSelect, "Choose a title to promote")
promoteSelect = Select("title", [promote1, promote2, promote3], "Select a title")
promote1 = SelectItem("stranger-nights", "Stranger Nights")
promote2 = SelectItem("crown-of-ash", "The Crown of Ash")
promote3 = SelectItem("neon-harbor", "Neon Harbor")
promoteSlot = FormControl("Placement", promoteRadio, "Where should it appear?")
promoteRadio = RadioGroup("placement", [slotHero, slotRow, slotRow2])
slotHero = RadioItem("Hero banner", "Top of the home screen", "hero")
slotRow = RadioItem("Featured row", "Second row of the home screen", "row")
slotRow2 = RadioItem("Continue row", "Below in-progress titles", "continue")
promoteButtons = Buttons([promoteBtn, promoteCancel])
promoteBtn = Button("Promote now", null, "primary")
promoteCancel = Button("Cancel", null, "tertiary")