<?php
require_once 'auth.php';

// View debug log
$logFile = __DIR__ . '/debug.log';

echo "<h1>Debug Log Viewer</h1>";

if (file_exists($logFile)) {
    $logContent = file_get_contents($logFile);
    if (!empty($logContent)) {
        echo "<h2>Log Contents:</h2>";
        echo "<pre style='background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;'>";
        echo htmlspecialchars($logContent);
        echo "</pre>";
        
        echo "<p><a href='?clear=1'>Clear Log</a></p>";
    } else {
        echo "<p>Log file is empty.</p>";
    }
} else {
    echo "<p>No debug log file found.</p>";
}

// Clear log if requested
if (isset($_GET['clear'])) {
    file_put_contents($logFile, '');
    echo "<p>✅ Log cleared. <a href='view-debug-log.php'>Refresh</a></p>";
}

echo "<p><a href='manage-cities-services.php'>Back to Admin Panel</a></p>";
?>