Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Layout

Namespace Nexamas.UI.Composition

    ''' <summary>
    ''' Internal root-screen layout policy tokens.
    ''' These values are owned by Nexamas UI so external projects do not hard-code region widths,
    ''' gutters, or screen partition formulas.
    ''' </summary>
    Friend NotInheritable Class MASScreenRegionLayoutTokens
        Private Sub New()
        End Sub

        Friend Const SideCombinedMaxShareWithContent As Single = 0.5F
        Friend Const NavigationMaxShareWithContent As Single = 0.36F
        Friend Const InspectorMaxShareWithContent As Single = 0.3F

        ''' <summary>
        ''' Neutral structural height from the button and application-chrome contracts. It is
        ''' intentionally not returned directly as the Default Command slot height; the final
        ''' Default contract is rebased below so the previous Compact visual height becomes
        ''' the new Default source value.
        ''' </summary>
        Friend Const CommandRegionStructuralHeight As Single = MASComponentSizeContractTokens.ButtonDefaultHeight + MASComponentSizeContractTokens.ApplicationTopBarDefaultHeight

        ''' <summary>
        ''' Command regions are application workspace chrome, not another TopBar. The default
        ''' command slot therefore uses the platform Compact height scale as its source
        ''' baseline, then all runtime profiles continue moving through MASSizeProfile.
        ''' This keeps the rebalanced height centralized in Nexamas UI instead of forcing
        ''' consumers to compensate with local bounds.
        ''' </summary>
        Private Shared ReadOnly CommandRegionDefaultHeightSourceScale As Single = MASSizeProfile.Compact.HeightScale

        ''' <summary>
        ''' Command action buttons are wider than normal dialog buttons but must not expand
        ''' until they consume the whole command region. The ratio is owned here so product
        ''' screens request a semantic command action row instead of assigning local widths.
        ''' </summary>
        Private Const CommandActionWidthToButtonRatio As Single = 11.0F / 5.0F

        ''' <summary>
        ''' Command actions need a slightly taller presence than the base button contract in
        ''' app workspaces. Height still flows through MASSizeProfile so Compact, Default,
        ''' Comfortable, Large, and TouchFriendly remain coherent.
        ''' </summary>
        Private Const CommandActionHeightToButtonRatio As Single = 11.0F / 10.0F

        ''' <summary>
        ''' Minimum readable width for command actions before the row must move trailing
        ''' actions into overflow. The ratio is intentionally tied to the same button token
        ''' family as normal command action width so all size profiles remain coherent.
        ''' </summary>
        Private Const CommandActionMinimumWidthToButtonRatio As Single = 8.0F / 5.0F

        ''' <summary>
        ''' Compact overflow action width. The overflow button is a real command participant,
        ''' but it uses the base button width rather than the wider command-action width.
        ''' </summary>
        Private Const CommandActionOverflowWidthToButtonRatio As Single = 1.0F

        ''' <summary>
        ''' Base distance between command actions. The value is intentionally owned by the
        ''' command-action contract so consumers never simulate breathing room through
        ''' local margins or manual button bounds.
        ''' </summary>
        Private Const CommandActionBaseSpacing As Single = 9.0F

        Private Const CommandBackgroundBasePaddingX As Single = 16.0F
        Private Const CommandBackgroundBasePaddingY As Single = 8.0F

        Friend Shared ReadOnly Property CommandRegionDefaultHeight As Single
            Get
                Return CommandRegionStructuralHeight * CommandRegionDefaultHeightSourceScale
            End Get
        End Property

        Friend Shared ReadOnly Property CommandActionDefaultWidth As Single
            Get
                Return MASComponentSizeContractTokens.ButtonDefaultWidth * CommandActionWidthToButtonRatio
            End Get
        End Property

        Friend Shared ReadOnly Property CommandActionDefaultHeight As Single
            Get
                Return MASComponentSizeContractTokens.ButtonDefaultHeight * CommandActionHeightToButtonRatio
            End Get
        End Property

        Friend Shared ReadOnly Property CommandActionMinimumDefaultWidth As Single
            Get
                Return MASComponentSizeContractTokens.ButtonDefaultWidth * CommandActionMinimumWidthToButtonRatio
            End Get
        End Property

        Friend Shared ReadOnly Property CommandActionOverflowDefaultWidth As Single
            Get
                Return MASComponentSizeContractTokens.ButtonDefaultWidth * CommandActionOverflowWidthToButtonRatio
            End Get
        End Property

        Friend Shared Function ResolveCommandRegionHeight(profile As MASSizeProfile) As Single
            Dim safeProfile As MASSizeProfile = MASSizeProfile.Normalize(profile)
            Return CommandRegionDefaultHeight * safeProfile.HeightScale
        End Function

        Friend Shared Function ResolveCommandActionWidth(profile As MASSizeProfile) As Single
            Dim safeProfile As MASSizeProfile = MASSizeProfile.Normalize(profile)
            Return CommandActionDefaultWidth * safeProfile.WidthScale
        End Function

        Friend Shared Function ResolveCommandActionHeight(profile As MASSizeProfile) As Single
            Dim safeProfile As MASSizeProfile = MASSizeProfile.Normalize(profile)
            Return CommandActionDefaultHeight * safeProfile.HeightScale
        End Function

        Friend Shared Function ResolveCommandActionMinimumWidth(profile As MASSizeProfile) As Single
            Dim safeProfile As MASSizeProfile = MASSizeProfile.Normalize(profile)
            Return CommandActionMinimumDefaultWidth * safeProfile.WidthScale
        End Function

        Friend Shared Function ResolveCommandActionOverflowWidth(profile As MASSizeProfile) As Single
            Dim safeProfile As MASSizeProfile = MASSizeProfile.Normalize(profile)
            Return CommandActionOverflowDefaultWidth * safeProfile.WidthScale
        End Function

        Friend Shared Function ResolveCommandActionSpacing(profile As MASSizeProfile) As Single
            Dim safeProfile As MASSizeProfile = MASSizeProfile.Normalize(profile)
            Return CommandActionBaseSpacing * safeProfile.GapScale
        End Function

        Friend Shared Function ResolveCommandBackgroundPadding(profile As MASSizeProfile) As MASLayoutThickness
            Dim safeProfile As MASSizeProfile = MASSizeProfile.Normalize(profile)

            Return New MASLayoutThickness(
                CommandBackgroundBasePaddingX * safeProfile.WidthScale,
                CommandBackgroundBasePaddingY * safeProfile.HeightScale,
                CommandBackgroundBasePaddingX * safeProfile.WidthScale,
                CommandBackgroundBasePaddingY * safeProfile.HeightScale)
        End Function
    End Class

End Namespace
