<?php
require_once '../../config/config.php';
require_once '../../includes/auth.php';

requireAdminLogin();

// Hizmet kategorilerini listele
$stmt = $pdo->query("
    SELECT sc.*, 
           (SELECT COUNT(*) FROM services WHERE service_category_id = sc.id) as service_count
    FROM service_categories sc
    ORDER BY sc.created_at DESC
");
$categories = $stmt->fetchAll();

$page_title = 'Hizmet Kategorileri';
include '../includes/header.php';
?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="h3">Hizmet Kategorileri</h1>
    <a href="create.php" class="btn btn-primary">
        <i class="fas fa-plus me-2"></i>Yeni Hizmet Kategorisi Ekle
    </a>
</div>

<div class="card">
    <div class="card-body">
        <?php if (empty($categories)): ?>
            <p class="text-muted text-center py-5">Henüz hizmet kategorisi eklenmemiş.</p>
        <?php else: ?>
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Kategori Adı</th>
                            <th>Açıklama</th>
                            <th>Hizmet Sayısı</th>
                            <th>Durum</th>
                            <th>Oluşturulma</th>
                            <th>İşlemler</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($categories as $category): ?>
                            <tr>
                                <td><?= $category['id'] ?></td>
                                <td><?= e($category['name']) ?></td>
                                <td><?= excerpt($category['description'], 50) ?></td>
                                <td>
                                    <span class="badge bg-info"><?= $category['service_count'] ?></span>
                                </td>
                                <td>
                                    <span class="badge bg-<?= $category['status'] === 'active' ? 'success' : 'secondary' ?>">
                                        <?= $category['status'] === 'active' ? 'Aktif' : 'Pasif' ?>
                                    </span>
                                </td>
                                <td><?= formatDate($category['created_at'], 'd.m.Y H:i') ?></td>
                                <td>
                                    <a href="edit.php?id=<?= $category['id'] ?>" class="btn btn-sm btn-warning">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    <a href="delete.php?id=<?= $category['id'] ?>" class="btn btn-sm btn-danger btn-delete" onclick="return confirm('Bu kategoriyi silmek istediğinize emin misiniz?')">
                                        <i class="fas fa-trash"></i>
                                    </a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php endif; ?>
    </div>
</div>

<?php include '../includes/footer.php'; ?>





