<?php
require_once "../../db.php";

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

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

$stmt = $conn->prepare(
  "INSERT INTO merch_categories (name) VALUES (?)"
);
$stmt->bind_param("s", $name);

if ($stmt->execute()) {
  echo json_encode(["success" => true]);
} else {
  http_response_code(409);
  echo json_encode(["error" => "Category already exists"]);
}
