Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports Nexamas.UI.Controls
Imports Nexamas.UI.Host
Imports Nexamas.UI.Layout
Imports Nexamas.UI.Theming
Imports SkiaSharp

Namespace Nexamas.UI.Application


    Friend NotInheritable Class MASApplicationLayoutSectionEntry
        Private ReadOnly _children As List(Of MASApplicationLayoutControlEntry)
        Private ReadOnly _spacing As Single
        Private ReadOnly _padding As MASLayoutInset

        Friend Sub New(children As IEnumerable(Of MASApplicationLayoutControlEntry),
                       spacing As Single,
                       padding As MASLayoutInset)
            _children = New List(Of MASApplicationLayoutControlEntry)()
            If children IsNot Nothing Then _children.AddRange(children)
            _spacing = MASApplicationLayoutPageBuilder.SafeNonNegative(spacing)
            _padding = padding
        End Sub

        Friend Function BuildNode(Optional sizeProfile As MASSizeProfile = Nothing) As MASLayoutNode
            Dim profile As MASSizeProfile = MASSizeProfile.Normalize(sizeProfile)
            Dim nodes As New List(Of MASLayoutNode)()
            For Each child As MASApplicationLayoutControlEntry In _children
                nodes.Add(child.BuildNode())
            Next
            Return MASLayoutBuilder.Section(nodes,
                                            MASLayoutSpacingResolver.ScaleLength(_spacing, profile),
                                            MASLayoutSpacingResolver.ScaleInset(_padding, profile))
        End Function

        Friend Sub CollectControls(target As IList(Of MASControlBase))
            If target Is Nothing Then Return
            For Each child As MASApplicationLayoutControlEntry In _children
                child.CollectControls(target)
            Next
        End Sub
    End Class

End Namespace
