Option Strict On
Option Explicit On

Imports System
Imports SkiaSharp

Namespace Nexamas.UI.Components

    ''' <summary>
    ''' Immutable Friend-only hosted-content slot snapshot. It records ownership,
    ''' lifecycle generation, visibility, and placement facts without exposing child
    ''' controls or creating a public host/shell API.
    ''' </summary>
    Friend NotInheritable Class MASHostedContentSlotSnapshot

        Friend Sub New(ownerComponentId As String,
                       slotKey As String,
                       slotKind As MASHostedContentSlotKind,
                       childTypeName As String,
                       childName As String,
                       isHosted As Boolean,
                       isVisible As Boolean,
                       hasPlacement As Boolean,
                       boundsLogical As SKRect,
                       clipBoundsLogical As System.Nullable(Of SKRect),
                       lifecycleGeneration As Integer)
            Me.OwnerComponentId = Normalize(ownerComponentId)
            Me.SlotKey = Normalize(slotKey)
            Me.SlotKind = slotKind
            Me.ChildTypeName = Normalize(childTypeName)
            Me.ChildName = Normalize(childName)
            Me.IsHosted = isHosted
            Me.IsVisible = isVisible
            Me.HasPlacement = hasPlacement
            Me.BoundsLogical = boundsLogical
            Me.ClipBoundsLogical = clipBoundsLogical
            Me.LifecycleGeneration = Math.Max(0, lifecycleGeneration)
        End Sub

        Friend ReadOnly Property OwnerComponentId As String
        Friend ReadOnly Property SlotKey As String
        Friend ReadOnly Property SlotKind As MASHostedContentSlotKind
        Friend ReadOnly Property ChildTypeName As String
        Friend ReadOnly Property ChildName As String
        Friend ReadOnly Property IsHosted As Boolean
        Friend ReadOnly Property IsVisible As Boolean
        Friend ReadOnly Property HasPlacement As Boolean
        Friend ReadOnly Property BoundsLogical As SKRect
        Friend ReadOnly Property ClipBoundsLogical As System.Nullable(Of SKRect)
        Friend ReadOnly Property LifecycleGeneration As Integer

        Friend ReadOnly Property IsStructurallyValid As Boolean
            Get
                Return OwnerComponentId.Length > 0 AndAlso
                       SlotKey.Length > 0 AndAlso
                       SlotKind <> MASHostedContentSlotKind.Unknown AndAlso
                       LifecycleGeneration >= 0
            End Get
        End Property

        Private Shared Function Normalize(value As String) As String
            If value Is Nothing Then Return String.Empty
            Dim text As String = value.Trim()
            If text.Length = 0 Then Return String.Empty
            Do While text.Contains("  ")
                text = text.Replace("  ", " ")
            Loop
            Return text
        End Function

    End Class

End Namespace
