source/Private/CurrentConfigurationAnalysis.ps1

function Show-RJCurrentConfiguration {
    <#
    .SYNOPSIS
    Displays the current RealmJoin configuration in a readable format.
 
    .PARAMETER Configuration
    The configuration object from Get-RJCurrentConfiguration
    #>


    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [PSCustomObject]$Configuration
    )

    Clear-Host
    Write-Host "Current RealmJoin Configuration" -ForegroundColor White
    Write-Host ("-" * 50) -ForegroundColor DarkGray
    Write-Host ""

    if ($Configuration.ConfiguredFeatures.Count -eq 0) {
        Write-Host "No RealmJoin features are currently configured." -ForegroundColor Yellow
        Write-Host ""
    } else {
        Write-Host "CONFIGURED FEATURES" -ForegroundColor White
        Write-Host ("-" * 30) -ForegroundColor DarkGray
        Write-Host ""

        # Group by mandatory status
        $mandatory = $Configuration.ConfiguredFeatures | Where-Object { $_.IsMandatory }
        $optional = $Configuration.ConfiguredFeatures | Where-Object { -not $_.IsMandatory }

        if ($mandatory) {
            Write-Host "Mandatory:" -ForegroundColor Gray
            foreach ($feature in $mandatory) {
                Write-Host " * $($feature.Name)" -ForegroundColor Cyan
                if ($feature.CurrentPermissions.Count -gt 0) {
                    Write-Host " Permissions ($($feature.CurrentPermissions.Count)):" -ForegroundColor DarkGray
                    foreach ($permission in $feature.CurrentPermissions) {
                        Write-Host " - $permission" -ForegroundColor Gray
                    }
                } else {
                    Write-Host " No permissions currently assigned" -ForegroundColor Red
                }
                Write-Host ""
            }
        }

        if ($optional) {
            Write-Host "Optional:" -ForegroundColor Gray
            foreach ($feature in $optional) {
                Write-Host " * $($feature.Name)" -ForegroundColor White
                if ($feature.CurrentPermissions.Count -gt 0) {
                    Write-Host " Permissions ($($feature.CurrentPermissions.Count)):" -ForegroundColor DarkGray
                    foreach ($permission in $feature.CurrentPermissions) {
                        Write-Host " - $permission" -ForegroundColor Gray
                    }
                } else {
                    Write-Host " No permissions currently assigned" -ForegroundColor Red
                }
                Write-Host ""
            }
        }
    }

    if ($Configuration.LegacyApplications.Count -gt 0) {
        Write-Host "LEGACY APPLICATIONS" -ForegroundColor White
        Write-Host ("-" * 30) -ForegroundColor DarkGray
        Write-Host ""

        foreach ($app in $Configuration.LegacyApplications) {
            Write-Host " * $($app.DisplayName)" -ForegroundColor DarkYellow
        }
        Write-Host ""
        Write-Host " These legacy applications should be removed." -ForegroundColor DarkGray
        Write-Host ""
    }

    Write-Host ("-" * 50) -ForegroundColor DarkGray
    Write-Host ""
}

function Show-RJUpdateOptionsMenu {
    <#
    .SYNOPSIS
    Shows menu for selecting what to update in the configuration.
    #>


    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [PSCustomObject]$CurrentConfiguration
    )

    Clear-Host
    Write-Host "Update Options" -ForegroundColor White
    Write-Host ("-" * 50) -ForegroundColor DarkGray
    Write-Host ""
    Write-Host "What would you like to update?" -ForegroundColor White
    Write-Host ""

    $options = @(
        [PSCustomObject]@{ Key = 'AddFeatures'; Display = '[1] Add New Features'; Description = 'Enable additional RealmJoin features' }
        [PSCustomObject]@{ Key = 'RemoveFeatures'; Display = '[2] Remove Features'; Description = 'Disable existing features' }
        [PSCustomObject]@{ Key = 'ChangePermissions'; Display = '[3] Change Permission Mode'; Description = 'Switch between Read/Write and Read-Only' }
    )

    if ($CurrentConfiguration.LegacyApplications.Count -gt 0) {
        $options += [PSCustomObject]@{
            Key = 'RemoveLegacy'
            Display = "[4] Remove Legacy Applications ($($CurrentConfiguration.LegacyApplications.Count) found)"
            Description = 'Clean up old RealmJoin apps'
        }
    }

    $options += [PSCustomObject]@{ Key = 'Cancel'; Display = '[X] Cancel'; Description = 'Return to main menu' }

    $selectedIndex = 0
    $key = $null

    while ($key -ne 13) { # 13 = Enter key
        Clear-Host
        Write-Host "Update Options" -ForegroundColor White
        Write-Host ("-" * 50) -ForegroundColor DarkGray
        Write-Host ""
        Write-Host "What would you like to update?" -ForegroundColor White
        Write-Host ""

        for ($i = 0; $i -lt $options.Count; $i++) {
            if ($i -eq $selectedIndex) {
                Write-Host " > $($options[$i].Display)" -ForegroundColor White -NoNewline
                Write-Host " - $($options[$i].Description)" -ForegroundColor Gray
            } else {
                Write-Host " $($options[$i].Display)" -ForegroundColor DarkGray -NoNewline
                Write-Host " - $($options[$i].Description)" -ForegroundColor DarkGray
            }
        }

        Write-Host ""
        Write-Host "Use arrow keys to navigate, Enter to select" -ForegroundColor DarkGray

        $keyInput = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
        $key = $keyInput.VirtualKeyCode

        switch ($key) {
            38 { # Up arrow
                if ($selectedIndex -gt 0) {
                    $selectedIndex--
                }
            }
            40 { # Down arrow
                if ($selectedIndex -lt ($options.Count - 1)) {
                    $selectedIndex++
                }
            }
            49 { $selectedIndex = 0; $key = 13 } # 1 key
            50 { $selectedIndex = 1; $key = 13 } # 2 key
            51 { $selectedIndex = 2; $key = 13 } # 3 key
            52 { # 4 key
                if ($options.Count -gt 4) {
                    $selectedIndex = 3
                    $key = 13
                }
            }
            88 { # X key
                $selectedIndex = $options.Count - 1
                $key = 13
            }
        }
    }

    return $options[$selectedIndex].Key
}