controls/variable-grid.ps1

function New-VariableGrid 
{
    param ([bool] $isEdit = $true)

    if($isEdit -eq $false)
    {
        New-UDGrid -Id "VariablesGrid" -Title "Variables" -Headers @("Id","Name", "Value", "PowerShell") -Properties @("Id", "Name", "Value", "PowerShell") -Endpoint {
            $Variables = Get-UAVariable
            $Variables | ForEach-Object {
                $ScriptHelpButton = New-UDButton -Text "Script" -Icon code -OnClick {
                    New-PowerShellHelpModal -Object $_
                }

                [PSCustomObject]@{
                    Id = $_.Id
                    Name = $_.Name
                    Value = $_.Value
                    PowerShell = $ScriptHelpButton
                }            

            } | Out-UDGridData
        }
    }
    else {
        New-UDGrid -Id "VariablesGrid" -Title "Variables" -Headers @("Id", "Name", "Value","Actions") -Properties @("Id", "Name", "Value","Actions") -Endpoint {
            $Variables = Get-UAVariable
            $Variables | ForEach-Object{
                $Variable = $_
                $ExistingValue = $_.Value
                
                
                $RemoveButton = New-UDButton -Text "" -Icon ban -OnClick {
                    New-UDDeleteVariableModal -Variable $Variable
                }
    
                $EditButton = New-UDButton -Text "" -Icon edit -OnClick {
                    New-UDEditVariableModal -Variable $Variable
                }
                
                if ($Session:UserRole -eq 'Administrator' -or $Session:UserRole -eq 'Operator')
                {
                    $Buttons =  New-UDElement -Tag div -Content{
                        New-UDTooltip -Content{$EditButton} -TooltipContent {"Edit Variable"}
                        " "
                        New-UDTooltip -Content{$RemoveButton} -TooltipContent {"Remove Variable"}
                    }
                }
                
                [PSCustomObject]@{
                    Id = $_.Id
                    Name = $_.Name
                    Value = $_.Value
                    Actions = $Buttons
                }
            }  | Out-UDGridData
            
            
        
        }
    }
    


}