<div class="d-flex justify-content-between align-items-center tw-mb-10 flex-wrap tw-gap-4">
    <div>
        <h3 class="tw-font-black tw-text-2xl tw-text-gray-900 tw-mb-1 tw-tracking-tight">İlanı Düzenle</h3>
        <p class="tw-text-gray-500 tw-text-sm tw-font-medium tw-mb-0 d-flex align-items-center">
            <span class="tw-bg-blue-600 tw-text-white tw-px-2 tw-py-0.5 tw-rounded tw-text-[10px] tw-font-black tw-uppercase tw-mr-2">ID: #<?php echo $property->id; ?></span>
            <span class="tw-truncate tw-max-w-[300px]"><?php echo htmlspecialchars($property->title); ?></span>
        </p>
    </div>
    <div class="d-flex tw-gap-3">
        <a href="<?php echo BASE_URL; ?>/properties/detail?slug=<?php echo $property->slug; ?>" target="_blank" class="btn tw-bg-white tw-border tw-border-gray-200 tw-text-gray-600 tw-rounded-xl tw-px-5 tw-py-2.5 tw-font-bold tw-text-sm hover:tw-bg-gray-50 tw-transition-all d-flex align-items-center shadow-sm">
            <i class="fa-solid fa-eye tw-mr-2"></i> Sitede Gör
        </a>
        <a href="<?php echo BASE_URL; ?>/admin/properties" class="btn tw-bg-gray-100 tw-text-gray-500 tw-rounded-xl tw-px-5 tw-py-2.5 tw-font-bold tw-text-sm hover:tw-bg-gray-200 tw-transition-all d-flex align-items-center">
            <i class="fa-solid fa-arrow-left tw-mr-2"></i> Vazgeç
        </a>
    </div>
</div>

