Public/Show-AnyBoxBuilder.ps1

function Show-AnyBoxBuilder
{
    [hashtable]$txt_style = @{
        GroupWidth = 300
        MessagePadLeft = 12
    }
    [hashtable]$chk_style = @{
        GroupWidth = 300
        MessagePadRight = 18
    }

    [hashtable]$style = @{
        Order = 0
        Tab = 'Main'
        MessagePosition = 'Left'
    }
    $prompts = @(
        New-Prompt @style @txt_style -Name 'param_Icon' -Message 'Icon:' -ValidateSet (@('') + [System.Drawing.SystemIcons].GetProperties().Name)
        New-Prompt @style @txt_style -Name 'param_Title' -Message 'Title:' -DefaultValue 'AnyBox'
        New-Prompt @style @txt_style -Name 'param_Message' -Message 'Message:' -DefaultValue 'Hello world'
        New-Prompt @style @txt_style -Name 'param_Comment' -Message 'Comment:' -DefaultValue '* and to you too'
        New-Prompt @style @txt_style -Name 'param_Orientation' -Message 'Orientation:' -ValidateSet 'Vertical', 'Horizontal' -DefaultValue 'Vertical'
        New-Prompt @style @txt_style -Name 'param_ContentAlignment' -Message 'Alignment:' -ValidateSet 'Center', 'Left' -DefaultValue 'Center'
        New-Prompt @style @txt_style -Name 'param_WindowStartupLocation' -Message 'Start Pos:' -ValidateSet @([enum]::getvalues([type]'AnyBox.WindowStartupLocation')) -DefaultValue 'Center'
        New-Prompt @style @chk_style -InputType Checkbox -Name 'param_Topmost' -Message 'Topmost' -DefaultValue $true
        New-Prompt @style @chk_style -InputType Checkbox -Name 'param_HideTaskbarIcon' -Message 'Hide Taskbar Icon'
    )

    [hashtable]$style = @{
        Order = 0
        Tab = 'Style'
        MessagePosition = 'Left'
    }
    $prompts += @(
        New-Prompt @style @txt_style -Name 'param_WindowStyle' -Message 'Window:' -ValidateSet @([enum]::getvalues([type]'System.Windows.WindowStyle')) -DefaultValue 'SingleBorderWindow'
        New-Prompt @style @txt_style -Name 'param_Image' -InputType FileOpen -Message 'Image:'
        New-Prompt @style @txt_style -Name 'param_FontFamily' -Message 'Font:' -ValidateSet @([System.Windows.Media.Fonts]::SystemFontFamilies.Source | Sort-Object) -DefaultValue 'Segoe UI'
        New-Prompt @style @txt_style -Name 'param_FontColor' -Message 'Font Color:' -ValidateSet @([System.Windows.Media.Brushes].GetProperties().Name | Sort-Object) -DefaultValue 'Black'
        New-Prompt @style @txt_style -Name 'param_BackgroundColor' -Message 'Background:' -ValidateSet @([System.Windows.Media.Brushes].GetProperties().Name | Sort-Object) -DefaultValue 'White'
        New-Prompt @style @txt_style -Name 'param_AccentColor' -Message 'Accent:' -ValidateSet @([System.Windows.Media.Brushes].GetProperties().Name | Sort-Object) -DefaultValue 'Gainsboro'
    )

    [hashtable]$style = @{
        Order = 0
        Tab = 'Timer'
        MessagePosition = 'Left'
    }
    $prompts += @(
        New-Prompt @style @txt_style -Name 'param_Timeout' -Message 'Timeout:' -DefaultValue 10 -ValidateNumber
        New-Prompt @style @chk_style -InputType Checkbox -Name 'param_ShowTimeout' -Message 'Show Timeout' -DefaultValue $true
        New-Prompt @style @chk_style -InputType Checkbox -Name 'param_ProgressBar' -Message 'Progress Bar' -DefaultValue $true
        New-Prompt @style @chk_style -InputType Checkbox -Name 'param_CountUp' -Message 'Count Up'
    )

    [hashtable]$style = @{
        Order = 0
        Tab = 'Size'
        MessagePosition = 'Left'
    }
    $prompts += @(
        New-Prompt @style @txt_style -Name 'param_ResizeMode' -Message 'Resize:' -ValidateSet @([enum]::getvalues([type]'System.Windows.ResizeMode')) -DefaultValue 'CanMinimize'
        New-Prompt @style @txt_style -Name 'param_MinWidth' -Message 'Min Width:' -ValidateInteger -DefaultValue 300
        New-Prompt @style @txt_style -Name 'param_MaxWidth' -Message 'Max Width:' -ValidateInteger -DefaultValue 0
        New-Prompt @style @txt_style -Name 'param_MinHeight' -Message 'Min Height:' -ValidateInteger -DefaultValue 100
        New-Prompt @style @txt_style -Name 'param_MaxHeight' -Message 'Max Height:' -ValidateInteger -DefaultValue 0
    )

    for ($i = 0; $i -lt 4; $i++)
    {
        [int]$idx = $i + 1
        [hashtable]$style = @{
            MessagePosition = 'Left'
            Tab = "Prompt $idx"
            Order = 1
            FontFamily = 'Consolas'
        }

        # TODO: set default value based on index

        [string[]]$prompt_types = [enum]::getvalues([type]'AnyBox.InputType')
        $prompts += @(
            New-Prompt @style @txt_style -Name "prompt_${idx}_Name" -Message 'Name:' -DefaultValue "prompt_${idx}" -ReadOnly
            New-Prompt @style @txt_style -Name "prompt_${idx}_InputType" -Message 'Type:' -ValidateSet $prompt_types -DefaultValue 'Text'
            New-Prompt @style @txt_style -Name "prompt_${idx}_Order" -Message 'Order:' -ValidateSet @(0..9) -DefaultValue 0
            New-Prompt @style @txt_style -Name "prompt_${idx}_Message" -Message 'Message:'
            New-Prompt @style @txt_style -Name "prompt_${idx}_DefaultValue" -Message 'Default:'
            New-Prompt @style @txt_style -Name "prompt_${idx}_ValidateRegEx" -Message 'Match:'
            New-Prompt @style @txt_style -Name "prompt_${idx}_Tab" -Message 'Tab:'
            New-Prompt @style @txt_style -Name "prompt_${idx}_Group" -Message 'Group:' -DefaultValue 0
            New-Prompt @style @txt_style -Name "prompt_${idx}_GroupWidth" -Message 'Group Width:' -ValidateInteger -DefaultValue 100
            New-Prompt @style @chk_style -InputType Checkbox -Name "prompt_${idx}_ShowSeparator" -Message 'Separator'
            New-Prompt @style @chk_style -InputType Checkbox -Name "prompt_${idx}_ReadOnly" -Message 'Read Only'
            New-Prompt @style @chk_style -InputType Checkbox -Name "prompt_${idx}_Mandatory" -Message 'Mandatory' -DefaultValue $true -ShowSeparator

            New-Prompt @style -InputType Link -Message 'www.fresh2.dev/doc/anybox' -DefaultValue 'https://www.fresh2.dev/doc/anybox'
        )
    }

    for ($i = 0; $i -lt 4; $i++)
    {
        [int]$idx = $i + 1
        [hashtable]$style = @{
            MessagePosition = 'Left'
            Tab = "Button $idx"
            Order = 2
        }
        $prompts += @(
            New-Prompt @style @txt_style -Name "button_${idx}_Name" -Message 'Name:' -DefaultValue "button_${idx}" -ReadOnly
            New-Prompt @style @txt_style -Name "button_${idx}_Text" -Message 'Text:'
            New-Prompt @style @txt_style -Name "button_${idx}_ToolTip" -Message 'ToolTip:'
            New-Prompt @style @chk_style -InputType Checkbox -Name "button_${idx}_IsDefault" -Message 'Is Default'
            New-Prompt @style @chk_style -InputType Checkbox -Name "button_${idx}_IsCancel" -Message 'Is Cancel'
        )
    }

    $btn_build = new-button -Text 'Build' -IsDefault -OnClick {
        $check = Test-ValidInput -Prompts $Prompts -Inputs $form.Result
        if (-not $check.IsValid)
        {
            Show-AnyBox @childWinParams -Icon 'Error' -Message $check.Message -Button 'OK'
        }
        else
        {
            $resp_params = Get-DictSubset $form.Result -KeyStartsWith 'param_' -Trim
            $resp_prompts = Get-DictSubset $form.Result -KeyStartsWith 'prompt_'
            $resp_buttons = Get-DictSubset $form.Result -KeyStartsWith 'button_'

            [string]$command = Write-FunctionCall -FunctionName 'Show-AnyBox' -ParamValues $resp_params -Newlines

            $command += " ``" + [System.Environment]::NewLine
            $command += '-Prompts @(' + [System.Environment]::NewLine
            $command += [string]::join([environment]::NewLine, @(
                    1..4 | ForEach-Object {
                        $this_prompt = Get-DictSubset $resp_prompts -KeyStartsWith ('prompt_' + $_ + '_') -Trim
                        if ($this_prompt.Message)
                        {
                            Write-FunctionCall -FunctionName 'New-Prompt' -ParamValues $this_prompt
                        }
                    }
                ))
            $command += [System.Environment]::NewLine + ") ``" + [System.Environment]::NewLine
            $command += '-Buttons @(' + [System.Environment]::NewLine
            $command += [string]::join([environment]::NewLine, @(
                    1..4 | ForEach-Object {
                        $this_button = Get-DictSubset $resp_buttons -KeyStartsWith ('button_' + $_ + '_') -Trim
                        if ($this_button.Text)
                        {
                            Write-FunctionCall -FunctionName 'New-Button' -ParamValues $this_button
                        }
                    }
                ))
            $command += [System.Environment]::NewLine + ')'

            Show-AnyBox @childWinParams `
                -MinWidth 400 `
                -Messages $command `
                -ContentAlignment Left `
                -FontFamily 'Consolas' `
                -Buttons @(
                'Exit',
            (New-Button -Template CopyMessage),
            (New-Button -Name 'Show' -Text 'Show' -IsDefault -OnClick {
                    Invoke-Expression $command
                })
            ) -CancelButton 'Exit'
        }
    }

    $resp = Show-AnyBox `
        -Title 'Build-a-Box' `
        -AccentColor DarkGray `
        -FontSize 14 `
        -FontFamily 'Consolas' `
        -Prompts $prompts `
        -Orientation 'Horizontal' `
        -Buttons $btn_build
    # -MinWidth 300 `
    # -MinHeight 600 `
}