import { c as _c } from "react/compiler-runtime";
import React, { createContext, useContext, useMemo } from 'react';
import { Mailbox } from '../utils/mailbox.js';
const MailboxContext = createContext<Mailbox | undefined>(undefined);
type Props = {
  children: React.ReactNode;
};
export function MailboxProvider(t0) {
  const $ = _c(3);
  const {
    children
  } = t0;
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = new Mailbox();
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const mailbox = t1;
  let t2;
  if ($[1] !== children) {
    t2 = <MailboxContext.Provider value={mailbox}>{children}</MailboxContext.Provider>;
    $[1] = children;
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  return t2;
}
export function useMailbox() {
  const mailbox = useContext(MailboxContext);
  if (!mailbox) {
    throw new Error("useMailbox must be used within a MailboxProvider");
  }
  return mailbox;
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJSZWFjdCIsImNyZWF0ZUNvbnRleHQiLCJ1c2VDb250ZXh0IiwidXNlTWVtbyIsIk1haWxib3giLCJNYWlsYm94Q29udGV4dCIsInVuZGVmaW5lZCIsIlByb3BzIiwiY2hpbGRyZW4iLCJSZWFjdE5vZGUiLCJNYWlsYm94UHJvdmlkZXIiLCJ0MCIsIiQiLCJfYyIsInQxIiwiU3ltYm9sIiwiZm9yIiwibWFpbGJveCIsInQyIiwidXNlTWFpbGJveCIsIkVycm9yIl0sInNvdXJjZXMiOlsibWFpbGJveC50c3giXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFJlYWN0LCB7IGNyZWF0ZUNvbnRleHQsIHVzZUNvbnRleHQsIHVzZU1lbW8gfSBmcm9tICdyZWFjdCdcbmltcG9ydCB7IE1haWxib3ggfSBmcm9tICcuLi91dGlscy9tYWlsYm94LmpzJ1xuXG5jb25zdCBNYWlsYm94Q29udGV4dCA9IGNyZWF0ZUNvbnRleHQ8TWFpbGJveCB8IHVuZGVmaW5lZD4odW5kZWZpb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