"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 _nonSecure = require("nanoid/non-secure");
var _sonner = require("sonner");
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)(_sonner.Toaster, {
    position: "bottom-left",
    gap: 8,
    offset: 20,
    mobileOffset: 20
  });
}

/** Direct access to the underlying Sonner API. Use sparingly. */
const api = exports.api = _sonner.toast;
function dispatch(content, type, options = {}) {
  const id = (0, _nonSecure.nanoid)();
  if (typeof content === 'string') {
    (0, _sonner.toast)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.ToastConfigProvider, {
      id: id,
      type: type,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Toast.Outer, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.Icon, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.Text, {
          children: content
        })]
      })
    }), {
      ...options,
      unstyled: true,
      id,
      duration: options?.duration ?? _const.DURATION
    });
  } else if (/*#__PURE__*/(0, _react.isValidElement)(content)) {
    (0, _sonner.toast)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.ToastConfigProvider, {
      id: id,
      type: type,
      children: content
    }), {
      ...options,
      unstyled: true,
      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. 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.toast.dismiss(id);
const toast = exports.toast = toastImpl;
const show = exports.show = toastImpl;
//# sourceMappingURL=index.web.js.map