import { j as r } from "../../../_virtual/jsx-runtime.js";
import { createContext as u, useContext as E, useReducer as f, useMemo as x, useRef as A, createElement as _ } from "react";
import { createPortal as M } from "react-dom";
import { getComponentRoot as l } from "../../../utils/index.js";
import { MessageProviderToast as I } from "./components/MessageProviderToast.js";
import { INITIAL_MESSAGE_CONTEXT_VALUE as O, TOAST_TYPE_COMPACT as i, MESSAGE_POSITION_DEFAULT as g, AUTO_HIDE_DURATION_DEFAULT as P, TOAST_TYPE_DEFAULT as C } from "./constants.js";
import { messagesReducer as S, initialMessagesState as v } from "./reducer.js";
import { ToastWrapper as D } from "./styles.js";
import { createMessageMethods as o } from "./utils/createMessageMethods.js";
const n = u(
  O
), G = () => E(n), R = {
  action: "acknowledge",
  autoHideDuration: P,
  position: g,
  toastType: i,
  zIndex: 6e3
};
function H({
  children: a,
  messageRoot: m,
  options: p
}) {
  const [c, t] = f(S, v), e = {
    ...R,
    ...p
  }, T = x(
    () => ({
      compact: o(t, {
        ...e,
        toastType: i
      }),
      default: o(t, {
        ...e,
        toastType: C
      }),
      ...o(t, e)
    }),
    []
  ), d = A(l(m));
  return /* @__PURE__ */ r.jsxs(n.Provider, { value: T, children: [
    a,
    M(
      /* @__PURE__ */ r.jsx(
        D,
        {
          position: e.position,
          zIndex: e.zIndex,
          children: c.messages.map((s) => /* @__PURE__ */ _(
            I,
            {
              ...s,
              key: s.id,
              position: e.position
            }
          ))
        }
      ),
      d.current
    )
  ] });
}
export {
  H as MessageProvider,
  G as useMessageContext
};
