<?php
session_start();
require_once 'config/database.php';
require_once 'includes/site_settings.php';

// Get site settings
$settings = get_all_settings($pdo);
$logo_image = $settings['logo_image'] ?? null;
$site_name = $settings['site_name'] ?? 'Your Institution Name';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Site Logo Viewer</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-5">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header bg-primary text-white">
                        <h3 class="mb-0"><i class="fas fa-image me-2"></i>Site Logo Display</h3>
                    </div>
                    <div class="card-body text-center">
                        <h4 class="mb-4">Current Site Logo</h4>
                        
                        <?php if ($logo_image): ?>
                            <div class="mb-4">
                                <img src="<?php echo htmlspecialchars($logo_image); ?>" 
                                     alt="Site Logo" 
                                     class="img-fluid border rounded shadow"
                                     style="max-height: 200px; max-width: 300px;">
                            </div>
                            
                            <div class="alert alert-success">
                                <h5><i class="fas fa-check-circle me-2"></i>Logo Found!</h5>
                                <p class="mb-1"><strong>File Path:</strong> <?php echo htmlspecialchars($logo_image); ?></p>
                                <p class="mb-1"><strong>Institution Name:</strong> <?php echo htmlspecialchars($site_name); ?></p>
                                <p class="mb-0"><strong>Status:</strong> Successfully loaded and displayed</p>
                            </div>
                            
                            <div class="row mt-4">
                                <div class="col-md-6">
                                    <div class="card bg-light">
                                        <div class="card-body">
                                            <h6>Where This Logo Appears:</h6>
                                            <ul class="text-start">
                                                <li>Header Banner (Top of all pages)</li>
                                                <li>All Certificate Documents</li>
                                                <li>Sidebar Navigation</li>
                                                <li>Exam Routines</li>
                                                <li>Reports and Mark Sheets</li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="card bg-light">
                                        <div class="card-body">
                                            <h6>Logo Specifications:</h6>
                                            <?php
                                            $full_path = __DIR__ . '/' . ltrim($logo_image, './');
                                            if (file_exists($full_path)) {
                                                $file_size = filesize($full_path);
                                                $file_info = getimagesize($full_path);
                                                echo "<p class='mb-1'><strong>File Size:</strong> " . round($file_size/1024, 2) . " KB</p>";
                                                echo "<p class='mb-1'><strong>Dimensions:</strong> " . $file_info[0] . " × " . $file_info[1] . " pixels</p>";
                                                echo "<p class='mb-1'><strong>Format:</strong> " . $file_info['mime'] . "</p>";
                                                echo "<p class='mb-0'><strong>File Exists:</strong> <span class='text-success'>Yes ✓</span></p>";
                                            }
                                            ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                        <?php else: ?>
                            <div class="alert alert-warning">
                                <h5><i class="fas fa-exclamation-triangle me-2"></i>No Logo Configured</h5>
                                <p>No logo has been uploaded to the site settings yet.</p>
                                <a href="admin/site_settings.php" class="btn btn-primary">
                                    <i class="fas fa-upload me-1"></i>Upload Logo in Site Settings
                                </a>
                            </div>
                        <?php endif; ?>
                        
                        <div class="mt-4">
                            <a href="admin/site_settings.php" class="btn btn-outline-primary me-2">
                                <i class="fas fa-cog me-1"></i>Site Settings
                            </a>
                            <a href="." class="btn btn-outline-secondary">
                                <i class="fas fa-home me-1"></i>Home Page
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/js/all.min.js"></script>
</body>
</html>