<?php
/**
 * Home Controller
 */
class HomeController {
    
    public function index() {
        // Show welcome page
        $this->showWelcomePage();
    }
    
    private function showWelcomePage() {
        // Check database connection
        $dbStatus = 'Not Connected';
        $dbColor = '#e74c3c';
        $userCount = 0;
        
        try {
            $db = Database::getInstance();
            $stmt = $db->query("SELECT COUNT(*) as count FROM users");
            $result = $stmt->fetch();
            $userCount = $result['count'] ?? 0;
            $dbStatus = 'Connected (' . $userCount . ' users)';
            $dbColor = '#27ae60';
        } catch (Exception $e) {
            $dbStatus = 'Connection Failed';
        }
        
        // Get base URL
        $baseUrl = defined('BASE_URL') ? BASE_URL : 'http://localhost/nis_ams';
        ?>
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>NIS Asset Management System</title>
            <style>
                * { margin: 0; padding: 0; box-sizing: border-box; }
                body { 
                    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
                    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
                    min-height: 100vh; 
                    display: flex; 
                    align-items: center; 
                    justify-content: center; 
                    padding: 20px;
                }
                .container { 
                    background: white; 
                    border-radius: 20px; 
                    padding: 40px; 
                    max-width: 900px; 
                    width: 100%;
                    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
                    animation: slideIn 0.5s ease-out;
                }
                @keyframes slideIn {
                    from { transform: translateY(-20px); opacity: 0; }
                    to { transform: translateY(0); opacity: 1; }
                }
                h1 { 
                    color: #2c3e50; 
                    margin-bottom: 20px; 
                    font-size: 2.5em;
                    text-align: center;
                    border-bottom: 3px solid #27ae60;
                    padding-bottom: 15px;
                }
                .subtitle {
                    text-align: center;
                    color: #7f8c8d;
                    margin-bottom: 30px;
                    font-size: 1.1em;
                }
                .success-box { 
                    background: #d4edda; 
                    color: #155724; 
                    padding: 25px; 
                    border-radius: 10px; 
                    margin: 20px 0; 
                    border-left: 4px solid #28a745;
                    animation: fadeIn 1s ease-in;
                }
                .info-box { 
                    background: #e7f3ff; 
                    padding: 25px; 
                    border-radius: 10px; 
                    margin: 20px 0;
                    border-left: 4px solid #17a2b8;
                }
                @keyframes fadeIn {
                    from { opacity: 0; }
                    to { opacity: 1; }
                }
                .btn { 
                    display: inline-block; 
                    background: #28a745; 
                    color: white; 
                    padding: 12px 30px; 
                    text-decoration: none; 
                    border-radius: 5px; 
                    margin: 10px; 
                    transition: all 0.3s;
                    border: none;
                    cursor: pointer;
                    font-size: 1em;
                    font-weight: 600;
                }
                .btn:hover { 
                    transform: translateY(-2px); 
                    box-shadow: 0 5px 15px rgba(40,167,69,0.3); 
                }
                .btn-secondary { 
                    background: #17a2b8; 
                }
                .btn-warning {
                    background: #ffc107;
                    color: #212529;
                }
                .path { 
                    background: #f8f9fa; 
                    padding: 15px; 
                    border-radius: 5px; 
                    font-family: 'Courier New', monospace; 
                    margin: 10px 0;
                    border: 1px solid #e9ecef;
                }
                .stats-grid {
                    display: grid;
                    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
                    gap: 15px;
                    margin: 20px 0;
                }
                .stat-card {
                    background: #f8f9fa;
                    padding: 15px;
                    border-radius: 8px;
                    text-align: center;
                }
                .stat-card h3 {
                    color: #2c3e50;
                    margin-bottom: 5px;
                    font-size: 0.9em;
                }
                .stat-card .value {
                    font-size: 1.5em;
                    font-weight: bold;
                    color: #27ae60;
                }
                .footer {
                    text-align: center;
                    margin-top: 30px;
                    padding-top: 20px;
                    border-top: 1px solid #e9ecef;
                    color: #6c757d;
                }
                .button-group {
                    display: flex;
                    justify-content: center;
                    gap: 10px;
                    flex-wrap: wrap;
                }
            </style>
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
        </head>
        <body>
            <div class="container">
                <h1>
                    <i class="fas fa-shield-alt" style="color: #27ae60;"></i> 
                    NIS Asset Management System
                </h1>
                <p class="subtitle">Nigeria Immigration Service - Works & Logistics Directorate</p>
                
                <div class="success-box">
                    <i class="fas fa-check-circle" style="font-size: 2em; margin-bottom: 10px;"></i>
                    <h2 style="margin: 10px 0;">✅ System is Running!</h2>
                    <p>Your NIS Asset Management System is now operational.</p>
                </div>
                
                <div class="info-box">
                    <h3 style="margin-bottom: 15px;"><i class="fas fa-info-circle"></i> System Information</h3>
                    <div class="stats-grid">
                        <div class="stat-card">
                            <h3>PHP Version</h3>
                            <div class="value"><?php echo phpversion(); ?></div>
                        </div>
                        <div class="stat-card">
                            <h3>Database</h3>
                            <div class="value" style="color: <?php echo $dbColor; ?>"><?php echo $dbStatus; ?></div>
                        </div>
                        <div class="stat-card">
                            <h3>Environment</h3>
                            <div class="value">Development</div>
                        </div>
                    </div>
                    
                    <div class="path">
                        <strong>Base URL:</strong> <?php echo $baseUrl; ?><br>
                        <strong>Project Path:</strong> <?php echo __DIR__; ?><br>
                        <strong>Request URI:</strong> <?php echo $_SERVER['REQUEST_URI']; ?>
                    </div>
                </div>
                
                <div class="button-group">
                    <a href="<?php echo $baseUrl; ?>/dashboard" class="btn">
                        <i class="fas fa-tachometer-alt"></i> Dashboard
                    </a>
                    <a href="<?php echo $baseUrl; ?>/setup_check.php" class="btn btn-secondary">
                        <i class="fas fa-stethoscope"></i> Diagnostics
                    </a>
                </div>
                
                <div class="footer">
                    <p>&copy; <?php echo date('Y'); ?> Nigeria Immigration Service. All rights reserved.</p>
                    <p style="font-size: 0.9em; margin-top: 10px;">
                        <i class="fas fa-code-branch"></i> Version 2.0.0
                    </p>
                </div>
            </div>
        </body>
        </html>
        <?php
    }
}