<?php
session_start();

echo "<h2>Session Debug Information</h2>";
echo "<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.info-box { background: #f5f5f5; padding: 15px; border-radius: 5px; margin: 10px 0; }
.admin { background: #ffebee; }
.customer { background: #e3f2fd; }
.none { background: #fff3e0; }
</style>";

echo "<h3>Current Session Status:</h3>";

if (isset($_SESSION['login']) && !empty($_SESSION['login'])) {
    $role = isset($_SESSION['role']) ? $_SESSION['role'] : 'NOT SET';
    $class = '';
    $message = '';

    if ($role === 'admin') {
        $class = 'admin';
        $message = '✅ ADMIN - Button WILL be visible';
    } elseif ($role === 'customer') {
        $class = 'customer';
        $message = '❌ CUSTOMER - Button will NOT be visible';
    } else {
        $class = 'none';
        $message = '⚠️ NO ROLE - Button will NOT be visible';
    }

    echo "<div class='info-box $class'>";
    echo "<h4>$message</h4>";
    echo "<p><strong>Logged in as:</strong> {$_SESSION['login']}</p>";
    echo "<p><strong>User ID:</strong> {$_SESSION['id']}</p>";
    echo "<p><strong>Username:</strong> {$_SESSION['username']}</p>";
    echo "<p><strong>Role:</strong> <code>$role</code></p>";
    echo "</div>";

} else {
    echo "<div class='info-box none'>";
    echo "<h4>❌ NOT LOGGED IN - Button will NOT be visible</h4>";
    echo "<p>Please login first.</p>";
    echo "</div>";
}

echo "<h3>Admin Button Visibility Logic:</h3>";
echo "<div class='info-box'>";
echo "<p>The admin button will ONLY show when:</p>";
echo "<pre style='background: #263238; color: #aed581; padding: 15px; border-radius: 5px;'>";
echo htmlspecialchars("<?php if (isset(\$_SESSION['role']) && \$_SESSION['role'] === 'admin'): ?>
    <!-- ADMIN BUTTON SHOWS HERE -->
<?php endif; ?>");
echo "</pre>";
echo "<p><strong>This means:</strong></p>";
echo "<ul>";
echo "<li>✅ If role = 'admin' → Button shows</li>";
echo "<li>❌ If role = 'customer' → Button hidden</li>";
echo "<li>❌ If role not set → Button hidden</li>";
echo "<li>❌ If not logged in → Button hidden</li>";
echo "</ul>";
echo "</div>";

echo "<h3>Test Your Session:</h3>";
echo "<div class='info-box'>";

if (isset($_SESSION['role']) && $_SESSION['role'] === 'admin') {
    echo "<p style='color: green; font-weight: bold;'>✅ PASS: You are an admin. The button SHOULD be visible.</p>";
} else {
    echo "<p style='color: orange; font-weight: bold;'>❌ NOT ADMIN: The button will NOT be visible (as expected).</p>";
}

echo "</div>";

echo "<h3>All Session Variables:</h3>";
echo "<div class='info-box'>";
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
echo "</div>";

echo "<br>";
echo "<a href='index.php' style='padding: 10px 20px; background: #2196f3; color: white; text-decoration: none; border-radius: 5px;'>Go to Homepage</a> ";
echo "<a href='setup-admin-roles.php' style='padding: 10px 20px; background: #f44336; color: white; text-decoration: none; border-radius: 5px; margin-left: 10px;'>Setup Admin Roles</a> ";
echo "<a href='logout.php' style='padding: 10px 20px; background: #666; color: white; text-decoration: none; border-radius: 5px; margin-left: 10px;'>Logout</a>";
?>
