/** 用户通过关闭确认框放弃分配 holder，submit / checkout 应中止且不弹错误 */
export var HOLDER_CONFIRM_CANCELLED = Symbol('HOLDER_CONFIRM_CANCELLED');
/**
 * 创建实例级 Holder 确认弹窗 bridge。
 *
 * @example
 * await bridge.show({ bookingTicket, tempOrder, bookingConfig, snapshotLineKeys });
 */
export function createHolderConfirmBridge() {
  var pending = null;
  var listeners = new Set();
  var notify = function notify() {
    listeners.forEach(function (listener) {
      return listener();
    });
  };
  return {
    show: function show(ctx) {
      return new Promise(function (resolve, reject) {
        pending = {
          open: true,
          ctx: ctx,
          resolve: resolve,
          reject: reject
        };
        notify();
      });
    },
    subscribe: function subscribe(listener) {
      listeners.add(listener);
      return function () {
        return listeners.delete(listener);
      };
    },
    getSnapshot: function getSnapshot() {
      return pending;
    },
    complete: function complete() {
      if (!pending) return;
      var _pending = pending,
        resolve = _pending.resolve;
      pending = null;
      notify();
      resolve();
    },
    cancel: function cancel() {
      if (!pending) return;
      var _pending2 = pending,
        reject = _pending2.reject;
      pending = null;
      notify();
      reject(HOLDER_CONFIRM_CANCELLED);
    },
    refresh: function refresh() {
      var _pending3;
      if (!((_pending3 = pending) !== null && _pending3 !== void 0 && _pending3.open)) return;
      notify();
    }
  };
}
export function isHolderConfirmCancelled(error) {
  return error === HOLDER_CONFIRM_CANCELLED;
}