"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BloomDialogProvider = BloomDialogProvider;
var _react = _interopRequireWildcard(require("react"));
var _DialogWeb = require("./Dialog.web.js");
var _alertStore = require("./alert-store.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); }
/**
 * Web variant of `BloomDialogProvider`. Identical surface area to the
 * native version — it just uses the web-fork `Dialog` (`Dialog.web.tsx`)
 * underneath instead of the bottom-sheet variant.
 *
 * See the native file (`./BloomDialogProvider.tsx`) for the full design
 * notes; this fork exists purely so the bundler's `browser` condition can
 * resolve to a `Dialog` that doesn't pull in the native gesture-handler /
 * reanimated stack.
 */
function BloomDialogProvider({
  children
}) {
  const [queue, setQueue] = (0, _react.useState)([]);
  (0, _react.useEffect)(() => (0, _alertStore.subscribeAlerts)(setQueue), []);
  const head = queue[0];
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [children, head ? /*#__PURE__*/(0, _jsxRuntime.jsx)(AlertHost, {
      entry: head
    }, head.id) : null]
  });
}
function AlertHost({
  entry
}) {
  const actions = entry.buttons.map(_alertStore.buttonToAction);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DialogWeb.AutoMountedDialog, {
    title: entry.title,
    description: entry.message,
    actions: actions,
    onResolve: () => (0, _alertStore.dismissAlert)(entry.id)
  });
}
//# sourceMappingURL=BloomDialogProvider.web.js.map