Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Layout
Imports Nexamas.UI.Theming
Imports SkiaSharp

Namespace Nexamas.UI.Controls

    Friend NotInheritable Class MASTabControlLayoutPlan
        Friend Shared ReadOnly Thresholds As New MASResponsiveLayoutThresholds(
            fullWidthDip:=360.0F,
            denseWidthDip:=260.0F,
            compactWidthDip:=180.0F,
            minimalWidthDip:=96.0F,
            fullHeightDip:=40.0F,
            denseHeightDip:=34.0F,
            compactHeightDip:=27.0F,
            minimalHeightDip:=18.0F)

        Friend ReadOnly Property ResponsiveProfile As MASResponsiveLayoutProfile
        Friend ReadOnly Property Dpi As Single
        Friend ReadOnly Property MetricDpi As Single

        Private Sub New(profile As MASResponsiveLayoutProfile)
            Dim safeProfile As MASResponsiveLayoutProfile = If(profile, MASResponsiveLayoutResolver.FromLogicalSize(MASSizeLayoutIntegrationContext.Empty, SKSize.Empty, MASSize.Default, Thresholds))
            Me.ResponsiveProfile = safeProfile
            Me.Dpi = safeProfile.DpiScale
            Me.MetricDpi = safeProfile.DpiScale * Clamp(safeProfile.ContentScale, 0.66F, 1.24F)
        End Sub

        Friend Shared Function Create(ctx As MASThemeContext,
                                      availableBoundsPx As SKRect,
                                      sizeIntent As MASSize) As MASTabControlLayoutPlan
            Return New MASTabControlLayoutPlan(MASResponsiveLayoutResolver.FromTheme(ctx, availableBoundsPx, sizeIntent, Thresholds))
        End Function

        Private Shared Function Clamp(value As Single, minValue As Single, maxValue As Single) As Single
            If Single.IsNaN(value) OrElse Single.IsInfinity(value) OrElse value <= 0.0F Then Return 1.0F
            If value < minValue Then Return minValue
            If value > maxValue Then Return maxValue
            Return value
        End Function
    End Class

End Namespace
