<?php
if (!isset($page_title)) {
    $page_title = 'Admin Panel';
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= e($page_title) ?> - <?= SITE_NAME ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="<?= ASSETS_URL ?>/css/admin.css">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="<?= ADMIN_URL ?>/dashboard.php">
                <i class="fas fa-skiing me-2"></i><?= SITE_NAME ?>
            </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">
                    <li class="nav-item">
                        <a class="nav-link" href="<?= ADMIN_URL ?>/dashboard.php">
                            <i class="fas fa-home me-1"></i>Dashboard
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= ADMIN_URL ?>/companies/index.php">
                            <i class="fas fa-building me-1"></i>Firmalar
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= ADMIN_URL ?>/categories/index.php">
                            <i class="fas fa-tags me-1"></i>Kategoriler
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= ADMIN_URL ?>/service-categories/index.php">
                            <i class="fas fa-list me-1"></i>Hizmet Kategorileri
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= ADMIN_URL ?>/reviews/index.php">
                            <i class="fas fa-comments me-1"></i>Yorumlar
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= ADMIN_URL ?>/blog/index.php">
                            <i class="fas fa-blog me-1"></i>Blog
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= ADMIN_URL ?>/sliders/index.php">
                            <i class="fas fa-images me-1"></i>Slider
                        </a>
                    </li>
                    <?php
                    // Sayfalar ve Menü menülerini kontrol et (tablolar varsa göster)
                    try {
                        $stmt = $pdo->query("SHOW TABLES LIKE 'pages'");
                        if ($stmt->rowCount() > 0) {
                            echo '<li class="nav-item">';
                            echo '<a class="nav-link" href="' . ADMIN_URL . '/pages/index.php">';
                            echo '<i class="fas fa-file-alt me-1"></i>Sayfalar';
                            echo '</a>';
                            echo '</li>';
                            
                            echo '<li class="nav-item">';
                            echo '<a class="nav-link" href="' . ADMIN_URL . '/menu/index.php">';
                            echo '<i class="fas fa-bars me-1"></i>Menü';
                            echo '</a>';
                            echo '</li>';
                        }
                    } catch (PDOException $e) {
                        // Tablolar yoksa menüyü gösterme
                    }
                    ?>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= ADMIN_URL ?>/settings.php">
                            <i class="fas fa-cog me-1"></i>Ayarlar
                        </a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="fas fa-user me-1"></i><?= e($_SESSION['admin_username']) ?>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="<?= SITE_URL ?>"><i class="fas fa-globe me-2"></i>Siteyi Görüntüle</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="<?= ADMIN_URL ?>/logout.php"><i class="fas fa-sign-out-alt me-2"></i>Çıkış Yap</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    
    <div class="container-fluid mt-4">
        <?php
        $flash = getFlashMessage();
        if ($flash):
        ?>
            <div class="alert alert-<?= $flash['type'] === 'error' ? 'danger' : $flash['type'] ?> alert-dismissible fade show">
                <?= e($flash['message']) ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        <?php endif; ?>
