"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createAlertDialogHost = createAlertDialogHost;
var _react = _interopRequireWildcard(require("react"));
var _confirmStore = require("./confirm-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); }
/**
 * Build the `<AlertDialogHost />` bound to a platform `AlertDialog`. The
 * platform entry files (`index.ts` / `index.web.ts`) inject the correct one.
 *
 * The host mounts the imperative `confirm()` UI. Wrap your app root once
 * (after `BloomThemeProvider`) and you can call `confirm()` from anywhere —
 * including before the host mounts (entries are queued and drained on
 * subscribe). Confirms present one at a time in FIFO order.
 */
function createAlertDialogHost(AlertDialog) {
  function ConfirmHost({
    entry
  }) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(AlertDialog, {
      visible: true,
      title: entry.title,
      description: entry.description,
      confirmLabel: entry.confirmLabel,
      cancelLabel: entry.cancelLabel,
      destructive: entry.destructive,
      hideCancel: entry.hideCancel,
      dismissible: entry.dismissible,
      onConfirm: () => (0, _confirmStore.resolveConfirm)(entry.id, true),
      onCancel: () => (0, _confirmStore.resolveConfirm)(entry.id, false),
      onClose: () => (0, _confirmStore.resolveConfirm)(entry.id, false)
    });
  }
  function AlertDialogHost() {
    const [queue, setQueue] = (0, _react.useState)([]);
    (0, _react.useEffect)(() => (0, _confirmStore.subscribeConfirms)(setQueue), []);
    const head = queue[0];
    if (!head) return null;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(ConfirmHost, {
      entry: head
    }, head.id);
  }
  AlertDialogHost.displayName = 'AlertDialogHost';
  return AlertDialogHost;
}
//# sourceMappingURL=AlertDialogHost.js.map