import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
async function fetchRoleOptions(query, params) {
  const searchParams = new URLSearchParams({ page: "1", pageSize: "20" });
  if (query && query.trim()) searchParams.set("search", query.trim());
  const tenantId = typeof params?.tenantId === "string" && params.tenantId.trim().length ? params.tenantId.trim() : null;
  if (tenantId) searchParams.set("tenantId", tenantId);
  try {
    const call = await apiCall(
      `/api/auth/roles?${searchParams.toString()}`,
      void 0,
      { fallback: { items: [] } }
    );
    if (!call.ok || !Array.isArray(call.result?.items)) return [];
    const { items } = call.result;
    return items.map((item) => {
      const id = typeof item?.id === "string" ? item.id.trim() : "";
      const name = typeof item?.name === "string" ? item?.name.trim() : "";
      if (!id || !name) return null;
      if (name === "superadmin" && !params?.includeSuperAdmin) return null;
      return { value: id, label: name };
    }).filter((opt) => !!opt);
  } catch {
    return [];
  }
}
export {
  fetchRoleOptions
};
//# sourceMappingURL=roleOptions.js.map
