{"version":3,"file":"handlerState.js","names":[],"sources":["esm/platform/notifications/handlerState.js"],"sourcesContent":["const showAllBehavior = {\n  shouldShowBanner: true,\n  shouldShowList: true,\n  shouldPlaySound: true,\n  shouldSetBadge: true\n};\nconst suppressBehavior = {\n  shouldShowBanner: false,\n  shouldShowList: false,\n  shouldPlaySound: false,\n  shouldSetBadge: false\n};\nfunction normalizeBehavior(input) {\n  if (!input || typeof input !== \"object\") return { ...suppressBehavior };\n  return {\n    shouldShowBanner: \"shouldShowBanner\" in input && input.shouldShowBanner === true,\n    shouldShowList: \"shouldShowList\" in input && input.shouldShowList === true,\n    shouldPlaySound: \"shouldPlaySound\" in input && input.shouldPlaySound === true,\n    shouldSetBadge: \"shouldSetBadge\" in input && input.shouldSetBadge === true\n  };\n}\nclass ForegroundHandler {\n  constructor(present) {\n    this.present = present;\n  }\n  present;\n  handler = null;\n  nulled = false;\n  pending = /* @__PURE__ */ new Set();\n  setHandler(handler) {\n    this.handler = handler;\n    this.nulled = handler === null;\n  }\n  // returns false for a duplicate of an in-flight id; the caller skips\n  // listener delivery for those.\n  receive(requestId, notification) {\n    if (this.pending.has(requestId)) return false;\n    if (!this.handler) {\n      this.present(requestId, { ...this.nulled ? suppressBehavior : showAllBehavior });\n      return true;\n    }\n    const handler = this.handler;\n    this.pending.add(requestId);\n    Promise.resolve().then(() => handler.handleNotification(notification)).then(\n      (behavior) => this.settle(requestId, normalizeBehavior(behavior)),\n      () => this.settle(requestId, showAllBehavior)\n    );\n    return true;\n  }\n  settle(requestId, behavior) {\n    if (!this.pending.delete(requestId)) return;\n    this.present(requestId, { ...behavior });\n  }\n}\nexport {\n  ForegroundHandler,\n  normalizeBehavior,\n  showAllBehavior,\n  suppressBehavior\n};\n//# sourceMappingURL=handlerState.js.map\n"],"mappings":";AAAA,MAAM,kBAAkB;CACtB,kBAAkB;CAClB,gBAAgB;CAChB,iBAAiB;CACjB,gBAAgB;AAClB;AACA,MAAM,mBAAmB;CACvB,kBAAkB;CAClB,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