<?php 
require_once __DIR__ . '/../layouts/header.php'; 
?>

<section class="tw-relative tw-h-[40vh] tw-min-h-[350px] d-flex align-items-center justify-content-center tw-mt-[-80px] tw-pt-[80px]">
    <div class="tw-absolute tw-inset-0 tw-z-0">
        <img src="<?php echo BASE_URL; ?>/assets/img/projects-bg.jpg" 
             class="tw-w-full tw-h-full tw-object-cover" 
             alt="Projelerimiz"
             onerror="this.onerror=null; this.src='https://images.unsplash.com/photo-1486406146926-c627a92ad1ab?ixlib=rb-4.0.3&auto=format&fit=crop&w=1920&q=80'">
        <div class="tw-absolute tw-inset-0 tw-bg-gradient-to-r tw-from-[#0f172a]/90 tw-to-blue-900/80"></div>
    </div>

    <div class="container tw-relative tw-z-10 text-center text-white">
        <span class="tw-inline-block tw-bg-blue-500/20 tw-border tw-border-blue-400/30 tw-backdrop-blur-md tw-px-5 tw-py-1.5 tw-rounded-full tw-text-xs tw-font-black tw-uppercase tw-tracking-widest tw-mb-4">
            PREMİUM YAŞAM ALANLARI
        </span>
        <h1 class="tw-font-black tw-text-4xl md:tw-text-6xl tw-mb-4 tw-tracking-tight tw-drop-shadow-lg">
            Projelerimiz
        </h1>
        <p class="tw-text-blue-100 tw-text-lg md:tw-text-xl tw-font-medium tw-max-w-2xl tw-mx-auto">
            Geleceğinize değer katacak, kalite ve güvenle inşa edilmiş seçkin projelerimizi keşfedin.
        </p>
    </div>
</section>

