Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Icons
Imports Nexamas.UI.Values

Namespace Nexamas.UI.Rendering

    ''' <summary>
    ''' Internal visual contract for MAS dialog-like surfaces hosted by MASPanelShell.
    ''' The options are intentionally content-neutral: FilePicker, FileExplorer,
    ''' MessageBox, and SelectionDialog supply different content, while public
    ''' projects stay on MASApplication gateway APIs instead of this raw shell recipe.
    ''' </summary>
    Friend NotInheritable Class MASPanelShellDialogOptions

        Friend Property Title As String = String.Empty
        Friend Property Subtitle As String = String.Empty
        Friend Property IconKind As MASIconKind = MASIconKind.Info
        Friend Property ShowIcon As Boolean = False
        Friend Property ShowCloseButton As Boolean = True
        Friend Property HeaderSize As MASPanelShellHeaderSize = MASPanelShellHeaderSize.Compact
        Friend Property Density As MASPanelShellDensity = MASPanelShellDensity.Normal
        Friend Property BorderStrength As MASPanelShellStrength = MASPanelShellStrength.Level5
        Friend Property SurfaceStrength As MASPanelShellStrength = MASPanelShellStrength.Level5
        ''' <summary>
        ''' Complete reusable surface visual style used by this dialog host.
        ''' PlatformDialogFrame is the canonical FilePicker/FileExplorer/MessageBox/PanelShellFloat look.
        ''' </summary>
        Friend Property SurfaceVisualStyleKey As String = MASSurfaceVisualStyleIds.PlatformDialogFrame

        ''' <summary>
        ''' Optional material override. Leave Auto to use the material declared by SurfaceVisualStyleKey.
        ''' </summary>
        Friend Property SurfaceMaterialKey As String = MASSurfaceMaterialIds.Auto
        Friend Property PaddingLeftDip As Single = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogDefaultPaddingDip
        Friend Property PaddingTopDip As Single = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogDefaultPaddingDip
        Friend Property PaddingRightDip As Single = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogDefaultPaddingDip
        Friend Property PaddingBottomDip As Single = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogDefaultPaddingDip
        Friend Property DrawSeparator As Boolean = True
        Friend Property DrawGloss As Boolean = True
        Friend Property DrawCrown As Boolean = True
        Friend Property DrawSeam As Boolean = True
        Friend Property DrawInnerRim As Boolean = True
        Friend Property HeaderIconStyle As MASIconStyle = MASIconStyle.Outline
        Friend Property AllowHeaderDrag As Boolean = True

        Friend Shared Function SelectionDialog(Optional title As String = "Selection") As MASPanelShellDialogOptions
            Return New MASPanelShellDialogOptions() With {
                .Title = NormalizeText(title),
                .Subtitle = String.Empty,
                .IconKind = MASIconKind.Info,
                .ShowIcon = True,
                .ShowCloseButton = True,
                .HeaderSize = MASPanelShellHeaderSize.Compact,
                .Density = MASPanelShellDensity.Normal,
                .BorderStrength = MASPanelShellStrength.Level5,
                .SurfaceStrength = MASPanelShellStrength.Level5,
                .SurfaceVisualStyleKey = MASSurfaceVisualStyleIds.PlatformDialogFrame,
                .SurfaceMaterialKey = MASSurfaceMaterialIds.Auto,
                .PaddingLeftDip = PanelShellTokens.SelectionDialogPaddingXDip,
                .PaddingTopDip = PanelShellTokens.SelectionDialogPaddingTopDip,
                .PaddingRightDip = PanelShellTokens.SelectionDialogPaddingXDip,
                .PaddingBottomDip = PanelShellTokens.SelectionDialogPaddingBottomDip,
                .AllowHeaderDrag = True
            }
        End Function

        Friend Shared Function FilePicker(Optional title As String = "File Picker") As MASPanelShellDialogOptions
            Return New MASPanelShellDialogOptions() With {
                .Title = NormalizeText(title),
                .Subtitle = String.Empty,
                .IconKind = MASIconKind.Folder,
                .ShowIcon = True,
                .ShowCloseButton = True,
                .HeaderSize = MASPanelShellHeaderSize.Compact,
                .Density = MASPanelShellDensity.Normal,
                .BorderStrength = MASPanelShellStrength.Level5,
                .SurfaceStrength = MASPanelShellStrength.Level5,
                .SurfaceVisualStyleKey = MASSurfaceVisualStyleIds.PlatformDialogFrame,
                .SurfaceMaterialKey = MASSurfaceMaterialIds.Auto,
                .PaddingLeftDip = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogFilePickerPaddingDip,
                .PaddingTopDip = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogFilePickerPaddingDip,
                .PaddingRightDip = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogFilePickerPaddingDip,
                .PaddingBottomDip = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogFilePickerPaddingDip,
                .AllowHeaderDrag = True
            }
        End Function

        Friend Shared Function FileExplorer(Optional title As String = "File Explorer") As MASPanelShellDialogOptions
            Return New MASPanelShellDialogOptions() With {
                .Title = NormalizeText(title),
                .Subtitle = String.Empty,
                .IconKind = MASIconKind.Folder,
                .ShowIcon = True,
                .ShowCloseButton = True,
                .HeaderSize = MASPanelShellHeaderSize.Compact,
                .Density = MASPanelShellDensity.Normal,
                .BorderStrength = MASPanelShellStrength.Level5,
                .SurfaceStrength = MASPanelShellStrength.Level5,
                .SurfaceVisualStyleKey = MASSurfaceVisualStyleIds.PlatformDialogFrame,
                .SurfaceMaterialKey = MASSurfaceMaterialIds.Auto,
                .PaddingLeftDip = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogFileExplorerPaddingDip,
                .PaddingTopDip = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogFileExplorerPaddingDip,
                .PaddingRightDip = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogFileExplorerPaddingDip,
                .PaddingBottomDip = Nexamas.UI.Layout.MASApplicationSurfaceSizeTokens.PanelShellDialogFileExplorerPaddingDip,
                .AllowHeaderDrag = True
            }
        End Function

        Friend Shared Function MessageBox(Optional title As String = "") As MASPanelShellDialogOptions
            Return New MASPanelShellDialogOptions() With {
                .Title = NormalizeText(title),
                .Subtitle = String.Empty,
                .IconKind = MASIconKind.Info,
                .ShowIcon = True,
                .ShowCloseButton = True,
                .HeaderSize = MASPanelShellHeaderSize.Compact,
                .Density = MASPanelShellDensity.Normal,
                .BorderStrength = MASPanelShellStrength.Level3,
                .SurfaceStrength = MASPanelShellStrength.Level3,
                .SurfaceVisualStyleKey = MASSurfaceVisualStyleIds.PlatformDialogFrame,
                .SurfaceMaterialKey = MASSurfaceMaterialIds.Auto,
                .PaddingLeftDip = MessageBoxTokens.BodyPaddingLeftDip,
                .PaddingTopDip = MessageBoxTokens.BodyPaddingTopDip,
                .PaddingRightDip = MessageBoxTokens.BodyPaddingRightDip,
                .PaddingBottomDip = MessageBoxTokens.BodyPaddingBottomDip,
                .AllowHeaderDrag = True
            }
        End Function

        Friend Function WithTitle(value As String) As MASPanelShellDialogOptions
            Dim copy As MASPanelShellDialogOptions = Clone()
            copy.Title = NormalizeText(value)
            Return copy
        End Function

        Friend Function Clone() As MASPanelShellDialogOptions
            Return New MASPanelShellDialogOptions() With {
                .Title = NormalizeText(Me.Title),
                .Subtitle = NormalizeText(Me.Subtitle),
                .IconKind = Me.IconKind,
                .ShowIcon = Me.ShowIcon,
                .ShowCloseButton = Me.ShowCloseButton,
                .HeaderSize = MASPanelShellValueNormalizer.NormalizeHeaderSize(Me.HeaderSize),
                .Density = MASPanelShellValueNormalizer.NormalizeDensity(Me.Density),
                .BorderStrength = MASPanelShellValueNormalizer.NormalizeStrength(Me.BorderStrength),
                .SurfaceStrength = MASPanelShellValueNormalizer.NormalizeStrength(Me.SurfaceStrength),
                .SurfaceVisualStyleKey = MASPanelShellValueNormalizer.NormalizeKey(Me.SurfaceVisualStyleKey, MASSurfaceVisualStyleIds.PlatformDialogFrame),
                .SurfaceMaterialKey = MASPanelShellValueNormalizer.NormalizeKey(Me.SurfaceMaterialKey, MASSurfaceMaterialIds.Auto),
                .PaddingLeftDip = MASPanelShellValueNormalizer.NormalizeNonNegativeDip(Me.PaddingLeftDip, 0.0F),
                .PaddingTopDip = MASPanelShellValueNormalizer.NormalizeNonNegativeDip(Me.PaddingTopDip, 0.0F),
                .PaddingRightDip = MASPanelShellValueNormalizer.NormalizeNonNegativeDip(Me.PaddingRightDip, 0.0F),
                .PaddingBottomDip = MASPanelShellValueNormalizer.NormalizeNonNegativeDip(Me.PaddingBottomDip, 0.0F),
                .DrawSeparator = Me.DrawSeparator,
                .DrawGloss = Me.DrawGloss,
                .DrawCrown = Me.DrawCrown,
                .DrawSeam = Me.DrawSeam,
                .DrawInnerRim = Me.DrawInnerRim,
                .HeaderIconStyle = Me.HeaderIconStyle,
                .AllowHeaderDrag = Me.AllowHeaderDrag
            }
        End Function

        Private Shared Function NormalizeText(value As String) As String
            Return If(value, String.Empty).Trim()
        End Function

        Friend Shared Function SafeClone(source As MASPanelShellDialogOptions) As MASPanelShellDialogOptions
            If source Is Nothing Then Return SelectionDialog()
            Return source.Clone()
        End Function

    End Class

End Namespace
