<?php
/**
 * Admin Ortak Header (Menü) - Güncellenmiş Bildirimli
 * Konum: /magaza/admin/header.php
 */

// Dosya yollarını sabitlemek için __DIR__ kullanıyoruz
require_once __DIR__ . '/../includes/db.php';

$base_url = "/magaza/admin/"; 
$current_page = $_SERVER['PHP_SELF'];

// Yeni Ziyaretçi Mesajı Sayısını Çek
$mesaj_stmt = $db->query("SELECT COUNT(id) FROM contact_messages WHERE status = 'new'");
$yeni_mesaj_sayisi = $mesaj_stmt->fetchColumn() ?: 0;

// Bekleyen Havale/Dekont Sayısını Çek
$dekont_stmt = $db->query("SELECT COUNT(id) FROM payments WHERE payment_method = 'bank_transfer' AND status = 'pending'");
$bekleyen_dekont_sayisi = $dekont_stmt->fetchColumn() ?: 0;

// Bekleyen (Yeni) Sipariş Sayısını Çek
$siparis_stmt = $db->query("SELECT COUNT(id) FROM orders WHERE status = 'pending'");
$bekleyen_siparis_sayisi = $siparis_stmt->fetchColumn() ?: 0;

// Açık Destek Talebi Sayısını Çek
$destek_stmt = $db->query("SELECT COUNT(id) FROM support_tickets WHERE status = 'open'");
$acik_destek_sayisi = $destek_stmt->fetchColumn() ?: 0;
?>
<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sınav Koçu Admin</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        .navbar-admin { background-color: #212529; }
        .nav-link { color: rgba(255,255,255,0.7) !important; font-weight: 500; transition: color 0.2s; }
        .nav-link:hover, .nav-link.active { color: #fff !important; }
        .dropdown-menu { border: none; box-shadow: 0 10px 30px rgba(0,0,0,0.1); border-radius: 8px; }
        .dropdown-item { padding: 8px 20px; font-weight: 500; }
        .dropdown-item:hover { background-color: #f8f9fa; color: #0d6efd; }
    </style>
</head>
<body class="bg-light">

<nav class="navbar navbar-expand-xl navbar-dark navbar-admin shadow-sm mb-4 py-3">
    <div class="container-fluid px-4">
        <a class="navbar-brand fw-bold fs-4" href="<?= $base_url ?>index.php">
            <i class="bi bi-shield-check text-warning me-2"></i>Sınav Koçu
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto align-items-center">
                
                <li class="nav-item">
                    <a class="nav-link <?= strpos($current_page, '/admin/index.php') !== false ? 'active text-warning fw-bold' : '' ?>" href="<?= $base_url ?>index.php">
                        <i class="bi bi-speedometer2 me-1"></i> Özet
                    </a>
                </li>
                
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle <?= strpos($current_page, '/finans/') !== false ? 'active text-info fw-bold' : '' ?>" href="#" role="button" data-bs-toggle="dropdown">
                        <i class="bi bi-wallet2 me-1"></i> Finans 
                        <?php if($bekleyen_dekont_sayisi > 0): ?>
                            <span class="badge bg-danger rounded-pill ms-1"><?= $bekleyen_dekont_sayisi ?></span>
                        <?php endif; ?>
                    </a>
                    <ul class="dropdown-menu shadow">
                        <li><a class="dropdown-item" href="<?= $base_url ?>finans/index.php"><i class="bi bi-graph-up-arrow text-primary me-2"></i>Finans Dashboard</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>finans/dekontlar.php">
                            <i class="bi bi-bank text-warning me-2"></i>Dekontlar
                            <?php if($bekleyen_dekont_sayisi > 0): ?>
                                <span class="badge bg-danger rounded-pill float-end"><?= $bekleyen_dekont_sayisi ?></span>
                            <?php endif; ?>
                        </a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>finans/faturalar.php"><i class="bi bi-file-earmark-pdf text-info me-2"></i>E-Fatura Merkezi</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item fw-bold" href="<?= $base_url ?>finans/satislar.php"><i class="bi bi-list-columns-reverse text-success me-2"></i>Satış ve Gelir Raporu</a></li>
                    </ul>
                </li>

                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle <?= (strpos($current_page, '/siparisler/') !== false || strpos($current_page, '/abonelikler/') !== false) ? 'active text-white fw-bold' : '' ?>" href="#" role="button" data-bs-toggle="dropdown">
                        <i class="bi bi-box-seam me-1"></i> Sipariş & Lojistik
                        <?php if($bekleyen_siparis_sayisi > 0): ?>
                            <span class="badge bg-danger rounded-pill ms-1"><?= $bekleyen_siparis_sayisi ?></span>
                        <?php endif; ?>
                    </a>
                    <ul class="dropdown-menu shadow">
                        <li><h6 class="dropdown-header text-muted fw-bold">SİPARİŞLER</h6></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>siparisler/index.php">
                            <i class="bi bi-cart-check text-success me-2"></i>Tüm Siparişler
                            <?php if($bekleyen_siparis_sayisi > 0): ?>
                                <span class="badge bg-danger rounded-pill float-end"><?= $bekleyen_siparis_sayisi ?></span>
                            <?php endif; ?>
                        </a></li>
                         <li><a class="dropdown-item" href="<?= $base_url ?>siparisler/kargo-takvimi.php"><i class="bi bi-truck text-success me-2"></i>Kargo Takvimi</a></li>
                         
                         <li><a class="dropdown-item" href="<?= $base_url ?>siparisler/iadeler.php"><i class="bi bi-arrow-counterclockwise text-success me-2"></i>İade Talepleri</a></li>
                          <li><a class="dropdown-item" href="<?= $base_url ?>siparisler/iptaller.php"><i class="bi bi-x-octagon text-success me-2"></i>İptal Talepleri</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><h6 class="dropdown-header text-muted fw-bold">DENEME PAKETİ YÖNETİMİ</h6></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>denemepaket/index.php"><i class="bi bi-people text-primary me-2"></i>Aktif Deneme Siparişleri</a></li>

                    </ul>
                </li>
                
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle <?= strpos($current_page, '/urunler/') !== false ? 'active text-white fw-bold' : '' ?>" href="#" role="button" data-bs-toggle="dropdown">
                        <i class="bi bi-tags me-1"></i> Ürün & Kategori
                    </a>
                    <ul class="dropdown-menu shadow">
                        <li><a class="dropdown-item" href="<?= $base_url ?>urunler/index.php"><i class="bi bi-list-ul text-primary me-2"></i>Ürün Listesi</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>urunler/ekle.php"><i class="bi bi-plus-circle text-success me-2"></i>Yeni Ürün Ekle</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>deneme"><i class="bi bi-plus-circle text-success me-2"></i>Denemeler</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>denemesonuc/index.php"><i class="bi bi-plus-circle text-success me-2"></i>Deneme Sonuç Ekle</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>denemetakvimi/index.php"><i class="bi bi-calendar3 text-success me-2"></i>Deneme Takvimi Ekle</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>stok-alarmlari/index.php"><i class="bi bi-alarm-fill text-info me-2"></i>Stok Alarmı</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>urunler/kategoriler.php"><i class="bi bi-folder text-warning me-2"></i>Kategoriler</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>urunler/markalar.php"><i class="bi bi-bookmark-star text-info me-2"></i>Markalar / Yayınevleri</a></li>
                        
                    </ul>
                </li>
                
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle <?= (strpos($current_page, '/musteri/') !== false || strpos($current_page, '/kuponlar/') !== false || strpos($current_page, '/destek/') !== false) ? 'active text-white fw-bold' : '' ?>" href="#" role="button" data-bs-toggle="dropdown">
                        <i class="bi bi-person-hearts me-1"></i> Müşteri & CRM
                        <?php if($acik_destek_sayisi > 0): ?>
                            <span class="badge bg-danger rounded-pill ms-1"><?= $acik_destek_sayisi ?></span>
                        <?php endif; ?>
                    </a>
                    <ul class="dropdown-menu shadow">
                        <li><a class="dropdown-item" href="<?= $base_url ?>musteri/index.php"><i class="bi bi-people text-primary me-2"></i>Müşteriler</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>kuponlar/index.php"><i class="bi bi-ticket-perforated text-warning me-2"></i>İndirim Kuponları</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>ayarlar/kargo_ayarlari.php"><i class="bi bi-cart-check text-success me-2"></i>Kargo Kampanyaları</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>widget/index.php"><i class="bi bi-window-sidebar text-success me-2"></i>Widget</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>destek/index.php">
                            <i class="bi bi-headset text-info me-2"></i>Destek Talepleri
                            <?php if($acik_destek_sayisi > 0): ?>
                                <span class="badge bg-danger rounded-pill float-end"><?= $acik_destek_sayisi ?></span>
                            <?php endif; ?>
                        </a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>sayac/stats.php"><i class="bi bi-bar-chart-fill text-info me-2"></i>Sayaç</a></li>
                    </ul>
                </li>

                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle <?= (strpos($current_page, '/sayfalar/') !== false || strpos($current_page, '/mesajlar/') !== false) ? 'active text-white fw-bold' : '' ?>" href="#" role="button" data-bs-toggle="dropdown">
                        <i class="bi bi-globe me-1"></i> İçerik & İletişim
                        <?php if($yeni_mesaj_sayisi > 0): ?>
                            <span class="badge bg-danger rounded-pill ms-1"><?= $yeni_mesaj_sayisi ?></span>
                        <?php endif; ?>
                    </a>
                    <ul class="dropdown-menu shadow">
                        <li><a class="dropdown-item" href="<?= $base_url ?>mesajlar/index.php">
                            <i class="bi bi-envelope-paper text-primary me-2"></i>Gelen Mesajlar
                            <?php if($yeni_mesaj_sayisi > 0): ?>
                                <span class="badge bg-danger rounded-pill float-end"><?= $yeni_mesaj_sayisi ?></span>
                            <?php endif; ?>
                        </a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>blog/index.php"><i class="bi bi-file-earmark-richtext text-secondary me-2"></i>Bloglar</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>sayfalar/index.php"><i class="bi bi-file-earmark-richtext text-secondary me-2"></i>Sayfalar</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>marquee/index.php"><i class="bi bi-file-earmark-richtext text-secondary me-2"></i>Kayan Yazı</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>slider/index.php"><i class="bi bi-file-earmark-richtext text-secondary me-2"></i>Slider</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>yorumlar/index.php"><i class="bi bi-file-earmark-richtext text-secondary me-2"></i>Yorumlar</a></li>
                        <li><a class="dropdown-item" href="<?= $base_url ?>sss/index.php"><i class="bi bi-file-earmark-richtext text-secondary me-2"></i>SSS</a></li>
                    </ul>
                </li>

                <li class="nav-item ms-lg-2">
                    <a class="nav-link <?= strpos($current_page, '/ayarlar/') !== false ? 'active text-white fw-bold' : '' ?>" href="<?= $base_url ?>ayarlar/index.php"><i class="bi bi-gear me-1"></i> Ayarlar</a>
                </li>
            </ul>
            
            <div class="navbar-nav">
                <a class="nav-link text-white bg-danger rounded px-3 fw-bold shadow-sm" href="<?= $base_url ?>cikis.php">
                    <i class="bi bi-box-arrow-right me-1"></i> Güvenli Çıkış
                </a>
            </div>
        </div>
    </div>
</nav>

<div class="container pb-5">