Option Strict On
Option Explicit On

Imports System
Imports SkiaSharp

Namespace Nexamas.UI.Application

    ''' <summary>
    ''' Internal PanelShell body section.
    ''' Padding and scrollbar placement are owned here so gateway builders do not
    ''' duplicate shell chrome offsets or manual scrollbar gutters.
    ''' </summary>
    Friend NotInheritable Class MASApplicationPanelShellContentSection

        Private ReadOnly _groupBox As MASApplicationPanelShellContentGroupBox

        Friend Sub New()
            _groupBox = New MASApplicationPanelShellContentGroupBox()
        End Sub

        ''' <summary>
        ''' Optional themed inner GroupBox surface for caller content.
        ''' When enabled, ContentBuilder receives the inner frame content bounds.
        ''' </summary>
        Friend ReadOnly Property GroupBox As MASApplicationPanelShellContentGroupBox
            Get
                Return _groupBox
            End Get
        End Property

        Friend Function UseGroupBox(Optional title As String = Nothing) As MASApplicationPanelShellContentGroupBox
            Return _groupBox.UseForContentBody(title)
        End Function

        Friend Function UseScrollableGroupBox(Optional title As String = Nothing) As MASApplicationPanelShellContentGroupBox
            Return _groupBox.UseForScrollableArea(title)
        End Function

        Friend Sub DisableGroupBox()
            _groupBox.Disable()
        End Sub

        Friend Property PaddingLeftPx As Single = 0.0F
        Friend Property PaddingTopPx As Single = 0.0F
        Friend Property PaddingRightPx As Single = 0.0F
        Friend Property PaddingBottomPx As Single = 0.0F

        ''' <summary>
        ''' Safe distance between the scrollbar track right edge and the shell content edge.
        ''' Lower values move the scrollbar closer to the edge without touching the chrome.
        ''' </summary>
        Friend Property ScrollbarEdgeInsetPx As Single = 6.0F

        Friend Sub SetPadding(allPx As Single)
            SetPadding(allPx, allPx, allPx, allPx)
        End Sub

        Friend Sub SetPadding(horizontalPx As Single,
                              verticalPx As Single)

            SetPadding(horizontalPx, verticalPx, horizontalPx, verticalPx)

        End Sub

        Friend Sub SetPadding(leftPx As Single,
                              topPx As Single,
                              rightPx As Single,
                              bottomPx As Single)

            PaddingLeftPx = Math.Max(0.0F, leftPx)
            PaddingTopPx = Math.Max(0.0F, topPx)
            PaddingRightPx = Math.Max(0.0F, rightPx)
            PaddingBottomPx = Math.Max(0.0F, bottomPx)

        End Sub

        Friend Function ApplyPadding(boundsPx As SKRect) As SKRect

            If boundsPx.IsEmpty Then Return boundsPx

            Dim result As New SKRect(
                boundsPx.Left + Math.Max(0.0F, PaddingLeftPx),
                boundsPx.Top + Math.Max(0.0F, PaddingTopPx),
                boundsPx.Right - Math.Max(0.0F, PaddingRightPx),
                boundsPx.Bottom - Math.Max(0.0F, PaddingBottomPx))

            If result.Right <= result.Left OrElse result.Bottom <= result.Top Then
                Return SKRect.Empty
            End If

            Return result

        End Function

    End Class

End Namespace
