# Login and get all menu routes via API
$body = '{"tenantCode":"T202605253515","username":"admin","password":"admin123"}'
$loginResp = Invoke-WebRequest -Uri 'http://localhost:8006/login' -Method Post -ContentType 'application/json' -Body $body -UseBasicParsing
$loginJson = $loginResp.Content | ConvertFrom-Json
$token = $loginJson.token
Write-Host "Login OK, token length: $($token.Length)"

# Get routes (menu structure)
Write-Host "`n=== Getting Routes ==="
$routesResp = Invoke-WebRequest -Uri 'http://localhost:8006/getRouters' -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing
$routesJson = $routesResp.Content | ConvertFrom-Json
Write-Host "Routes code: $($routesJson.code)"

# Extract all menu paths
$menuPaths = @()
function ExtractPaths($items, $prefix="") {
    foreach ($item in $items) {
        $path = $item.path
        $component = $item.component
        $name = $item.name
        $perms = $item.perms
        $menuType = $item.menuType
        
        if ($path -and $path -ne '/' -and $path -ne '#') {
            $menuPaths += [PSCustomObject]@{
                Name=$name
                Path=$path
                Component=$component
                Perms=$perms
                MenuType=$menuType
            }
        }
        
        if ($item.children) {
            ExtractPaths $item.children
        }
    }
}

ExtractPaths $routesJson.data
Write-Host "Total menu items found: $($menuPaths.Count)"

# Print all menu paths
$menuPaths | Format-Table -Property Name, Path, Component, Perms, MenuType -AutoSize

# Save to file for analysis
$menuPaths | ConvertTo-Json -Depth 3 | Out-File -FilePath 'd:\ylrz\saasadminui\menu_data.json' -Encoding UTF8
Write-Host "`nMenu data saved to d:\ylrz\saasadminui\menu_data.json"
