    <?php

require_once __DIR__ . '/../db.php';

$name = trim($_POST['name'] ?? '');

if ($name === '') {
  http_response_code(400);
  echo json_encode(["error" => "Category name required"]);
  exit;
}

$slug = strtolower(preg_replace('/[^a-z0-9]+/', '-', $name));

$stmt = $conn->prepare(
  "INSERT INTO menu_categories (name, slug) VALUES (?, ?)"
);
$stmt->bind_param("ss", $name, $slug);
$stmt->execute();

echo json_encode([
  "id" => $stmt->insert_id,
  "name" => $name,
  "slug" => $slug
]);
