<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

require_once __DIR__ . '/../../includes/config.php';

$pdo = getDB();
echo "PDO OK\n";

// Simulate being logged in
$_SESSION['super_admin_id'] = 1;

// Test the table
$stmt = $pdo->query("SELECT COUNT(*) FROM saas_settings");
echo "saas_settings count: " . $stmt->fetchColumn() . "\n";

// Test getSetting
function getSetting($pdo, $key, $default = '') {
    $stmt = $pdo->prepare("SELECT setting_value FROM saas_settings WHERE setting_key = ?");
    $stmt->execute([$key]);
    $result = $stmt->fetchColumn();
    return $result !== false ? $result : $default;
}

$name = getSetting($pdo, 'saas_name', 'default');
echo "saas_name: $name\n";

// Test getSuperAdmin
$superAdmin = getSuperAdmin();
echo "Super Admin: " . ($superAdmin ? $superAdmin['name'] : 'NOT FOUND') . "\n";

// Include header
echo "Including header...\n";
$pageTitle = 'Test';
ob_start();
include __DIR__ . '/includes/header.php';
$headerContent = ob_get_clean();
echo "Header OK, length: " . strlen($headerContent) . "\n";

echo "\nAll tests passed!";
