Option Strict On
Option Explicit On

Imports Nexamas.UI.General
Imports Nexamas.UI.Values
Imports SkiaSharp

Namespace Nexamas.UI.Scroll

    '========================================================
    ' ScrollRailPolicy (SSOT)
    ' - Reserves a right-side rail for scrollbar (Thickness + Gap)
    ' - Dynamic tension (SmootherStep) like your FormLayout philosophy
    ' - Returns ContentRect which MUST be used for drawing hover/selected/items
    '========================================================
    Friend NotInheritable Class ScrollRailPolicy

        Private Sub New()
        End Sub

        Friend Structure Metrics
            Friend HostRect As SKRect
            Friend ContentRect As SKRect
            Friend RailRect As SKRect
            Friend RailWidth As Single
            Friend GapPx As Single
            Friend ThicknessPx As Single
        End Structure

        Friend Shared Function Build(hostRectPx As SKRect, dpi As Single) As Metrics

            Dim m As New Metrics With {
        .HostRect = hostRectPx,
        .ContentRect = hostRectPx,
        .RailRect = SKRect.Empty,
        .RailWidth = 0.0F,
        .GapPx = 0.0F,
        .ThicknessPx = 0.0F
    }

            If hostRectPx.IsEmpty OrElse hostRectPx.Width < 10 OrElse hostRectPx.Height < 10 Then Return m
            dpi = PixelSnap.SafeDpi(dpi)

            Dim thick As Single = FensterTokens.ScrollbarWidth * dpi
            Dim gap As Single = FensterTokens.ScrollbarGapDip * dpi

            thick = Math.Max(4.0F * dpi, thick)
            gap = Math.Max(0.0F, gap)

            '=====================================
            ' Rail (مكان السكرول)
            '=====================================
            Dim railLeft As Single = hostRectPx.Right - thick
            Dim contentRight As Single = railLeft - gap

            Dim rail As SKRect = PixelSnap.SnapRectHalf(
    New SKRect(
        railLeft,
        hostRectPx.Top,
        hostRectPx.Right,
        hostRectPx.Bottom
    )
)

            Dim content As SKRect = PixelSnap.SnapRectHalf(
    New SKRect(
        hostRectPx.Left,
        hostRectPx.Top,
        contentRight,
        hostRectPx.Bottom
    )
)

            m.RailRect = rail
            m.ContentRect = content
            m.RailWidth = thick
            m.GapPx = gap
            m.ThicknessPx = thick

            Return m

        End Function



    End Class

End Namespace
