﻿Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Application
Imports Nexamas.UI.Components
Imports Nexamas.UI.Controls
Imports Nexamas.UI.Layout

Partial Friend NotInheritable Class ShowcasePageHostContentBuilder

    Private Shared Sub BuildCoreDocumentationMap(page As MASApplicationLayoutPageBuilder,
                                                 window As MASApplicationWindow)
        Dim title As MASLabel = Heading(window, "Core Documentation Map: every live route must be explainable from docs")
        Dim intro As MASLabel = Body(window, "This page is the Showcase alignment contract. It maps the Phase 7 core documentation pages to real Showcase routes and states the boundary each route must respect. If a capability cannot be explained from these documents, it should not be sold through the Showcase until documentation is added.")

        Dim sourceCard As MASLabel = InfoCard(window,
            "Documentation is source-of-truth copy",
            "The Showcase may own presentation metadata, sample values, and route order. It must not invent APIs, call Friend/internal engines, scan source reports from runtime UI, or create parallel render/layout/theme/localization systems.")
        Dim consumerCard As MASLabel = InfoCard(window,
            "External consumer posture",
            "All live samples are hosted through MASApplicationWindow.Pages and use public facades such as Window.Controls, Window.Theme, Window.Services, Window.Sizing, MASLocalizationRtl.AttachPage, MASDataGrid, MASDataView, and MASApplication.Output.")
        Dim gapCard As MASLabel = InfoCard(window,
            "Missing coverage rule",
            "A missing documented system becomes a visible row here before launch. The fix is documentation plus a public-safe Showcase page, not a secret demo-only helper.")
        Dim proofCard As MASLabel = InfoCard(window,
            "No magic rule",
            "The Showcase does not claim hidden activation, automatic licensing expiry, internal diagnostics dashboards, private theme/material registries, translation catalogs, internal motion catalogs, or package execution from runtime UI.")

        Dim map As MASDataGrid = window.Controls.AddDataGrid()
        map.SelectionMode = MASDataGridSelectionMode.Row
        map.RowHeightDip = 34.0F
        map.HeaderHeightDip = 42.0F
        AddReadOnlyDataGridColumn(map, "doc", "Core document", 260.0F)
        AddReadOnlyDataGridColumn(map, "publicRoute", "Documented public route", 300.0F)
        AddReadOnlyDataGridColumn(map, "showcaseRoute", "Showcase route", 260.0F)
        AddReadOnlyDataGridColumn(map, "boundary", "Boundary enforced", 520.0F)
        map.AddRow("application-and-window-lifetime.md", "MASApplication.Create / AttachWindow / CreateWindow", "Application Architecture", "No RootHost, renderer, diagnostics channel, or Showcase helper as an application start point.")
        map.AddRow("layout-and-composition.md", "Window.Controls.LayoutPage / ApplicationSurface / MASSize / MASLayoutSpacing", "Application Architecture / Productivity Navigation", "No manual chrome reservation, fixed pixel layout engine, or hidden Form-per-page host.")
        map.AddRow("controls-and-component-factories.md", "window.Controls.Add* factories", "Buttons / Inputs / Feedback / Lists / Files", "No native WinForms replacements, wrappers, adapters, or compatibility aliases.")
        map.AddRow("theme-and-surface-materials.md", "window.Theme + MASApplicationSurfaceMaterialGateway / Scope", "Theme / Readability + Surface Materials", "No internal theme host, material registry, painter, or Surface Designer internals.")
        map.AddRow("datagrid-and-dataview.md", "MASDataGrid + MASDataView", "DataGrid / DataView + Data Analytics", "No virtualization engine, projection index, measurement cache, or invalidation internals.")
        map.AddRow("localization-and-rtl.md", "MASLocalizationRtl.AttachPage(window, page)", "Localization / RTL", "No public string catalog, culture snapshot, readiness report, or Thread culture mutation.")
        map.AddRow("motion-behavior.md", "Public controls and product-owned interaction behavior", "Motion", "No motion clock, timeline runner, token catalog, or readiness report dependency.")
        map.AddRow("diagnostics-and-quality-proof.md", "MASApplication.Diagnostics + maintainer proof commands", "Diagnostics Dashboard / Certification Center", "Runtime UI does not parse source reports, execute gates, or expose internal diagnostics layouts.")
        map.AddRow("packaging-and-external-consumer-use.md", "NuGet package + packed consumer proof", "Packaging / Consumer Proof", "No ProjectReference proof, no package execution from runtime UI, and no source-only shortcut.")
        map.AddRow("pricing-and-evaluation.md / LICENSE.md", "Seven-day legal evaluation + commercial license", "Licensing / Evaluation", "No automatic expiry or online activation claim until a verified licensing system exists.")
        map.SelectedRowIndex = 0
        FitDataGridToRows(map)

        Dim openApplication As MASButton = window.Controls.AddButton("Open Application Architecture").AsPrimary()
        Dim openDataGrid As MASButton = window.Controls.AddButton("View DataGrid page")
        Dim openLicensing As MASButton = window.Controls.AddButton("Open Licensing")
        openApplication.WithSize(MASSize.Compact)
        openDataGrid.WithSize(MASSize.Compact)
        openLicensing.WithSize(MASSize.Compact)

        AddHandler openApplication.Click, Sub() window.Pages.NavigateTo("showcase.open.application.architecture")
        AddHandler openDataGrid.Click, Sub() window.Pages.NavigateTo("showcase.open.datagrid")
        AddHandler openLicensing.Click, Sub() window.Pages.NavigateTo("showcase.open.licensing.evaluation")

        Dim documentationBoundary As MASExpander = window.Controls.AddExpander("Developer documentation boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                                      expander.WithSize(MASSize.FillWidth.OffsetHeight(320.0F))
                                                                                                                                                      expander.Add(intro)
                                                                                                                                                      expander.Add(sourceCard)
                                                                                                                                                      expander.Add(consumerCard)
                                                                                                                                                      expander.Add(gapCard)
                                                                                                                                                      expander.Add(proofCard)
                                                                                                                                                  End Sub)

        AddShowcaseContent(page, title, MASSize.HugContent)
        AddShowcaseContent(page, map, MASSize.FillWidth)
        AddNaturalActionGroup(page, openApplication, openDataGrid, openLicensing)
        AddShowcaseContent(page, documentationBoundary, MASSize.FillWidth)
    End Sub

    Private Shared Sub BuildLicensingEvaluation(page As MASApplicationLayoutPageBuilder,
                                                window As MASApplicationWindow)
        Dim title As MASLabel = Heading(window, "Licensing / Evaluation: seven-day legal evaluation, sales not yet open")
        Dim intro As MASLabel = Body(window, "Nexamas.UI is proprietary commercial software. Commercial sales are not currently open in this Showcase snapshot. The page explains the legal boundary without exposing pricing, purchase, checkout, payment, invoice, license-delivery, runtime license-server, telemetry-meter, or automatic seven-day lockout routes.")

        Dim evaluationCard As MASLabel = InfoCard(window,
            "Seven-day evaluation",
            "The default evaluation lasts seven consecutive calendar days starting from the first download, receipt, install, package restore, source access, documentation-pack access, or related SDK use.")
        Dim allowedCard As MASLabel = InfoCard(window,
            "Allowed during evaluation",
            "Internal technical review, compatibility testing, learning, and non-production prototypes. Production use, paid client work, customer delivery, and redistribution require a commercial license.")
        Dim noBypassCard As MASLabel = InfoCard(window,
            "No repeated trial bypass",
            "Repeated evaluation cycles are not allowed. Continued use after the evaluation period requires a separately executed commercial license. While sales are not open, stop using Nexamas.UI and delete unlicensed copies when the evaluation ends.")
        Dim availabilityCard As MASLabel = InfoCard(window,
            "Current sales availability",
            "Commercial sales are not currently open. Pricing, checkout, payment, invoicing, and delivery remain intentionally unavailable until administrative, tax, invoicing, payment, and delivery readiness is complete.")
        Dim implementationCard As MASLabel = InfoCard(window,
            "Contract-only in this snapshot",
            "The evaluation is a legal/commercial term only. The Showcase makes no automatic runtime lockout, expiry, activation, subscription-enforcement, or usage-metering claim.")

        Dim matrix As MASDataGrid = window.Controls.AddDataGrid()
        matrix.SelectionMode = MASDataGridSelectionMode.Row
        matrix.RowHeightDip = 34.0F
        matrix.HeaderHeightDip = 42.0F
        AddReadOnlyDataGridColumn(matrix, "area", "License area", 220.0F)
        AddReadOnlyDataGridColumn(matrix, "decision", "Decision", 320.0F)
        AddReadOnlyDataGridColumn(matrix, "showcaseCopy", "Showcase wording", 560.0F)
        matrix.AddRow("Product model", "Proprietary / Commercial", "Nexamas.UI is not presented as Open Source by the Showcase.")
        matrix.AddRow("Evaluation", "Seven days", "Internal evaluation only; no production, redistribution, paid client work, or customer delivery.")
        matrix.AddRow("Commercial use", "Requires separate written license", "Commercial application development and distribution require separately executed written commercial terms.")
        matrix.AddRow("Sales availability", "Not currently available", "No purchase, checkout, payment, invoice, or license-delivery route is exposed in this snapshot.")
        matrix.AddRow("Source access", "Special terms only", "Source delivery, private feeds, or customer-specific terms require an explicit written agreement.")
        matrix.AddRow("Runtime enforcement", "Not implemented here", "The Showcase must not imply automatic expiry, online activation, telemetry metering, or hidden lockout.")
        matrix.SelectedRowIndex = 0
        FitDataGridToRows(matrix)

        Dim licensingToast As MASButton = window.Controls.AddButton("Show licensing boundary")
        licensingToast.WithSize(MASSize.Compact)
        AddHandler licensingToast.Click,
            Sub()
                window.Services.Toasts.Info("Commercial sales are not currently open; the seven-day evaluation is contract copy only and no automatic runtime lockout is claimed.", "Licensing / Evaluation")
            End Sub

        Dim licensingBoundary As MASExpander = window.Controls.AddExpander("Developer licensing boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                                expander.WithSize(MASSize.FillWidth.OffsetHeight(440.0F))
                                                                                                                                                expander.Add(intro)
                                                                                                                                                expander.Add(evaluationCard)
                                                                                                                                                expander.Add(allowedCard)
                                                                                                                                                expander.Add(noBypassCard)
                                                                                                                                                expander.Add(availabilityCard)
                                                                                                                                                expander.Add(implementationCard)
                                                                                                                                            End Sub)

        AddShowcaseContent(page, title, MASSize.HugContent)
        AddShowcaseContent(page, matrix, MASSize.FillWidth)
        page.ActionGroup(Sub(actions As MASApplicationActionGroupLayoutBuilder)
                             actions.AlignCenter().Add(licensingToast, MASSize.[Default])
                         End Sub)
        AddShowcaseContent(page, licensingBoundary, MASSize.FillWidth)
    End Sub

    Private Shared Sub BuildPackagingConsumerUse(page As MASApplicationLayoutPageBuilder,
                                                 window As MASApplicationWindow)
        Dim title As MASLabel = Heading(window, "Packaging / Consumer Proof: NuGet delivery without source shortcuts")
        Dim intro As MASLabel = Body(window, "This page mirrors the packaging documentation. It explains how the package is produced and tested, but the running Showcase does not pack, restore, build, or execute release gates. Maintainers run those commands from PowerShell outside the demo UI.")

        Dim readmeCard As MASLabel = InfoCard(window,
            "Package README",
            "Nexamas.UI.nuspec includes README.md as the package readme and sets license acceptance so NuGet consumers see the commercial boundary before adoption.")
        Dim localPackageCard As MASLabel = InfoCard(window,
            "Local package feed",
            "Release proof uses .artifacts\\nuget as the local package source and verifies the .nupkg / .snupkg output before external consumer validation.")
        Dim consumerProofCard As MASLabel = InfoCard(window,
            "External consumer proof",
            "Test-NexamasUIPackedConsumer.ps1 builds a separate packed consumer probe against the package folder. The proof must not depend on a ProjectReference to source.")
        Dim versionCard As MASLabel = InfoCard(window,
            "Version lane",
            "Internal packaging can stay on 0.0.x. The release candidate should become 1.0.0-rc.1 and the first stable commercial release should become 1.0.0.")

        Dim matrix As MASDataGrid = window.Controls.AddDataGrid()
        matrix.SelectionMode = MASDataGridSelectionMode.Row
        matrix.RowHeightDip = 34.0F
        matrix.HeaderHeightDip = 42.0F
        AddReadOnlyDataGridColumn(matrix, "step", "Maintainer step", 260.0F)
        AddReadOnlyDataGridColumn(matrix, "command", "Command / file", 360.0F)
        AddReadOnlyDataGridColumn(matrix, "meaning", "What it proves", 480.0F)
        matrix.AddRow("Documentation gate", ".\\tools\\docs\\Invoke-NexamasUIDocumentationGate.ps1", "Docs and claim ledger remain consistent before packaging.")
        matrix.AddRow("Source-contract suite", ".\\eng\\tests\\Run-NexamasUITestSuite.ps1 -Configuration Release -Platform x64", "Public API, source hygiene, and quality gates pass before packaging.")
        matrix.AddRow("NuGet pack", ".\\eng\\ci\\Pack-Nexamas.UI.ps1 -Configuration Release -Platform x64", "Creates Nexamas.UI .nupkg and .snupkg from the commercial package spec.")
        matrix.AddRow("Packed consumer proof", ".\\eng\\ci\\Test-NexamasUIPackedConsumer.ps1 -Configuration Release -Platform x64", "A separate consumer probe restores and runs from the package, not from source.")
        matrix.AddRow("README payload", "Nexamas.UI.nuspec <readme>README.md</readme>", "The NuGet package page has first-run guidance and commercial-license context.")
        matrix.AddRow("License acceptance", "Nexamas.UI.nuspec requireLicenseAcceptance=true", "Consumers are required to accept the proprietary commercial license.")
        matrix.SelectedRowIndex = 0
        FitDataGridToRows(matrix)

        Dim proofToast As MASButton = window.Controls.AddButton("Show proof boundary")
        proofToast.WithSize(MASSize.Compact)
        AddHandler proofToast.Click,
            Sub()
                window.Services.Toasts.Info("Packaging proof is a maintainer command-chain, not runtime behavior owned by the Showcase window.", "Packaging / Consumer Proof")
            End Sub

        Dim packagingBoundary As MASExpander = window.Controls.AddExpander("Developer packaging boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                              expander.WithSize(MASSize.FillWidth.OffsetHeight(320.0F))
                                                                                                                                              expander.Add(intro)
                                                                                                                                              expander.Add(readmeCard)
                                                                                                                                              expander.Add(localPackageCard)
                                                                                                                                              expander.Add(consumerProofCard)
                                                                                                                                              expander.Add(versionCard)
                                                                                                                                          End Sub)

        AddShowcaseContent(page, title, MASSize.HugContent)
        AddShowcaseContent(page, matrix, MASSize.FillWidth)
        page.ActionGroup(Sub(actions As MASApplicationActionGroupLayoutBuilder)
                             actions.AlignCenter().Add(proofToast, MASSize.[Default])
                         End Sub)
        AddShowcaseContent(page, packagingBoundary, MASSize.FillWidth)
    End Sub

End Class
