Option Strict On
Option Explicit On

Imports System
Imports System.Windows.Forms

Namespace Nexamas.UI.Application

    ''' <summary>
    ''' Official window-chrome facade for one MASApplicationWindow.
    ''' It owns native shadow / rounded-corner integration without exposing MASDwmShadowHost, MASDwmShadow,
    ''' NativeMethods, or raw Win32 constants to external projects.
    ''' </summary>
    Public NotInheritable Class MASApplicationWindowChrome
        Implements IDisposable

        Private ReadOnly _controller As MASWindowChromeController

        Friend Sub New(owner As Form)
            If owner Is Nothing Then Throw New ArgumentNullException(NameOf(owner))
            _controller = New MASWindowChromeController(owner, NameOf(MASApplicationWindowChrome))
        End Sub

        Public ReadOnly Property IsDisposed As Boolean
            Get
                Return _controller.IsDisposed
            End Get
        End Property

        Public ReadOnly Property HasShadow As Boolean
            Get
                Return _controller.HasShadow
            End Get
        End Property

        ''' <summary>
        ''' Enables the standard MAS rounded borderless-window chrome.
        ''' This is the SDK path that replaces direct MASDwmShadowHost usage.
        ''' </summary>
        Public Function UseSoftShadow(Optional mode As MASWindowShadowMode = MASWindowShadowMode.PopupSafe,
                                      Optional applyDelayMs As Integer = 0,
                                      Optional usePulseFix As Boolean = False) As MASApplicationWindowChrome

            Dim options As New MASWindowChromeOptions() With {
                .ShadowMode = mode,
                .ApplyDelayMs = applyDelayMs,
                .UsePulseFix = usePulseFix
            }

            Return UseSoftShadow(options)

        End Function

        ''' <summary>
        ''' Enables native chrome integration using explicit options.
        ''' </summary>
        Friend Function UseSoftShadow(options As MASWindowChromeOptions) As MASApplicationWindowChrome

            _controller.UseSoftShadow(options)
            Return Me

        End Function

        ''' <summary>
        ''' Re-applies the current native chrome attributes. Useful after handle recreation.
        ''' </summary>
        Public Sub Apply()
            _controller.Apply()
        End Sub

        ''' <summary>
        ''' Detaches MAS-owned native chrome hooks from the owner form.
        ''' </summary>
        Public Sub Clear()
            _controller.Clear()
        End Sub

        Public Sub Dispose() Implements IDisposable.Dispose
            _controller.Dispose()
        End Sub

    End Class

End Namespace
