Option Strict On
Option Explicit On

Imports System
Imports SkiaSharp

Namespace Nexamas.UI.Components

    Friend NotInheritable Class MASPropertyGridTokens
        Private Sub New()
        End Sub

        Friend Shared ReadOnly DesiredSizeDip As New SKSize(360.0F, 420.0F)
        Friend Shared ReadOnly MinimumSizeDip As New SKSize(260.0F, 220.0F)

        Friend Const SurfaceRadiusDip As Single = 13.0F
        Friend Const HeaderHeightDip As Single = 38.0F
        Friend Const CategoryHeightDip As Single = 25.0F
        Friend Const RowHeightDip As Single = 29.0F
        Friend Const ContentInsetDip As Single = 10.0F
        Friend Const NameColumnWidthDip As Single = 145.0F
        Friend Const CellInsetDip As Single = 8.0F
        Friend Const SplitterStrokeDip As Single = 1.0F

        Friend Shared Function ToPx(valueDip As Single, dpi As Single) As Single
            If Single.IsNaN(dpi) OrElse Single.IsInfinity(dpi) OrElse dpi <= 0.0F Then dpi = 1.0F
            Return valueDip * dpi
        End Function

        Friend Shared Function ResolveGridRect(boundsPx As SKRect, dpi As Single) As SKRect
            Dim inset As Single = ToPx(ContentInsetDip, dpi)
            Dim header As Single = ToPx(HeaderHeightDip, dpi)
            Return New SKRect(boundsPx.Left + inset, boundsPx.Top + header, boundsPx.Right - inset, boundsPx.Bottom - inset)
        End Function

        Friend Shared Function NormalizeScrollOffset(offsetPx As Single, totalContentHeightPx As Single, viewportHeightPx As Single) As Single
            If Single.IsNaN(offsetPx) OrElse Single.IsInfinity(offsetPx) OrElse offsetPx < 0.0F Then Return 0.0F
            Dim maxOffset As Single = Math.Max(0.0F, totalContentHeightPx - Math.Max(0.0F, viewportHeightPx))
            If offsetPx > maxOffset Then Return maxOffset
            Return offsetPx
        End Function

    End Class

End Namespace
