"use strict";

/**
 * Holds URLs while the linking pipeline is not ready and replays them in
 * order once it becomes ready.
 *
 * Readiness is set by the owning `LinkingHandler` and reflects the combined
 * state of:
 *   - whether the first `setRoot` has resolved (so a modal can be presented),
 *   - whether the user-supplied `isReady` predicate (if any) returns `true`.
 */
export class DeferredLinkQueue {
  queue = [];
  ready = false;
  flushCallback = null;
  setFlushCallback(callback) {
    this.flushCallback = callback;
  }
  setReady(ready) {
    const becameReady = !this.ready && ready;
    this.ready = ready;
    if (becameReady) {
      this.flush();
    }
  }
  isReady() {
    return this.ready;
  }

  /**
   * Enqueue a URL for later processing. Should only be called when the
   * queue is not ready; the handler decides when to enqueue vs process.
   */
  enqueue(url) {
    this.queue.push(url);
  }
  flush() {
    if (!this.flushCallback) return;
    const pending = [...this.queue];
    this.queue = [];
    for (const url of pending) {
      this.flushCallback(url);
    }
  }
  clear() {
    this.queue = [];
  }
  pending() {
    return [...this.queue];
  }
}
//# sourceMappingURL=DeferredLinkQueue.js.map