<?php 
// 1. HEADER ÇAĞIRMA
require_once __DIR__ . '/../layouts/header.php'; 

// 2. VERİ HAZIRLIĞI (Danışman Bilgileri)
$agentName  = !empty($project->agent_name) ? $project->agent_name : ($globalSettings->site_title ?? 'Müşteri Temsilcisi');
$agentPhone = !empty($project->agent_phone) ? $project->agent_phone : ($globalSettings->phone ?? '');
$agentEmail = !empty($project->agent_email) ? $project->agent_email : ($globalSettings->email ?? '');
$agentImg   = !empty($project->agent_image) ? BASE_URL . '/' . $project->agent_image : 'https://ui-avatars.com/api/?name=' . urlencode($agentName) . '&background=2563eb&color=fff&size=128';

// Temiz Telefon ve WhatsApp Linki
$cleanPhone = preg_replace('/[^0-9]/', '', $agentPhone);
$waPhone = (substr($cleanPhone, 0, 1) == '0') ? '9'.$cleanPhone : $cleanPhone;

// PHP 7 ve 8 uyumlu Durum Badge Ayarları (Match yerine Switch kullanıldı)
$status = $project->status ?? '';
switch($status) {
    case 'active':
    case 'devam-ediyor':
        $badgeColor = 'tw-bg-orange-500';
        $statusText = 'Devam Ediyor';
        break;
    case 'completed':
    case 'tamamlandi':
        $badgeColor = 'tw-bg-emerald-500';
        $statusText = 'Tamamlandı';
        break;
    case 'planned':
    case 'planlanan':
        $badgeColor = 'tw-bg-slate-500';
        $statusText = 'Planlanıyor';
        break;
    default:
        $badgeColor = 'tw-bg-blue-600';
        $statusText = 'Satışta';
        break;
}

// Kategori (Villa, Daire vb.)
$projectCategory = !empty($project->type) ? mb_strtoupper($project->type, 'UTF-8') : 'PROJE';

// Kapak Görseli
$cover = !empty($project->image) ? BASE_URL . '/' . $project->image : 'https://placehold.co/1920x800?text=Gorsel+Yok';
?>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css" />
<script src="https://cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js"></script>

<style>
    .hero-project-bg { height: 45vh; min-height: 400px; }
    @media (min-width: 768px) { .hero-project-bg { height: 60vh; } }
</style>

<div class="tw-relative hero-project-bg tw-mt-[-80px] tw-pt-[80px] tw-overflow-hidden tw-flex tw-flex-col">
    <div class="tw-absolute tw-inset-0">
        <img src="<?php echo $cover; ?>" class="tw-w-full tw-h-full tw-object-cover" alt="<?php echo htmlspecialchars($project->title); ?>">
        <div class="tw-absolute tw-inset-0 tw-bg-gradient-to-t tw-from-[#0f172a] tw-via-[#0f172a]/40 tw-to-transparent"></div>
    </div>

    <div class="container tw-relative tw-h-full tw-flex-1 d-flex flex-column tw-z-10 tw-py-12 md:tw-py-16">
        
        <div class="tw-mb-auto">
            <a href="<?php echo BASE_URL; ?>/projects" class="tw-inline-flex tw-items-center tw-bg-white/10 hover:tw-bg-white/20 tw-border tw-border-white/20 tw-text-white tw-backdrop-blur-md tw-px-5 tw-py-2.5 tw-rounded-xl tw-text-sm tw-font-bold tw-transition-all tw-no-underline">
                <i class="fa-solid fa-arrow-left tw-mr-2"></i> Tüm Projelere Dön
            </a>
        </div>

        <div class="tw-mt-8">
            <div class="tw-flex tw-gap-3 tw-mb-4">
                <span class="tw-bg-blue-600 tw-text-white tw-px-4 tw-py-1.5 tw-rounded-lg tw-text-[10px] tw-font-black tw-uppercase tw-tracking-widest tw-shadow-lg">
                    <i class="fa-solid fa-layer-group tw-mr-1.5"></i><?php echo $projectCategory; ?>
                </span>
                <span class="<?php echo $badgeColor; ?> tw-text-white tw-px-4 tw-py-1.5 tw-rounded-lg tw-text-[10px] tw-font-black tw-uppercase tw-tracking-widest tw-shadow-lg">
                    <?php echo $statusText; ?>
                </span>
                <a href="<?php echo $cover; ?>" class="glightbox tw-bg-white/10 hover:tw-bg-white/20 tw-border tw-border-white/20 tw-text-white tw-backdrop-blur-md tw-px-4 tw-py-1.5 tw-rounded-lg tw-text-[10px] tw-font-black tw-uppercase tw-tracking-widest tw-no-underline" data-gallery="gallery">
                    <i class="fa-solid fa-expand tw-mr-1.5"></i> Fotoğrafı Büyüt
                </a>
            </div>

            <h1 class="tw-text-3xl md:tw-text-6xl tw-font-black tw-text-white tw-mb-3 tw-tracking-tight tw-drop-shadow-lg">
                <?php echo htmlspecialchars($project->title); ?>
            </h1>
            
            <div class="tw-text-blue-50 tw-text-base md:tw-text-lg tw-flex align-items-center tw-font-medium tw-opacity-90">
                <i class="fa-solid fa-location-dot tw-text-blue-400 tw-mr-2.5 tw-text-xl"></i> 
                <?php echo htmlspecialchars($project->location); ?>
            </div>
        </div>
    </div>
