Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Values

Namespace Nexamas.UI.Components

    ''' <summary>
    ''' Public immutable app-layout visual snapshot. It captures the responsive slot
    ''' labels/text and visibility choices owned by MASAppLayout, while routing,
    ''' PageHost state, child controls, native shell integration, and external storage
    ''' remain outside the control.
    ''' </summary>
    Public NotInheritable Class MASAppLayoutSnapshot
        Public Sub New(version As Integer,
                       title As String,
                       navigationTitle As String,
                       navigationText As String,
                       contentTitle As String,
                       contentText As String,
                       detailTitle As String,
                       detailText As String,
                       statusText As String,
                       showNavigation As Boolean,
                       showDetails As Boolean,
                       showStatusBar As Boolean)
            Me.Version = Math.Max(1, version)
            Me.Title = MASAppLayoutPolicy.NormalizeTitle(title)
            Me.NavigationTitle = MASAppLayoutPolicy.NormalizeSectionTitle(navigationTitle, AppLayoutTokens.DefaultNavigationTitle)
            Me.NavigationText = MASAppLayoutPolicy.NormalizeSectionText(navigationText, AppLayoutTokens.DefaultNavigationText)
            Me.ContentTitle = MASAppLayoutPolicy.NormalizeSectionTitle(contentTitle, AppLayoutTokens.DefaultContentTitle)
            Me.ContentText = MASAppLayoutPolicy.NormalizeSectionText(contentText, AppLayoutTokens.DefaultContentText)
            Me.DetailTitle = MASAppLayoutPolicy.NormalizeSectionTitle(detailTitle, AppLayoutTokens.DefaultDetailTitle)
            Me.DetailText = MASAppLayoutPolicy.NormalizeSectionText(detailText, AppLayoutTokens.DefaultDetailText)
            Me.StatusText = MASAppLayoutPolicy.NormalizeStatusText(statusText)
            Me.ShowNavigation = showNavigation
            Me.ShowDetails = showDetails
            Me.ShowStatusBar = showStatusBar
        End Sub

        Public ReadOnly Property Version As Integer
        Public ReadOnly Property Title As String
        Public ReadOnly Property NavigationTitle As String
        Public ReadOnly Property NavigationText As String
        Public ReadOnly Property ContentTitle As String
        Public ReadOnly Property ContentText As String
        Public ReadOnly Property DetailTitle As String
        Public ReadOnly Property DetailText As String
        Public ReadOnly Property StatusText As String
        Public ReadOnly Property ShowNavigation As Boolean
        Public ReadOnly Property ShowDetails As Boolean
        Public ReadOnly Property ShowStatusBar As Boolean
    End Class

    Partial Public NotInheritable Class MASAppLayout

        Public Function CreateLayoutSnapshot() As MASAppLayoutSnapshot
            Return New MASAppLayoutSnapshot(
                1,
                _title,
                _navigationTitle,
                _navigationText,
                _contentTitle,
                _contentText,
                _detailTitle,
                _detailText,
                _statusText,
                _showNavigation,
                _showDetails,
                _showStatusBar)
        End Function

        Public Function RestoreLayoutSnapshot(snapshot As MASAppLayoutSnapshot) As Boolean
            If snapshot Is Nothing Then Return False
            _title = snapshot.Title
            _navigationTitle = snapshot.NavigationTitle
            _navigationText = snapshot.NavigationText
            _contentTitle = snapshot.ContentTitle
            _contentText = snapshot.ContentText
            _detailTitle = snapshot.DetailTitle
            _detailText = snapshot.DetailText
            _statusText = snapshot.StatusText
            _showNavigation = snapshot.ShowNavigation
            _showDetails = snapshot.ShowDetails
            _showStatusBar = snapshot.ShowStatusBar
            RequestSizeLayoutRefreshForSizeAffectingChange("MASAppLayout.RestoreLayoutSnapshot")
            InvalidateVisual()
            Return True
        End Function

        Public Function ResetLayoutSlots() As MASAppLayout
            _navigationTitle = AppLayoutTokens.DefaultNavigationTitle
            _navigationText = AppLayoutTokens.DefaultNavigationText
            _contentTitle = AppLayoutTokens.DefaultContentTitle
            _contentText = AppLayoutTokens.DefaultContentText
            _detailTitle = AppLayoutTokens.DefaultDetailTitle
            _detailText = AppLayoutTokens.DefaultDetailText
            _statusText = AppLayoutTokens.DefaultStatusText
            _showNavigation = True
            _showDetails = True
            _showStatusBar = True
            RequestSizeLayoutRefreshForSizeAffectingChange("MASAppLayout.ResetLayoutSlots")
            InvalidateVisual()
            Return Me
        End Function

        Friend Function HasLayoutSnapshotForTests() As Boolean
            Dim snapshot As MASAppLayoutSnapshot = CreateLayoutSnapshot()
            Return snapshot IsNot Nothing AndAlso
                   Not String.IsNullOrWhiteSpace(snapshot.Title) AndAlso
                   Not String.IsNullOrWhiteSpace(snapshot.ContentTitle)
        End Function
    End Class

End Namespace
