controls/script-edit-modal.ps1

function Edit-UDScriptModal {
    param (
        [Parameter(Mandatory = $true)]
        $Script
    )

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

        New-UDPageHeader -Text ("Edit Script")
        New-UDParagraph -Text "Updating Script: $($Script.Name)" 

        New-UDTabContainer -Tabs {
            New-UDTab -Text 'General' -Content {
                New-UDParagraph -Text "General Script Settings"
                New-UDCard -Content {
                    New-UDTextbox -Id "EditScriptModalTextBoxName" -Label "Name" -Type text -Value $Script.Name
                    New-UDTextbox -Id "EditScriptModalTextBoxDescription" -Label "Description" -Type text -Value $Script.Description
                    New-UDTextbox -Id "EditScriptModalTextBoxManualTime" -Type text -Label "Manual Time" -Value $Script.ManualTime
                }
            }

            New-UDTab -Text "Execution Options" -Content {
                New-UDParagraph -Text "Execution Options"
                New-UDCard -Content {
                    $PowerShellVersions = Get-UAPowerShellVersion
                    
                    New-UDSelect -Id "EditScriptModalSelectPowerShellVersion" -Label "PowerShell Version" -Option {
                        
                        New-UDSelectOption -Name "Default" -Value "Any"
                        $PowerShellVersions | ForEach-Object {
                            New-UDSelectOption -Name $_.Version -Value $_.Version
                        }
                    } -OnChange {
                        
                    }

                    if($Script.DisableManualInvocation -eq $true)
                    {
                        $DisableManualInvokeCheckBox = (New-UDCheckbox -Id "EditScriptModalCheckboxDisableManualInvocation" -Label 'Disable Manual Invocation' -Checked)
                    }
                    else {
                        $DisableManualInvokeCheckBox = (New-UDCheckbox -Id "EditScriptModalCheckboxDisableManualInvocation" -Label 'Disable Manual Invocation')
                    }
                    
                    New-UDTooltip -Content {$DisableManualInvokeCheckBox} -TooltipContent {"Can the script be manually executed outside a schedule?"}
                
                }
            }
            
            New-UDTab -Text 'Finalize' -Content {
                
                New-UDCard -Content {
                    New-UDTextbox -Id "EditScriptModalTextBoxCommitMessage" -Label "Commit Message" -Type text
                }
                    
                New-UDElement -Tag div -Attributes @{
                    style = @{
                        textAlign = "right"
                    }
                } -Content {
                    New-UDButton -Text "Save Changes" -Icon edit -OnClick {
                        # Get Input Data
                        $Name = ((Get-UDElement -Id 'EditScriptModalTextBoxName').Attributes["value"])
                        $Description = ((Get-UDElement -Id 'EditScriptModalTextBoxDescription').Attributes["value"])
                        $ManualTime = ((Get-UDElement -Id 'EditScriptModalTextBoxManualTime').Attributes["value"])
                        $CommitMessage = ((Get-UDElement -Id 'EditScriptModalTextBoxCommitMessage').Attributes["value"])
                        #$ArgumentOverrides = ((Get-UDElement -Id 'EditScriptModalTextBoxArgumentOverrides').Attributes["value"])
                        $RequiredPowerShellVersion = ((Get-UDElement -Id 'EditScriptModalSelectPowerShellVersion').Attributes["value"])
                        $DisableManualInvoke = ((Get-UDElement -Id 'EditScriptModalCheckboxDisableManualInvocation').Attributes["checked"])

                        # Null Checks
                        $ManualTime = if (!$ManualTime -or $ManualTime -eq "" -or $ManualTime -eq "null") {0} else { $ManualTime }
                        #$ArgumentOverrides = if (!$ArgumentOverrides -or $ArgumentOverrides -eq "" -or $ArgumentOverrides -eq "null") {""} else {$ArgumentOverrides}
                        $RequiredPowerShellVersion = if (!$RequiredPowerShellVersion -or $RequiredPowerShellVersion -eq "" -or $RequiredPowerShellVersion -eq "0") {""} else {$RequiredPowerShellVersion}

                        $ScriptSwitches = @{}
                        if($DisableManualInvoke -eq $true){$ScriptSwitches.add("-DisableManualInvocation", $True)} else {$ScriptSwitches.add("-DisableManualInvocation", $False)}
                        
                        if($RequiredPowerShellVersion -eq "Any" -or $RequiredPowerShellVersion -eq "null")
                        {
                            $RequiredPowerShellVersion = $null
                        }


                        # Update Script
                        $Script | Set-UAScript -Name $Name -Description $Description -ManualTime $ManualTime -Notes $CommitMessage -RequiredPowerShellVersion $RequiredPowerShellVersion @ScriptSwitches
                        
                        # Grid Sync
                        Sync-UDElement -Id "ScriptsGrid" -Broadcast
                        Sync-UDElement -Id "ScriptPageHeader" -Broadcast
                        Sync-UDElement -Id "ScriptPageTagDiv" -Broadcast
                        Sync-UDElement -Id "TagGrid" -Broadcast
                        Invoke-UDRedirect -Url "/script/$($Script.Id)"
                        Hide-UDModal
                    }
            
                }

            }

        }
    }
}