<?php
require dirname(__DIR__) . '/app/bootstrap.php';

$root = dirname(__DIR__);
$viewFile = $root . '/app/Views/action_center/index.php';
$layoutFile = $root . '/app/Views/layouts/main.php';
$cssFile = __DIR__ . '/assets/css/action-center.css';

$view = is_file($viewFile) ? (string)file_get_contents($viewFile) : '';
$layout = is_file($layoutFile) ? (string)file_get_contents($layoutFile) : '';
$css = is_file($cssFile) ? (string)file_get_contents($cssFile) : '';

$checks = [
    'phase_header_updated' => strpos($layout, 'Phase 10.6.4 — Review Workflow Management Integration') !== false,
    'css_cache_buster_updated' => strpos($layout, 'phase10-6-4-1-review-management-ui-polish') !== false,
    'leadership_progress_v2' => strpos($view, 'review-management-summary-v2') !== false,
    'progress_bar_present' => strpos($view, 'review-progress-track') !== false && strpos($view, 'role="progressbar"') !== false,
    'compact_kpi_cards_present' => strpos($view, 'review-management-kpis') !== false && strpos($view, 'review-kpi-audit') !== false,
    'latest_activity_card_present' => strpos($view, 'review-management-last-activity-v2') !== false,
    'polish_css_loaded' => strpos($css, 'Phase 10.6.4.1 — Review Management UI Polish Hotfix') !== false,
    'oracle_repository_untouched_by_ui_gate' => is_file($root . '/app/Repositories/ExecutiveActionReviewRepository.php'),
];

$allPass = !in_array(false, $checks, true);
http_response_code($allPass ? 200 : 500);
header('Content-Type: text/plain; charset=UTF-8');
echo "Executive Action Review Management UI QA\n";
echo "Phase: 10.6.4.1 — Review Management UI Polish Hotfix\n\n";
echo "QA Gates:\n";
foreach ($checks as $name => $pass) {
    echo sprintf("[%s] %-38s | %s\n", $pass ? 'PASS' : 'FAIL', $name, $pass ? 'YES' : 'NO');
}
echo "\nResult: " . ($allPass ? 'PASS' : 'FAIL') . "\n";
echo "Scope: UI presentation only; Oracle tables, audit history, repository save logic, and transition rules are unchanged.\n";
