Option Strict On
Option Explicit On

Imports System
Imports System.Linq
Imports System.Windows.Forms
Imports Nexamas.UI.Application
Imports Nexamas.UI.Components
Imports Nexamas.UI.Controls
Imports Nexamas.UI.Layout
Imports Nexamas.UI.TextInput

''' <summary>
''' Repository-owned consumer compile host for Batch 2 documentation recipes.
''' This project must use only public package-facing APIs. It is not a Showcase helper,
''' not a Friend test harness, and not proof that the recipes are Showcase-ready.
''' </summary>
Friend Module Program
    <STAThread>
    Public Sub Main(args As String())
        Global.System.Windows.Forms.Application.EnableVisualStyles()
        Global.System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(False)
        Dim smokeMode As Boolean = args IsNot Nothing AndAlso
            args.Any(Function(value As String) String.Equals(value, "--smoke", StringComparison.OrdinalIgnoreCase))

        Global.System.Windows.Forms.Application.Run(New Batch2RecipeVerificationForm(smokeMode))
    End Sub
End Module

''' <summary>
''' Runtime host for the Batch 2 sample.
''' </summary>
Friend NotInheritable Class Batch2RecipeVerificationForm
    Inherits Form

    Private Shared ReadOnly RuntimeRouteIds As String() = New String() {"overview", "feedback", "inputs", "surfaces", "navigation", "data-grid"}

    Private ReadOnly _application As MASApplication
    Private ReadOnly _window As MASApplicationWindow
    Private ReadOnly _smokeTimer As Timer
    Private _smokeRouteIndex As Integer

    Public Sub New(smokeMode As Boolean)
        Text = "Nexamas UI Batch 2 Recipe Verification"
        Width = 1360
        Height = 900
        MinimumSize = New System.Drawing.Size(1080, 720)
        StartPosition = FormStartPosition.CenterScreen
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
        Me.DoubleBuffered = True

        _application = MASApplication.Create()
        _window = _application.CreateWindow(owner:=Me)

        Batch2RecipeSnippets.ConfigureRuntimePages(_window)

        If smokeMode Then
            _smokeTimer = New Timer() With {.Interval = 1200}
            AddHandler _smokeTimer.Tick, AddressOf HandleSmokeTick
            _smokeTimer.Start()
        End If
    End Sub

    Private Sub HandleSmokeTick(sender As Object, e As EventArgs)
        If _smokeRouteIndex < RuntimeRouteIds.Length - 1 Then
            _smokeRouteIndex += 1
            _window.Pages.NavigateTo(RuntimeRouteIds(_smokeRouteIndex))
            Return
        End If

        _smokeTimer.Stop()
        Close()
    End Sub

    Protected Overrides Sub OnFormClosed(e As FormClosedEventArgs)
        If _smokeTimer IsNot Nothing Then
            RemoveHandler _smokeTimer.Tick, AddressOf HandleSmokeTick
            _smokeTimer.Dispose()
        End If
        If _window IsNot Nothing Then _window.Dispose()
        If _application IsNot Nothing Then _application.Dispose()
        MyBase.OnFormClosed(e)
    End Sub
End Class

