"use strict";
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);
var expect_exports = {};
__export(expect_exports, {
  getSizableExpectData: () => getSizableExpectData,
  prepareChecklyData: () => prepareChecklyData
});
module.exports = __toCommonJS(expect_exports);
const parseJson = (json) => {
  try {
    JSON.parse(JSON.stringify(json));
  } catch {
    return false;
  }
  return true;
};
const getInputLength = (input) => {
  let byteLength = 0;
  try {
    if (typeof input === "string") {
      byteLength = new TextEncoder().encode(input).length;
    } else if (Array.isArray(input) || typeof input === "object" && input !== null) {
      const jsonString = JSON.stringify(input);
      byteLength = new TextEncoder().encode(jsonString).length;
    } else {
      const stringValue = String(input);
      byteLength = new TextEncoder().encode(stringValue).length;
    }
    return byteLength;
  } catch (error) {
    return Infinity;
  }
};
const prepareChecklyData = (actual, title, expectedData) => {
  try {
    const data = { actual: getSizableExpectData(actual), title, expectedData: getSizableExpectData(expectedData) };
    if (parseJson(data))
      return data;
    data.actual = "<Value cannot be displayed>";
    if (parseJson(data))
      return data;
    data.expectedData = "<Value cannot be displayed>";
    if (parseJson(data))
      return data;
    data.title = "<Value cannot be displayed>";
    return data;
  } catch {
    return {};
  }
};
const getSizableExpectData = (value) => {
  try {
    if (!value)
      return value;
    const len = getInputLength(value);
    const limit = parseInt(process.env.CHECKLY_EXPECTED_DATA_MAX_LENGTH ?? "0", 10) || 1e3;
    if (len > limit)
      return `<Value is too big to be displayed (size: ${len} bytes; limit: ${limit} bytes)>`;
    return value;
  } catch {
    return `<Cannot retrieve value>`;
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getSizableExpectData,
  prepareChecklyData
});
