<?php
declare(strict_types=1);

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

header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
    <title>Settings Test</title>
    <style>
        body { font-family: monospace; padding: 20px; }
        .success { color: green; }
        .error { color: red; }
        table { border-collapse: collapse; margin-top: 20px; }
        th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
        th { background-color: #f2f2f2; }
    </style>
</head>
<body>
    <h1>Settings System Test</h1>
    
    <?php
    try {
        echo '<p class="success">✓ Settings class loaded</p>';
        
        $appName = Settings::get('app_name', 'NOT FOUND');
        echo '<p class="success">✓ App Name from Settings: <strong>' . htmlspecialchars($appName) . '</strong></p>';
        
        $appEmail = Settings::get('app_email', 'NOT FOUND');
        echo '<p class="success">✓ App Email from Settings: <strong>' . htmlspecialchars($appEmail) . '</strong></p>';
        
        echo '<h2>All Settings:</h2>';
        echo '<table>';
        echo '<tr><th>Setting Key</th><th>Value</th></tr>';
        
        $all = Settings::all();
        foreach ($all as $key => $value) {
            echo '<tr>';
            echo '<td>' . htmlspecialchars($key) . '</td>';
            echo '<td>' . htmlspecialchars($value) . '</td>';
            echo '</tr>';
        }
        echo '</table>';
        
        echo '<p class="success" style="margin-top: 20px;">✓ Settings system is working correctly!</p>';
        echo '<p>If you change settings in Admin Panel → Settings and refresh this page, you should see the changes.</p>';
        
    } catch (Throwable $e) {
        echo '<p class="error">✗ Error: ' . htmlspecialchars($e->getMessage()) . '</p>';
        echo '<p class="error">File: ' . htmlspecialchars($e->getFile()) . '</p>';
        echo '<p class="error">Line: ' . $e->getLine() . '</p>';
    }
    ?>
    
    <p style="margin-top: 30px;">
        <a href="/pest/public/admin/settings.php">Go to Settings Page</a> | 
        <a href="/pest/public/admin/index.php">Go to Admin Dashboard</a>
    </p>
</body>
</html>
