Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Controls

    Friend NotInheritable Class MASWizardLayoutPlan
        Friend Shared ReadOnly Thresholds As New MASResponsiveLayoutThresholds(
            fullWidthDip:=560.0F,
            denseWidthDip:=430.0F,
            compactWidthDip:=310.0F,
            minimalWidthDip:=190.0F,
            fullHeightDip:=420.0F,
            denseHeightDip:=320.0F,
            compactHeightDip:=230.0F,
            minimalHeightDip:=130.0F)

        Friend ReadOnly Property ResponsiveProfile As MASResponsiveLayoutProfile
        Friend ReadOnly Property PaddingLeftDip As Single
        Friend ReadOnly Property PaddingTopDip As Single
        Friend ReadOnly Property PaddingRightDip As Single
        Friend ReadOnly Property PaddingBottomDip As Single
        Friend ReadOnly Property ContentGapDip As Single
        Friend ReadOnly Property StepperSlotHeightDip As Single
        Friend ReadOnly Property VerticalStepperWidthDip As Single
        Friend ReadOnly Property ForceStacked As Boolean
        Friend ReadOnly Property HideContent As Boolean

        Private Sub New(profile As MASResponsiveLayoutProfile)
            Dim safeProfile As MASResponsiveLayoutProfile = If(profile, MASResponsiveLayoutResolver.FromLogicalSize(MASSizeLayoutIntegrationContext.Empty, SKSize.Empty, MASSize.Default, Thresholds))
            Dim chromeScale As Single = Clamp(safeProfile.ChromeScale, 0.64F, 1.26F)
            Dim gapScale As Single = Clamp(safeProfile.GapScale, 0.5F, 1.2F)
            Dim contentScale As Single = Clamp(safeProfile.ContentScale, 0.64F, 1.22F)
            Me.ResponsiveProfile = safeProfile
            Me.PaddingLeftDip = StepperTokens.WizardPaddingLeftDip * chromeScale
            Me.PaddingTopDip = StepperTokens.WizardPaddingTopDip * chromeScale
            Me.PaddingRightDip = StepperTokens.WizardPaddingRightDip * chromeScale
            Me.PaddingBottomDip = StepperTokens.WizardPaddingBottomDip * chromeScale
            Me.ContentGapDip = StepperTokens.WizardContentGapDip * gapScale
            Me.StepperSlotHeightDip = StepperTokens.WizardStepperSlotHeightDip * contentScale
            Me.VerticalStepperWidthDip = StepperTokens.WizardVerticalStepperWidthDip * contentScale
            Me.ForceStacked = safeProfile.Mode = MASResponsiveLayoutMode.Compact OrElse safeProfile.Mode = MASResponsiveLayoutMode.Minimal OrElse safeProfile.Mode = MASResponsiveLayoutMode.Collapsed
            Me.HideContent = safeProfile.IsCollapsed
        End Sub

        Friend Shared Function CreateForLogical(availableSizeDip As SKSize,
                                                sizeIntent As MASSize) As MASWizardLayoutPlan
            Dim integration As MASSizeLayoutIntegrationContext = MASSizeLayoutIntegrationGateway.Create(Nothing, MASRuntimeSizeProfileService.Current, 1.0F)
            Return New MASWizardLayoutPlan(MASResponsiveLayoutResolver.FromLogicalSize(integration, availableSizeDip, 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
