"use strict";

import React, { useEffect, useState } from 'react';
import { AutoMountedDialog } from "./Dialog.web.js";
import { buttonToAction, dismissAlert, subscribeAlerts } from "./alert-store.js";

/**
 * 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.
 */
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export function BloomDialogProvider({
  children
}) {
  const [queue, setQueue] = useState([]);
  useEffect(() => subscribeAlerts(setQueue), []);
  const head = queue[0];
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [children, head ? /*#__PURE__*/_jsx(AlertHost, {
      entry: head
    }, head.id) : null]
  });
}
function AlertHost({
  entry
}) {
  const actions = entry.buttons.map(buttonToAction);
  return /*#__PURE__*/_jsx(AutoMountedDialog, {
    title: entry.title,
    description: entry.message,
    actions: actions,
    onResolve: () => dismissAlert(entry.id)
  });
}
//# sourceMappingURL=BloomDialogProvider.web.js.map