Option Strict On
Option Explicit On

Imports Nexamas.UI.Values

Namespace Nexamas.UI.Components

    ''' <summary>
    ''' Friend-only proof that MASSplitView can snapshot and restore bounded ratios,
    ''' pane text, and collapse state without becoming a dock engine, shell router,
    ''' child host, native panel wrapper, or external storage system.
    ''' </summary>
    Friend NotInheritable Class MASSplitViewPersistenceGate
        Private Sub New()
        End Sub

        Friend Shared Function Passes() As Boolean
            Try
                If Not MASSplitViewPolicy.HasLayoutSnapshotPersistencePath() Then Return False

                Dim split As MASSplitView = MASSplitView.Create("Gate split")
                split.LeftPaneTitle = "Left"
                split.ContentPaneTitle = "Work"
                split.RightPaneTitle = "Right"
                split.SetPaneTexts("Navigation", "Content", "Inspector")
                split.LeftPaneRatio = 0.2F
                split.RightPaneRatio = 0.25F
                split.CollapseRight(True)

                Dim snapshot As MASSplitViewLayoutSnapshot = split.CreateLayoutSnapshot()
                If snapshot Is Nothing Then Return False
                If snapshot.Title <> "Gate split" Then Return False
                If snapshot.LeftPaneTitle <> "Left" Then Return False
                If snapshot.RightPaneCollapsed = False Then Return False
                If snapshot.LeftPaneRatio < SplitViewTokens.MinPaneRatio Then Return False
                If snapshot.RightPaneRatio < SplitViewTokens.MinPaneRatio Then Return False

                split.ResetPaneLayout()
                If split.IsRightPaneCollapsed Then Return False
                If Not split.RestoreLayoutSnapshot(snapshot) Then Return False
                If split.LeftPaneTitle <> "Left" Then Return False
                If split.ContentPaneTitle <> "Work" Then Return False
                If split.RightPaneTitle <> "Right" Then Return False
                If Not split.IsRightPaneCollapsed Then Return False
                If System.Math.Abs(split.LeftPaneRatio - snapshot.LeftPaneRatio) > 0.001F Then Return False
                If System.Math.Abs(split.RightPaneRatio - snapshot.RightPaneRatio) > 0.001F Then Return False
                If Not split.HasLayoutSnapshotForTests() Then Return False

                Return True
            Catch ex As System.Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDiagnosticOnly(ex, "MASSplitViewPersistenceGate")
                Return False
            End Try
        End Function
    End Class

End Namespace
