﻿Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports Nexamas.UI.Components
Imports Nexamas.UI.Controls
Imports Nexamas.UI.Application
Imports Nexamas.UI.Layout

Partial Friend Class NexamasUIShowcase

    Private Const HomeRouteSummary As String = "A live, guided Nexamas.UI experience. The Showcase remains a pure consumer: it supplies only sample copy, route metadata, demo values, and page composition while Nexamas.UI owns controls, layout, services, theme, RTL, rendering, output, and proof surfaces."

    Private Sub ApplyShowcaseWorkspaceSurface(page As MASApplicationLayoutPageBuilder)
        If page Is Nothing Then Return

        ' Root Showcase layout contract: every registered PageHost route receives
        ' the same vertical rhythm with no page-local max-width preset. The
        ' PageHost owns the outer workspace gutter; route summaries are rendered
        ' by BuildShowcaseRouteSummary(...) inside the same body layout as the
        ' rest of the Showcase content so descriptive text does not come from a
        ' second header-description slot with different alignment.
        page.Spacing(MASLayoutSpacing.Large).
            Padding(MASLayoutSpacing.Small)
    End Sub

    Private Sub BuildShowcaseRouteSummary(page As MASApplicationLayoutPageBuilder,
                                          text As String)
        If page Is Nothing Then Return

        AddShowcaseContent(page, CreateBody(text), MASSize.FillWidth)
    End Sub

    Private Sub BuildCapabilityClassificationBanner(page As MASApplicationLayoutPageBuilder,
                                                    entry As ShowcaseNavigationEntry)
        If page Is Nothing OrElse entry Is Nothing Then Return

        Dim tone As MASToastTone = MASToastTone.Info
        Select Case entry.Classification
            Case ShowcaseCapabilityClassification.Stable
                tone = MASToastTone.Success
            Case ShowcaseCapabilityClassification.Preview,
                 ShowcaseCapabilityClassification.Compat
                tone = MASToastTone.Warning
            Case ShowcaseCapabilityClassification.Advanced,
                 ShowcaseCapabilityClassification.Evidence
                tone = MASToastTone.Info
        End Select

        Dim classificationTitle As String = ShowcaseNavigationCatalog.ResolveClassificationTitle(entry.Classification)
        Dim banner As MASStatusBanner = Window.Controls.AddStatusBanner(
            title:="Capability classification · " & classificationTitle,
            message:=ShowcaseNavigationCatalog.ResolveClassificationSummary(entry.Classification),
            tone:=tone)
        banner.WithSize(MASSize.FillWidth)
        AddShowcaseContent(page, banner, MASSize.FillWidth)
    End Sub

    Private Function CreateCategoryCard(category As ShowcaseNavigationCategory) As MASMetricCard
        Dim entries As IReadOnlyList(Of ShowcaseNavigationEntry) = ShowcaseNavigationCatalog.GetEntries(category)
        Dim card As MASMetricCard = Window.Controls.AddMetricCard(
            ShowcaseNavigationCatalog.ResolveCategoryTitle(category),
            entries.Count.ToString(CultureInfo.InvariantCulture))
        card.Subtitle = ShowcaseNavigationCatalog.ResolveCategorySummary(category)
        card.TrendText = ShowcaseNavigationCatalog.ResolveCategoryKind(category)
        card.WithSize(MASSize.FillWidth)
        Return card
    End Function

    Private Function CreateEntryCard(entry As ShowcaseNavigationEntry) As MASMetricCard
        If entry Is Nothing Then
            Return CreateMetric("Capability", "N/A", "No entry metadata was provided.")
        End If

        Dim kind As ShowcaseNavigationEntryKind = ShowcaseNavigationCatalog.ResolveEntryKind(entry)
        Dim card As MASMetricCard = Window.Controls.AddMetricCard(entry.Title, ShowcaseNavigationCatalog.ResolveEntryKindTitle(kind))
        card.Subtitle = entry.Summary
        card.TrendText = ShowcaseNavigationCatalog.ResolveCategoryTitle(entry.Category) & " · " & ShowcaseNavigationCatalog.ResolveClassificationTitle(entry.Classification)
        card.WithSize(MASSize.FillWidth)
        Return card
    End Function

    Private Function CreateKindCard(kind As ShowcaseNavigationEntryKind) As MASMetricCard
        Dim entries As IReadOnlyList(Of ShowcaseNavigationEntry) = ShowcaseNavigationCatalog.GetEntries(kind)
        Dim card As MASMetricCard = Window.Controls.AddMetricCard(ShowcaseNavigationCatalog.ResolveEntryKindTitle(kind), entries.Count.ToString(CultureInfo.InvariantCulture))
        card.Subtitle = ShowcaseNavigationCatalog.ResolveEntryKindSummary(kind)
        card.TrendText = "Metadata lane"
        card.WithSize(MASSize.FillWidth)
        Return card
    End Function

    Private Function CreateMetric(title As String,
                                  valueText As String,
                                  subtitle As String) As MASMetricCard
        Dim card As MASMetricCard = Window.Controls.AddMetricCard(title, valueText)
        card.Subtitle = If(subtitle, String.Empty)
        card.WithSize(MASSize.FillWidth)
        Return card
    End Function

    Private Function CreateBody(text As String) As MASLabel
        Dim label As MASLabel = Window.Controls.AddLabel(If(text, String.Empty))
        label.LabelVariant = MASLabelVariant.Body
        label.TextRole = MASLabelTextRole.Primary
        label.MultiLine = True
        label.WordWrap = True
        label.WithSize(MASSize.FillWidth)
        Return label
    End Function

    Private Function CreateMuted(text As String) As MASLabel
        Dim label As MASLabel = Window.Controls.AddLabel(If(text, String.Empty))
        label.LabelVariant = MASLabelVariant.Caption
        label.TextRole = MASLabelTextRole.Muted
        label.MultiLine = True
        label.WordWrap = True
        label.WithSize(MASSize.FillWidth)
        Return label
    End Function
End Class
