.temp_commit_revert/UserAdminModule-6383df066ad425f1fcb580c09aa46e3edd8eeea2/Shell/Public/Open-ModuleMenuApp.ps1

function Open-ModuleMenuApp {
    <#
    .SYNOPSIS
        Opens the UserAdminModule Function Reference app in the default browser.

    .DESCRIPTION
        Locates the ModuleMenuApp.html file bundled with the UserAdminModule and launches it
        in the user's default browser using Start-Process. The HTML app provides an interactive
        reference for all 500+ exported functions across the 30 UserAdminModule submodules,
        with expandable categories, full comment-based help display, and a live search feature.

        The app is located at:
            <ModuleRoot>\resources\ModuleMenuApp.html

        If the file does not exist, the user is advised to regenerate it by running
        New-ModuleMenuApp.ps1 in the same resources folder.

    .PARAMETER Regenerate
        If specified, ensures FunctionIndex.json is current (running Invoke-FunctionIndexRegeneration
        automatically if it does not exist), then regenerates the HTML app from FunctionIndex.json
        before opening it. Use this after adding or removing functions from your library.

    .EXAMPLE
        Open-ModuleMenuApp

        Opens the UserAdminModule Function Reference app in the default browser.

    .EXAMPLE
        Open-ModuleMenuApp -Regenerate

        Regenerates the HTML app from the latest FunctionIndex.json, then opens it.

    .EXAMPLE
        omma

        Short alias — opens the app using the default browser.

    .NOTES
        Author: Luke Leigh
        Alias: omma
        Requires: ModuleMenuApp.html generated by resources\New-ModuleMenuApp.ps1
        Reference: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/start-process
    #>


    [CmdletBinding()]
    param(
        [Parameter()]
        [switch]$Regenerate
    )

    begin {
        trap {
            Write-Error "Failed to open ModuleMenuApp: $_"
            break
        }

        $moduleRoot  = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)   # Shell\Public\ -> Shell\ -> UserAdminModule\
        $resourceDir = Join-Path $moduleRoot 'resources'
        $appPath     = Join-Path $resourceDir 'ModuleMenuApp.html'
        $genScript   = Join-Path $resourceDir 'New-ModuleMenuApp.ps1'
    }

    process {
        trap {
            Write-Error "Error while opening ModuleMenuApp: $_"
            break
        }

        if ($Regenerate) {
            if (-not (Test-Path $genScript)) {
                Write-Error "Generator script not found at $($genScript). Cannot regenerate."
                return
            }

            # Ensure FunctionIndex.json is current before generating the HTML.
            # If it does not exist in the module root, regenerate it first so
            # New-ModuleMenuApp.ps1 has valid input to work from.
            $indexPath = Join-Path $moduleRoot 'FunctionIndex.json'
            if (-not (Test-Path $indexPath)) {
                Write-Verbose "FunctionIndex.json not found — running Invoke-FunctionIndexRegeneration first"
                Invoke-FunctionIndexRegeneration
            }

            Write-Verbose "Regenerating ModuleMenuApp from $($genScript)"
            & $genScript
        }

        if (-not (Test-Path $appPath)) {
            Write-Error "ModuleMenuApp.html not found at $($appPath). Run New-ModuleMenuApp.ps1 in the resources folder to generate it, or use -Regenerate."
            return
        }

        Write-Verbose "Opening $($appPath) in default browser"
        Invoke-Item -Path $appPath
    }
}

Set-Alias -Name omma -Value Open-ModuleMenuApp