Option Strict On
Option Explicit On

Imports SkiaSharp

Namespace Nexamas.UI.Application

    ''' <summary>
    ''' Public Application-level layout result for drawing a MAS PanelShell inside a layered scene.
    ''' It intentionally exposes only stable geometry needed by application hosts: base, header,
    ''' content, and close-button rectangles in physical pixels.
    ''' </summary>
    <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
    Friend NotInheritable Class MASApplicationPanelShellChromeResult

        Public Shared ReadOnly Empty As MASApplicationPanelShellChromeResult =
            New MASApplicationPanelShellChromeResult(
                baseRectPx:=SKRect.Empty,
                headerRectPx:=SKRect.Empty,
                contentRectPx:=SKRect.Empty,
                closeButtonRectPx:=SKRect.Empty,
                radiusPx:=0.0F,
                hasHeader:=False)

        Friend ReadOnly Property BaseRectPx As SKRect
        Friend ReadOnly Property HeaderRectPx As SKRect
        Friend ReadOnly Property ContentRectPx As SKRect
        Friend ReadOnly Property CloseButtonRectPx As SKRect
        Friend ReadOnly Property RadiusPx As Single
        Friend ReadOnly Property HasHeader As Boolean

        Friend Sub New(baseRectPx As SKRect,
                       headerRectPx As SKRect,
                       contentRectPx As SKRect,
                       closeButtonRectPx As SKRect,
                       radiusPx As Single,
                       hasHeader As Boolean)

            Me.BaseRectPx = baseRectPx
            Me.HeaderRectPx = headerRectPx
            Me.ContentRectPx = contentRectPx
            Me.CloseButtonRectPx = closeButtonRectPx
            Me.RadiusPx = Math.Max(0.0F, radiusPx)
            Me.HasHeader = hasHeader

        End Sub

        Friend ReadOnly Property HasContent As Boolean
            Get
                Return ContentRectPx.Width > 0.5F AndAlso ContentRectPx.Height > 0.5F
            End Get
        End Property

        Friend ReadOnly Property HasCloseButton As Boolean
            Get
                Return CloseButtonRectPx.Width > 0.5F AndAlso CloseButtonRectPx.Height > 0.5F
            End Get
        End Property

        Friend Function IsInsideCloseButton(pointPx As SKPoint) As Boolean
            If Not HasCloseButton Then Return False
            Return CloseButtonRectPx.Contains(pointPx.X, pointPx.Y)
        End Function

        Friend Function IsInsideHeader(pointPx As SKPoint,
                                       Optional includeCloseButton As Boolean = True) As Boolean
            If Not HasHeader Then Return False
            If HeaderRectPx.Width <= 0.5F OrElse HeaderRectPx.Height <= 0.5F Then Return False
            If Not includeCloseButton AndAlso IsInsideCloseButton(pointPx) Then Return False
            Return HeaderRectPx.Contains(pointPx.X, pointPx.Y)
        End Function

    End Class

End Namespace
