Option Strict On
Option Explicit On

Namespace Nexamas.UI.FloatRuntime

    ' ============================================================
    ' MASFloatRuntime Contract
    ' Class: MASFloatBootstrap
    '
    ' Purpose:
    '   Provides centralized registration of default MASFloatRuntime Float
    '   descriptors.
    '
    ' Responsibility:
    '   Registers the official built-in Float types into MASFloatRegistry
    '   during runtime/platform bootstrap.
    '
    ' Owns:
    '   Default descriptor construction logic only.
    '
    ' Does Not Own:
    '   Runtime lifecycle.
    '   Open Float instances.
    '   Content creation.
    '   Feature callbacks.
    '   Host state.
    '   Policy execution.
    '   Input routing.
    '   Focus ownership.
    '   Result delivery.
    '
    ' Forbidden Dependencies:
    '   Legacy Overlay classes.
    '   OverlayHost.
    '   OverlayManager.
    '   OverlayContent.
    '   OverlayLayer.
    '   OverlayService.
    '   BlockingControlsOverlayContent.
    '   MASFilePickerOverlayService.
    '   MASOverlayPanelService.
    '   MessageBoxOverlayService.
    '   MASFileExplorerOverlayService.
    '   DropDownMenuPopupService.
    '   Feature-owned lifecycle services.
    ' ============================================================
    Friend NotInheritable Class MASFloatBootstrap

        Private Sub New()
        End Sub

        Friend Shared Sub RegisterDefaultFloats(registry As MASFloatRegistry)
            If registry Is Nothing Then
                Throw New ArgumentNullException(NameOf(registry))
            End If

            RegisterIfMissing(registry, CreateMessageBoxDescriptor())
            RegisterIfMissing(registry, CreatePanelDescriptor())
            RegisterIfMissing(registry, CreateFilePickerDescriptor())
            RegisterIfMissing(registry, CreateFileExplorerDescriptor())
            RegisterIfMissing(registry, CreateFileExplorerViewModeMenuDescriptor())
            RegisterIfMissing(registry, CreateDropDownMenuDescriptor())
            RegisterIfMissing(registry, CreateMenuBarDropDownMenuDescriptor())
            RegisterIfMissing(registry, CreateDropDownListDescriptor())
            RegisterIfMissing(registry, CreateDatePickerCalendarDescriptor())
            RegisterIfMissing(registry, CreateTimePickerClockDescriptor())
            RegisterIfMissing(registry, CreateContextMenuDescriptor())
            RegisterIfMissing(registry, CreateTooltipDescriptor())
            RegisterIfMissing(registry, CreateDrawerDescriptor())
            RegisterIfMissing(registry, CreateToastDescriptor())
            RegisterIfMissing(registry, CreateProgressDescriptor())

        End Sub
        Private Shared Function CreateProgressDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.Progress,
                .DisplayName = "Progress",
                .Category = MASFloatCategory.System,
                .DefaultSlot = MASFloatSlot.System,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Passive,
                .Capabilities = MASFloatCapabilities.None,
                .DefaultPresentation = MASFloatPresentationProfiles.Progress(),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function

        Private Shared Function CreateToastDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
        .Key = MASFloatKeys.Toast,
        .DisplayName = "Toast",
        .Category = MASFloatCategory.Toast,
        .DefaultSlot = MASFloatSlot.System,
        .DefaultScope = MASFloatScope.Owner,
        .DefaultLayer = MASFloatLayerLevel.Passive,
        .Capabilities = MASFloatCapabilities.PointerInput,
        .DefaultPresentation = MASFloatPresentationProfiles.Toast(),
        .CanQueue = False,
        .CanReplaceSameOwner = False,
        .RequiresOwnerKey = True
    }
        End Function
        Private Shared Sub RegisterIfMissing(registry As MASFloatRegistry,
                                             descriptor As MASFloatDescriptor)

            If descriptor Is Nothing Then
                Throw New ArgumentNullException(NameOf(descriptor))
            End If

            If registry.Contains(descriptor.Key) Then
                Return
            End If

            registry.Register(descriptor)
        End Sub

        Private Shared Function CreateMessageBoxDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
        .Key = MASFloatKeys.MessageBox,
        .DisplayName = "Message Box",
        .Category = MASFloatCategory.Message,
        .DefaultSlot = MASFloatSlot.MainModal,
        .DefaultScope = MASFloatScope.Owner,
        .DefaultLayer = MASFloatLayerLevel.Modal,
        .Capabilities = MASFloatCapabilities.PointerInput Or
                        MASFloatCapabilities.KeyboardInput Or
                        MASFloatCapabilities.ModalBlocking Or
                        MASFloatCapabilities.EscapeDismiss Or
                        MASFloatCapabilities.OutsideDismiss Or
                        MASFloatCapabilities.OwnsFocus,
        .DefaultPresentation = MASFloatPresentationProfiles.Modal(0.32F),
        .CanQueue = True,
        .CanReplaceSameOwner = False,
        .RequiresOwnerKey = True
    }
        End Function

        Private Shared Function CreatePanelDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.Panel,
                .DisplayName = "Panel",
                .Category = MASFloatCategory.Panel,
                .DefaultSlot = MASFloatSlot.MainModal,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Modal,
                .Capabilities = MASFloatCapabilities.PointerInput Or
                                MASFloatCapabilities.KeyboardInput Or
                                MASFloatCapabilities.ModalBlocking Or
                                MASFloatCapabilities.OwnsFocus,
                .DefaultPresentation = MASFloatPresentationProfiles.Modal(0.28F),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function

        Private Shared Function CreateFilePickerDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.FilePicker,
                .DisplayName = "File Picker",
                .Category = MASFloatCategory.Picker,
                .DefaultSlot = MASFloatSlot.MainModal,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Modal,
                .Capabilities = MASFloatCapabilities.PointerInput Or
                                MASFloatCapabilities.KeyboardInput Or
                                MASFloatCapabilities.TextInput Or
                                MASFloatCapabilities.ModalBlocking Or
                                MASFloatCapabilities.EscapeDismiss Or
                                MASFloatCapabilities.OwnsFocus,
                .DefaultPresentation = MASFloatPresentationProfiles.Modal(0.32F),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function

        Private Shared Function CreateFileExplorerDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
        .Key = MASFloatKeys.FileExplorer,
        .DisplayName = "File Explorer",
        .Category = MASFloatCategory.Explorer,
        .DefaultSlot = MASFloatSlot.MainModal,
        .DefaultScope = MASFloatScope.Owner,
        .DefaultLayer = MASFloatLayerLevel.Modal,
        .Capabilities = MASFloatCapabilities.PointerInput Or
                        MASFloatCapabilities.KeyboardInput Or
                        MASFloatCapabilities.TextInput Or
                        MASFloatCapabilities.ModalBlocking Or
                        MASFloatCapabilities.EscapeDismiss Or
                        MASFloatCapabilities.OwnsFocus,
        .DefaultPresentation = MASFloatPresentationProfiles.Modal(0.32F),
        .CanQueue = False,
        .CanReplaceSameOwner = True,
        .RequiresOwnerKey = True
    }
        End Function
        Private Shared Function CreateFileExplorerViewModeMenuDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
        .Key = MASFloatKeys.FileExplorerViewModeMenu,
        .DisplayName = "File Explorer View Mode Menu",
        .Category = MASFloatCategory.Menu,
        .DefaultSlot = MASFloatSlot.Popup,
        .DefaultScope = MASFloatScope.ParentFloat,
        .DefaultLayer = MASFloatLayerLevel.Interactive,
        .Capabilities = MASFloatCapabilities.PointerInput Or
                        MASFloatCapabilities.KeyboardInput Or
                        MASFloatCapabilities.OutsideDismiss Or
                        MASFloatCapabilities.EscapeDismiss Or
                        MASFloatCapabilities.OwnsFocus,
        .DefaultPresentation = MASFloatPresentationProfiles.AnchoredDropDownMenu(),
        .CanQueue = False,
        .CanReplaceSameOwner = True,
        .RequiresOwnerKey = True
    }
        End Function

        Private Shared Function CreateDropDownMenuDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.DropDownMenu,
                .DisplayName = "Drop Down Menu",
                .Category = MASFloatCategory.Menu,
                .DefaultSlot = MASFloatSlot.Popup,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Interactive,
                .Capabilities = MASFloatCapabilities.PointerInput Or
                                MASFloatCapabilities.KeyboardInput Or
                                MASFloatCapabilities.OutsideDismiss Or
                                MASFloatCapabilities.EscapeDismiss Or
                                MASFloatCapabilities.OwnsFocus,
                .DefaultPresentation = MASFloatPresentationProfiles.AnchoredDropDownMenu(),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function


        ''' <summary>
        ''' Creates the dedicated descriptor for MASMenuBar-owned shell navigation dropdowns.
        ''' It stays separate from the general DropDownMenu key so MenuBar popup styling and
        ''' outside-click pass-through policy cannot leak into other menu surfaces.
        ''' </summary>
        Private Shared Function CreateMenuBarDropDownMenuDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.MenuBarDropDownMenu,
                .DisplayName = "Menu Bar Drop Down Menu",
                .Category = MASFloatCategory.Menu,
                .DefaultSlot = MASFloatSlot.Popup,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Interactive,
                .Capabilities = MASFloatCapabilities.PointerInput Or
                                MASFloatCapabilities.KeyboardInput Or
                                MASFloatCapabilities.OutsideDismiss Or
                                MASFloatCapabilities.EscapeDismiss Or
                                MASFloatCapabilities.OwnsFocus,
                .DefaultPresentation = MASFloatPresentationProfiles.AnchoredDropDownMenu(),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function

        ''' <summary>
        ''' Creates the dedicated descriptor for ComboBox-owned dropdown-list popups.
        ''' A dropdown list receives its compact pixel bounds from MASComboBox itself,
        ''' so its default presentation is explicit-bounds rather than the fullscreen
        ''' overlay default used by general menu content.
        ''' </summary>
        Private Shared Function CreateDropDownListDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.DropDownList,
                .DisplayName = "Drop Down List",
                .Category = MASFloatCategory.Menu,
                .DefaultSlot = MASFloatSlot.Popup,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Interactive,
                .Capabilities = MASFloatCapabilities.PointerInput Or
                                MASFloatCapabilities.OutsideDismiss,
                .DefaultPresentation = MASFloatPresentationProfiles.DropDownList(),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function

        ''' <summary>
        ''' Creates the dedicated descriptor for DatePicker-owned calendar popups.
        ''' The popup receives compact explicit bounds from MASDatePicker and hosts
        ''' only MAS-owned calendar controls through FloatRuntime.
        ''' </summary>
        Private Shared Function CreateDatePickerCalendarDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.DatePickerCalendar,
                .DisplayName = "Date Picker Calendar",
                .Category = MASFloatCategory.Picker,
                .DefaultSlot = MASFloatSlot.Popup,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Interactive,
                .Capabilities = MASFloatCapabilities.PointerInput Or
                                MASFloatCapabilities.KeyboardInput Or
                                MASFloatCapabilities.OutsideDismiss Or
                                MASFloatCapabilities.EscapeDismiss Or
                                MASFloatCapabilities.OwnsFocus,
                .DefaultPresentation = MASFloatPresentationProfiles.DropDownList(),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function


        ''' <summary>
        ''' Creates the dedicated descriptor for TimePicker-owned compact clock popups.
        ''' The popup receives compact explicit bounds from MASTimePicker and hosts
        ''' MAS-owned clock-stepper content without a WinForms DateTimePicker wrapper.
        ''' </summary>
        Private Shared Function CreateTimePickerClockDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.TimePickerClock,
                .DisplayName = "Time Picker Clock",
                .Category = MASFloatCategory.Picker,
                .DefaultSlot = MASFloatSlot.Popup,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Interactive,
                .Capabilities = MASFloatCapabilities.PointerInput Or
                                MASFloatCapabilities.KeyboardInput Or
                                MASFloatCapabilities.TextInput Or
                                MASFloatCapabilities.OutsideDismiss Or
                                MASFloatCapabilities.EscapeDismiss Or
                                MASFloatCapabilities.OwnsFocus,
                .DefaultPresentation = MASFloatPresentationProfiles.DropDownList(),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function

        Private Shared Function CreateContextMenuDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.ContextMenu,
                .DisplayName = "Context Menu",
                .Category = MASFloatCategory.Menu,
                .DefaultSlot = MASFloatSlot.Popup,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Interactive,
                .Capabilities = MASFloatCapabilities.PointerInput Or
                                MASFloatCapabilities.KeyboardInput Or
                                MASFloatCapabilities.OutsideDismiss Or
                                MASFloatCapabilities.EscapeDismiss Or
                                MASFloatCapabilities.OwnsFocus,
                .DefaultPresentation = MASFloatPresentationProfiles.AnchoredContextMenu(),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function

        Private Shared Function CreateDrawerDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.Drawer,
                .DisplayName = "Drawer",
                .Category = MASFloatCategory.Panel,
                .DefaultSlot = MASFloatSlot.MainModal,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Modal,
                .Capabilities = MASFloatCapabilities.PointerInput Or
                                MASFloatCapabilities.KeyboardInput Or
                                MASFloatCapabilities.ModalBlocking Or
                                MASFloatCapabilities.OutsideDismiss Or
                                MASFloatCapabilities.EscapeDismiss Or
                                MASFloatCapabilities.OwnsFocus,
                .DefaultPresentation = MASFloatPresentationProfiles.Drawer(MASFloatPlacement.DockRight),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function

        Private Shared Function CreateTooltipDescriptor() As MASFloatDescriptor
            Return New MASFloatDescriptor() With {
                .Key = MASFloatKeys.Tooltip,
                .DisplayName = "Tooltip",
                .Category = MASFloatCategory.Passive,
                .DefaultSlot = MASFloatSlot.Tooltip,
                .DefaultScope = MASFloatScope.Owner,
                .DefaultLayer = MASFloatLayerLevel.Passive,
                .Capabilities = MASFloatCapabilities.None,
                .DefaultPresentation = MASFloatPresentationProfiles.Tooltip(),
                .CanQueue = False,
                .CanReplaceSameOwner = True,
                .RequiresOwnerKey = True
            }
        End Function

    End Class

End Namespace