"use client";
let r = 0;
const i = [], d = (n, t, e) => {
  const s = {
    type: n,
    id: String(++r),
    date: /* @__PURE__ */ new Date()
  };
  t && (s.message = t), h(s);
}, p = ({ type: n, message: t, data: e, context: s }) => {
  const o = {
    type: n,
    id: String(++r),
    date: /* @__PURE__ */ new Date()
  };
  t && (o.message = t), e && (o.data = e), s && (o.context = s), h(o);
};
class c {
  type;
  context;
  constructor(t, e) {
    this.type = t, this.context = e;
  }
  trace(t, e) {
    p({
      type: this.type,
      message: t,
      data: e,
      context: this.context
    });
  }
  getContext() {
    return this.context;
  }
  setContext(t) {
    this.context = t;
  }
  updateContext(t) {
    this.context = { ...this.context, ...t };
  }
  getType() {
    return this.type;
  }
  setType(t) {
    this.type = t;
  }
  /**
   * Create a new instance of the LocalTracer with an updated `type`
   *
   * It does not mutate the calling instance, but returns a new LocalTracer,
   * following a simple builder pattern.
   */
  withType(t) {
    return new c(t, this.context);
  }
  /**
   * Create a new instance of the LocalTracer with a new `context`
   *
   * It does not mutate the calling instance, but returns a new LocalTracer,
   * following a simple builder pattern.
   *
   * @param context A TraceContext, that can undefined to reset the context
   */
  withContext(t) {
    return new c(this.type, t);
  }
  /**
   * Create a new instance of the LocalTracer with an updated `context`,
   * on which an additional context is merged with the existing one.
   *
   * It does not mutate the calling instance, but returns a new LocalTracer,
   * following a simple builder pattern.
   */
  withUpdatedContext(t) {
    return new c(this.type, { ...this.context, ...t });
  }
}
const x = (n) => (i.push(n), () => {
  const t = i.indexOf(n);
  t !== -1 && (i[t] = i[i.length - 1], i.pop());
});
function h(n) {
  for (let t = 0; t < i.length; t++)
    try {
      i[t](n);
    } catch (e) {
      console.error(e);
    }
}
typeof window < "u" && (window.__ledgerLogsListen = x);
export {
  c as L,
  d as l
};
