Option Strict On
Option Explicit On

Imports Nexamas.UI.Theming
Imports SkiaSharp

Namespace Nexamas.UI.Components.DropDownMenu

    ''' <summary>
    ''' Maps MASMenuBarPaletteTheme colors into the generic MAS interaction palette bridge.
    ''' It owns color mapping only; state legality, strength, geometry, and drawing remain
    ''' owned by MASInteractionResolver and MASSurfaceInteractionRing.
    ''' </summary>
    Friend NotInheritable Class MASMenuBarInteractionPaletteFactory

        Private Sub New()
        End Sub

        Friend Shared Function CreateBarItemPalette(palette As MASMenuBarPaletteTheme,
                                                    popupOpen As Boolean) As IMASInteractionTheme

            Dim selectedFill As SKColor = If(popupOpen, palette.ItemPopupOpenFill, palette.ItemSelectedFill)

            Return New MASInteractionPaletteTheme(
                hover:=State(fill:=palette.ItemHoverFill),
                pressed:=State(fill:=palette.ItemPressedFill),
                selected:=State(fill:=selectedFill),
                focused:=State(fill:=SKColors.Transparent, ring:=palette.FocusRing),
                disabledFill:=MASInteractionThemeLayer.None)
        End Function

        Friend Shared Function CreateDropDownRowPalette(palette As MASMenuBarPaletteTheme) As IMASInteractionTheme

            Return New MASInteractionPaletteTheme(
                hover:=State(fill:=palette.PopupHoverFill),
                pressed:=State(fill:=palette.ItemPressedFill),
                selected:=State(fill:=palette.PopupSelectedFill),
                focused:=State(fill:=SKColors.Transparent, ring:=palette.FocusRing),
                disabledFill:=MASInteractionThemeLayer.None)
        End Function

        Private Shared Function State(fill As SKColor,
                                      Optional ring As SKColor = Nothing) As MASInteractionThemeState

            Return New MASInteractionThemeState(
                fill:=Layer(fill),
                ring:=Layer(ring))
        End Function

        Private Shared Function Layer(color As SKColor) As MASInteractionThemeLayer
            If color.Alpha = 0 Then Return MASInteractionThemeLayer.None
            Return New MASInteractionThemeLayer(True, color)
        End Function

    End Class

End Namespace
