"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "Action", {
  enumerable: true,
  get: function () {
    return _Toast.Action;
  }
});
Object.defineProperty(exports, "DURATION", {
  enumerable: true,
  get: function () {
    return _const.DURATION;
  }
});
Object.defineProperty(exports, "Icon", {
  enumerable: true,
  get: function () {
    return _Toast.Icon;
  }
});
Object.defineProperty(exports, "Outer", {
  enumerable: true,
  get: function () {
    return _Toast.Outer;
  }
});
Object.defineProperty(exports, "Text", {
  enumerable: true,
  get: function () {
    return _Toast.Text;
  }
});
Object.defineProperty(exports, "ToastConfigProvider", {
  enumerable: true,
  get: function () {
    return _Toast.ToastConfigProvider;
  }
});
exports.ToastOutlet = ToastOutlet;
exports.toast = exports.show = exports.api = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _nonSecure = require("nanoid/non-secure");
var _sonnerNative = require("sonner-native");
var _const = require("./const.js");
var _Toast = require("./Toast.js");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/**
 * Toasts are rendered in a global outlet, which is placed at the top of the
 * component tree.
 */
function ToastOutlet() {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_sonnerNative.Toaster, {
    pauseWhenPageIsHidden: true,
    gap: 8
  });
}
function OuterWrapper({
  children
}) {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: wrapperStyles.container,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.Outer, {
      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.
 */
const api = exports.api = _sonnerNative.toast;
function dispatch(content, type, options = {}) {
  const id = (0, _nonSecure.nanoid)();
  if (typeof content === 'string') {
    _sonnerNative.toast.custom(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.ToastConfigProvider, {
      id: id,
      type: type,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(OuterWrapper, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.Icon, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.Text, {
          children: content
        })]
      })
    }), {
      ...options,
      id,
      duration: options?.duration ?? _const.DURATION
    });
  } else if (/*#__PURE__*/(0, _react.isValidElement)(content)) {
    _sonnerNative.toast.custom(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.ToastConfigProvider, {
      id: id,
      type: type,
      children: content
    }), {
      ...options,
      id,
      duration: options?.duration ?? _const.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 => _sonnerNative.toast.dismiss(id);
const toast = exports.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.
 */
const show = exports.show = toastImpl;

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

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