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.Rendering
Imports Nexamas.UI.Theming
Imports Nexamas.UI.Components
Imports SkiaSharp

Namespace Nexamas.UI.Application

    Partial Public NotInheritable Class MASApplicationSurfaceLayoutBuilder
        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
        Friend Function Gap(value As Single) As MASApplicationSurfaceLayoutBuilder
            ApplyAllRegionGaps(SafeNonNegative(value))
            Return Me
        End Function

        ''' <summary>
        ''' Uses the official MASLayout semantic spacing vocabulary for every distance between
        ''' application-surface regions. More specific gaps can be overridden afterwards through
        ''' CommandBodyGap, BodyFooterGap, ColumnGap, or SidebarFooterGap.
        ''' </summary>

        Public Function Gap(value As MASLayoutSpacing) As MASApplicationSurfaceLayoutBuilder
            ApplyAllRegionGaps(MASLayoutSpacingResolver.ResolveBase(value))
            Return Me
        End Function

        ''' <summary>
        ''' Applies a complete Nexamas UI application-surface rhythm preset. This is the preferred way to
        ''' make a whole application surface compact, comfortable, or spacious without scattering manual gaps.
        ''' </summary>

        Public Function Rhythm(value As MASApplicationSurfaceRhythm) As MASApplicationSurfaceLayoutBuilder
            Select Case NormalizeRhythm(value)
                Case MASApplicationSurfaceRhythm.Compact
                    ApplyRhythm(MASLayoutSpacing.Small,
                                MASLayoutSpacing.Small,
                                MASLayoutSpacing.Small,
                                MASLayoutSpacing.Small,
                                MASLayoutSpacing.Small)
                Case MASApplicationSurfaceRhythm.Spacious
                    ApplyRhythm(MASLayoutSpacing.Spacious,
                                MASLayoutSpacing.Spacious,
                                MASLayoutSpacing.Large,
                                MASLayoutSpacing.Large,
                                MASLayoutSpacing.Large)
                Case Else
                    ApplyRhythm(MASLayoutSpacing.Large,
                                MASLayoutSpacing.Large,
                                MASLayoutSpacing.Large,
                                MASLayoutSpacing.Large,
                                MASLayoutSpacing.Large)
            End Select

            Return Me
        End Function

        Public Function CompactRhythm() As MASApplicationSurfaceLayoutBuilder
            Return Rhythm(MASApplicationSurfaceRhythm.Compact)
        End Function

        Public Function ComfortableRhythm() As MASApplicationSurfaceLayoutBuilder
            Return Rhythm(MASApplicationSurfaceRhythm.Comfortable)
        End Function

        Public Function SpaciousRhythm() As MASApplicationSurfaceLayoutBuilder
            Return Rhythm(MASApplicationSurfaceRhythm.Spacious)
        End Function

        ''' <summary>
        ''' Sets the semantic vertical distance between the command bar and the body area.
        ''' </summary>

        Public Function CommandBodyGap(value As MASLayoutSpacing) As MASApplicationSurfaceLayoutBuilder
            _commandBodyGap = MASLayoutSpacingResolver.ResolveBase(value)
            Return Me
        End Function

        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
        Friend Function CommandBodyGap(value As Single) As MASApplicationSurfaceLayoutBuilder
            _commandBodyGap = SafeNonNegative(value)
            Return Me
        End Function

        ''' <summary>
        ''' Sets the semantic vertical distance between the body area and the footer.
        ''' </summary>

        Public Function BodyFooterGap(value As MASLayoutSpacing) As MASApplicationSurfaceLayoutBuilder
            _bodyFooterGap = MASLayoutSpacingResolver.ResolveBase(value)
            Return Me
        End Function

        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
        Friend Function BodyFooterGap(value As Single) As MASApplicationSurfaceLayoutBuilder
            _bodyFooterGap = SafeNonNegative(value)
            Return Me
        End Function

        ''' <summary>
        ''' Sets the semantic horizontal distance between sidebar, content, and inspector columns.
        ''' </summary>

        Public Function ColumnGap(value As MASLayoutSpacing) As MASApplicationSurfaceLayoutBuilder
            _columnGap = MASLayoutSpacingResolver.ResolveBase(value)
            Return Me
        End Function

        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
        Friend Function ColumnGap(value As Single) As MASApplicationSurfaceLayoutBuilder
            _columnGap = SafeNonNegative(value)
            Return Me
        End Function

        ''' <summary>
        ''' Sets the semantic vertical distance between the sidebar main region and its sidebar footer.
        ''' </summary>

        Public Function SidebarFooterGap(value As MASLayoutSpacing) As MASApplicationSurfaceLayoutBuilder
            _sidebarFooterGap = MASLayoutSpacingResolver.ResolveBase(value)
            Return Me
        End Function

        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
        Friend Function SidebarFooterGap(value As Single) As MASApplicationSurfaceLayoutBuilder
            _sidebarFooterGap = SafeNonNegative(value)
            Return Me
        End Function

        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
        Friend Function Padding(all As Single) As MASApplicationSurfaceLayoutBuilder
            _outerPadding = New MASLayoutInset(all)
            Return Me
        End Function

        ''' <summary>
        ''' Uses semantic outer application-surface padding from MASLayout instead of raw logical numbers.
        ''' </summary>

        Public Function Padding(value As MASLayoutSpacing) As MASApplicationSurfaceLayoutBuilder
            _outerPadding = MASLayoutSpacingResolver.ResolveInsetBase(value)
            Return Me
        End Function

        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
        Friend Function Padding(left As Single,
                                top As Single,
                                right As Single,
                                bottom As Single) As MASApplicationSurfaceLayoutBuilder
            _outerPadding = New MASLayoutInset(left, top, right, bottom)
            Return Me
        End Function

        Public Function SidebarSize(size As MASApplicationSurfaceSideSize) As MASApplicationSurfaceLayoutBuilder
            _sidebarSize = NormalizeSidebarSize(size)
            Return Me
        End Function

        Public Function InspectorSize(size As MASApplicationSurfaceSideSize) As MASApplicationSurfaceLayoutBuilder
            _inspectorSize = NormalizeSidebarSize(size)
            Return Me
        End Function

        Public Function CommandBarSize(size As MASApplicationSurfaceBarSize) As MASApplicationSurfaceLayoutBuilder
            _commandBarSize = NormalizeBarSize(size)
            Return Me
        End Function

        ''' <summary>
        ''' Shows or hides the official command-region background. Consumers only choose whether
        ''' a background exists; Nexamas UI owns the internal visual source and currently paints
        ''' the background with the borderless/default card surface used by application-surface regions.
        ''' </summary>

        Public Function FooterSize(size As MASApplicationSurfaceBarSize) As MASApplicationSurfaceLayoutBuilder
            _footerSize = NormalizeBarSize(size)
            Return Me
        End Function

        Public Function SidebarFooterSize(size As MASApplicationSurfaceBarSize) As MASApplicationSurfaceLayoutBuilder
            _sidebarFooterSize = NormalizeBarSize(size)
            Return Me
        End Function

        ''' <summary>
        ''' Sets the minimum logical/DIP true workspace/content area width preserved before optional side panels are compressed.
        ''' This is a layout policy, not direct control sizing.
        ''' </summary>
        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
        Friend Function MinimumContentWidth(value As Single) As MASApplicationSurfaceLayoutBuilder
            _minimumContentWidth = SafeNonNegative(value)
            Return Me
        End Function
    End Class

End Namespace
