"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunk7QVYU63Ejs = require('./chunk-7QVYU63E.js');

// src/client/request.ts
async function directFetch(params) {
  const response = {
    data: void 0,
    ok: false,
    status: 0,
    statusText: ""
  };
  const additionalHeaders = { ...params.additionalHeaders };
  if (params.companyId) {
    additionalHeaders["x-companyid"] = params.companyId;
  }
  additionalHeaders["x-language"] = params.language;
  let requestBody = void 0;
  if (params.files) {
    const formData = new FormData();
    if (params.body && typeof params.body === "object") {
      for (const key in params.body) {
        if (Object.prototype.hasOwnProperty.call(params.body, key)) {
          formData.append(
            key,
            typeof params.body[key] === "object" ? JSON.stringify(params.body[key]) : params.body[key]
          );
        }
      }
    }
    if (params.files instanceof Blob) {
      formData.append("file", params.files);
    } else if (typeof params.files === "object" && params.files !== null) {
      for (const key in params.files) {
        if (Object.prototype.hasOwnProperty.call(params.files, key)) {
          formData.append(key, params.files[key]);
        }
      }
    }
    requestBody = formData;
  } else if (params.body !== void 0) {
    requestBody = JSON.stringify(params.body);
    additionalHeaders["Content-Type"] = "application/json";
  }
  const options = {
    method: params.method,
    headers: { Accept: "application/json", ...additionalHeaders }
  };
  if (requestBody !== void 0) {
    options.body = requestBody;
  }
  if (params.token) {
    options.headers = { ...options.headers, Authorization: `Bearer ${params.token}` };
  }
  try {
    const apiResponse = await fetch(params.url, options);
    response.ok = apiResponse.ok;
    response.status = apiResponse.status;
    response.statusText = apiResponse.statusText;
    try {
      response.data = await apiResponse.json();
    } catch (e) {
      response.data = void 0;
    }
  } catch (e2) {
    response.ok = false;
    response.status = 500;
    response.data = void 0;
  }
  return response;
}
_chunk7QVYU63Ejs.__name.call(void 0, directFetch, "directFetch");



exports.directFetch = directFetch;
//# sourceMappingURL=chunk-IBS6NI7D.js.map