﻿Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.IO
Imports Nexamas.UI.Application
Imports Nexamas.UI.Components
Imports Nexamas.UI.Components.DropDownMenu
Imports Nexamas.UI.Controls
Imports Nexamas.UI.FileSystem
Imports Nexamas.UI.Icons
Imports Nexamas.UI.Layout
Imports Nexamas.UI.Localization
Imports Nexamas.UI.Output
Imports Nexamas.UI.Theming
Imports Nexamas.UI.TextInput
Imports Nexamas.UI.Verification
Imports SkiaSharp

Partial Friend NotInheritable Class ShowcasePageHostContentBuilder

    Private Shared Sub BuildPlanningWorkspace(page As MASApplicationLayoutPageBuilder,
                                               window As MASApplicationWindow)
        Dim status As MASLabel = Heading(window, "Planning Workspace: Kanban, agenda, and content carousel")
        Dim intro As MASLabel = Body(window, "This page shows the planning controls as a product workspace. KanbanBoard owns visual columns/cards and selection, AgendaView owns a single-day visual schedule, and ContentCarousel owns featured content navigation. Showcase does not add task storage, workflow engines, recurrence/reminder services, external calendar providers, content providers, auto-rotation timers, adapters, bridges, or native controls.")
        Dim routeCard As MASLabel = InfoCard(window, "Official planning routes", "Window.Controls.AddKanbanBoard(...), AddAgendaView(...), and AddContentCarousel(...) are used directly. State changes update labels and toasts only; no persistence, booking, provider sync, or workflow execution path is created in Showcase.")
        Dim planningBoundary As MASExpander = window.Controls.AddExpander("Developer planning boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                             expander.WithSize(MASSize.FillWidth.OffsetHeight(250.0F))
                                                                                                                                             expander.Add(intro)
                                                                                                                                             expander.Add(routeCard)
                                                                                                                                         End Sub)

        Dim kanbanStatus As MASLabel = Muted(window, "KanbanBoard: selected card changes are visual workspace state only.")
        Dim kanban As MASKanbanBoard = window.Controls.AddKanbanBoard("Release board", Sub(board As MASKanbanBoard)
                                                                                           board.AddColumn("backlog", "Backlog")
                                                                                           board.AddColumn("build", "Build")
                                                                                           board.AddColumn("review", "Review")
                                                                                           board.AddColumn("done", "Done")
                                                                                           board.AddCard("backlog", "nav-rail", "NavigationRail", "Next navigation element candidate", "Next")
                                                                                           board.AddCard("build", "agenda", "AgendaView", "Single-day schedule surface", "Built")
                                                                                           board.AddCard("review", "pivot", "PivotTable", "Cross-tab summary validation", "Review")
                                                                                           board.AddCard("done", "kanban", "KanbanBoard", "Planning surface ready", "Done")
                                                                                           board.SelectCard("pivot")
                                                                                           board.WithSize(MASSize.FillWidth.OffsetHeight(360.0F))
                                                                                       End Sub)
        AddHandler kanban.SelectedCardChanged,
            Sub(sender As Object, e As EventArgs)
                kanbanStatus.Text = "KanbanBoard selected card: " & If(String.IsNullOrWhiteSpace(kanban.SelectedCardKey), "none", kanban.SelectedCardKey)
            End Sub
        AddHandler kanban.CardMoved,
            Sub(sender As Object, e As EventArgs)
                kanbanStatus.Text = "KanbanBoard card moved; Showcase did not persist or execute workflow state."
            End Sub

        Dim agendaStatus As MASLabel = Muted(window, "AgendaView: same-day product schedule with no recurrence or provider sync.")
        Dim agenda As MASAgendaView = window.Controls.AddAgendaView("Design day", New Nullable(Of Date)(New Date(2026, 6, 25)), Sub(view As MASAgendaView)
                                                                                                                                view.WithHours(8, 18)
                                                                                                                                view.AddEvent("standup", "Platform standup", New Date(2026, 6, 25, 8, 30, 0), New Date(2026, 6, 25, 9, 0, 0), "Review active control work.")
                                                                                                                                view.AddEvent("design", "Premium review", New Date(2026, 6, 25, 10, 0, 0), New Date(2026, 6, 25, 11, 30, 0), "Check visual hierarchy and spacing.")
                                                                                                                                view.AddEvent("ship", "Gate package", New Date(2026, 6, 25, 14, 0, 0), New Date(2026, 6, 25, 15, 30, 0), "Prepare static validation package.")
                                                                                                                                view.SelectEvent("design")
                                                                                                                                view.WithSize(MASSize.FillWidth.OffsetHeight(360.0F))
                                                                                                                            End Sub)
        AddHandler agenda.SelectedEventChanged,
            Sub(sender As Object, e As EventArgs)
                agendaStatus.Text = "AgendaView selected event: " & If(String.IsNullOrWhiteSpace(agenda.SelectedEventKey), "none", agenda.SelectedEventKey)
            End Sub

        Dim carouselStatus As MASLabel = Muted(window, "ContentCarousel: featured workspace cards; not an ImageViewer or auto-rotating content provider.")
        Dim carousel As MASContentCarousel = window.Controls.AddContentCarousel("Workspace highlights", Sub(control As MASContentCarousel)
                                                                                                            control.WithLooping(True)
                                                                                                            control.AddItem("analytics", "Analytics now visible", "MetricCard + PivotTable", "Data strength is shown through public Nexamas.UI controls.")
                                                                                                            control.AddItem("planning", "Planning surfaces", "Kanban + Agenda", "Workflow-facing visuals are product-ready without adding engines.")
                                                                                                            control.AddItem("selection", "Selection coverage", "TransferList + Rating", "Specialized controls appear on their natural pages.")
                                                                                                            control.SelectItem("planning")
                                                                                                            control.WithSize(MASSize.FillWidth.OffsetHeight(230.0F))
                                                                                                        End Sub)
        AddHandler carousel.SelectedItemChanged,
            Sub(sender As Object, e As EventArgs)
                carouselStatus.Text = "ContentCarousel selected item: " & If(String.IsNullOrWhiteSpace(carousel.SelectedItemKey), "none", carousel.SelectedItemKey)
            End Sub

        Dim previousCarousel As MASButton = window.Controls.AddButton("Carousel previous")
        Dim nextCarousel As MASButton = window.Controls.AddButton("Carousel next").AsPrimary()
        AddHandler previousCarousel.Click,
            Sub(sender As Object, e As EventArgs)
                carousel.MovePrevious()
                carouselStatus.Text = "ContentCarousel moved previous: " & carousel.SelectedItemKey
            End Sub
        AddHandler nextCarousel.Click,
            Sub(sender As Object, e As EventArgs)
                carousel.MoveNext()
                carouselStatus.Text = "ContentCarousel moved next: " & carousel.SelectedItemKey
            End Sub

        AddShowcaseContent(page, status, MASSize.HugContent)
        AddShowcaseContent(page, Heading(window, "KanbanBoard"), MASSize.HugContent)
        AddShowcaseContent(page, kanban, MASSize.FillWidth)
        AddShowcaseContent(page, kanbanStatus, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "AgendaView"), MASSize.HugContent)
        AddShowcaseContent(page, agenda, MASSize.FillWidth)
        AddShowcaseContent(page, agendaStatus, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "ContentCarousel"), MASSize.HugContent)
        AddShowcaseContent(page, carousel, MASSize.FillWidth)
        AddShowcaseContent(page, carouselStatus, MASSize.FillWidth)
        AddNaturalActionGroup(page, previousCarousel, nextCarousel)
        AddShowcaseContent(page, planningBoundary, MASSize.FillWidth)
    End Sub

    Private Shared Sub BuildProductivityNavigation(page As MASApplicationLayoutPageBuilder,
                                                   window As MASApplicationWindow)
        Dim status As MASLabel = Heading(window, "Productivity / Navigation: rail, menu, command, palette, disclosure, trail, paging, and loading surfaces")
        Dim intro As MASLabel = Body(window, "This page shows the newest premium Nexamas.UI productivity controls as one business workspace recipe. Showcase consumes only public Nexamas.UI routes: AddNavigationRail, shell-owned AddMenuBar, AddCommandBar, AddCommandPalette, AddExpander, AddAccordion, MASToolbar.AddCommand, MASToolbar.AddSplitCommand, MASDropDownMenuBuilder, AddBreadcrumb, FilterBar field/action authoring, AddPagination, and AddLoadingSkeleton. It does not own commands, menus, filtering, paging, loading lifetime, disclosure policy, or data projection.")

        Dim routeCard As MASLabel = InfoCard(window, "Official routes only", "NavigationRail is the compact vertical navigation surface through Window.Controls.AddNavigationRail(...). The wide MainMenuBar above the workspace is attached once by the Showcase shell through Window.Controls.AddMenuBar(...); this page does not host MASMenuBar inside PageHost content. CommandBar is the upgraded MASToolbar surface through Window.Controls.AddCommandBar(...). CommandPalette is the official command-launcher control through Window.Controls.AddCommandPalette(...). Disclosure content uses AddExpander and AddAccordion. Breadcrumb and Pagination are same-surface controls. LoadingSkeleton is visual-only and does not start timers or data loading.")
        Dim boundaryCard As MASLabel = InfoCard(window, "No data ownership", "The sample changes status text and toasts only. It does not mutate DataGrid/DataView sources, create adapters, open popup services, run background tasks, or build parallel command/filter/page engines.")
        Dim productivityBoundary As MASExpander = window.Controls.AddExpander("Developer productivity boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                                 expander.WithSize(MASSize.FillWidth.OffsetHeight(270.0F))
                                                                                                                                                 expander.Add(intro)
                                                                                                                                                 expander.Add(routeCard)
                                                                                                                                                 expander.Add(boundaryCard)
                                                                                                                                             End Sub)

        Dim railStatus As MASLabel = Muted(window, "NavigationRail: selected route is visual navigation state only; Showcase does not create a router or own PageHost destinations.")
        Dim rail As MASNavigationRail = window.Controls.AddNavigationRail("Workspace rail", Sub(control As MASNavigationRail)
                                                                                                  control.WithCompact(False)
                                                                                                  control.AddItem("overview", "Overview", "", "OV")
                                                                                                  control.AddItem("analytics", "Analytics", "4", "AN")
                                                                                                  control.AddItem("planning", "Planning", "", "PL")
                                                                                                  control.AddItem("settings", "Settings", "", "ST")
                                                                                                  control.SelectItem("analytics")
                                                                                                  control.WithSize(MASSize.FillWidth.OffsetHeight(260.0F))
                                                                                              End Sub)
        AddHandler rail.SelectedItemChanged,
            Sub(sender As Object, e As EventArgs)
                railStatus.Text = "NavigationRail selected item: " & If(String.IsNullOrWhiteSpace(rail.SelectedItemKey), "none", rail.SelectedItemKey)
            End Sub

        Dim breadcrumb As MASBreadcrumb = window.Controls.AddBreadcrumb(New String() {"Home", "Sales", "Orders", "June Review"}, Sub(trail As MASBreadcrumb)
                                                                                                                                       trail.WithSelectedIndex(3)
                                                                                                                                       trail.WithSize(MASSize.FillWidth)
                                                                                                                                   End Sub)

        Dim commandBar As MASToolbar = window.Controls.AddCommandBar(Sub(bar As MASToolbar)
                                                                         bar.AddCommand(commandId:="refresh", text:="Refresh", description:="Refresh visible workspace", iconKind:=MASIconKind.Refresh, action:=Sub(button As MASButton)
                                                                                                                                                                                                     status.Text = "CommandBar: Refresh executed through the upgraded MASToolbar command surface."
                                                                                                                                                                                                     window.Services.Toasts.Info("Refresh command executed through AddCommandBar.", "CommandBar")
                                                                                                                                                                                                 End Sub, intent:=MASButtonIntent.Primary)
                                                                         bar.AddSplitCommand(commandId:="export", text:="Export", configureMenu:=Sub(menu As MASDropDownMenuBuilder)
                                                                                                                                                                menu.AddAction("Export PDF", "export.pdf", Sub()
                                                                                                                                                                                                             status.Text = "CommandBar: Export PDF selected from MASSplitButton menu."
                                                                                                                                                                                                             window.Services.Toasts.Success("Export PDF selected through MASDropDownMenuBuilder.", "Split command")
                                                                                                                                                                                                         End Sub, True, "Ctrl+E")
                                                                                                                                                                menu.AddAction("Export Excel", "export.excel", Sub()
                                                                                                                                                                                                                 status.Text = "CommandBar: Export Excel selected from MASSplitButton menu."
                                                                                                                                                                                                                 window.Services.Toasts.Info("Export Excel selected through MASDropDownMenuBuilder.", "Split command")
                                                                                                                                                                                                             End Sub)
                                                                                                                                                                menu.AddSeparator()
                                                                                                                                                                menu.AddAction("Copy link", "export.copy-link", Sub()
                                                                                                                                                                                                                  status.Text = "CommandBar: Copy link selected from MASSplitButton menu."
                                                                                                                                                                                                                  window.Services.Toasts.Info("Copy link selected through the official split-command menu.", "Split command")
                                                                                                                                                                                                              End Sub)
                                                                                                                                                            End Sub, description:="Export selected report with alternate formats", primaryAction:=Sub(button As MASSplitButton)
                                                                                                                                                                                                                 status.Text = "CommandBar: default Export action executed through MASSplitButton primary region."
                                                                                                                                                                                                                 window.Services.Toasts.Success("Default export command executed through AddSplitCommand.", "Split command")
                                                                                                                                                                                                             End Sub, intent:=MASButtonIntent.Primary)
                                                                         bar.AddCommand(commandId:="settings", text:="Settings", description:="Open workspace settings", iconKind:=MASIconKind.Settings, action:=Sub(button As MASButton)
                                                                                                                                                                                                        status.Text = "CommandBar: Settings command stayed on the same Nexamas.UI surface."
                                                                                                                                                                                                        window.Services.Toasts.Info("Settings command preview.", "CommandBar")
                                                                                                                                                                                                    End Sub)
                                                                     End Sub)


        Dim pager As MASPagination = window.Controls.AddPagination(currentPage:=3, totalPages:=24, configure:=Sub(pagination As MASPagination)
                                                                                                                        pagination.WithPageWindow(5)
                                                                                                                        pagination.WithSize(MASSize.FillWidth)
                                                                                                                    End Sub)

        Dim skeletonRows As MASLoadingSkeleton = window.Controls.AddLoadingSkeleton(4, Sub(skeleton As MASLoadingSkeleton)
                                                                                          skeleton.WithRows(4)
                                                                                          skeleton.WithSize(MASSize.FillWidth)
                                                                                      End Sub)
        Dim skeletonCard As MASLoadingSkeleton = window.Controls.AddLoadingSkeleton(1, Sub(skeleton As MASLoadingSkeleton)
                                                                                          skeleton.WithAvatarText(3)
                                                                                          skeleton.WithSize(MASSize.FillWidth)
                                                                                      End Sub)
        Dim skeletonBlock As MASLoadingSkeleton = window.Controls.AddLoadingSkeleton(2, Sub(skeleton As MASLoadingSkeleton)
                                                                                           skeleton.WithBlock(2)
                                                                                           skeleton.WithSize(MASSize.FillWidth)
                                                                                       End Sub)

        Dim commandPalette As MASCommandPalette = window.Controls.AddCommandPalette("Command Palette", Sub(palette As MASCommandPalette)
                                                                                                          palette.WithSize(MASSize.FillWidth.OffsetHeight(260.0F))
                                                                                                          palette.AddCommand("orders.refresh", "Refresh orders", Sub()
                                                                                                                                                                      status.Text = "CommandPalette: Refresh orders executed through the official command-launcher control."
                                                                                                                                                                      window.Services.Toasts.Info("Refresh command executed from MASCommandPalette.", "Command Palette")
                                                                                                                                                                  End Sub, category:="Orders", description:="Refresh the visible workspace")
                                                                                                          palette.AddCommand("orders.export", "Export current report", Sub()
                                                                                                                                                                          status.Text = "CommandPalette: Export current report selected."
                                                                                                                                                                          window.Services.Toasts.Success("Export command preview executed from MASCommandPalette.", "Command Palette")
                                                                                                                                                                      End Sub, category:="Reports", description:="Export the current business report")
                                                                                                          palette.AddCommand("workspace.settings", "Open workspace settings", Sub()
                                                                                                                                                                                status.Text = "CommandPalette: Settings command stayed inside the same Showcase page."
                                                                                                                                                                            End Sub, category:="Workspace", description:="Open settings in a host-owned destination")
                                                                                                          palette.Query = "order"
                                                                                                      End Sub)
        Dim executePaletteCommand As MASButton = window.Controls.AddButton("Execute selected palette command").AsPrimary()

        Dim settingsExpander As MASExpander = window.Controls.AddExpander("Advanced workspace filters", expanded:=True, configure:=Sub(expander As MASExpander)
                                                                                                                                            expander.WithSize(MASSize.FillWidth.OffsetHeight(170.0F))
                                                                                                                                            expander.Add(MASLabel.Create("Expanded content can host Nexamas.UI controls or text without building a custom settings panel. Use it for advanced filters, FAQ details, and long configuration pages."))
                                                                                                                                        End Sub)
        Dim settingsAccordion As MASAccordion = window.Controls.AddAccordion(allowMultipleExpanded:=False, configure:=Sub(accordion As MASAccordion)
                                                                                                                                           accordion.WithSize(MASSize.FillWidth.OffsetHeight(265.0F))
                                                                                                                                           Dim filterSection As MASExpander = accordion.AddSection("Filter presets", True)
                                                                                                                                           filterSection.Add(MASLabel.Create("Saved filters, common views, and workspace presets can be grouped here."))
                                                                                                                                           Dim keyboardSection As MASExpander = accordion.AddSection("Keyboard help", False)
                                                                                                                                           keyboardSection.Add(MASLabel.Create("Command and navigation help can stay available without overcrowding the main workspace."))
                                                                                                                                           Dim boundarySection As MASExpander = accordion.AddSection("Boundary", False)
                                                                                                                                           boundarySection.Add(MASLabel.Create("The accordion orchestrates Expanders; Showcase does not duplicate disclosure state management."))
                                                                                                                                       End Sub)

        Dim coverageMatrix As MASListView = window.Controls.AddListView(configure:=Sub(view As MASListView)
                                                                            view.WithDetailsView()
                                                                            view.StandaloneChrome()
                                                                            view.AddColumn("Surface", 190.0F)
                                                                            view.AddColumn("Showcase route", 330.0F)
                                                                            view.AddColumn("Ownership boundary", 430.0F)
                                                                        End Sub)
        coverageMatrix.WithDefaultSize()
        PopulateProductivityNavigationRows(coverageMatrix)
        Dim coverageExpander As MASExpander = window.Controls.AddExpander("Developer coverage boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                            expander.WithSize(MASSize.FillWidth.OffsetHeight(235.0F))
                                                                                                                                            expander.Add(coverageMatrix)
                                                                                                                                        End Sub)

        AddHandler breadcrumb.SelectedIndexChanged,
            Sub(sender As Object, e As EventArgs)
                status.Text = "Breadcrumb: selected '" & breadcrumb.SelectedText & "' at index " & breadcrumb.SelectedIndex.ToString(CultureInfo.InvariantCulture) & ". Navigation decisions remain owned by the host application."
            End Sub

        AddHandler pager.PageChanged,
            Sub(sender As Object, e As EventArgs)
                status.Text = "Pagination: page " & pager.CurrentPage.ToString(CultureInfo.InvariantCulture) & " of " & pager.TotalPages.ToString(CultureInfo.InvariantCulture) & ". Data loading remains outside the pager control."
            End Sub
        AddHandler commandPalette.SelectionChanged,
            Sub(sender As Object, e As EventArgs)
                status.Text = "CommandPalette: selected command id '" & commandPalette.SelectedCommandId & "'."
            End Sub
        AddHandler executePaletteCommand.Click,
            Sub()
                If Not commandPalette.ExecuteSelectedCommand() Then
                    status.Text = "CommandPalette: no executable command is currently selected."
                End If
                window.Refresh()
            End Sub

        AddShowcaseContent(page, status, MASSize.HugContent)
        AddShowcaseContent(page, Heading(window, "NavigationRail"), MASSize.HugContent)
        AddShowcaseContent(page, rail, MASSize.FillWidth)
        AddShowcaseContent(page, railStatus, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "CommandBar + Breadcrumb"), MASSize.HugContent)
        AddShowcaseContent(page, commandBar, MASSize.FillWidth)
        AddShowcaseContent(page, breadcrumb, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "Command Palette"), MASSize.HugContent)
        AddShowcaseContent(page, commandPalette, MASSize.FillWidth)
        AddNaturalActionGroup(page, executePaletteCommand)
        AddShowcaseContent(page, Heading(window, "Expander + Accordion"), MASSize.HugContent)
        page.Grid(2).Gap(MASLayoutSpacing.Large).EqualItemSize().Add(settingsExpander, MASSize.FillWidth).Add(settingsAccordion, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "Premium FilterBar"), MASSize.HugContent)
        page.FilterBar(Sub(filters As MASApplicationFilterBarLayoutBuilder)
                           filters.Wrap().Gap(MASLayoutSpacing.Medium).HugContent().
                               SearchBox("Search orders...", Sub(box As MASSearchTextBox)
                                                                 box.SetSuggestions(New String() {"status:Ready", "owner:Design", "region:DE", "score>=90"})
                                                             End Sub, MASSize.Compact).
                               ComboBox(New String() {"All statuses", "Ready", "Review", "Blocked"}, 0, Nothing, MASSize.Compact).
                               ComboBox(New String() {"All owners", "Design", "Runtime", "QA"}, 0, Nothing, MASSize.Compact).
                               DatePicker(New Nullable(Of Date)(New Date(2026, 6, 23)), Sub(picker As MASDatePicker)
                                                                                             picker.WithPlaceholder("Due date")
                                                                                             picker.WithSize(MASSize.Compact)
                                                                                         End Sub, MASSize.Compact).
                               ClearAction("Clear", Sub(button As MASButton)
                                                         status.Text = "FilterBar: clear action triggered; host application decides which fields or data projection reset."
                                                     End Sub, Nothing, MASSize.Compact).
                               ApplyAction("Apply", Sub(button As MASButton)
                                                         status.Text = "FilterBar: apply action triggered; no hidden DataGrid adapter or query engine was created."
                                                     End Sub, Nothing, MASSize.Compact)
                       End Sub)
        AddShowcaseContent(page, Heading(window, "Pagination"), MASSize.HugContent)
        AddShowcaseContent(page, pager, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "LoadingSkeleton states"), MASSize.HugContent)
        page.Grid(3).Gap(MASLayoutSpacing.Large).EqualItemSize().Add(skeletonRows, MASSize.FillWidth).Add(skeletonCard, MASSize.FillWidth).Add(skeletonBlock, MASSize.FillWidth)
        AddShowcaseContent(page, productivityBoundary, MASSize.FillWidth)
        AddShowcaseContent(page, coverageExpander, MASSize.FillWidth)
    End Sub

    Private Shared Sub BuildChartDashboard(page As MASApplicationLayoutPageBuilder,
                                                 window As MASApplicationWindow)
        Dim status As MASLabel = Heading(window, "Chart Dashboard: line, bar, donut, KPI, sparkline, and legend")
        Dim intro As MASLabel = Body(window, "MASChart and MASChartLegend are shown as real public business-control surfaces. The Showcase creates charts through Window.Controls.AddChart(...), creates the legend through Window.Controls.AddChartLegend(...), feeds public points/items, and does not import chart foundation snapshots, renderer primitives, legend render plans, or analytics internals.")
        Dim gatewayCard As MASLabel = InfoCard(window, "Public chart gateway", "Each chart below is a MASChart created through the public Window.Controls.AddChart route, and the separate legend is created through Window.Controls.AddChartLegend just like external consumers would.")
        Dim dashboardCard As MASLabel = InfoCard(window, "Dashboard value", "The page proves dashboard and reporting readiness: time series, category comparison, share distribution, headline KPI, and compact trend preview.")
        Dim boundaryCard As MASLabel = InfoCard(window, "Owned renderer boundary", "Chart geometry, tokens, surfaces, and rendering remain Nexamas.UI-owned. Showcase supplies only titles and data points.")
        Dim themeCard As MASLabel = InfoCard(window, "Theme-aware visuals", "Charts are hosted in the same PageHost as the rest of the app, so theme, sizing, and layout are consumed through Nexamas.UI rather than local drawing code.")
        Dim chartBoundary As MASExpander = window.Controls.AddExpander("Developer chart boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                         expander.WithSize(MASSize.FillWidth.OffsetHeight(325.0F))
                                                                                                                                         expander.Add(intro)
                                                                                                                                         expander.Add(gatewayCard)
                                                                                                                                         expander.Add(dashboardCard)
                                                                                                                                         expander.Add(boundaryCard)
                                                                                                                                         expander.Add(themeCard)
                                                                                                                                     End Sub)

        Dim lineChart As MASChart = window.Controls.AddChart(Sub(chart As MASChart)
                                                                 chart.WithLineChart("Monthly revenue")
                                                                 chart.AddPoint("jan", "Jan", 42.0R)
                                                                 chart.AddPoint("feb", "Feb", 48.0R)
                                                                 chart.AddPoint("mar", "Mar", 55.0R)
                                                                 chart.AddPoint("apr", "Apr", 63.0R)
                                                                 chart.AddPoint("may", "May", 71.0R)
                                                                 chart.AddPoint("jun", "Jun", 82.0R)
                                                             End Sub)
        lineChart.WithSize(MASSize.FillWidth)

        Dim barChart As MASChart = window.Controls.AddChart(Sub(chart As MASChart)
                                                                chart.WithBarChart("Control coverage")
                                                                chart.AddPoint("controls", "Controls", 31.0R)
                                                                chart.AddPoint("systems", "Systems", 12.0R)
                                                                chart.AddPoint("gates", "Gates", 18.0R)
                                                                chart.AddPoint("pages", "Pages", 19.0R)
                                                            End Sub)
        barChart.WithSize(MASSize.FillWidth)

        Dim donutChart As MASChart = window.Controls.AddChart(Sub(chart As MASChart)
                                                                  chart.WithDonutChart("Readiness split")
                                                                  chart.AddPoint("ready", "Ready", 76.0R)
                                                                  chart.AddPoint("review", "Review", 18.0R)
                                                                  chart.AddPoint("planned", "Planned", 6.0R)
                                                              End Sub)
        donutChart.WithSize(MASSize.FillWidth)

        Dim kpiChart As MASChart = window.Controls.AddChart(Sub(chart As MASChart)
                                                                chart.WithKpiChart("Commercial readiness")
                                                                chart.AddTrendPoint("score", "Score", 92.4R, 7.8R)
                                                            End Sub)
        kpiChart.WithSize(MASSize.FillWidth)

        Dim sparklineChart As MASChart = window.Controls.AddChart(Sub(chart As MASChart)
                                                                      chart.WithSparklineChart("Frame-time trend")
                                                                      chart.AddPoint("p1", "1", 16.8R)
                                                                      chart.AddPoint("p2", "2", 15.9R)
                                                                      chart.AddPoint("p3", "3", 15.6R)
                                                                      chart.AddPoint("p4", "4", 14.8R)
                                                                      chart.AddPoint("p5", "5", 14.1R)
                                                                      chart.AddPoint("p6", "6", 13.7R)
                                                                  End Sub)
        sparklineChart.WithSize(MASSize.FillWidth)

        Dim legendStatus As MASLabel = Muted(window, "ChartLegend: selected key changes legend state only; it does not couple to MASChart rendering or analytics engines.")
        Dim chartLegend As MASChartLegend = window.Controls.AddChartLegend("Revenue legend", Sub(legend As MASChartLegend)
                                                                                                   legend.AddItem("enterprise", "Enterprise", "€82k")
                                                                                                   legend.AddItem("services", "Services", "€35k")
                                                                                                   legend.AddItem("showcase", "Showcase", "€21k")
                                                                                                   legend.AddItem("planned", "Planned", "€6k")
                                                                                                   legend.SelectItem("enterprise")
                                                                                                   legend.WithSize(MASSize.FillWidth.OffsetHeight(260.0F))
                                                                                               End Sub)
        AddHandler chartLegend.SelectedItemChanged,
            Sub(sender As Object, e As EventArgs)
                legendStatus.Text = "ChartLegend selected key: " & If(String.IsNullOrWhiteSpace(chartLegend.SelectedItemKey), "none", chartLegend.SelectedItemKey)
            End Sub

        Dim refresh As MASButton = window.Controls.AddButton("Refresh chart proof").AsPrimary()
        AddHandler refresh.Click,
            Sub()
                window.Services.Toasts.Success("Chart Dashboard is built from public MASChart data points.", "Chart Dashboard")
            End Sub

        AddShowcaseContent(page, status, MASSize.HugContent)
        page.Grid(2).Gap(MASLayoutSpacing.Large).EqualItemSize().Add(lineChart, MASSize.FillWidth).Add(barChart, MASSize.FillWidth)
        page.Grid(3).Gap(MASLayoutSpacing.Large).EqualItemSize().Add(donutChart, MASSize.FillWidth).Add(kpiChart, MASSize.FillWidth).Add(sparklineChart, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "ChartLegend"), MASSize.HugContent)
        AddShowcaseContent(page, chartLegend, MASSize.FillWidth)
        AddShowcaseContent(page, legendStatus, MASSize.FillWidth)
        AddShowcaseContent(page, chartBoundary, MASSize.FillWidth)
        AddNaturalActionGroup(page, refresh)
    End Sub

    Private Shared Sub BuildPropertyGridInspector(page As MASApplicationLayoutPageBuilder,
                                                  window As MASApplicationWindow)
        Dim status As MASLabel = Heading(window, "PropertyGrid / MasterDetail: categorized public object and entity surfaces")
        Dim intro As MASLabel = Body(window, "MASPropertyGrid and MASMasterDetailView are shown as real public developer-tool and entity-browser controls. The Showcase creates them through Window.Controls.AddPropertyGrid(...) and Window.Controls.AddMasterDetailView(...), adds categorized property rows and entity records, and demonstrates selection/edit feedback without importing property-grid inspector, snapshot, renderer, object-provider, or conversion internals.")
        Dim inspectorStory As MASLabel = InfoCard(window, "Inspector scenario", "PropertyGrid is valuable for design tools, admin settings, diagnostics panels, and future visual editors because it turns object state into a theme-aware MAS surface.")
        Dim editStory As MASLabel = InfoCard(window, "Editable rows", "Boolean rows can be toggled by the control. Text and numeric values are updated below through the public TrySetValue / TrySetValueText surface.")
        Dim boundaryStory As MASLabel = InfoCard(window, "Owned conversion boundary", "Value text, categories, selection behavior, scrolling, and rendering are MASPropertyGrid responsibilities. Showcase does not create a local grid renderer or reflection engine.")
        Dim compositionStory As MASLabel = InfoCard(window, "Composes with other controls", "The page pairs PropertyGrid with MasterDetailView, a MAS-owned EmptyState material surface, buttons, and status labels so the inspector composition stays inside public Nexamas.UI controls.")
        Dim inspectorBoundary As MASExpander = window.Controls.AddExpander("Developer inspector boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                              expander.WithSize(MASSize.FillWidth.OffsetHeight(330.0F))
                                                                                                                                              expander.Add(intro)
                                                                                                                                              expander.Add(inspectorStory)
                                                                                                                                              expander.Add(editStory)
                                                                                                                                              expander.Add(boundaryStory)
                                                                                                                                              expander.Add(compositionStory)
                                                                                                                                          End Sub)
        Dim detailSurface As MASEmptyState = window.Controls.AddEmptyState("Selected component", "Revenue chart — the inspector below edits public rows that describe this dashboard component.", Sub(state As MASEmptyState)
                                                                                                                                                                        state.WithIllustration(False)
                                                                                                                                                                        state.WithSize(MASSize.FillWidth.OffsetHeight(220.0F))
                                                                                                                                                                    End Sub)

        Dim masterStatus As MASLabel = Muted(window, "MasterDetailView: selected record is a visual browser state; no object provider, router, or data-binding engine is created.")
        Dim masterDetail As MASMasterDetailView = window.Controls.AddMasterDetailView("Component browser", Sub(view As MASMasterDetailView)
                                                                                                                view.AddItem("chart", "Revenue chart", "Analytics surface", "Revenue chart", "Line, bar, donut, KPI, sparkline, and legend controls are displayed through public chart routes.", "Chart")
                                                                                                                view.AddItem("grid", "Operations dashboard", "Dashboard surface", "Operations dashboard", "DashboardGrid arranges visual widget cards without owning metrics, telemetry, or refresh engines.", "Dashboard")
                                                                                                                view.AddItem("navigation", "Workspace rail", "Navigation surface", "Workspace rail", "NavigationRail presents navigation choices without owning application routing or PageHost destinations.", "Nav")
                                                                                                                view.SelectItem("chart")
                                                                                                                view.WithSize(MASSize.FillWidth.OffsetHeight(320.0F))
                                                                                                            End Sub)
        AddHandler masterDetail.SelectedItemChanged,
            Sub(sender As Object, e As EventArgs)
                masterStatus.Text = "MasterDetailView selected record: " & If(String.IsNullOrWhiteSpace(masterDetail.SelectedItemKey), "none", masterDetail.SelectedItemKey)
            End Sub

        Dim grid As MASPropertyGrid = window.Controls.AddPropertyGrid(configure:=Sub(propertyGrid As MASPropertyGrid)
                                                                          propertyGrid.WithTitle("Component properties")
                                                                          propertyGrid.AddProperty("Identity", "Name", "Revenue chart", True)
                                                                          propertyGrid.AddProperty("Identity", "Owner", "Nexamas UI Showcase", False)
                                                                          propertyGrid.AddProperty("Appearance", "Theme aware", True, True)
                                                                          propertyGrid.AddProperty("Appearance", "Surface", "Card / dashboard", False)
                                                                          propertyGrid.AddProperty("Data", "Series count", 3, False)
                                                                          propertyGrid.AddProperty("Data", "Refresh interval", "Manual", True)
                                                                          propertyGrid.AddProperty("Behavior", "Selectable", True, True)
                                                                          propertyGrid.AddProperty("Behavior", "Editable", True, True)
                                                                      End Sub)
        grid.WithSize(MASSize.FillWidth)

        Dim selectionStatus As MASLabel = Muted(window, "Selected property: " & grid.SelectedPropertyName & " = " & grid.SelectedValueText)
        Dim applyName As MASButton = window.Controls.AddButton("Rename inspected item")
        Dim toggleRefresh As MASButton = window.Controls.AddButton("Set refresh interval")
        Dim selectSeries As MASButton = window.Controls.AddButton("Select Series count")

        Dim updateSelectionStatus As Action =
            Sub()
                selectionStatus.Text = "Selected property: " & If(grid.SelectedPropertyName, String.Empty) & " = " & If(grid.SelectedValueText, String.Empty) & "  |  Rows: " & grid.PropertyCount.ToString(CultureInfo.InvariantCulture) & "  |  Categories: " & grid.CategoryCount.ToString(CultureInfo.InvariantCulture)
            End Sub

        AddHandler grid.SelectionChanged, Sub(sender As Object, e As EventArgs) updateSelectionStatus.Invoke()
        AddHandler grid.PropertyValueChanged, Sub(sender As Object, e As EventArgs) updateSelectionStatus.Invoke()
        AddHandler applyName.Click,
            Sub()
                grid.TrySetValueText("Name", "Revenue chart " & DateTime.Now.ToString("HH:mm", CultureInfo.InvariantCulture))
                grid.SelectProperty("Name")
                updateSelectionStatus.Invoke()
                window.Refresh()
            End Sub
        AddHandler toggleRefresh.Click,
            Sub()
                grid.TrySetValueText("Refresh interval", "5 minutes")
                grid.SelectProperty("Refresh interval")
                updateSelectionStatus.Invoke()
                window.Refresh()
            End Sub
        AddHandler selectSeries.Click,
            Sub()
                grid.SelectProperty("Series count")
                updateSelectionStatus.Invoke()
                window.Services.Toasts.Info("Selection is reported by MASPropertyGrid.SelectedPropertyName.", "PropertyGrid")
            End Sub
        updateSelectionStatus.Invoke()

        AddShowcaseContent(page, status, MASSize.HugContent)
        AddShowcaseContent(page, detailSurface, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "MasterDetailView"), MASSize.HugContent)
        AddShowcaseContent(page, masterDetail, MASSize.FillWidth)
        AddShowcaseContent(page, masterStatus, MASSize.FillWidth)
        AddShowcaseContent(page, grid, MASSize.FillWidth)
        AddShowcaseContent(page, selectionStatus, MASSize.HugContent)
        AddShowcaseContent(page, inspectorBoundary, MASSize.FillWidth)
        AddNaturalActionGroup(page, applyName, toggleRefresh, selectSeries)
    End Sub

End Class
