import { a, b, c, d, e, f, g, h, i, j } from "../chunks/api-BQ_tS-9F.esm.js";
let baseUrl = "";
let defaultHeaders = {};
function sanitizeUrl(url) {
  if (url.endsWith("/")) {
    return url.slice(0, -1);
  } else {
    return url;
  }
}
const setBaseUrl = (newUrl) => {
  baseUrl = sanitizeUrl(newUrl);
};
const setDefaultHeaders = (headers) => {
  defaultHeaders = headers;
};
const _getV1Dashboard = async (url, request) => {
  const queryParameters = ["filter_type"];
  const searchParams = new URLSearchParams();
  queryParameters.forEach((qp) => {
    var _a;
    if (request[qp]) {
      if (Array.isArray(request[qp])) {
        request[qp].forEach((p) => {
          searchParams.append(qp, p);
        });
      } else {
        searchParams.append(qp, ((_a = request[qp]) == null ? void 0 : _a.toString()) || "");
      }
    }
    delete request[qp];
  });
  const headers = {
    ...defaultHeaders
  };
  if (request["x-token"] !== void 0) {
    headers["x-token"] = request["x-token"];
    delete request["x-token"];
  }
  if (request["x-timezone"] !== void 0) {
    headers["x-timezone"] = request["x-timezone"];
    delete request["x-timezone"];
  }
  const response = await fetch(`${url}/v1/dashboard/?${searchParams.toString()}`, {
    headers
  });
  if (!response.ok) {
    throw new Error(await response.text());
  }
  return await response.json();
};
const getV1Dashboard = async (request) => {
  return await _getV1Dashboard(baseUrl, request);
};
const _getV1DashboardUserActivity = async (url, request) => {
  const queryParameters = ["filter_type"];
  const searchParams = new URLSearchParams();
  queryParameters.forEach((qp) => {
    var _a;
    if (request[qp]) {
      if (Array.isArray(request[qp])) {
        request[qp].forEach((p) => {
          searchParams.append(qp, p);
        });
      } else {
        searchParams.append(qp, ((_a = request[qp]) == null ? void 0 : _a.toString()) || "");
      }
    }
    delete request[qp];
  });
  const headers = {
    ...defaultHeaders
  };
  if (request["x-token"] !== void 0) {
    headers["x-token"] = request["x-token"];
    delete request["x-token"];
  }
  if (request["x-timezone"] !== void 0) {
    headers["x-timezone"] = request["x-timezone"];
    delete request["x-timezone"];
  }
  const response = await fetch(`${url}/v1/dashboard/user-activity?${searchParams.toString()}`, {
    headers
  });
  if (!response.ok) {
    throw new Error(await response.text());
  }
  return await response.json();
};
const getV1DashboardUserActivity = async (request) => {
  return await _getV1DashboardUserActivity(baseUrl, request);
};
function build(url, options) {
  url = sanitizeUrl(url);
  if (options == null ? void 0 : options.headers) {
    defaultHeaders = options.headers;
  }
  return {
    getV1Dashboard: _getV1Dashboard.bind(url, ...arguments),
    getV1DashboardUserActivity: _getV1DashboardUserActivity.bind(url, ...arguments)
  };
}
const api = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: build,
  getV1Dashboard,
  getV1DashboardUserActivity,
  setBaseUrl,
  setDefaultHeaders
}, Symbol.toStringTag, { value: "Module" }));
export {
  a as AccountingApi,
  b as AiFeatureApi,
  c as DriveApi,
  d as InventoryApi,
  e as ManufacturingApi,
  f as PurchaseApi,
  g as RbacApi,
  h as RentalApi,
  i as SalesApi,
  j as SystemFeatureApi,
  api as UserApi
};
//# sourceMappingURL=index.esm.js.map
