Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Components

    Friend NotInheritable Class MASBreadcrumbLayoutPlan
        Friend Shared ReadOnly Thresholds As New MASResponsiveLayoutThresholds(
            fullWidthDip:=360.0F,
            denseWidthDip:=260.0F,
            compactWidthDip:=170.0F,
            minimalWidthDip:=88.0F,
            fullHeightDip:=36.0F,
            denseHeightDip:=30.0F,
            compactHeightDip:=24.0F,
            minimalHeightDip:=16.0F)

        Friend ReadOnly Property ResponsiveProfile As MASResponsiveLayoutProfile
        Friend ReadOnly Property Dpi As Single
        Friend ReadOnly Property MetricDpi As Single
        Friend ReadOnly Property PaddingHorizontalPx As Single
        Friend ReadOnly Property PaddingVerticalPx As Single
        Friend ReadOnly Property ItemPaddingHorizontalPx As Single
        Friend ReadOnly Property SeparatorWidthPx As Single
        Friend ReadOnly Property SeparatorGapPx As Single
        Friend ReadOnly Property ItemRadiusPx As Single
        Friend ReadOnly Property FocusInflatePx As Single
        Friend ReadOnly Property FocusStrokePx As Single
        Friend ReadOnly Property CollapseToTailOnly As Boolean

        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.64F, 1.24F)
            Me.PaddingHorizontalPx = safeProfile.ChromeDipToPx(BreadcrumbTokens.PaddingHorizontalDip)
            Me.PaddingVerticalPx = safeProfile.ChromeDipToPx(BreadcrumbTokens.PaddingVerticalDip)
            Me.ItemPaddingHorizontalPx = safeProfile.ChromeDipToPx(BreadcrumbTokens.ItemPaddingHorizontalDip)
            Me.SeparatorWidthPx = safeProfile.ContentDipToPx(BreadcrumbTokens.SeparatorWidthDip)
            Me.SeparatorGapPx = safeProfile.GapDipToPx(BreadcrumbTokens.SeparatorGapDip)
            Me.ItemRadiusPx = Math.Max(3.0F * safeProfile.DpiScale, safeProfile.ChromeDipToPx(BreadcrumbTokens.ItemRadiusDip))
            Me.FocusInflatePx = Math.Max(0.5F * safeProfile.DpiScale, safeProfile.GapDipToPx(1.0F))
            Me.FocusStrokePx = Math.Max(1.0F, safeProfile.ChromeDipToPx(BreadcrumbTokens.FocusStrokeDip))
            Me.CollapseToTailOnly = safeProfile.IsCollapsed
        End Sub

        Friend Shared Function Create(ctx As MASThemeContext,
                                      availableBoundsPx As SKRect,
                                      sizeIntent As MASSize) As MASBreadcrumbLayoutPlan
            Return New MASBreadcrumbLayoutPlan(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
