import { jsx, jsxs } from "react/jsx-runtime";
import * as RadixToast from "@radix-ui/react-toast";
import * as React from "react";
import * as ReactDOM from "react-dom";
import { useArmstrongConfig } from "../config/config.context.js";
import { Toast } from "./toast.component.js";
import "./toast.theme.css.js";
const initialContext = {
  addToast: () => {
    throw new Error("Unable to dispatch toast, are you sure you've added either the <ArmstrongProvider> or <ToastProvider>?");
  }
};
const ToastContext = React.createContext(initialContext);
const ToastProvider = ({ children, duration, position, closeButtonIcon }) => {
  const [toasts, addToast] = React.useReducer((state, action) => [...state, action], []);
  const globals = useArmstrongConfig({
    toastDuration: duration,
    toastPosition: position,
    toastCloseButtonIcon: closeButtonIcon
  });
  const swipeDirection = globals.toastPosition === "bottom-left" || globals.toastPosition === "top-left" ? "left" : "right";
  return jsx(ToastContext.Provider, { value: { addToast }, children: jsxs(RadixToast.Provider, { swipeDirection, duration: globals.toastDuration, children: [children, toasts.map((toast, i) => jsx(Toast, { duration: globals.toastDuration, position: globals.toastPosition, closeButtonIcon: globals.toastCloseButtonIcon, ...toast }, `${toast.title}-${i}`)), globals.globalPortalTo && ReactDOM.createPortal(jsx(RadixToast.Viewport, { className: "arm-toast-viewport", "data-position": globals.toastPosition }), globals.globalPortalTo)] }) });
};
ToastProvider.displayName = "ToastProvider";
export {
  ToastContext,
  ToastProvider
};
//# sourceMappingURL=toast.context.js.map
