Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports Nexamas.UI.Controls
Imports Nexamas.UI.Host
Imports Nexamas.UI.Layout
Imports Nexamas.UI.Rendering
Imports Nexamas.UI.Theming
Imports Nexamas.UI.Components
Imports SkiaSharp

Namespace Nexamas.UI.Application

    Partial Public NotInheritable Class MASApplicationSurfaceLayoutBuilder
        Public Function ShowCommandBackground(visible As Boolean) As MASApplicationSurfaceLayoutBuilder
            _showCommandBackground = visible
            Return Me
        End Function

        ''' <summary>
        ''' Shows or hides official Nexamas UI-owned card backgrounds for application surface
        ''' regions such as Sidebar, Content, Inspector, and Footer. The consuming application
        ''' only requests application-surface region surfaces; Nexamas UI owns the visual style, render pass,
        ''' DPI conversion, and cleanup lifecycle.
        ''' </summary>

        Public Function ShowRegionBackgrounds(visible As Boolean) As MASApplicationSurfaceLayoutBuilder
            _showRegionBackgrounds = visible
            Return Me
        End Function

        Public Function WithCommandBackgroundSurfaceMaterial(materialKey As String) As MASApplicationSurfaceLayoutBuilder
            _commandBackgroundSurfaceMaterialKey = MASSurfaceTreatmentMaterialKeyNormalizer.NormalizeForStorage(materialKey)
            Return Me
        End Function

        Public Function WithRegionBackgroundSurfaceMaterial(materialKey As String) As MASApplicationSurfaceLayoutBuilder
            _regionBackgroundSurfaceMaterialKey = MASSurfaceTreatmentMaterialKeyNormalizer.NormalizeForStorage(materialKey)
            Return Me
        End Function

        ''' <summary>
        ''' Reserves the standard MAS application chrome area before application-surface regions are
        ''' computed. Consumers pass the official Shell facade instead of carrying local
        ''' TopBar/MainMenuBar heights, Y offsets, or title/menu-bar constants.
        ''' </summary>

        Public Function ReserveStandardTopBar(shell As MASApplicationWindowShell) As MASApplicationSurfaceLayoutBuilder
            If shell Is Nothing Then Throw New ArgumentNullException(NameOf(shell))
            _standardChromeShell = shell
            Return Me
        End Function

        ''' <summary>
        ''' Alias for ReserveStandardTopBar(...), useful when an application surface is read as the
        ''' content surface below the MAS application chrome. When the shell owns a standard
        ''' MainMenuBar, the reserved inset includes it automatically.
        ''' </summary>

        Public Function ApplicationChrome(shell As MASApplicationWindowShell) As MASApplicationSurfaceLayoutBuilder
            Return ReserveStandardTopBar(shell)
        End Function

        ''' <summary>
        ''' Selects where the command bar lives in an application surface. Auto places it over the
        ''' main work area when a sidebar exists, otherwise it remains a full-width application-surface row.
        ''' </summary>

        Public Function CommandBarPlacement(placement As MASApplicationSurfaceCommandBarPlacement) As MASApplicationSurfaceLayoutBuilder
            _commandBarPlacement = NormalizeCommandBarPlacement(placement)
            Return Me
        End Function

        ''' <summary>
        ''' Places the command bar above the whole application surface, including the sidebar.
        ''' </summary>

        Public Function CommandBarFullApplicationSurfaceTop() As MASApplicationSurfaceLayoutBuilder
            Return CommandBarPlacement(MASApplicationSurfaceCommandBarPlacement.FullApplicationSurfaceTop)
        End Function

        ''' <summary>
        ''' Places the command bar at the top of the main work area beside the sidebar.
        ''' </summary>

        Public Function CommandBarMainAreaTop() As MASApplicationSurfaceLayoutBuilder
            Return CommandBarPlacement(MASApplicationSurfaceCommandBarPlacement.MainAreaTop)
        End Function

        ''' <summary>
        ''' Selects where the footer lives in an application surface. The default keeps existing
        ''' global-footers unchanged; MainAreaBottom is for applications whose left navigation must
        ''' remain a full-height navigation rail while footer tools belong to the main work area.
        ''' </summary>

        Public Function FooterPlacement(placement As MASApplicationSurfaceFooterPlacement) As MASApplicationSurfaceLayoutBuilder
            _footerPlacement = NormalizeFooterPlacement(placement)
            Return Me
        End Function

        ''' <summary>
        ''' Places the footer at the bottom of the whole application surface, including side regions.
        ''' </summary>

        Public Function FooterFullApplicationSurfaceBottom() As MASApplicationSurfaceLayoutBuilder
            Return FooterPlacement(MASApplicationSurfaceFooterPlacement.FullApplicationSurfaceBottom)
        End Function

        ''' <summary>
        ''' Places the footer under the main work area so navigation/sidebar regions keep their full height.
        ''' </summary>

        Public Function FooterMainAreaBottom() As MASApplicationSurfaceLayoutBuilder
            Return FooterPlacement(MASApplicationSurfaceFooterPlacement.MainAreaBottom)
        End Function
    End Class

End Namespace
