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

requireAdminLogin();

$error = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name'] ?? '');
    $description = trim($_POST['description'] ?? '');
    $status = $_POST['status'] ?? 'active';
    
    if (empty($name)) {
        $error = 'Kategori adı gereklidir.';
    } else {
        try {
            $stmt = $pdo->prepare("
                INSERT INTO service_categories (name, description, status)
                VALUES (?, ?, ?)
            ");
            $stmt->execute([$name, $description, $status]);
            
            setFlashMessage('success', 'Hizmet kategorisi başarıyla oluşturuldu.');
            redirect('index.php');
        } catch (PDOException $e) {
            $error = 'Kategori oluşturulurken bir hata oluştu.';
        }
    }
}

$page_title = 'Yeni Hizmet Kategorisi Ekle';
include '../includes/header.php';
?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="h3">Yeni Hizmet Kategorisi Ekle</h1>
    <a href="index.php" class="btn btn-secondary">
        <i class="fas fa-arrow-left me-2"></i>Geri Dön
    </a>
</div>

<?php if ($error): ?>
    <div class="alert alert-danger"><?= e($error) ?></div>
<?php endif; ?>

<div class="card">
    <div class="card-body">
        <form method="POST">
            <div class="mb-3">
                <label for="name" class="form-label">Kategori Adı <span class="text-danger">*</span></label>
                <input type="text" class="form-control" id="name" name="name" required>
                <small class="text-muted">Örn: Kayak Eğitimi, Snowboard Eğitimi</small>
            </div>
            
            <div class="mb-3">
                <label for="description" class="form-label">Açıklama</label>
                <textarea class="form-control" id="description" name="description" rows="4"></textarea>
            </div>
            
            <div class="mb-3">
                <label for="status" class="form-label">Durum</label>
                <select class="form-select" id="status" name="status">
                    <option value="active">Aktif</option>
                    <option value="inactive">Pasif</option>
                </select>
            </div>
            
            <div class="mt-4">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-save me-2"></i>Kaydet
                </button>
                <a href="index.php" class="btn btn-secondary">İptal</a>
            </div>
        </form>
    </div>
</div>

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





