import { d as deleteCategory, g as getCategoryTree, c as createCategory, u as updateCategory } from '../../../chunks/category-manager_oFBF0xlN.mjs';
export { renderers } from '../../../renderers.mjs';

const GET = async ({ url }) => {
  try {
    const dimension = url.searchParams.get("dimension") || void 0;
    const tree = await getCategoryTree(dimension);
    return new Response(JSON.stringify({ categories: tree }), {
      headers: { "Content-Type": "application/json" }
    });
  } catch (e) {
    return new Response(JSON.stringify({ error: e.message }), { status: 500 });
  }
};
const POST = async ({ request }) => {
  try {
    const data = await request.json();
    const category = await createCategory(data);
    return new Response(JSON.stringify(category), {
      status: 201,
      headers: { "Content-Type": "application/json" }
    });
  } catch (e) {
    return new Response(JSON.stringify({ error: e.message }), { status: 400 });
  }
};
const PUT = async ({ request }) => {
  try {
    const { id, ...data } = await request.json();
    if (!id) return new Response(JSON.stringify({ error: "id required" }), { status: 400 });
    const category = await updateCategory(id, data);
    if (!category) return new Response(JSON.stringify({ error: "Not found" }), { status: 404 });
    return new Response(JSON.stringify(category), {
      headers: { "Content-Type": "application/json" }
    });
  } catch (e) {
    return new Response(JSON.stringify({ error: e.message }), { status: 400 });
  }
};
const DELETE = async ({ request }) => {
  try {
    const { id } = await request.json();
    if (!id) return new Response(JSON.stringify({ error: "id required" }), { status: 400 });
    const deleted = await deleteCategory(id);
    return new Response(JSON.stringify({ deleted }), {
      headers: { "Content-Type": "application/json" }
    });
  } catch (e) {
    return new Response(JSON.stringify({ error: e.message }), { status: 400 });
  }
};

const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
  __proto__: null,
  DELETE,
  GET,
  POST,
  PUT
}, Symbol.toStringTag, { value: 'Module' }));

const page = () => _page;

export { page };
