Option Strict On
Option Explicit On

Imports Nexamas.UI.Icons
Imports SkiaSharp

Namespace Nexamas.UI.Rendering

    ''' <summary>
    ''' Internal fluent builder used by Nexamas UI-owned PanelShell gateways.
    ''' It intentionally does not form part of the external SDK surface.
    ''' </summary>
    Friend NotInheritable Class MASPanelShellBuilder

        Private _boundsPx As SKRect
        Private _density As MASPanelShellDensity = MASPanelShellDensity.Normal
        Private _header As MASPanelShellHeaderSpec = MASPanelShellHeaderSpec.None
        Private _borderStrength As MASPanelShellStrength = MASPanelShellStrength.ThemeDefault
        Private _surfaceStrength As MASPanelShellStrength = MASPanelShellStrength.ThemeDefault
        Private _padding As MASPanelShellPadding = MASPanelShellPadding.ThemeDefault
        Private _surfaceVisualStyleKey As String = MASSurfaceVisualStyleIds.Auto
        Private _surfaceVisualStyle As MASSurfaceVisualStyle = Nothing
        Private _surfaceMaterialKey As String = MASSurfaceMaterialIds.Auto

        Friend Sub New(boundsPx As SKRect)
            _boundsPx = MASPanelShellValueNormalizer.NormalizeBoundsPx(boundsPx)
        End Sub

        Friend Function WithBounds(boundsPx As SKRect) As MASPanelShellBuilder
            _boundsPx = MASPanelShellValueNormalizer.NormalizeBoundsPx(boundsPx)
            Return Me
        End Function

        Friend Function WithDensity(value As MASPanelShellDensity) As MASPanelShellBuilder
            _density = MASPanelShellValueNormalizer.NormalizeDensity(value)
            _header = _header.WithDensity(_density)
            Return Me
        End Function

        Friend Function WithoutHeader() As MASPanelShellBuilder
            _header = MASPanelShellHeaderSpec.None.WithDensity(_density)
            Return Me
        End Function

        Friend Function WithHeader(title As String,
                                   Optional subtitle As String = "",
                                   Optional iconKind As MASIconKind = MASIconKind.Info,
                                   Optional showIcon As Boolean = False,
                                   Optional showCloseButton As Boolean = False,
                                   Optional size As MASPanelShellHeaderSize = MASPanelShellHeaderSize.Normal) As MASPanelShellBuilder

            _header = MASPanelShellHeaderSpec.Create(
                title:=title,
                subtitle:=subtitle,
                iconKind:=iconKind,
                showIcon:=showIcon,
                showCloseButton:=showCloseButton,
                size:=size,
                density:=_density)

            Return Me
        End Function

        Friend Function WithHeader(headerSpec As MASPanelShellHeaderSpec) As MASPanelShellBuilder
            _header = If(headerSpec, MASPanelShellHeaderSpec.None).WithDensity(_density)
            Return Me
        End Function

        Friend Function WithHeaderSize(value As MASPanelShellHeaderSize) As MASPanelShellBuilder
            _header = _header.WithSize(MASPanelShellValueNormalizer.NormalizeHeaderSize(value)).WithDensity(_density)
            Return Me
        End Function

        Friend Function WithStrengths(border As MASPanelShellStrength,
                                      surface As MASPanelShellStrength) As MASPanelShellBuilder
            _borderStrength = MASPanelShellValueNormalizer.NormalizeStrength(border)
            _surfaceStrength = MASPanelShellValueNormalizer.NormalizeStrength(surface)
            Return Me
        End Function

        Friend Function WithBorderStrength(value As MASPanelShellStrength) As MASPanelShellBuilder
            _borderStrength = MASPanelShellValueNormalizer.NormalizeStrength(value)
            Return Me
        End Function

        Friend Function WithSurfaceStrength(value As MASPanelShellStrength) As MASPanelShellBuilder
            _surfaceStrength = MASPanelShellValueNormalizer.NormalizeStrength(value)
            Return Me
        End Function


        Friend Function WithSurfaceVisualStyleKey(styleKey As String) As MASPanelShellBuilder
            _surfaceVisualStyleKey = MASPanelShellValueNormalizer.NormalizeKey(styleKey, MASSurfaceVisualStyleIds.Auto)
            _surfaceVisualStyle = Nothing
            Return Me
        End Function

        Friend Function WithSurfaceVisualStyle(style As MASSurfaceVisualStyle) As MASPanelShellBuilder
            _surfaceVisualStyle = style
            _surfaceVisualStyleKey = If(style Is Nothing, MASSurfaceVisualStyleIds.Auto, style.Id)
            Return Me
        End Function

        Friend Function WithSurfaceMaterialKey(materialKey As String) As MASPanelShellBuilder
            _surfaceMaterialKey = MASPanelShellValueNormalizer.NormalizeKey(materialKey, MASSurfaceMaterialIds.Auto)
            Return Me
        End Function

        Friend Function WithPadding(allDip As Single) As MASPanelShellBuilder
            _padding = MASPanelShellPadding.All(allDip)
            Return Me
        End Function

        Friend Function WithPadding(horizontalDip As Single,
                                    verticalDip As Single) As MASPanelShellBuilder
            _padding = MASPanelShellPadding.Symmetric(horizontalDip, verticalDip)
            Return Me
        End Function

        Friend Function WithPadding(leftDip As Single,
                                    topDip As Single,
                                    rightDip As Single,
                                    bottomDip As Single) As MASPanelShellBuilder
            _padding = New MASPanelShellPadding(leftDip, topDip, rightDip, bottomDip)
            Return Me
        End Function

        Friend Function Build() As MASPanelShellSpec
            Return New MASPanelShellSpec(
                boundsPx:=_boundsPx,
                density:=_density,
                header:=_header.WithDensity(_density),
                borderStrength:=_borderStrength,
                surfaceStrength:=_surfaceStrength,
                padding:=_padding,
                surfaceVisualStyleKey:=_surfaceVisualStyleKey,
                surfaceMaterialKey:=_surfaceMaterialKey,
                surfaceVisualStyle:=_surfaceVisualStyle)
        End Function

    End Class

End Namespace
