Option Strict On
Option Explicit On

Imports Nexamas.UI.FileSystem

Namespace Nexamas.UI.Components

    ''' <summary>
    ''' Defines what entries a MASFileBrowser is allowed to select.
    ''' </summary>
    ''' <remarks>
    ''' This policy belongs to the browser level, not to FilePicker, Overlay, or Float.
    ''' FilePicker may configure this policy, but the browser must remain independent.
    ''' </remarks>
    Friend NotInheritable Class MASFileBrowserSelectionPolicy

        Friend Property AllowMultiSelect As Boolean = False

        Friend Property AllowFileSelection As Boolean = True

        Friend Property AllowFolderSelection As Boolean = False

        Friend Property AllowDriveSelection As Boolean = False

        Friend Property AllowSpecialSelection As Boolean = False

        Friend Function CanSelect(entry As FileSystemEntry) As Boolean
            If entry Is Nothing Then Return False

            If entry.IsFile Then
                Return AllowFileSelection
            End If

            Select Case entry.EntryType
                Case FileSystemEntryType.Folder
                    Return AllowFolderSelection

                Case FileSystemEntryType.Drive
                    Return AllowDriveSelection

                Case FileSystemEntryType.Special
                    Return AllowSpecialSelection

                Case Else
                    Return False
            End Select
        End Function

        Friend Shared Function FilesOnly(Optional allowMultiSelect As Boolean = False) As MASFileBrowserSelectionPolicy
            Return New MASFileBrowserSelectionPolicy() With {
                .AllowMultiSelect = allowMultiSelect,
                .AllowFileSelection = True,
                .AllowFolderSelection = False,
                .AllowDriveSelection = False,
                .AllowSpecialSelection = False
            }
        End Function

        Friend Shared Function FoldersOnly(Optional allowMultiSelect As Boolean = False) As MASFileBrowserSelectionPolicy
            Return New MASFileBrowserSelectionPolicy() With {
                .AllowMultiSelect = allowMultiSelect,
                .AllowFileSelection = False,
                .AllowFolderSelection = True,
                .AllowDriveSelection = True,
                .AllowSpecialSelection = False
            }
        End Function

        Friend Shared Function FilesAndFolders(Optional allowMultiSelect As Boolean = False) As MASFileBrowserSelectionPolicy
            Return New MASFileBrowserSelectionPolicy() With {
                .AllowMultiSelect = allowMultiSelect,
                .AllowFileSelection = True,
                .AllowFolderSelection = True,
                .AllowDriveSelection = True,
                .AllowSpecialSelection = False
            }
        End Function

    End Class

End Namespace