<?php

$base = '/var/www/html/easychair';

echo "=== EasyChair Homepage Studio Diagnostics ===\n\n";

$files = [
    "$base/app/views/admin/conference_home/studio.php",
    "$base/app/controllers/AdminConferenceHomeController.php",
    "$base/config/routes.php",
];

foreach ($files as $file) {
    echo "Checking PHP syntax: $file\n";
    $cmd = 'php -l ' . escapeshellarg($file) . ' 2>&1';
    echo shell_exec($cmd) . "\n";
}

echo "\n=== Route checks ===\n";

$routes = file_get_contents("$base/config/routes.php");

$neededRoutes = [
    '/admin/conference-home/studio',
    '/admin/conference-home/preview',
    '/admin/conference-home/ai-generate',
    '/admin/conference-home/ai-import',
    '/admin/conference-home/ai-write',
    '/admin/conference-home/ai-conference',
    '/admin/conference-home/marketplace',
    '/admin/conference-home/blueprints',
    '/admin/conference-home/sections',
    '/admin/conference-home/blocks',
];

foreach ($neededRoutes as $r) {
    echo str_contains($routes, $r)
        ? "[OK] $r\n"
        : "[MISSING] $r\n";
}

echo "\n=== Controller method checks ===\n";

$controller = file_get_contents("$base/app/controllers/AdminConferenceHomeController.php");

$methods = [
    'studio',
    'preview',
    'aiGenerateHomepage',
    'aiImport',
    'aiWriteHomepage',
    'aiConferenceComposer',
    'marketplace',
    'blueprints',
    'sections',
    'blocks',
    'snapshot',
    'reorder',
];

foreach ($methods as $m) {
    echo preg_match('/function\s+' . preg_quote($m, '/') . '\s*\(/', $controller)
        ? "[OK] $m()\n"
        : "[MISSING] $m()\n";
}

echo "\n=== View markers ===\n";

$studio = file_get_contents("$base/app/views/admin/conference_home/studio.php");

$markers = [
    'Homepage Studio',
    'AI Generate',
    'AI Writer',
    'AI Conference',
    'Marketplace',
    'Blueprint',
    'Visual Designer',
    'Program Timeline',
    'Proceedings Composer',
    'homepageSearch',
    'livePreview',
];

foreach ($markers as $x) {
    echo str_contains($studio, $x)
        ? "[OK] $x\n"
        : "[MISSING] $x\n";
}

echo "\nDiagnostics completed.\n";
