"use strict";

import React, { isValidElement } from 'react';
import { nanoid } from 'nanoid/non-secure';
import { toast as sonner, Toaster } from 'sonner';
import { DURATION } from "./const.js";
import { Icon as ToastIcon, Outer as ToastOuter, Text as ToastText, ToastConfigProvider } from "./Toast.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export { DURATION } from "./const.js";
export { Action, Icon, Outer, Text, ToastConfigProvider } from "./Toast.js";
/**
 * Toasts are rendered in a global outlet, which is placed at the top of the
 * component tree.
 */
export function ToastOutlet() {
  return /*#__PURE__*/_jsx(Toaster, {
    position: "bottom-left",
    gap: 8,
    offset: 20,
    mobileOffset: 20
  });
}

/** Direct access to the underlying Sonner API. Use sparingly. */
export const api = sonner;
function dispatch(content, type, options = {}) {
  const id = nanoid();
  if (typeof content === 'string') {
    sonner(/*#__PURE__*/_jsx(ToastConfigProvider, {
      id: id,
      type: type,
      children: /*#__PURE__*/_jsxs(ToastOuter, {
        children: [/*#__PURE__*/_jsx(ToastIcon, {}), /*#__PURE__*/_jsx(ToastText, {
          children: content
        })]
      })
    }), {
      ...options,
      unstyled: true,
      id,
      duration: options?.duration ?? DURATION
    });
  } else if (/*#__PURE__*/isValidElement(content)) {
    sonner(/*#__PURE__*/_jsx(ToastConfigProvider, {
      id: id,
      type: type,
      children: content
    }), {
      ...options,
      unstyled: true,
      id,
      duration: options?.duration ?? DURATION
    });
  } else {
    throw new Error(`Toast can be a string or a React element, got ${typeof content}`);
  }
}

/**
 * Show a toast notification. Identical API to the native variant — see
 * `./index.tsx` for the full usage docs.
 */

const toastImpl = (content, options = {}) => {
  dispatch(content, options.type ?? 'default', options);
};
toastImpl.success = (content, options) => dispatch(content, 'success', options ?? {});
toastImpl.error = (content, options) => dispatch(content, 'error', options ?? {});
toastImpl.warning = (content, options) => dispatch(content, 'warning', options ?? {});
toastImpl.info = (content, options) => dispatch(content, 'info', options ?? {});
toastImpl.dismiss = id => sonner.dismiss(id);
export const toast = toastImpl;
export const show = toastImpl;
//# sourceMappingURL=index.web.js.map