var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/systemSettings/registry/services.ts
var services_exports = {};
__export(services_exports, {
  createGroup: () => createGroup,
  createItem: () => createItem,
  deleteGroup: () => deleteGroup,
  deleteItem: () => deleteItem,
  getGroupList: () => getGroupList,
  getItemList: () => getItemList,
  getSectionList: () => getSectionList,
  sortGroups: () => sortGroups,
  sortItems: () => sortItems,
  updateGroup: () => updateGroup,
  updateItem: () => updateItem
});
module.exports = __toCommonJS(services_exports);
var createGroup = async (request, params) => {
  try {
    if (!params.title || !params.code || !params.section_code || params.sort === void 0) {
      throw new Error("Missing required parameters for group creation");
    }
    const response = await request.post(
      "/api/setting_group:create",
      params,
      {
        isNocobase: true,
        headers: {
          "x-data-source": "pisell2"
        }
      }
    );
    return response;
  } catch (error) {
    console.error("Failed to create group:", error);
    throw error;
  }
};
var updateGroup = async (request, params) => {
  try {
    if (!params.id || !params.title || !params.code) {
      throw new Error("Missing required parameters for group update");
    }
    const response = await request.post(
      `/api/setting_group:update?filterByTk=${params.id}`,
      params,
      {
        isNocobase: true,
        headers: {
          "x-data-source": "pisell2"
        }
      }
    );
    return response;
  } catch (error) {
    console.error("Failed to update group:", error);
    throw error;
  }
};
var deleteGroup = async (request, params) => {
  try {
    if (!params.id) {
      throw new Error("Missing required parameters for group deletion");
    }
    const response = await request.post(
      `/api/setting_group:update?filterByTk=${params.id}`,
      {
        deleted_at: (/* @__PURE__ */ new Date()).toISOString()
      },
      {
        isNocobase: true,
        headers: {
          "x-data-source": "pisell2"
        }
      }
    );
    return response;
  } catch (error) {
    console.error("Failed to delete group:", error);
    throw error;
  }
};
var sortGroups = async (request, params) => {
  try {
    if (!params.section_code || !params.group_ids || !Array.isArray(params.group_ids)) {
      throw new Error("Missing required parameters for group sorting");
    }
    const response = await request.post(
      "/admin/setting/group/sort",
      {
        section_code: params.section_code,
        group_ids: params.group_ids
      },
      {
        headers: {
          "Content-Type": "application/json"
        }
      }
    );
    return response;
  } catch (error) {
    console.error("Failed to sort groups:", error);
    throw error;
  }
};
var getSectionList = async (request, params) => {
  try {
    const { page = 1, pageSize = 20, filter = {} } = params;
    const filterWithSoftDelete = {
      ...filter,
      deleted_at: null
    };
    const queryParams = new URLSearchParams({
      page: page.toString(),
      pageSize: pageSize.toString(),
      filter: JSON.stringify(filterWithSoftDelete)
    });
    const response = await request.get(
      `/api/section:list?${queryParams.toString()}`,
      {},
      {
        isNocobase: true,
        headers: {
          "x-data-source": "pisell2"
        }
      }
    );
    return response;
  } catch (error) {
    console.error("Failed to fetch section list:", error);
    throw error;
  }
};
var getGroupList = async (request, params) => {
  try {
    const { filter = {} } = params;
    const filterWithSoftDelete = {
      ...filter,
      deleted_at: null
      // "items.deleted_at": null
    };
    const queryParams = new URLSearchParams({
      paginate: "false",
      filter: JSON.stringify(filterWithSoftDelete),
      appends: "items",
      sort: "sort,id"
    });
    const response = await request.get(
      `/api/setting_group:list?${queryParams.toString()}`,
      {},
      {
        isNocobase: true,
        headers: {
          "x-data-source": "pisell2"
        }
      }
    );
    if (response.data.length > 0) {
      response.data.forEach((item) => {
        item.items = item.items.filter((item2) => item2.deleted_at === null);
      });
    }
    return response;
  } catch (error) {
    console.error("Failed to fetch group list:", error);
    throw error;
  }
};
var createItem = async (request, params) => {
  try {
    if (!params.section_code || !params.group_id || !params.title || !params.code || !params.type) {
      throw new Error("Missing required parameters for item creation");
    }
    const response = await request.post(
      "/admin/setting/item",
      params
    );
    return response;
  } catch (error) {
    console.error("Failed to create item:", error);
    throw error;
  }
};
var updateItem = async (request, params) => {
  try {
    if (!params.id || !params.section_code || !params.group_id || !params.title || !params.code || !params.type) {
      throw new Error("Missing required parameters for item update");
    }
    const response = await request.put(
      `/admin/setting/item/${params.id}`,
      params
    );
    return response;
  } catch (error) {
    console.error("Failed to update item:", error);
    throw error;
  }
};
var deleteItem = async (request, params) => {
  try {
    console.log(request);
    if (!params.id) {
      throw new Error("Missing required parameters for item deletion");
    }
    const response = await request.remove(
      `/admin/setting/item/${params.id}`,
      {}
    );
    return response;
  } catch (error) {
    console.error("Failed to delete item:", error);
    throw error;
  }
};
var sortItems = async (request, params) => {
  try {
    if (!params.id || !params.group_id || !params.item_ids) {
      throw new Error("Missing required parameters for item sorting");
    }
    const response = await request.post(
      `/admin/setting/item/${params.id}/sort`,
      {
        group_id: params.group_id,
        item_ids: params.item_ids
      },
      {
        headers: {
          "Content-Type": "application/json"
        }
      }
    );
    return response;
  } catch (error) {
    console.error("Failed to sort items:", error);
    throw error;
  }
};
var getItemList = async (request, params) => {
  try {
    const { page = 1, pageSize = 20, filter = {} } = params;
    const filterWithSoftDelete = {
      ...filter,
      deleted_at: null
    };
    const queryParams = new URLSearchParams({
      page: page.toString(),
      pageSize: pageSize.toString(),
      filter: JSON.stringify(filterWithSoftDelete)
    });
    const response = await request.get(
      `/api/setting_item:list?${queryParams.toString()}`,
      {}
    );
    return response;
  } catch (error) {
    console.error("Failed to fetch item list:", error);
    throw error;
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createGroup,
  createItem,
  deleteGroup,
  deleteItem,
  getGroupList,
  getItemList,
  getSectionList,
  sortGroups,
  sortItems,
  updateGroup,
  updateItem
});