<section class="tw-py-20 tw-bg-[#f8fafc] tw-min-h-[50vh]">
    <div class="container">
        
        <div class="d-flex justify-content-center tw-mb-16 tw-flex-wrap tw-gap-3">
            <?php $currentStatus = $_GET['status'] ?? ''; ?>
            
            <a href="<?php echo BASE_URL; ?>/projects" 
               class="btn tw-rounded-xl tw-px-8 tw-py-3 tw-font-bold tw-transition-all tw-shadow-sm hover:tw-shadow-md hover:tw--translate-y-0.5 <?php echo $currentStatus === '' ? 'tw-bg-blue-600 tw-text-white tw-shadow-blue-500/30' : 'tw-bg-white tw-text-gray-600 tw-border tw-border-gray-200 hover:tw-text-blue-600 hover:tw-border-blue-300'; ?>">
                Tüm Projeler
            </a>
            
            <a href="<?php echo BASE_URL; ?>/projects?status=devam-ediyor" 
               class="btn tw-rounded-xl tw-px-8 tw-py-3 tw-font-bold tw-transition-all tw-shadow-sm hover:tw-shadow-md hover:tw--translate-y-0.5 <?php echo $currentStatus === 'devam-ediyor' ? 'tw-bg-blue-600 tw-text-white tw-shadow-blue-500/30' : 'tw-bg-white tw-text-gray-600 tw-border tw-border-gray-200 hover:tw-text-blue-600 hover:tw-border-blue-300'; ?>">
                Devam Edenler
            </a>
            
            <a href="<?php echo BASE_URL; ?>/projects?status=tamamlandi" 
               class="btn tw-rounded-xl tw-px-8 tw-py-3 tw-font-bold tw-transition-all tw-shadow-sm hover:tw-shadow-md hover:tw--translate-y-0.5 <?php echo $currentStatus === 'tamamlandi' ? 'tw-bg-blue-600 tw-text-white tw-shadow-blue-500/30' : 'tw-bg-white tw-text-gray-600 tw-border tw-border-gray-200 hover:tw-text-blue-600 hover:tw-border-blue-300'; ?>">
                Tamamlananlar
            </a>
        </div>

        <div class="row g-4 md:g-5">
            <?php if (!empty($projects)): ?>
                <?php foreach($projects as $project): ?>
                    <div class="col-lg-4 col-md-6">
                        <div class="card tw-border-0 tw-shadow-sm hover:tw-shadow-xl tw-h-full tw-group tw-rounded-[1.5rem] tw-overflow-hidden tw-transition-all tw-duration-300 hover:tw--translate-y-2">
                            
                            <div class="tw-relative tw-h-72 tw-overflow-hidden tw-p-2 tw-pb-0">
                                <div class="tw-relative tw-w-full tw-h-full tw-rounded-[1rem] tw-overflow-hidden">
                                    
                                    <?php 
                                        $projectImg = !empty($project->image) ? BASE_URL . '/' . htmlspecialchars($project->image) : 'https://placehold.co/800x600?text=Resim+Yok';
                                    ?>
                                    <img src="<?php echo $projectImg; ?>" 
                                         class="tw-w-full tw-h-full tw-object-cover tw-transition-transform tw-duration-700 group-hover:tw-scale-110" 
                                         alt="<?php echo htmlspecialchars($project->title); ?>"
                                         onerror="this.onerror=null; this.src='https://placehold.co/800x600?text=Resim+Yok'">
                                    
                                    <div class="tw-absolute tw-inset-0 tw-bg-gradient-to-t tw-from-gray-900/60 tw-via-transparent tw-to-transparent"></div>
                                    
                                    <div class="tw-absolute tw-inset-0 tw-bg-blue-900/40 tw-opacity-0 group-hover:tw-opacity-100 tw-transition-opacity tw-duration-300 tw-backdrop-blur-[2px] tw-flex tw-items-center tw-justify-center tw-z-20">
                                        <a href="<?php echo BASE_URL; ?>/projects/detail?slug=<?php echo $project->slug; ?>" class="btn tw-bg-white tw-text-blue-700 hover:tw-bg-blue-50 tw-rounded-xl tw-px-8 tw-py-3 tw-font-bold tw-transition-transform tw-transform tw-scale-90 group-hover:tw-scale-100 tw-shadow-xl">
                                            Projeyi İncele <i class="fa-solid fa-arrow-right tw-ml-2"></i>
                                        </a>
                                    </div>
                                    
                                    <?php 
                                        $badgeColor = 'tw-bg-blue-600';
                                        $badgeText = 'Satışta';
                                        if($project->status == 'devam-ediyor' || $project->status == 'active') { 
                                            $badgeColor = 'tw-bg-orange-500'; 
                                            $badgeText = 'Devam Ediyor'; 
                                        } elseif($project->status == 'tamamlandi' || $project->status == 'completed') { 
                                            $badgeColor = 'tw-bg-emerald-500'; 
                                            $badgeText = 'Tamamlandı'; 
                                        } elseif($project->status == 'planlanan' || $project->status == 'planned') { 
                                            $badgeColor = 'tw-bg-slate-500'; 
                                            $badgeText = 'Planlanıyor'; 
                                        }
                                    ?>
                                    <div class="tw-absolute tw-top-4 tw-left-4 tw-z-10 <?php echo $badgeColor; ?> tw-text-white tw-text-[10px] tw-font-black tw-uppercase tw-tracking-widest tw-px-3 tw-py-1.5 tw-rounded-lg tw-shadow-lg">
                                        <?php echo $badgeText; ?>
                                    </div>
                                </div>
                            </div>

                            <div class="card-body tw-p-6 tw-bg-white d-flex flex-column">
                                <h3 class="tw-font-black tw-text-xl tw-text-gray-900 tw-mb-3 tw-line-clamp-2 tw-flex-grow-1">
                                    <a href="<?php echo BASE_URL; ?>/projects/detail?slug=<?php echo $project->slug; ?>" class="text-decoration-none tw-text-inherit hover:tw-text-blue-600 tw-transition-colors">
                                        <?php echo htmlspecialchars($project->title); ?>
                                    </a>
                                </h3>
                                
                                <div class="tw-bg-gray-50 tw-rounded-xl tw-p-3 d-flex align-items-center tw-mb-2">
                                    <i class="fa-solid fa-location-dot tw-text-blue-500 tw-text-lg tw-mr-3"></i>
                                    <span class="tw-text-gray-600 tw-text-sm tw-font-medium">
                                        <?php echo htmlspecialchars($project->location); ?>
                                    </span>
                                </div>
                            </div>

                        </div>
                    </div>
                <?php endforeach; ?>
            <?php else: ?>
                <div class="col-12 text-center tw-py-20">
                    <div class="tw-bg-white tw-rounded-[2rem] tw-p-12 tw-shadow-sm tw-border tw-border-gray-100 tw-max-w-2xl tw-mx-auto">
                        <div class="tw-w-24 tw-h-24 tw-bg-gray-50 tw-rounded-full d-flex align-items-center justify-content-center tw-mx-auto tw-mb-6">
                            <i class="fa-regular fa-folder-open tw-text-5xl tw-text-gray-400"></i>
                        </div>
                        <h3 class="tw-text-gray-900 tw-font-black tw-text-2xl tw-mb-2">Henüz proje eklenmemiş.</h3>
                        <p class="tw-text-gray-500 tw-text-lg">Aradığınız kriterlere uygun bir gayrimenkul projesi şu an için sistemimizde bulunmuyor.</p>
                        <?php if($currentStatus !== ''): ?>
                            <a href="<?php echo BASE_URL; ?>/projects" class="btn tw-bg-blue-50 hover:tw-bg-blue-600 tw-text-blue-600 hover:tw-text-white tw-rounded-xl tw-font-bold tw-px-6 tw-py-3 tw-mt-4 tw-transition-colors">
                                Tüm Projeleri Göster
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endif; ?>
        </div>

    </div>
</section>

<?php 
require_once __DIR__ . '/../layouts/footer.php'; 
?>