param(
    [string]$BaseUrl = "http://localhost",
    [string]$OutputDir = ".\\evidence"
)

$ErrorActionPreference = "Stop"
$stamp = Get-Date -Format "yyyyMMdd_HHmmss"
$evidenceDir = Join-Path $OutputDir "E17_H10641_$stamp"
New-Item -ItemType Directory -Force -Path $evidenceDir | Out-Null

$base = $BaseUrl.TrimEnd('/')
$qaUrl = "$base/public/executive-action-review-management-ui-qa.php"
$actionCenterUrl = "$base/public/index.php?page=action-center&lang=en"

$qaOut = Join-Path $evidenceDir "ui_qa.txt"
$headersOut = Join-Path $evidenceDir "ui_qa_headers.txt"
$metaOut = Join-Path $evidenceDir "evidence_meta.txt"

try {
    $response = Invoke-WebRequest -Uri $qaUrl -UseBasicParsing -TimeoutSec 60
    $response.Content | Set-Content -Path $qaOut -Encoding UTF8
    $response.Headers | Out-String | Set-Content -Path $headersOut -Encoding UTF8
    if ($response.StatusCode -ne 200 -or $response.Content -notmatch "Result: PASS") {
        throw "Phase 10.6.4.1 UI QA did not pass."
    }
} catch {
    $_ | Out-String | Set-Content -Path (Join-Path $evidenceDir "error.txt") -Encoding UTF8
    throw
}

@"
Phase=10.6.4.1
Evidence=E17
GeneratedAt=$(Get-Date -Format o)
BaseUrl=$base
QAUrl=$qaUrl
ActionCenterUrl=$actionCenterUrl
Scope=Review Management UI Polish only
"@ | Set-Content -Path $metaOut -Encoding UTF8

$zip = Join-Path $OutputDir "evidence_E17_H10641_$stamp.zip"
Compress-Archive -Path (Join-Path $evidenceDir '*') -DestinationPath $zip -Force

Write-Host "PASS: Phase 10.6.4.1 Review Management UI Polish QA"
Write-Host "Open for screenshot review: $actionCenterUrl"
Write-Host "Evidence: $zip"
