"use strict";

import React, { isValidElement } from 'react';
import { View, StyleSheet } from 'react-native';
import { nanoid } from 'nanoid/non-secure';
import { toast as sonner, Toaster } from 'sonner-native';
import { DURATION } from "./const.js";
import { Icon as ToastIcon, Outer as BaseOuter, 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, {
    pauseWhenPageIsHidden: true,
    gap: 8
  });
}
function OuterWrapper({
  children
}) {
  return /*#__PURE__*/_jsx(View, {
    style: wrapperStyles.container,
    children: /*#__PURE__*/_jsx(BaseOuter, {
      children: children
    })
  });
}

/**
 * Direct access to the Sonner API. Use sparingly — `toast()` covers the
 * common case and keeps the surface tied to bloom's themed look.
 */
export const api = sonner;
function dispatch(content, type, options = {}) {
  const id = nanoid();
  if (typeof content === 'string') {
    sonner.custom(/*#__PURE__*/_jsx(ToastConfigProvider, {
      id: id,
      type: type,
      children: /*#__PURE__*/_jsxs(OuterWrapper, {
        children: [/*#__PURE__*/_jsx(ToastIcon, {}), /*#__PURE__*/_jsx(ToastText, {
          children: content
        })]
      })
    }), {
      ...options,
      id,
      duration: options?.duration ?? DURATION
    });
  } else if (/*#__PURE__*/isValidElement(content)) {
    sonner.custom(/*#__PURE__*/_jsx(ToastConfigProvider, {
      id: id,
      type: type,
      children: content
    }), {
      ...options,
      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.
 *
 * Pass a string for a simple text toast, or a React element for a custom
 * toast. The optional `options` argument accepts the standard Sonner
 * options plus a bloom `type` (defaults to `'default'`).
 *
 * ```ts
 * toast('Saved');
 * toast.success('Profile updated');
 * toast.error('Network error', { duration: 5000 });
 * toast.dismiss(id);
 * ```
 *
 * Pre-typed variants (`toast.success`, `toast.error`, `toast.warning`,
 * `toast.info`) are aliases for the corresponding `type`.
 */

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;

/**
 * Alias of `toast` kept for compatibility with the original 0.4.x surface
 * where `show()` was the documented entry point. New code should prefer
 * `toast()` directly.
 */
export const show = toastImpl;

/** Re-export the Toast function type so callers can refer to it. */

const wrapperStyles = StyleSheet.create({
  container: {
    paddingHorizontal: 20,
    width: '100%'
  }
});
//# sourceMappingURL=index.js.map