<?php
$settings = json_decode(file_get_contents('data/settings.json'), true);
$projects = json_decode(file_get_contents('data/projects.json'), true);

$project_id = $_GET['id'] ?? '';
$project = null;

foreach($projects as $p) {
    if ($p['id'] === $project_id) {
        $project = $p;
        break;
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $project ? htmlspecialchars($project['title']) : 'Project Not Found'; ?> - <?php echo htmlspecialchars($settings['site_title']); ?></title>
    
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <!-- Custom CSS -->
    <link rel="stylesheet" href="css/style.css">
    
    <style>
        .details-header { padding: 250px 0 100px; background-color: var(--primary); color: var(--text-white); text-align: center; }
        .project-meta { display: flex; justify-content: center; gap: 30px; margin-top: 30px; color: #a0aab2; font-size: 1.1rem; letter-spacing: 1px; }
        .project-meta span { display: flex; align-items: center; gap: 10px; }
        .project-status-badge { padding: 6px 18px; border-radius: 30px; font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 2px; }
        
        .main-image-container { width: 100%; height: 700px; margin-top: -60px; border-radius: 0; overflow: hidden; box-shadow: 0 30px 60px rgba(0,0,0,0.15); position: relative; z-index: 10; }
        .main-image-container img { width: 100%; height: 100%; object-fit: cover; }
        
        .content-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 80px; margin-top: 100px; }
        
        .project-description h3 { font-size: 2.5rem; margin-bottom: 30px; letter-spacing: 2px; }
        .project-description p { font-size: 1.2rem; color: var(--text-light); margin-bottom: 30px; white-space: pre-line; line-height: 2; }
        
        .sidebar-card { background: var(--bg-offset); padding: 50px 40px; border-radius: 0; position: sticky; top: 120px; border: 1px solid var(--border); }
        .amenities-list { margin-top: 30px; }
        .amenities-list li { margin-bottom: 20px; display: flex; align-items: center; gap: 15px; color: var(--text-dark); font-weight: 400; font-size: 1.1rem; }
        .amenities-list i { color: var(--accent); font-size: 1.3rem; width: 30px; text-align: center; }
        
        @media (max-width: 992px) { .content-grid { grid-template-columns: 1fr; } .main-image-container { height: 400px; } }
    </style>
</head>
<body>

<?php include 'header.php'; ?>

    <?php if ($project): 
        $statusBg = ($project['status'] === 'Completed') ? '#2ecc71' : 'var(--accent)';
        $statusColor = ($project['status'] === 'Completed') ? 'white' : 'var(--primary)';
    ?>
    <div class="details-header">
        <div class="container fade-up">
            <h1 class="page-title" style="font-size: 4.5rem; color: white;"><?php echo htmlspecialchars($project['title']); ?></h1>
            <div class="project-meta">
                <span class="project-status-badge" style="background-color: <?php echo $statusBg; ?>; color: <?php echo $statusColor; ?>;"><?php echo htmlspecialchars($project['status']); ?></span>
                <span><i class="fas fa-map-marker-alt" style="color: var(--accent);"></i> <?php echo htmlspecialchars($project['location']); ?></span>
            </div>
        </div>
    </div>
    
    <div class="container" style="padding-bottom: 150px;">
        <div class="main-image-container fade-up" style="transition-delay: 0.2s;">
            <img src="<?php echo htmlspecialchars($project['image']); ?>" alt="<?php echo htmlspecialchars($project['title']); ?>">
        </div>
        
        <div class="content-grid">
            <div class="project-description fade-up" style="transition-delay: 0.3s;">
                <h3 style="color: var(--primary);">About The Project</h3>
                <p><?php echo nl2br(htmlspecialchars($project['longDesc'])); ?></p>
                <div style="margin-top: 60px; padding-top: 40px; border-top: 1px solid var(--border);">
                    <p style="font-style: italic; font-size: 1.1rem;">For more information regarding available units, detailed floor plans, or exclusive pricing, please contact our dedicated sales team.</p>
                </div>
            </div>
            
            <div class="sidebar fade-up" style="transition-delay: 0.4s;">
                <div class="sidebar-card">
                    <h4 style="font-family: var(--font-heading); font-size: 1.8rem; margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--border); color: var(--primary);">Premium Amenities</h4>
                    <ul class="amenities-list">
                        <li><i class="fas fa-shield-alt"></i> 24/7 Advanced Security</li>
                        <li><i class="fas fa-parking"></i> Secure Underground Parking</li>
                        <li><i class="fas fa-bolt"></i> Full Power Backup</li>
                        <li><i class="fas fa-leaf"></i> Landscaped Green Spaces</li>
                        <li><i class="fas fa-water"></i> Modern Fire Safety System</li>
                        <li><i class="fas fa-concierge-bell"></i> Luxury Concierge Service</li>
                    </ul>
                    
                    <div style="margin-top: 50px;">
                        <a href="contact.php" class="btn btn-primary" style="width: 100%;">Inquire Now</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php else: ?>
    <div class="details-header" style="height: 70vh; display: flex; align-items: center; justify-content: center;">
        <div class="container">
            <h1 class="page-title" style="font-size: 4rem;">Project Not Found</h1>
            <a href="projects.php" class="btn btn-primary" style="margin-top: 40px;">Return to Portfolio</a>
        </div>
    </div>
    <?php endif; ?>

<?php include 'footer.php'; ?>