''' <summary>
''' Public-API-only snippets corresponding to Batch 2 recipe IDs.
''' These methods intentionally mirror the documentation snippets closely so a successful Windows build
''' can be recorded against the recipe build-verification ledger.
''' </summary>
Friend NotInheritable Class Batch2RecipeSnippets
    Private Sub New()
    End Sub

    Public Shared Sub BuildBatch2LandingPage(window As MASApplicationWindow)
        Dim title As MASTitle = window.Controls.AddTitle("Batch 2 recipes")
        Dim banner As MASStatusBanner = window.Controls.AddStatusBanner(
            title:="Documentation recipes prepared",
            message:="Feedback, navigation, surfaces, inputs, and DataGrid recipes are present in this consumer compile host.",
            tone:=MASToastTone.Info)

        Dim commandBar As MASToolbar = window.Controls.AddCommandBar(
            Sub(toolbar As MASToolbar)
                toolbar.AddCommand("refresh", "Refresh")
                toolbar.AddCommand("export", "Export")
                toolbar.AddSeparator()
                toolbar.AddSearchBox("search", "Search...")
            End Sub)

        Dim tabs As MASTabControl = window.Controls.AddTabControl(
            Sub(control As MASTabControl)
                control.WithTab("Overview", "overview").
                    WithTab("Details", "details").
                    WithTab("History", "history").
                    WithSelectedIndex(0)
            End Sub)

        Dim emptyState As MASEmptyState = window.Controls.AddEmptyState(
            title:="No selection yet",
            description:="Choose a row or command to continue.")

        Dim view As MASDataView = CreateCustomerDataView()
        Dim filterBox As MASSearchTextBox = window.Controls.AddSearchTextBox("Filter")
        Dim grid As MASDataGrid = window.Controls.AddDataGrid(
            Sub(dataGrid As MASDataGrid)
                dataGrid.SetDataView(view)
                dataGrid.SelectionMode = MASDataGridSelectionMode.Row
                dataGrid.SummaryFooterMode = MASDataGridSummaryFooterMode.Automatic
                dataGrid.SummaryAutoPreparationRowLimit = 5000
                dataGrid.WithSize(MASSize.FillWidth)
            End Sub)

        AddHandler filterBox.TextChanged,
            Sub(sender As Object, e As EventArgs)
                view.SetFilterText(filterBox.Text)
            End Sub

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.Spacing(MASLayoutSpacing.Medium)
                page.FullWidth(title, MASSize.FillWidth)
                page.FullWidth(banner, MASSize.FillWidth)
                page.FullWidth(commandBar, MASSize.FillWidth)
                page.FullWidth(tabs, MASSize.FillWidth)
                page.FullWidth(filterBox, MASSize.FillWidth)
                page.FullWidth(grid, MASSize.FillWidth)
                page.FullWidth(emptyState, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Feedback.StatusBanner
    Public Shared Sub BuildStatusBanner(window As MASApplicationWindow)
        Dim banner As MASStatusBanner = window.Controls.AddStatusBanner(
            title:="Profile saved",
            message:="The customer profile was updated successfully.",
            tone:=MASToastTone.Success)

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(banner, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Feedback.ValidationMessage
    Public Shared Sub BuildValidationMessage(window As MASApplicationWindow)
        Dim nameBox As MASTextBox = window.Controls.AddTextBox("Customer name")
        Dim validation As MASValidationMessage = window.Controls.AddValidationMessage(
            text:="Customer name is required.",
            state:=MASTextValidationState.Warning)

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.Spacing(MASLayoutSpacing.Medium)
                page.FullWidth(nameBox, MASSize.FillWidth)
                page.FullWidth(validation, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Feedback.EmptyState
    Public Shared Sub BuildEmptyState(window As MASApplicationWindow)
        Dim emptyState As MASEmptyState = window.Controls.AddEmptyState(
            title:="No customers yet",
            description:="Create the first customer to start filling this view.")

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(emptyState, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Feedback.Progress
    Public Shared Sub BuildProgress(window As MASApplicationWindow)
        Dim progress As MASOperationProgressBox = window.Controls.AddOperationProgressBox(
            titleText:="Importing data",
            statusText:="Preparing rows...")

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(progress, MASSize.FillWidth)
            End Sub)
    End Sub


    ' Recipe: Button.Split.Basic
    Public Shared Sub BuildSplitAction(window As MASApplicationWindow)
        Dim title As MASTitle = window.Controls.AddTitle("Actions")
        Dim splitButton As MASSplitButton = window.Controls.AddSplitButton("Export")

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.Spacing(MASLayoutSpacing.Medium)
                page.FullWidth(title, MASSize.FillWidth)
                page.ActionGroup(
                    Sub(actions As MASApplicationActionGroupLayoutBuilder)
                        actions.AlignEnd().EqualItemWidth().Add(splitButton, MASSize.Default)
                    End Sub)
            End Sub)
    End Sub

    ' Recipe: Input.ComboBox.Basic
    Public Shared Sub BuildComboBox(window As MASApplicationWindow)
        Dim title As MASTitle = window.Controls.AddTitle("Status")
        Dim statusBox As MASComboBox = window.Controls.AddComboBox(
            items:=New String() {"Active", "Pending", "Archived"},
            selectedIndex:=0)

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.Spacing(MASLayoutSpacing.Medium)
                page.FullWidth(title, MASSize.FillWidth)
                page.FullWidth(statusBox, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Input.Slider.Basic
    Public Shared Sub BuildSlider(window As MASApplicationWindow)
        Dim slider As MASSlider = window.Controls.AddSlider(
            minimum:=0.0,
            maximum:=100.0,
            value:=50.0,
            configure:=Sub(control As MASSlider)
                           control.WithStep(5.0).WithValueLabel()
                       End Sub)

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(slider, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Surface.GroupBox.Basic
    Public Shared Sub BuildGroupBox(window As MASApplicationWindow)
        Dim groupBox As MASGroupBox = window.Controls.AddGroupBox("Customer details")
        groupBox.Add(MASLabel.Create("Name, status, and account information."))

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(groupBox, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Surface.Expander.Basic
    Public Shared Sub BuildExpander(window As MASApplicationWindow)
        Dim expander As MASExpander = window.Controls.AddExpander(
            title:="Advanced options",
            expanded:=False)

        expander.Add(MASLabel.Create("Optional filters and secondary settings."))

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(expander, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Surface.Accordion.Basic
    Public Shared Sub BuildAccordion(window As MASApplicationWindow)
        Dim accordion As MASAccordion = window.Controls.AddAccordion(allowMultipleExpanded:=False)

        accordion.AddSection("Profile", expanded:=True).
            Add(MASLabel.Create("Identity and customer status."))

        accordion.AddSection("Billing", expanded:=False).
            Add(MASLabel.Create("Invoices, payment terms, and tax data."))

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(accordion, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Surface.TileBox.Basic
    Public Shared Sub BuildTileBox(window As MASApplicationWindow)
        Dim tileBox As MASTileBox = window.Controls.AddTileBox()

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(tileBox, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Navigation.Tabs.Basic
    Public Shared Sub BuildTabs(window As MASApplicationWindow)
        Dim tabs As MASTabControl = window.Controls.AddTabControl(
            Sub(control As MASTabControl)
                control.WithTab("Overview", "overview").
                    WithTab("Details", "details").
                    WithTab("History", "history").
                    WithSelectedIndex(0)
            End Sub)

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(tabs, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Navigation.Breadcrumb.Basic
    Public Shared Sub BuildBreadcrumb(window As MASApplicationWindow)
        Dim breadcrumb As MASBreadcrumb = window.Controls.AddBreadcrumb(
            items:=New String() {"Home", "Customers", "Alpha GmbH"})

        breadcrumb.WithSelectedIndex(2)

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(breadcrumb, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Navigation.Pagination.Basic
    Public Shared Sub BuildPagination(window As MASApplicationWindow)
        Dim pagination As MASPagination = window.Controls.AddPagination(
            currentPage:=1,
            totalPages:=12)

        pagination.WithPageWindow(5)

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(pagination, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: Navigation.CommandBar.Basic
    Public Shared Sub BuildCommandBar(window As MASApplicationWindow)
        Dim commandBar As MASToolbar = window.Controls.AddCommandBar(
            Sub(toolbar As MASToolbar)
                toolbar.AddCommand("refresh", "Refresh")
                toolbar.AddCommand("export", "Export")
                toolbar.AddSeparator()
                toolbar.AddSearchBox("search", "Search...")
            End Sub)

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.FullWidth(commandBar, MASSize.FillWidth)
            End Sub)
    End Sub

    ' Recipe: DataGrid.BasicRows
    Public Shared Sub BuildCustomerGrid(window As MASApplicationWindow)
        Dim view As MASDataView = CreateCustomerDataView()

        Dim filterBox As MASSearchTextBox = window.Controls.AddSearchTextBox("Filter")
        Dim grid As MASDataGrid = window.Controls.AddDataGrid(
            Sub(dataGrid As MASDataGrid)
                dataGrid.SetDataView(view)
                dataGrid.SelectionMode = MASDataGridSelectionMode.Row
                dataGrid.SummaryFooterMode = MASDataGridSummaryFooterMode.Automatic
                dataGrid.SummaryAutoPreparationRowLimit = 5000
                dataGrid.WithSize(MASSize.FillWidth)
            End Sub)

        AddHandler filterBox.TextChanged,
            Sub(sender As Object, e As EventArgs)
                view.SetFilterText(filterBox.Text)
            End Sub

        window.Controls.LayoutPage(
            Sub(page As MASApplicationLayoutPageBuilder)
                page.Padding(MASLayoutSpacing.Spacious)
                page.Spacing(MASLayoutSpacing.Medium)
                page.FullWidth(filterBox, MASSize.FillWidth)
                page.FullWidth(grid, MASSize.FillWidth)
            End Sub)
    End Sub

    Private Shared Function CreateCustomerDataView() As MASDataView
        Dim view As New MASDataView()

        view.AddColumn("id", "ID").WithWidth(80).ReadOnlyColumn()
        view.AddColumn("name", "Name").WithWidth(220)
        view.AddColumn("status", "Status").WithWidth(160)

        view.AddRows(New Object()() {
            New Object() {1, "Alpha GmbH", "Active"},
            New Object() {2, "Beta AG", "Pending"},
            New Object() {3, "Gamma KG", "Active"}
        })

        Return view
    End Function

    ''' <summary>
    ''' Hosts every Batch 2 visual category in its own PageHost route. This prevents tall feedback,
    ''' navigation, surface, and DataGrid controls from being squeezed into one fixed-height page.
    ''' </summary>
    Public Shared Sub ConfigureRuntimePages(window As MASApplicationWindow)
        If window Is Nothing Then Throw New ArgumentNullException(NameOf(window))

        Dim pages As MASApplicationPageHost = window.Pages
        pages.ClearPages()
        pages.RegisterPage("overview", "Overview", Bind(AddressOf BuildRuntimeOverviewPage, window), "Batch 2", "Command, tab, banner, and empty-state recipes arranged as one balanced overview.")
        pages.RegisterPage("feedback", "Feedback", Bind(AddressOf BuildRuntimeFeedbackPage, window), "Batch 2", "Status, validation, progress, and empty-state feedback with independent vertical space.")
        pages.RegisterPage("inputs", "Inputs and actions", Bind(AddressOf BuildRuntimeInputsPage, window), "Batch 2", "ComboBox, slider, and split-button recipes using semantic layout groups.")
        pages.RegisterPage("surfaces", "Surfaces", Bind(AddressOf BuildRuntimeSurfacesPage, window), "Batch 2", "GroupBox, Expander, Accordion, and TileBox surfaces in a responsive two-column grid.")
        pages.RegisterPage("navigation", "Navigation", Bind(AddressOf BuildRuntimeNavigationPage, window), "Batch 2", "Tabs, breadcrumbs, pagination, and command-bar navigation patterns.")
        pages.RegisterPage("data-grid", "DataGrid", Bind(AddressOf BuildRuntimeDataGridPage, window), "Batch 2", "A filterable DataGrid with a dedicated large surface and workspace scrolling.")

        pages.WithNavigationVisible(True).
            WithBreadcrumbVisible(True).
            WithBreadcrumbRootText("Recipe verification").
            WithRegionBackgrounds(True).
            WithRhythm(MASApplicationSurfaceRhythm.Comfortable).
            WithNavigationSize(MASApplicationSurfaceSideSize.Compact)
        pages.Show()
    End Sub

    Private Shared Function Bind(build As Action(Of MASApplicationWindow, MASApplicationLayoutPageBuilder),
                                 window As MASApplicationWindow) As Action(Of MASApplicationLayoutPageBuilder)
        Return Sub(page As MASApplicationLayoutPageBuilder) build.Invoke(window, page)
    End Function

    Private Shared Sub BuildRuntimeOverviewPage(window As MASApplicationWindow,
                                                page As MASApplicationLayoutPageBuilder)
        Dim banner As MASStatusBanner = window.Controls.AddStatusBanner(
            title:="Documentation recipes prepared",
            message:="Each visual category now owns a separate scroll-safe route instead of sharing one compressed canvas.",
            tone:=MASToastTone.Info)
        Dim commandBar As MASToolbar = window.Controls.AddCommandBar(
            Sub(toolbar As MASToolbar)
                toolbar.AddCommand("refresh", "Refresh")
                toolbar.AddCommand("export", "Export")
                toolbar.AddSeparator()
                toolbar.AddSearchBox("search", "Search...")
            End Sub)
        Dim tabs As MASTabControl = window.Controls.AddTabControl(
            Sub(control As MASTabControl)
                control.WithTab("Overview", "overview").
                    WithTab("Details", "details").
                    WithTab("History", "history").
                    WithSelectedIndex(0)
            End Sub)
        Dim emptyState As MASEmptyState = window.Controls.AddEmptyState(
            title:="No selection yet",
            description:="Choose a row or command to continue.")

        page.Spacing(MASLayoutSpacing.Large)
        page.FullWidth(banner, MASSize.FillWidth)
        page.FullWidth(commandBar, MASSize.FillWidth)
        page.FullWidth(tabs, MASSize.FillWidth)
        page.FullWidth(emptyState, MASSize.FillWidth.OffsetHeight(80.0F))
    End Sub

    Private Shared Sub BuildRuntimeFeedbackPage(window As MASApplicationWindow,
                                                page As MASApplicationLayoutPageBuilder)
        Dim banner As MASStatusBanner = window.Controls.AddStatusBanner("Profile saved", "The customer profile was updated successfully.", MASToastTone.Success)
        Dim nameBox As MASTextBox = window.Controls.AddTextBox("Customer name")
        Dim validation As MASValidationMessage = window.Controls.AddValidationMessage("Customer name is required.", MASTextValidationState.Warning)
        Dim progress As MASOperationProgressBox = window.Controls.AddOperationProgressBox("Importing data", "Preparing rows...")
        Dim emptyState As MASEmptyState = window.Controls.AddEmptyState("No customers yet", "Create the first customer to start filling this view.")

        page.Spacing(MASLayoutSpacing.Large)
        page.FullWidth(banner, MASSize.FillWidth)
        page.FullWidth(nameBox, MASSize.FillWidth)
        page.FullWidth(validation, MASSize.FillWidth)
        page.FullWidth(progress, MASSize.FillWidth)
        page.FullWidth(emptyState, MASSize.FillWidth.OffsetHeight(80.0F))
    End Sub

    Private Shared Sub BuildRuntimeInputsPage(window As MASApplicationWindow,
                                              page As MASApplicationLayoutPageBuilder)
        Dim combo As MASComboBox = window.Controls.AddComboBox(New String() {"Active", "Pending", "Archived"}, selectedIndex:=0)
        Dim slider As MASSlider = window.Controls.AddSlider(0.0, 100.0, 50.0, Sub(control As MASSlider) control.WithStep(5.0).WithValueLabel())
        Dim splitButton As MASSplitButton = window.Controls.AddSplitButton("Export")
        Dim note As MASLabel = window.Controls.AddLabel("Inputs use semantic size intents and remain separated from the action row at every supported viewport.")

        page.Spacing(MASLayoutSpacing.Large)
        page.FullWidth(note, MASSize.FillWidth)
        page.Grid(2).
            Gap(MASLayoutSpacing.Large).
            Add(combo, MASSize.FillWidth).
            Add(splitButton, MASSize.Default)
        page.FullWidth(slider, MASSize.FillWidth)
    End Sub

    Private Shared Sub BuildRuntimeSurfacesPage(window As MASApplicationWindow,
                                                page As MASApplicationLayoutPageBuilder)
        Dim groupBox As MASGroupBox = window.Controls.AddGroupBox("Customer details")
        groupBox.Add(MASLabel.Create("Name, status, and account information."))

        Dim expander As MASExpander = window.Controls.AddExpander("Advanced options", expanded:=True)
        expander.Add(MASLabel.Create("Optional filters and secondary settings."))

        Dim accordion As MASAccordion = window.Controls.AddAccordion(allowMultipleExpanded:=False)
        accordion.AddSection("Profile", expanded:=True).Add(MASLabel.Create("Identity and customer status."))
        accordion.AddSection("Billing", expanded:=False).Add(MASLabel.Create("Invoices, payment terms, and tax data."))

        Dim tileBox As MASTileBox = window.Controls.AddTileBox()

        page.Spacing(MASLayoutSpacing.Large)
        page.Grid(2).
            Gap(MASLayoutSpacing.Large).
            Add(groupBox, MASSize.FillWidth.OffsetHeight(90.0F)).
            Add(expander, MASSize.FillWidth.OffsetHeight(90.0F)).
            Add(accordion, MASSize.FillWidth.OffsetHeight(150.0F)).
            Add(tileBox, MASSize.FillWidth.OffsetHeight(150.0F))
    End Sub

    Private Shared Sub BuildRuntimeNavigationPage(window As MASApplicationWindow,
                                                  page As MASApplicationLayoutPageBuilder)
        Dim tabs As MASTabControl = window.Controls.AddTabControl(
            Sub(control As MASTabControl)
                control.WithTab("Overview", "overview").WithTab("Details", "details").WithTab("History", "history").WithSelectedIndex(0)
            End Sub)
        Dim breadcrumb As MASBreadcrumb = window.Controls.AddBreadcrumb(New String() {"Home", "Customers", "Alpha GmbH"})
        breadcrumb.WithSelectedIndex(2)
        Dim pagination As MASPagination = window.Controls.AddPagination(currentPage:=1, totalPages:=12)
        pagination.WithPageWindow(5)
        Dim commandBar As MASToolbar = window.Controls.AddCommandBar(
            Sub(toolbar As MASToolbar)
                toolbar.AddCommand("refresh", "Refresh")
                toolbar.AddCommand("export", "Export")
                toolbar.AddSeparator()
                toolbar.AddSearchBox("search", "Search...")
            End Sub)

        page.Spacing(MASLayoutSpacing.Large)
        page.FullWidth(commandBar, MASSize.FillWidth)
        page.FullWidth(breadcrumb, MASSize.FillWidth)
        page.FullWidth(tabs, MASSize.FillWidth)
        page.FullWidth(pagination, MASSize.FillWidth)
    End Sub

    Private Shared Sub BuildRuntimeDataGridPage(window As MASApplicationWindow,
                                                page As MASApplicationLayoutPageBuilder)
        Dim view As MASDataView = CreateCustomerDataView()
        Dim filterBox As MASSearchTextBox = window.Controls.AddSearchTextBox("Filter")
        Dim grid As MASDataGrid = window.Controls.AddDataGrid(
            Sub(dataGrid As MASDataGrid)
                dataGrid.SetDataView(view)
                dataGrid.SelectionMode = MASDataGridSelectionMode.Row
                dataGrid.SummaryFooterMode = MASDataGridSummaryFooterMode.Automatic
                dataGrid.SummaryAutoPreparationRowLimit = 5000
                dataGrid.WithSize(MASSize.FillWidth)
            End Sub)
        AddHandler filterBox.TextChanged, Sub(sender As Object, e As EventArgs) view.SetFilterText(filterBox.Text)

        page.Spacing(MASLayoutSpacing.Large)
        page.FullWidth(filterBox, MASSize.FillWidth)
        page.FullWidth(grid, MASSize.FillWidth.OffsetHeight(300.0F))
    End Sub

End Class