</div>

<section class="tw-py-12 md:tw-py-20 tw-bg-[#f8fafc]">
    <div class="container">
        <div class="row g-4 md:g-5">
            
            <div class="col-lg-8">
                <div class="tw-grid tw-grid-cols-2 md:tw-grid-cols-4 tw-gap-4 tw-mb-10">
                    <div class="tw-bg-white tw-p-6 tw-rounded-[2rem] tw-shadow-sm tw-border tw-border-gray-100 tw-text-center group">
                        <div class="tw-w-12 tw-h-12 tw-bg-blue-50 tw-text-blue-600 tw-rounded-xl d-flex align-items-center justify-content-center tw-mx-auto tw-mb-3 group-hover:tw-scale-110 tw-transition-transform">
                            <i class="fa-solid fa-house-chimney tw-text-xl"></i>
                        </div>
                        <div class="tw-text-[10px] tw-text-gray-400 tw-uppercase tw-font-black tw-tracking-widest tw-mb-1">Emlak Tipi</div>
                        <div class="tw-font-bold tw-text-gray-800"><?php echo htmlspecialchars($project->type); ?></div>
                    </div>

                    <div class="tw-bg-white tw-p-6 tw-rounded-[2rem] tw-shadow-sm tw-border tw-border-gray-100 tw-text-center group">
                        <div class="tw-w-12 tw-h-12 tw-bg-orange-50 tw-text-orange-500 tw-rounded-xl d-flex align-items-center justify-content-center tw-mx-auto tw-mb-3 group-hover:tw-scale-110 tw-transition-transform">
                            <i class="fa-solid fa-calendar-days tw-text-xl"></i>
                        </div>
                        <div class="tw-text-[10px] tw-text-gray-400 tw-uppercase tw-font-black tw-tracking-widest tw-mb-1">Teslim Tarihi</div>
                        <div class="tw-font-bold tw-text-gray-800"><?php echo htmlspecialchars($project->delivery_date); ?></div>
                    </div>

                    <div class="tw-bg-white tw-p-6 tw-rounded-[2rem] tw-shadow-sm tw-border tw-border-gray-100 tw-text-center group">
                        <div class="tw-w-12 tw-h-12 tw-bg-emerald-50 tw-text-emerald-500 tw-rounded-xl d-flex align-items-center justify-content-center tw-mx-auto tw-mb-3 group-hover:tw-scale-110 tw-transition-transform">
                            <i class="fa-solid fa-layer-group tw-text-xl"></i>
                        </div>
                        <div class="tw-text-[10px] tw-text-gray-400 tw-uppercase tw-font-black tw-tracking-widest tw-mb-1">Konut Sayısı</div>
                        <div class="tw-font-bold tw-text-gray-800">Mevcut</div>
                    </div>

                    <div class="tw-bg-white tw-p-6 tw-rounded-[2rem] tw-shadow-sm tw-border tw-border-gray-100 tw-text-center group">
                        <div class="tw-w-12 tw-h-12 tw-bg-purple-50 tw-text-purple-500 tw-rounded-xl d-flex align-items-center justify-content-center tw-mx-auto tw-mb-3 group-hover:tw-scale-110 tw-transition-transform">
                            <i class="fa-solid fa-shield-check tw-text-xl"></i>
                        </div>
                        <div class="tw-text-[10px] tw-text-gray-400 tw-uppercase tw-font-black tw-tracking-widest tw-mb-1">Güvenlik</div>
                        <div class="tw-font-bold tw-text-gray-800">7/24 Aktif</div>
                    </div>
                </div>

                <div class="tw-bg-white tw-p-8 md:tw-p-12 tw-rounded-[2.5rem] tw-shadow-sm tw-mb-10 tw-border tw-border-gray-100">
                    <h3 class="tw-font-black tw-text-2xl tw-mb-8 tw-text-gray-900 d-flex align-items-center">
                        <span class="tw-w-2 tw-h-8 tw-bg-blue-600 tw-rounded-full tw-mr-4"></span>
                        Proje Hakkında
                    </h3>
                    <div class="tw-text-gray-600 tw-leading-relaxed tw-text-base tw-whitespace-pre-line">
                        <?php echo htmlspecialchars($project->description); ?>
                    </div>
                </div>

                <div class="tw-bg-white tw-p-3 tw-rounded-[2.5rem] tw-shadow-sm tw-border tw-border-gray-100">
                    <iframe src="https://maps.google.com/maps?q=<?php echo urlencode($project->location); ?>&t=&z=14&ie=UTF8&iwloc=&output=embed" 
                        width="100%" height="450" style="border:0; border-radius: 2rem;" allowfullscreen="" loading="lazy"></iframe>
                </div>
            </div>

            <div class="col-lg-4">
                <div class="tw-sticky tw-top-24 tw-z-30 tw-space-y-6">
                    
                    <div class="tw-bg-white tw-rounded-[2.5rem] tw-shadow-xl tw-shadow-slate-200/60 tw-border tw-border-gray-100 tw-overflow-hidden">
                        <div class="tw-p-8 text-center">
                            <div class="tw-relative d-inline-block tw-mb-6">
                                <img src="<?php echo $agentImg; ?>" 
                                     class="tw-w-32 tw-h-32 tw-rounded-full tw-object-cover tw-border-[6px] tw-border-gray-50 tw-shadow-md">
                                <span class="tw-absolute tw-bottom-2 tw-right-2 tw-w-6 tw-h-6 tw-bg-emerald-500 tw-border-[4px] tw-border-white tw-rounded-full"></span>
                            </div>

                            <h5 class="tw-font-black tw-text-xl tw-mb-1 tw-text-gray-900"><?php echo htmlspecialchars($agentName); ?></h5>
                            <p class="tw-text-[11px] tw-text-blue-600 tw-font-black tw-uppercase tw-tracking-[0.2em] tw-mb-8">Yetkili Danışman</p>
                            
                            <div class="tw-space-y-3">
                                <?php if(!empty($agentPhone)): ?>
                                    <a href="tel:<?php echo $cleanPhone; ?>" class="btn tw-bg-blue-600 hover:tw-bg-blue-700 tw-text-white tw-w-full tw-py-4 tw-rounded-2xl tw-font-black tw-text-sm tw-transition-all tw-shadow-lg tw-shadow-blue-500/30">
                                        <i class="fa-solid fa-phone tw-mr-3"></i> HEMEN ARA
                                    </a>
                                    
                                    <a href="https://wa.me/<?php echo $waPhone; ?>?text=Merhaba, <?php echo urlencode($project->title); ?> projesi hakkında bilgi alabilir miyim?" 
                                       target="_blank" 
                                       class="btn tw-bg-[#25D366] hover:tw-bg-[#1DA851] tw-text-white tw-w-full tw-py-4 tw-rounded-2xl tw-font-black tw-text-sm tw-border-0 tw-shadow-lg tw-shadow-emerald-500/20">
                                        <i class="fa-brands fa-whatsapp tw-text-xl tw-mr-3"></i> WHATSAPP'TAN YAZ
                                    </a>
                                <?php endif; ?>
                            </div>
                        </div>

                        <div class="tw-bg-slate-50 tw-p-4 tw-text-center tw-border-t tw-border-gray-100">
                            <span class="tw-text-[10px] tw-font-black tw-text-slate-400 tw-uppercase tw-tracking-widest">
                                <i class="fa-regular fa-envelope tw-mr-1.5"></i> <?php echo htmlspecialchars($agentEmail); ?>
                            </span>
                        </div>
                    </div>

                    <div class="tw-bg-white tw-rounded-[2.5rem] tw-shadow-lg tw-p-8 tw-border tw-border-gray-100">
                        <h6 class="tw-font-black tw-text-lg tw-mb-6 tw-text-gray-900 d-flex align-items-center">
                            <i class="fa-solid fa-paper-plane tw-text-blue-500 tw-mr-3"></i> Proje Bilgi Formu
                        </h6>
                        <form action="<?php echo BASE_URL; ?>/contact/send" method="POST" class="tw-space-y-4">
                            <input type="hidden" name="project_name" value="<?php echo htmlspecialchars($project->title); ?>">
                            <input type="text" name="name" class="form-control tw-bg-gray-50 tw-border-0 tw-py-4 tw-rounded-xl tw-text-sm tw-font-bold focus:tw-bg-white focus:tw-ring-4 focus:tw-ring-blue-50 transition-all" placeholder="Adınız Soyadınız" required>
                            <input type="tel" name="phone" class="form-control tw-bg-gray-50 tw-border-0 tw-py-4 tw-rounded-xl tw-text-sm tw-font-bold focus:tw-bg-white focus:tw-ring-4 focus:tw-ring-blue-50 transition-all" placeholder="Telefon Numaranız" required>
                            <button type="submit" class="btn tw-bg-[#0f172a] hover:tw-bg-black tw-text-white w-100 tw-py-4 tw-rounded-2xl tw-font-black tw-text-xs tw-uppercase tw-tracking-widest">FORMU GÖNDER</button>
                        </form>
                    </div>

                </div>
            </div>
        </div>
    </div>
</section>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        const lightbox = GLightbox({
            selector: '.glightbox',
            touchNavigation: true,
            loop: true,
            zoomable: true
        });
    });
</script>

<?php 
// 3. FOOTER ÇAĞIRMA
require_once __DIR__ . '/../layouts/footer.php'; 
?>