controls/script-create-modal.ps1

function New-UDScriptModal {

    Show-UDModal -Width "75%"  -Content {

        New-UDPageHeader -Text ("Create a New Script")
        New-UDParagraph -Text " " #Spacer
        New-UDTabContainer -Tabs {
                
            New-UDTab -Text 'General' -Content {
                New-UDParagraph -Text "General Script Settings"
                New-UDCard -Content {
                    New-UDTextbox -Id "NewScriptModalTextBoxName" -Label "Name" -Type text
                    New-UDTextbox -Id "NewScriptModalTextBoxDescription" -Label "Description" -Type text 
                    New-UDTextbox -Id "NewScriptModalTextBoxManualTime" -Type text -Label "Manual Time" -Placeholder 0
                }
            }

             
            New-UDTab -Text 'Script' -Content {
                New-UDElement -Tag 'div' -Attributes @{
                    style = @{
                        height = "620px"
                    }
                } -Content {
                    New-UDParagraph -Text "Script Content"
                    New-UDCodeEditor -Id 'NewScriptEditor' -Language 'powershell' -Code '#Enter Script Here!' -Theme 'vs-dark' -Autosize
                }
            }

                
            New-UDTab -Text "Execution Options" -Content {
                New-UDParagraph -Text "Execution Options"
                New-UDCard -Content {
                    $PowerShellVersions = Get-UAPowerShellVersion
                    New-UDSelect -Id "NewScriptModalSelectPowerShellVersion" -Label "Required PowerShell Version" -Option {
                        New-UDSelectOption -Name "Default" -Value "Any"
                        $PowerShellVersions | ForEach-Object {
                            New-UDSelectOption -Name $_.Version -Value $_.Version
                        }
                    } -OnChange {
                            
                    }
                    #New-UDTextbox -Id "NewScriptModalTextBoxArgumentOverrides" -Type text -Label "Argument Overrides" -Value $Script.ArguementOverrides
                }
            }

            New-UDTab -Text 'Finalize' -Content {
                New-UDParagraph -Text "Script Finalization"
                New-UDCard -Content {
                    New-UDTextbox -Id "NewScriptModalTextBoxCommitMessage" -Label "Commit Message" -Type text
                    New-UDTooltip -TooltipContent { "Navigate to the new Script's page after creation" } -Content { 
                        New-UDCheckbox -Id "NewScriptModalCheckBoxGotoScript" -Label "Open Script"
                    }
                }
                    
                New-UDElement -Tag div -Attributes @{
                    style = @{
                        textAlign = "right"
                    }
                } -Content {
                    New-UDButton -Text "Create Script" -Icon folder_plus -OnClick {
                        
                        # Get Input Data
                        $Name = ((Get-UDElement -Id 'NewScriptModalTextBoxName').Attributes["value"])
                        $Description = ((Get-UDElement -Id 'NewScriptModalTextBoxDescription').Attributes["value"])
                        $CommitMessage = ((Get-UDElement -Id 'NewScriptModalTextBoxCommitMessage').Attributes["value"])
                        $ManualTime = ((Get-UDElement -Id 'NewScriptModalTextBoxManualTime').Attributes["value"])
                        $OpenScript = ((Get-UDElement -Id 'NewScriptModalCheckBoxGotoScript').Attributes["checked"])
                        #$ArgumentOverrides = ((Get-UDElement -Id 'NewScriptModalTextBoxArgumentOverrides').Attributes["value"])
                        $RequiredPowerShellVersion = ((Get-UDElement -Id 'NewScriptModalSelectPowerShellVersion').Attributes["value"])
                        $ScriptBlock = [ScriptBlock]::Create((Get-UDElement -Id 'NewScriptEditor').Attributes["code"])
                        
                        # Null Checks
                        if (!$ManualTime -or $ManualTime -eq "" -or $ManualTime -eq "null") { $ManualTime = 0 }
                        if (!$ArgumentOverrides -or $ArgumentOverrides -eq "" -or $ArgumentOverrides -eq "null") { $ArgumentOverrides = "" }
                        if ($null -eq $ScriptBlock -or $ScriptBlock -eq "" -or $ScriptBlock -eq " " -or $ScriptBlock -eq "null"){$ScriptBlock = [ScriptBlock]::Create("#Start Script")}

                        #Todo Update Default Version Call
                        $DefaultPowerShellVersion = Get-UAPowerShellVersion -Id 1
      
                        if($RequiredPowerShellVersion -eq "Any")
                        {
                            $RequiredPowerShellVersion = $null
                        }
                        
                        # Create Script
                        $NewUAScript = New-UAScript -Name $Name -ScriptBlock $ScriptBlock -ManualTime $ManualTime -Description $Description -Notes $CommitMessage -RequiredPowerShellVersion $RequiredPowerShellVersion
                                    
                        # Grid Sync
                        Sync-UDElement -Id "ScriptsGrid" -Broadcast
                        Sync-UDElement -Id "ScriptPageHeader" -Broadcast
                        Sync-UDElement -Id "ScriptPageTagDiv" -Broadcast
                        Sync-UDElement -Id "TagGrid" -Broadcast
                        if ($OpenScript -eq $true) {
                            Invoke-UDRedirect -Url "/script/$($NewUAScript.Id)"
                        }
                        else {
                            Hide-UDModal
                        }
                    }
                }
            }

        }
    }
}