<form action="<?php echo BASE_URL; ?>/admin/property_edit_save/<?php echo $property->id; ?>" method="POST" enctype="multipart/form-data">
    
    <div class="row g-5">
        
        <div class="col-lg-8">
            <div class="tw-bg-white tw-border tw-border-gray-100 tw-rounded-[2rem] tw-shadow-sm tw-overflow-hidden tw-mb-8">
                <div class="tw-p-6 tw-px-8 tw-bg-gray-50/50 tw-border-b tw-border-gray-100">
                    <h6 class="tw-font-black tw-text-sm tw-text-blue-600 tw-mb-0 tw-uppercase tw-tracking-widest">
                        <i class="fa-solid fa-circle-info tw-mr-2"></i>İLAN DETAYLARI
                    </h6>
                </div>
                <div class="tw-p-8 md:tw-p-10">
                    
                    <div class="tw-mb-8">
                        <label class="tw-text-xs tw-font-extrabold tw-text-gray-400 tw-uppercase tw-tracking-widest tw-mb-2 tw-block tw-px-1">İlan Başlığı</label>
                        <input type="text" name="title" class="form-control tw-bg-gray-50 tw-border-0 focus:tw-bg-white focus:tw-ring-4 focus:tw-ring-blue-50 focus:tw-border-blue-300 tw-py-4 tw-rounded-2xl tw-text-lg tw-font-black tw-text-gray-800 shadow-none transition-all" value="<?php echo htmlspecialchars($property->title); ?>" required>
                    </div>

                    <div class="row g-4 tw-mb-8">
                        <div class="col-md-6">
                            <label class="tw-text-xs tw-font-extrabold tw-text-gray-400 tw-uppercase tw-tracking-widest tw-mb-2 tw-block tw-px-1">Fiyat</label>
                            <div class="tw-relative">
                                <input type="number" name="price" class="tw-w-full tw-pl-4 tw-pr-12 tw-py-3.5 tw-bg-gray-50 tw-border tw-border-gray-100 tw-rounded-xl focus:tw-outline-none focus:tw-bg-white focus:tw-ring-4 focus:tw-ring-blue-50 focus:tw-border-blue-300 tw-transition-all tw-text-sm tw-font-black tw-text-emerald-600 shadow-none" value="<?php echo $property->price; ?>" required>
                                <span class="tw-absolute tw-inset-y-0 tw-right-0 tw-flex tw-items-center tw-pr-4 tw-font-black tw-text-gray-300 tw-text-xs">TL</span>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <label class="tw-text-xs tw-font-extrabold tw-text-gray-400 tw-uppercase tw-tracking-widest tw-mb-2 tw-block tw-px-1">İlan Tipi</label>
                            <select name="type" class="form-select tw-bg-gray-50 tw-border-0 tw-py-3.5 tw-rounded-xl tw-text-sm tw-font-bold tw-text-gray-700 focus:tw-ring-4 focus:tw-ring-blue-50 cursor-pointer">
                                <option value="SATILIK" <?php echo ($property->type == 'SATILIK') ? 'selected' : ''; ?>>Satılık</option>
                                <option value="KİRALIK" <?php echo ($property->type == 'KİRALIK') ? 'selected' : ''; ?>>Kiralık</option>
                                <option value="GÜNLÜK" <?php echo ($property->type == 'GÜNLÜK') ? 'selected' : ''; ?>>Günlük Kiralık</option>
                            </select>
                        </div>
                    </div>

                    <div class="tw-mb-8">
                        <label class="tw-text-xs tw-font-extrabold tw-text-gray-400 tw-uppercase tw-tracking-widest tw-mb-2 tw-block tw-px-1">Konum / Adres</label>
                        <div class="tw-relative">
                            <span class="tw-absolute tw-inset-y-0 tw-left-0 tw-flex tw-items-center tw-pl-4 tw-text-gray-400">
                                <i class="fa-solid fa-location-dot tw-text-red-500"></i>
                            </span>
                            <input type="text" name="location" class="tw-w-full tw-pl-11 tw-pr-4 tw-py-3.5 tw-bg-gray-50 tw-border tw-border-gray-100 tw-rounded-xl focus:tw-outline-none focus:tw-bg-white focus:tw-ring-4 focus:tw-ring-blue-50 focus:tw-border-blue-300 tw-transition-all tw-text-sm tw-font-bold tw-text-gray-800 shadow-none" value="<?php echo htmlspecialchars($property->location); ?>" required>
                        </div>
                    </div>

                    <div class="tw-mb-0">
                        <label class="tw-text-xs tw-font-extrabold tw-text-gray-400 tw-uppercase tw-tracking-widest tw-mb-2 tw-block tw-px-1">Açıklama Metni</label>
                        <textarea name="description" rows="10" class="form-control tw-bg-gray-50 tw-border-0 focus:tw-bg-white focus:tw-ring-4 focus:tw-ring-blue-50 focus:tw-border-blue-300 tw-p-6 tw-rounded-2xl tw-text-sm tw-font-medium tw-text-gray-600 shadow-none transition-all"><?php echo htmlspecialchars($property->description); ?></textarea>
                    </div>

                </div>
            </div>

            <div class="tw-bg-white tw-border tw-border-gray-100 tw-rounded-[2rem] tw-shadow-sm tw-overflow-hidden">
                <div class="tw-p-6 tw-px-8 tw-bg-gray-50/50 tw-border-b tw-border-gray-100 d-flex justify-content-between align-items-center">
                    <h6 class="tw-font-black tw-text-sm tw-text-blue-600 tw-mb-0 tw-uppercase tw-tracking-widest">
                        <i class="fa-regular fa-images tw-mr-2"></i>GALERİ YÖNETİMİ
                    </h6>
                    <span class="tw-bg-white tw-text-gray-600 tw-px-3 tw-py-1 tw-rounded-lg tw-text-[10px] tw-font-black tw-border tw-border-gray-100"><?php echo count($images); ?> RESİM</span>
                </div>
                <div class="tw-p-8 md:tw-p-10">
                    <?php if (!empty($images)): ?>
                        <div class="tw-grid tw-grid-cols-2 md:tw-grid-cols-4 lg:tw-grid-cols-5 tw-gap-4">
                            <?php foreach ($images as $img): ?>
                                <div class="tw-relative tw-aspect-square tw-rounded-2xl tw-overflow-hidden tw-border tw-border-gray-100 tw-group tw-shadow-sm hover:tw-shadow-md tw-transition-all">
                                    <img src="<?php echo BASE_URL . '/' . $img->image_path; ?>" class="tw-w-full tw-h-full tw-object-cover tw-transition tw-duration-500 group-hover:tw-scale-110">
                                    
                                    <div class="tw-absolute tw-inset-0 tw-bg-black/60 tw-opacity-0 group-hover:tw-opacity-100 tw-transition-all tw-flex tw-items-center tw-justify-center tw-backdrop-blur-[2px]">
                                        <a href="<?php echo BASE_URL; ?>/admin/image_delete/<?php echo $img->id; ?>/<?php echo $property->id; ?>" 
                                           class="tw-w-10 tw-h-10 tw-bg-white tw-text-red-600 tw-rounded-xl d-flex align-items-center justify-content-center tw-transition-transform hover:tw-scale-110 shadow-lg"
                                           onclick="return confirm('Bu resmi galeriden silmek istediğinize emin misiniz?');"
                                           title="Resmi Sil">
                                            <i class="fa-solid fa-trash-can"></i>
                                        </a>
                                    </div>
                                    
                                    <?php if($img->image_path == $property->image): ?>
                                        <span class="tw-absolute tw-top-2 tw-left-2 tw-bg-emerald-500 tw-text-white tw-text-[8px] tw-px-2 tw-py-1 tw-rounded-md tw-font-black tw-uppercase tw-tracking-widest tw-shadow-sm tw-z-10">Kapak</span>
                                    <?php endif; ?>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php else: ?>
                        <div class="text-center tw-py-10 tw-bg-gray-50 tw-rounded-2xl tw-border tw-border-dashed tw-border-gray-200">
                            <i class="fa-regular fa-image tw-text-4xl tw-text-gray-300 tw-mb-3"></i>
                            <p class="mb-0 tw-text-sm tw-font-bold tw-text-gray-400">Bu ilana henüz resim eklenmemiş.</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="tw-bg-white tw-border tw-border-gray-100 tw-rounded-[2rem] tw-shadow-sm tw-overflow-hidden tw-mb-6">
                <div class="tw-p-6 tw-bg-gray-50/50 tw-border-b tw-border-gray-100">
                    <h6 class="tw-font-black tw-text-sm tw-text-blue-600 tw-mb-0 tw-uppercase tw-tracking-widest">
                        <i class="fa-solid fa-sliders tw-mr-2"></i>ÖZELLİKLER
                    </h6>
                </div>
                <div class="tw-p-8">
                    <?php $features = json_decode($property->features); ?>
                    <div class="row g-4">
                        <div class="col-6">
                            <label class="tw-text-[10px] tw-font-black tw-text-gray-400 tw-uppercase tw-tracking-widest tw-mb-2 tw-block">Oda Sayısı</label>
                            <select name="features[oda]" class="form-select tw-bg-gray-50 tw-border-0 tw-py-2.5 tw-rounded-lg tw-text-xs tw-font-bold focus:tw-ring-4 focus:tw-ring-blue-50">
                                <?php 
                                    $options = ['1+0', '1+1', '2+1', '3+1', '4+1', 'Villa'];
                                    foreach($options as $opt) {
                                        $selected = (isset($features->oda) && $features->oda == $opt) ? 'selected' : '';
                                        echo "<option value='$opt' $selected>$opt</option>";
                                    }
                                ?>
                            </select>
                        </div>
                        <div class="col-6">
                            <label class="tw-text-[10px] tw-font-black tw-text-gray-400 tw-uppercase tw-tracking-widest tw-mb-2 tw-block">Banyo</label>
                            <input type="number" name="features[banyo]" class="form-control tw-bg-gray-50 tw-border-0 tw-py-2.5 tw-rounded-lg tw-text-xs tw-font-bold focus:tw-ring-4 focus:tw-ring-blue-50" value="<?php echo $features->banyo ?? ''; ?>">
                        </div>
                        <div class="col-6">
                            <label class="tw-text-[10px] tw-font-black tw-text-gray-400 tw-uppercase tw-tracking-widest tw-mb-2 tw-block">Net m²</label>
                            <input type="number" name="features[m2]" class="form-control tw-bg-gray-50 tw-border-0 tw-py-2.5 tw-rounded-lg tw-text-xs tw-font-bold focus:tw-ring-4 focus:tw-ring-blue-50" value="<?php echo $features->m2 ?? ''; ?>">
                        </div>
                        <div class="col-6">
                            <label class="tw-text-[10px] tw-font-black tw-text-gray-400 tw-uppercase tw-tracking-widest tw-mb-2 tw-block">Bina Yaşı</label>
                            <input type="number" name="features[yas]" class="form-control tw-bg-gray-50 tw-border-0 tw-py-2.5 tw-rounded-lg tw-text-xs tw-font-bold focus:tw-ring-4 focus:tw-ring-blue-50" value="<?php echo $features->yas ?? ''; ?>">
                        </div>
                    </div>
                </div>
            </div>

            <div class="tw-bg-white tw-border tw-border-gray-100 tw-rounded-[2rem] tw-shadow-sm tw-overflow-hidden">
                <div class="tw-p-6 tw-bg-gray-50/50 tw-border-b tw-border-gray-100">
                    <h6 class="tw-font-black tw-text-sm tw-text-blue-600 tw-mb-0 tw-uppercase tw-tracking-widest">
                        <i class="fa-solid fa-cloud-arrow-up tw-mr-2"></i>YENİ RESİM EKLE
                    </h6>
                </div>
                <div class="tw-p-8">
                    <div id="uploadBox" onclick="document.getElementById('imageInput').click()" class="tw-border-2 tw-border-dashed tw-border-gray-200 tw-bg-gray-50 tw-rounded-2xl tw-p-8 tw-text-center hover:tw-border-blue-400 hover:tw-bg-blue-50/30 tw-transition-all tw-cursor-pointer tw-relative group">
                        <input type="file" name="images[]" id="imageInput" multiple class="tw-hidden" accept="image/*">
                        <div class="tw-text-gray-400 group-hover:tw-scale-110 tw-transition-transform">
                            <i class="fa-solid fa-images tw-text-4xl tw-mb-3 tw-text-blue-500"></i>
                            <p class="tw-font-black tw-text-xs tw-text-gray-600 tw-uppercase tw-tracking-widest">Yeni Resim Seç</p>
                        </div>
                    </div>
                    <div class="tw-text-[10px] tw-font-bold tw-text-gray-400 tw-uppercase tw-text-center tw-mt-4">Birden fazla resim ekleyebilirsiniz.</div>
                </div>
            </div>
        </div>

        <div class="col-12 tw-sticky tw-bottom-6 tw-z-50 tw-mt-8">
            <div class="tw-bg-white/80 tw-backdrop-blur-xl tw-p-5 tw-px-8 tw-rounded-[1.5rem] tw-shadow-2xl tw-border tw-border-white tw-flex justify-content-between align-items-center">
                <div class="tw-flex tw-items-center tw-text-gray-500 tw-font-bold tw-text-xs tw-uppercase tw-tracking-widest d-none d-md-flex">
                    <div class="tw-w-2 tw-h-2 tw-bg-blue-600 tw-rounded-full tw-mr-2 tw-animate-pulse"></div>
                    Şu an düzenleme modundasınız
                </div>
                <button type="submit" class="btn tw-bg-blue-600 hover:tw-bg-blue-700 tw-text-white tw-px-10 tw-py-3.5 tw-rounded-xl tw-font-black tw-text-sm tw-tracking-widest tw-shadow-xl tw-shadow-blue-500/30 tw-transition-all hover:tw--translate-y-1">
                    <i class="fa-solid fa-floppy-disk tw-mr-2"></i> DEĞİŞİKLİKLERİ KAYDET
                </button>
            </div>
        </div>

    </div>
</form>