﻿Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.IO
Imports Nexamas.UI.Application
Imports Nexamas.UI.Components
Imports Nexamas.UI.Components.DropDownMenu
Imports Nexamas.UI.Controls
Imports Nexamas.UI.FileSystem
Imports Nexamas.UI.Icons
Imports Nexamas.UI.Layout
Imports Nexamas.UI.Localization
Imports Nexamas.UI.Output
Imports Nexamas.UI.Theming
Imports Nexamas.UI.TextInput
Imports Nexamas.UI.Verification
Imports SkiaSharp

Partial Friend NotInheritable Class ShowcasePageHostContentBuilder

    Private Shared Sub BuildListsAndTree(page As MASApplicationLayoutPageBuilder,
                                         window As MASApplicationWindow)
        Dim intro As MASLabel = Body(window, "Lists / Tree demonstrates three official collection surfaces: a compact ListBox, a details ListView, and a hierarchical TreeView. The page shows real selection/navigation controls instead of raw system rows.")
        Dim listCard As MASLabel = InfoCard(window, "ListBox", "Best for short single-column choices such as categories, filters, or simple navigation groups.")
        Dim detailsCard As MASLabel = InfoCard(window, "ListView", "Best for compact record lists where columns are useful but a full DataGrid would be too heavy.")
        Dim treeCard As MASLabel = InfoCard(window, "TreeView", "Best for grouped navigation and parent/child structure. The Showcase navigation itself is also hosted by Nexamas.UI tree controls.")
        Dim listBox As MASListBox = window.Controls.AddListBox(items:=New String() {"Buttons", "Inputs", "Selection", "File surfaces", "Layout", "Services"})
        listBox.SelectedIndex = 0
        Dim listView As MASListView = window.Controls.AddListView(configure:=Sub(view As MASListView)
                                                                      view.WithDetailsView()
                                                                      view.StandaloneChrome()
                                                                      view.AddColumn("Use case", 165.0F)
                                                                      view.AddColumn("Control", 170.0F)
                                                                      view.AddColumn("User value", 260.0F)
                                                                      view.Add(MASListViewItem.Create("Compact choices").WithSubItems(New String() {"MASListBox", "Fast category selection"}))
                                                                      view.Add(MASListViewItem.Create("Details list").WithSubItems(New String() {"MASListView", "Readable columns without DataGrid weight"}))
                                                                      view.Add(MASListViewItem.Create("Hierarchy").WithSubItems(New String() {"MASTreeView", "Parent/child navigation"}))
                                                                  End Sub)
        Dim tree As MASTreeView = window.Controls.AddTreeView(configure:=Sub(treeView As MASTreeView)
                                                                 Dim appRoot As MASTreeNode = treeView.AddRoot("Showcase")
                                                                 appRoot.Add("Product systems")
                                                                 appRoot.Add("Controls and inputs")
                                                                 appRoot.Add("Surfaces and tools")
                                                                 Dim controlsRoot As MASTreeNode = treeView.AddRoot("Controls")
                                                                 controlsRoot.Add("Buttons")
                                                                 controlsRoot.Add("Inputs")
                                                                 controlsRoot.Add("Selection")
                                                                 treeView.SelectedNode = appRoot
                                                             End Sub)
        AddShowcaseContent(page, intro, MASSize.FillWidth)
        page.Grid(3).Gap(MASLayoutSpacing.Large).EqualItemSize().Add(listCard, MASSize.FillWidth).Add(detailsCard, MASSize.FillWidth).Add(treeCard, MASSize.FillWidth)
        page.Grid(3).Gap(MASLayoutSpacing.Large).EqualItemSize().Add(listBox, MASSize.FillWidth).Add(listView, MASSize.FillWidth).Add(tree, MASSize.FillWidth)
    End Sub

    Private Shared Sub BuildTiles(page As MASApplicationLayoutPageBuilder,
                                  window As MASApplicationWindow)
        Dim intro As MASLabel = Body(window, "Tiles are visual selection surfaces for galleries, templates, launchers, and visual choices. They stay on the official MASTileBox route and are not hand-drawn by the Showcase.")
        Dim purpose As MASLabel = InfoCard(window, "When to use", "Use tiles when the image or visual preview is part of the choice. Use ListView or DataGrid when text and columns matter more.")
        Dim boundary As MASLabel = InfoCard(window, "Boundary", "Tile images here are generated sample bitmaps; selection, scrolling, and layout are owned by MASTileBox.")
        Dim tileBox As MASTileBox = window.Controls.AddTileBox(Sub(tileBoxControl As MASTileBox)
                                                                  tileBoxControl.AddItem("Blue", "Generated", CreateSampleTileBitmap(SKColor.Parse("#4D8DFF")), takeOwnership:=True)
                                                                  tileBoxControl.AddItem("Green", "Generated", CreateSampleTileBitmap(SKColor.Parse("#29B36A")), takeOwnership:=True)
                                                                  tileBoxControl.AddItem("Amber", "Generated", CreateSampleTileBitmap(SKColor.Parse("#D99A24")), takeOwnership:=True)
                                                                  tileBoxControl.AddItem("Rose", "Generated", CreateSampleTileBitmap(SKColor.Parse("#D56B86")), takeOwnership:=True)
                                                                  tileBoxControl.WithSelectedIndex(0)
                                                              End Sub)
        tileBox.WithDefaultSize()
        AddShowcaseContent(page, intro, MASSize.FillWidth)
        page.Grid(2).Gap(MASLayoutSpacing.Large).EqualItemSize().Add(purpose, MASSize.FillWidth).Add(boundary, MASSize.FillWidth)
        AddShowcaseContent(page, tileBox, MASSize.FillWidth)
    End Sub

    Private Shared Sub BuildVisualEditors(page As MASApplicationLayoutPageBuilder,
                                          window As MASApplicationWindow)
        Dim intro As MASLabel = Body(window, "Visual editors page shows the safe external pattern for editor-like surfaces: choose an option or color through public MAS factories, then present the selected state in a MAS-owned EmptyState material surface. The Showcase uses Window.Controls.AddColorPicker(...) and Window.Controls.AddEmptyState(...); it does not open a separate designer system, theme registry, native ColorDialog, or internal color-picker APIs.")
        Dim picker As MASComboBox = window.Controls.AddComboBox(items:=New String() {"Blue / Green", "Soft Mist", "Warm Paper", "Graphite"}, selectedIndex:=0)
        Dim colorPicker = window.Controls.AddColorPicker()
        colorPicker.ShowApplyColorOption = True
        colorPicker.ApplyColorText = "Apply preview color"
        colorPicker.WithSize(MASSize.FillWidth.OffsetHeight(300.0F))
        Dim previewSurface As MASEmptyState = window.Controls.AddEmptyState("Visual option preview", "Blue / Green — choose a public color option; the material surface stays owned by Nexamas.UI.", Sub(state As MASEmptyState)
                                                                                                                                                                           state.WithIllustration(False)
                                                                                                                                                                           state.WithSize(MASSize.FillWidth.OffsetHeight(220.0F))
                                                                                                                                                                       End Sub)
        AddHandler colorPicker.ColorChanged,
            Sub(sender, e)
                previewSurface.WithTitle("Color selection changed")
                previewSurface.WithDescription("A public color route changed the selected visual option; theme ownership remains inside Nexamas.UI.")
                window.Refresh()
            End Sub

        AddHandler picker.SelectionChanged,
            Sub(sender As Object, e As EventArgs)
                Dim text As String = picker.SelectedText
                If String.IsNullOrWhiteSpace(text) Then text = "Selected option"
                previewSurface.WithTitle("Visual option preview")
                previewSurface.WithDescription(text & " — selected through public MAS controls; the presentation surface remains a Nexamas.UI EmptyState material.")
                window.Refresh()
            End Sub
        AddShowcaseContent(page, intro, MASSize.FillWidth)
        page.Grid(2).Gap(MASLayoutSpacing.Large).EqualItemSize().Add(picker, MASSize.[Default]).Add(previewSurface, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "ColorPicker"), MASSize.HugContent)
        AddShowcaseContent(page, colorPicker, MASSize.FillWidth)
    End Sub

    Private Shared Sub BuildFileSurfaces(page As MASApplicationLayoutPageBuilder,
                                         window As MASApplicationWindow)
        Dim intro As MASLabel = Body(window, "File surfaces are shown as a practical intake and browsing flow: FileDropZone first, then FilePicker and FileExplorer. Developer boundary notes stay collapsed so the large live surfaces keep the page focus.")
        Dim dropZoneStatus As MASLabel = Muted(window, "FileDropZone: sample image and report files are accepted; Browse routes through Window.Services.FilePicker.")
        Dim dropZoneRouteCard As MASLabel = InfoCard(window, "FileDropZone route", "FileDropZone is created through Window.Controls.AddFileDropZone. Showcase feeds accepted paths and forwards BrowseRequested to the existing FilePicker service; it does not add OS drag/drop plumbing, upload transport, storage, scanning, thumbnails, or a parallel uploader service.")
        Dim dropZone As MASFileDropZone = window.Controls.AddFileDropZone("Drop proof assets", "PNG, SVG, and PDF files for a review batch", Sub(control As MASFileDropZone)
                                                                                                                                          control.WithAllowedExtensions(".png", ".svg", ".pdf")
                                                                                                                                          control.WithBrowseActionText("Browse files")
                                                                                                                                          control.WithSize(MASSize.FillWidth.OffsetHeight(260.0F))
                                                                                                                                          control.SetFiles(New String() {"C:\MASLab\proof\current.png", "C:\MASLab\proof\diff.png", "C:\MASLab\docs\release-notes.pdf"})
                                                                                                                                      End Sub)
        AddHandler dropZone.FilesChanged,
            Sub(sender As Object, args As EventArgs)
                Dim rejectedText As String = If(String.IsNullOrWhiteSpace(dropZone.LastRejectedReason), "none", dropZone.LastRejectedReason)
                dropZoneStatus.Text = "FileDropZone: " & dropZone.FileCount.ToString(CultureInfo.InvariantCulture) & " accepted, " & dropZone.RejectedFileCount.ToString(CultureInfo.InvariantCulture) & " rejected; last rejection='" & rejectedText & "'."
            End Sub
        AddHandler dropZone.BrowseRequested,
            Sub(sender As Object, args As EventArgs)
                window.Services.FilePicker.ShowOpenFile(ownerKey:="showcase.filedropzone.browse",
                                                        title:="Select file for FileDropZone",
                                                        initialPath:="C:\MASLab\proof",
                                                        filter:="*.png;*.svg;*.pdf",
                                                        primaryButtonText:="Use file",
                                                        footerText:="BrowseRequested stays a FileDropZone intent; Window.Services.FilePicker owns this file surface.",
                                                        onAccepted:=Sub(result As MASFilePickerResult)
                                                                        If result IsNot Nothing AndAlso Not String.IsNullOrWhiteSpace(result.SelectedPath) Then
                                                                            dropZone.AcceptDroppedFile(result.SelectedPath)
                                                                            dropZoneStatus.Text = "FileDropZone accepted from FilePicker: " & result.SelectedPath
                                                                        Else
                                                                            dropZoneStatus.Text = "FileDropZone BrowseRequested returned without a selected path."
                                                                        End If
                                                                    End Sub,
                                                        onCancelled:=Sub()
                                                                         dropZoneStatus.Text = "FileDropZone browse cancelled; no visual intake state was changed."
                                                                     End Sub)
                dropZoneStatus.Text = "FileDropZone BrowseRequested routed to Window.Services.FilePicker.ShowOpenFile(...)."
            End Sub
        Dim picker As MASFilePickerControl = window.Controls.AddFilePickerControl(Sub(control As MASFilePickerControl)
                                                                                      control.WithFooterText("Created through Window.Controls.AddFilePickerControl.")
                                                                                  End Sub)
        Dim explorer As MASFileExplorerView = window.Controls.AddFileExplorerView(Sub(control As MASFileExplorerView)
                                                                                     control.WithDefaultComputerRoot()
                                                                                     control.WithDetailsView()
                                                                                 End Sub)
        Dim fileBoundaryExpander As MASExpander = window.Controls.AddExpander("Developer file-surface boundary", expanded:=False, configure:=Sub(expander As MASExpander)
                                                                                                                                                   expander.WithSize(MASSize.FillWidth.OffsetHeight(155.0F))
                                                                                                                                                   expander.Add(dropZoneRouteCard)
                                                                                                                                               End Sub)
        picker.WithDefaultSize()
        explorer.WithDefaultSize()
        AddShowcaseContent(page, intro, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "File DropZone"), MASSize.HugContent)
        AddShowcaseContent(page, dropZone, MASSize.FillWidth)
        AddShowcaseContent(page, dropZoneStatus, MASSize.FillWidth)
        AddShowcaseContent(page, Heading(window, "File Picker / Explorer"), MASSize.HugContent)
        page.Grid(2).Gap(MASLayoutSpacing.Large).EqualItemSize().Add(picker, MASSize.[Default]).Add(explorer, MASSize.FillWidth)
        AddShowcaseContent(page, fileBoundaryExpander, MASSize.FillWidth)
    End Sub

End Class
