﻿Option Strict On
Option Explicit On

Imports Nexamas.UI.Application
Imports Nexamas.UI.Controls
Imports Nexamas.UI.Layout

Partial Friend NotInheritable Class ShowcasePageHostContentBuilder

    Friend Shared Sub BuildConsumerBoundaryFooter(page As MASApplicationLayoutPageBuilder,
                                                     window As MASApplicationWindow,
                                                     entry As ShowcaseNavigationEntry)
        If page Is Nothing OrElse window Is Nothing OrElse entry Is Nothing Then Return

        Dim kind As ShowcaseNavigationEntryKind = ShowcaseNavigationCatalog.ResolveEntryKind(entry)
        Dim kindTitle As String = ShowcaseNavigationCatalog.ResolveEntryKindTitle(kind)
        Dim presentationKind As ShowcasePresentationKind = ShowcaseNavigationCatalog.ResolvePresentationKind(entry)
        Dim boundaryText As String =
            "Consumer-only composition: this page uses Nexamas.UI controls, services, layout builders, and public application routes. Showcase owns copy, metadata, and demo data only." & Environment.NewLine & Environment.NewLine &
            kindTitle & ": " & ResolveConsumerBoundaryFooterText(kind) & Environment.NewLine & Environment.NewLine &
            "Surface: " & ShowcaseNavigationCatalog.ResolvePresentationKindTitle(presentationKind) & " — " & ShowcaseNavigationCatalog.ResolvePresentationDecision(presentationKind)

        Dim boundaryExpander As MASExpander = window.Controls.AddExpander("Consumer boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                           expander.WithSize(MASSize.FillWidth.OffsetHeight(185.0F))
                                                                                                                                           expander.Add(MASLabel.Create(boundaryText))
                                                                                                                                       End Sub)
        AddShowcaseContent(page, boundaryExpander, MASSize.FillWidth)

        BuildCapabilityRouteFooter(page, window, entry)
    End Sub

    Private Shared Sub BuildCapabilityRouteFooter(page As MASApplicationLayoutPageBuilder,
                                                   window As MASApplicationWindow,
                                                   entry As ShowcaseNavigationEntry)
        If page Is Nothing OrElse window Is Nothing OrElse entry Is Nothing Then Return

        Dim routeTitle As MASLabel = Muted(window, "Route sequence")
        routeTitle.LabelVariant = MASLabelVariant.Heading
        AddShowcaseContent(page, routeTitle, MASSize.FillWidth)

        Dim actions As MASApplicationLayoutFlowBuilder = page.Flow().Gap(MASLayoutSpacing.Small).EqualItemWidth()

        Dim previousEntry As ShowcaseNavigationEntry = ShowcaseNavigationCatalog.GetPreviousEntry(entry)
        If previousEntry IsNot Nothing Then
            Dim previousEntryForButton As ShowcaseNavigationEntry = previousEntry
            Dim previousButton As MASButton = window.Controls.AddButton("Previous: " & previousEntryForButton.Title)
            previousButton.WithSize(MASSize.[Default])
            AddHandler previousButton.Click,
                Sub()
                    window.Pages.NavigateTo(previousEntryForButton.CommandId)
                End Sub
            actions.Add(previousButton, MASSize.[Default])
        End If

        Dim areaButton As MASButton = window.Controls.AddButton("Area: " & ShowcaseNavigationCatalog.ResolveCategoryTitle(entry.Category))
        areaButton.WithSize(MASSize.[Default])
        AddHandler areaButton.Click,
            Sub()
                window.Pages.NavigateTo(ShowcaseNavigationCatalog.ResolveCategoryPageId(entry.Category))
            End Sub
        actions.Add(areaButton, MASSize.[Default])

        Dim nextEntry As ShowcaseNavigationEntry = ShowcaseNavigationCatalog.GetNextEntry(entry)
        If nextEntry IsNot Nothing Then
            Dim nextEntryForButton As ShowcaseNavigationEntry = nextEntry
            Dim nextButton As MASButton = window.Controls.AddButton("Next: " & nextEntryForButton.Title)
            nextButton.AsPrimary().WithSize(MASSize.[Default])
            AddHandler nextButton.Click,
                Sub()
                    window.Pages.NavigateTo(nextEntryForButton.CommandId)
                End Sub
            actions.Add(nextButton, MASSize.[Default])
        End If

    End Sub

    Private Shared Function ResolveConsumerBoundaryFooterText(kind As ShowcaseNavigationEntryKind) As String
        Select Case kind
            Case ShowcaseNavigationEntryKind.LiveDemo
                Return "Live visual surfaces are presented first; certification and diagnostics remain in the Quality area so the product view does not look like an internal test runner."
            Case ShowcaseNavigationEntryKind.ProductSystem
                Return "Product-system pages demonstrate public gateways and user-facing behavior without duplicating platform-owned engines, renderers, theming, localization, or layout logic."
            Case ShowcaseNavigationEntryKind.Foundation
                Return "Foundation pages document supported consumer boundaries and commercial decisions without exposing internal registries or creating compatibility wrappers."
            Case ShowcaseNavigationEntryKind.Proof
                Return "Proof pages deliberately host gates, matrices, diagnostics, and verification evidence. They are kept available but secondary to the Executive Tour and Area pages."
            Case Else
                Return "This capability is grouped through Showcase metadata and hosted by MASApplicationWindow.Pages."
        End Select
    End Function
End Class
