"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.libReactNativeJsi = libReactNativeJsi;
function libReactNativeJsi() {
  const tonClientJsiModule = global.tonClientJsiModule;
  return Promise.resolve({
    getLibName() {
      return Promise.resolve('react-native-jsi');
    },
    setResponseParamsHandler(handler) {
      tonClientJsiModule.setResponseParamsHandler(handler);
    },
    createContext(configJson) {
      return new Promise(resolve => {
        tonClientJsiModule.createContext(configJson, resolve);
      });
    },
    destroyContext(context) {
      tonClientJsiModule.destroyContext(context);
    },
    sendRequestParams(context, requestId, functionName, functionParams) {
      tonClientJsiModule.sendRequestParams(context, requestId, functionName, replaceBigInts(functionParams));
    }
  });
}
function replaceBigInts(value) {
  // original JS BigInt
  if (typeof value === 'bigint') {
    if (value < Number.MAX_SAFE_INTEGER && value > Number.MIN_SAFE_INTEGER) {
      return Number(value);
    } else {
      return value.toString();
    }
  }
  // BigInt polyfill on Android
  if (typeof value === 'object' && value !== null && value.toJSON != null) {
    return value.toJSON();
  }
  // nested object or array
  if (typeof value === 'object' && value !== null) {
    const result = Array.isArray(value) ? [] : {};
    for (const key in value) {
      result[key] = replaceBigInts(value[key]);
    }
    return result;
  }
  return value;
}
function __createBlob(blobId, offset, size) {
  const BlobManager = require('react-native/Libraries/Blob/BlobManager'); // memoized
  return BlobManager.createFromOptions({
    blobId,
    offset,
    size
  });
}
global.__createBlob = __createBlob;
//# sourceMappingURL=index.js.mapap