firebase 9.12.1 → 9.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/app/dist/index.cjs.js +1 -1
  3. package/app/dist/index.esm.js +1 -1
  4. package/app/dist/index.mjs +1 -1
  5. package/compat/app/dist/index.cjs.js +1 -1
  6. package/compat/app/dist/index.esm.js +1 -1
  7. package/compat/app/dist/index.mjs +1 -1
  8. package/compat/dist/index.esm.js +2 -2
  9. package/compat/dist/index.node.cjs +2 -2
  10. package/compat/dist/index.rn.cjs.js +2 -2
  11. package/firebase-analytics-compat.js +1 -1
  12. package/firebase-analytics.js +1 -1
  13. package/firebase-app-check-compat.js +1 -1
  14. package/firebase-app-check.js +1 -1
  15. package/firebase-app-compat.js +2 -2
  16. package/firebase-app.js +5 -5
  17. package/firebase-auth-compat.js +1 -1
  18. package/firebase-auth-cordova.js +1 -1
  19. package/firebase-auth-react-native.js +1 -1
  20. package/firebase-auth.js +1 -1
  21. package/firebase-compat.js +3 -3
  22. package/firebase-compat.js.map +1 -1
  23. package/firebase-database-compat.js +1 -1
  24. package/firebase-database-compat.js.map +1 -1
  25. package/firebase-database.js +1 -1
  26. package/firebase-database.js.map +1 -1
  27. package/firebase-firestore-compat.js +1 -1
  28. package/firebase-firestore-compat.js.map +1 -1
  29. package/firebase-firestore-lite.js +1 -1
  30. package/firebase-firestore-lite.js.map +1 -1
  31. package/firebase-firestore.js +1 -1
  32. package/firebase-firestore.js.map +1 -1
  33. package/firebase-functions-compat.js +1 -1
  34. package/firebase-functions.js +1 -1
  35. package/firebase-installations-compat.js +1 -1
  36. package/firebase-installations.js +1 -1
  37. package/firebase-messaging-compat.js +1 -1
  38. package/firebase-messaging-compat.js.map +1 -1
  39. package/firebase-messaging-sw.js +1 -1
  40. package/firebase-messaging-sw.js.map +1 -1
  41. package/firebase-messaging.js +1 -1
  42. package/firebase-messaging.js.map +1 -1
  43. package/firebase-performance-compat.js +1 -1
  44. package/firebase-performance-standalone-compat.es2017.js +7 -7
  45. package/firebase-performance-standalone-compat.js +1 -1
  46. package/firebase-performance.js +1 -1
  47. package/firebase-remote-config-compat.js +1 -1
  48. package/firebase-remote-config.js +1 -1
  49. package/firebase-storage-compat.js +1 -1
  50. package/firebase-storage-compat.js.map +1 -1
  51. package/firebase-storage.js +1 -1
  52. package/firebase-storage.js.map +1 -1
  53. package/package.json +28 -28
@@ -1,3 +1,3 @@
1
- import{_registerComponent as t,registerVersion as e,_getProvider as n,getApp as s,_removeServiceInstance as r,SDK_VERSION as i}from"https://www.gstatic.com/firebasejs/9.12.1/firebase-app.js";const o=function(t){const e=[];let n=0;for(let s=0;s<t.length;s++){let r=t.charCodeAt(s);r<128?e[n++]=r:r<2048?(e[n++]=r>>6|192,e[n++]=63&r|128):55296==(64512&r)&&s+1<t.length&&56320==(64512&t.charCodeAt(s+1))?(r=65536+((1023&r)<<10)+(1023&t.charCodeAt(++s)),e[n++]=r>>18|240,e[n++]=r>>12&63|128,e[n++]=r>>6&63|128,e[n++]=63&r|128):(e[n++]=r>>12|224,e[n++]=r>>6&63|128,e[n++]=63&r|128)}return e},a={byteToCharMap_:null,charToByteMap_:null,byteToCharMapWebSafe_:null,charToByteMapWebSafe_:null,ENCODED_VALS_BASE:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",get ENCODED_VALS(){return this.ENCODED_VALS_BASE+"+/="},get ENCODED_VALS_WEBSAFE(){return this.ENCODED_VALS_BASE+"-_."},HAS_NATIVE_SUPPORT:"function"==typeof atob,encodeByteArray(t,e){if(!Array.isArray(t))throw Error("encodeByteArray takes an array as a parameter");this.init_();const n=e?this.byteToCharMapWebSafe_:this.byteToCharMap_,s=[];for(let e=0;e<t.length;e+=3){const r=t[e],i=e+1<t.length,o=i?t[e+1]:0,a=e+2<t.length,u=a?t[e+2]:0,c=r>>2,h=(3&r)<<4|o>>4;let l=(15&o)<<2|u>>6,d=63&u;a||(d=64,i||(l=64)),s.push(n[c],n[h],n[l],n[d])}return s.join("")},encodeString(t,e){return this.HAS_NATIVE_SUPPORT&&!e?btoa(t):this.encodeByteArray(o(t),e)},decodeString(t,e){return this.HAS_NATIVE_SUPPORT&&!e?atob(t):function(t){const e=[];let n=0,s=0;for(;n<t.length;){const r=t[n++];if(r<128)e[s++]=String.fromCharCode(r);else if(r>191&&r<224){const i=t[n++];e[s++]=String.fromCharCode((31&r)<<6|63&i)}else if(r>239&&r<365){const i=((7&r)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536;e[s++]=String.fromCharCode(55296+(i>>10)),e[s++]=String.fromCharCode(56320+(1023&i))}else{const i=t[n++],o=t[n++];e[s++]=String.fromCharCode((15&r)<<12|(63&i)<<6|63&o)}}return e.join("")}(this.decodeStringToByteArray(t,e))},decodeStringToByteArray(t,e){this.init_();const n=e?this.charToByteMapWebSafe_:this.charToByteMap_,s=[];for(let e=0;e<t.length;){const r=n[t.charAt(e++)],i=e<t.length?n[t.charAt(e)]:0;++e;const o=e<t.length?n[t.charAt(e)]:64;++e;const a=e<t.length?n[t.charAt(e)]:64;if(++e,null==r||null==i||null==o||null==a)throw Error();const u=r<<2|i>>4;if(s.push(u),64!==o){const t=i<<4&240|o>>2;if(s.push(t),64!==a){const t=o<<6&192|a;s.push(t)}}}return s},init_(){if(!this.byteToCharMap_){this.byteToCharMap_={},this.charToByteMap_={},this.byteToCharMapWebSafe_={},this.charToByteMapWebSafe_={};for(let t=0;t<this.ENCODED_VALS.length;t++)this.byteToCharMap_[t]=this.ENCODED_VALS.charAt(t),this.charToByteMap_[this.byteToCharMap_[t]]=t,this.byteToCharMapWebSafe_[t]=this.ENCODED_VALS_WEBSAFE.charAt(t),this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[t]]=t,t>=this.ENCODED_VALS_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(t)]=t,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(t)]=t)}}},u=function(t){return function(t){const e=o(t);return a.encodeByteArray(e,!0)}(t).replace(/\./g,"")};function c(){return"undefined"!=typeof navigator&&"string"==typeof navigator.userAgent?navigator.userAgent:""}function h(){return!function(){try{return"[object process]"===Object.prototype.toString.call(global.process)}catch(t){return!1}}()&&navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")}const l=()=>function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("Unable to locate global object.")}().__FIREBASE_DEFAULTS__,d=()=>{if("undefined"==typeof document)return;let t;try{t=document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/)}catch(t){return}const e=t&&function(t){try{return a.decodeString(t,!0)}catch(t){console.error("base64Decode failed: ",t)}return null}(t[1]);return e&&JSON.parse(e)},f=()=>{try{return l()||(()=>{if("undefined"==typeof process||void 0===process.env)return;const t=process.env.__FIREBASE_DEFAULTS__;return t?JSON.parse(t):void 0})()||d()}catch(t){return void console.info(`Unable to get __FIREBASE_DEFAULTS__ due to: ${t}`)}},m=t=>{const e=(t=>{var e,n;return null===(n=null===(e=f())||void 0===e?void 0:e.emulatorHosts)||void 0===n?void 0:n[t]})(t);if(!e)return;const n=e.lastIndexOf(":");if(n<=0||n+1===e.length)throw new Error(`Invalid host ${e} with no separate hostname and port!`);const s=parseInt(e.substring(n+1),10);return"["===e[0]?[e.substring(1,n-1),s]:[e.substring(0,n),s]};class g extends Error{constructor(t,e,n){super(e),this.code=t,this.customData=n,this.name="FirebaseError",Object.setPrototypeOf(this,g.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,p.prototype.create)}}class p{constructor(t,e,n){this.service=t,this.serviceName=e,this.errors=n}create(t,...e){const n=e[0]||{},s=`${this.service}/${t}`,r=this.errors[t],i=r?function(t,e){return t.replace(y,((t,n)=>{const s=e[n];return null!=s?String(s):`<${n}?>`}))}(r,n):"Error",o=`${this.serviceName}: ${i} (${s}).`;return new g(s,o,n)}}const y=/\{\$([^}]+)}/g;function w(t,e){if(t===e)return!0;const n=Object.keys(t),s=Object.keys(e);for(const r of n){if(!s.includes(r))return!1;const n=t[r],i=e[r];if(v(n)&&v(i)){if(!w(n,i))return!1}else if(n!==i)return!1}for(const t of s)if(!n.includes(t))return!1;return!0}function v(t){return null!==t&&"object"==typeof t}function I(t){return t&&t._delegate?t._delegate:t}class b{constructor(t,e,n){this.name=t,this.instanceFactory=e,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}setInstantiationMode(t){return this.instantiationMode=t,this}setMultipleInstances(t){return this.multipleInstances=t,this}setServiceProps(t){return this.serviceProps=t,this}setInstanceCreatedCallback(t){return this.onInstanceCreated=t,this}}var E;!function(t){t[t.DEBUG=0]="DEBUG",t[t.VERBOSE=1]="VERBOSE",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR",t[t.SILENT=5]="SILENT"}(E||(E={}));const T={debug:E.DEBUG,verbose:E.VERBOSE,info:E.INFO,warn:E.WARN,error:E.ERROR,silent:E.SILENT},S=E.INFO,_={[E.DEBUG]:"log",[E.VERBOSE]:"log",[E.INFO]:"info",[E.WARN]:"warn",[E.ERROR]:"error"},D=(t,e,...n)=>{if(e<t.logLevel)return;const s=(new Date).toISOString(),r=_[e];if(!r)throw new Error(`Attempted to log a message with an invalid logType (value: ${e})`);console[r](`[${s}] ${t.name}:`,...n)};var x,A="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},C=C||{},N=A||self;function k(){}function R(t){var e=typeof t;return"array"==(e="object"!=e?e:t?Array.isArray(t)?"array":e:"null")||"object"==e&&"number"==typeof t.length}function L(t){var e=typeof t;return"object"==e&&null!=t||"function"==e}var M="closure_uid_"+(1e9*Math.random()>>>0),O=0;function V(t,e,n){return t.call.apply(t.bind,arguments)}function F(t,e,n){if(!t)throw Error();if(2<arguments.length){var s=Array.prototype.slice.call(arguments,2);return function(){var n=Array.prototype.slice.call(arguments);return Array.prototype.unshift.apply(n,s),t.apply(e,n)}}return function(){return t.apply(e,arguments)}}function P(t,e,n){return(P=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?V:F).apply(null,arguments)}function U(t,e){var n=Array.prototype.slice.call(arguments,1);return function(){var e=n.slice();return e.push.apply(e,arguments),t.apply(this,e)}}function B(t,e){function n(){}n.prototype=e.prototype,t.X=e.prototype,t.prototype=new n,t.prototype.constructor=t,t.Wb=function(t,n,s){for(var r=Array(arguments.length-2),i=2;i<arguments.length;i++)r[i-2]=arguments[i];return e.prototype[n].apply(t,r)}}function q(){this.s=this.s,this.o=this.o}var G={};q.prototype.s=!1,q.prototype.na=function(){if(!this.s&&(this.s=!0,this.M(),0)){var t=function(t){return Object.prototype.hasOwnProperty.call(t,M)&&t[M]||(t[M]=++O)}(this);delete G[t]}},q.prototype.M=function(){if(this.o)for(;this.o.length;)this.o.shift()()};const K=Array.prototype.indexOf?function(t,e){return Array.prototype.indexOf.call(t,e,void 0)}:function(t,e){if("string"==typeof t)return"string"!=typeof e||1!=e.length?-1:t.indexOf(e,0);for(let n=0;n<t.length;n++)if(n in t&&t[n]===e)return n;return-1};function j(t){const e=t.length;if(0<e){const n=Array(e);for(let s=0;s<e;s++)n[s]=t[s];return n}return[]}function $(t,e){for(let e=1;e<arguments.length;e++){const n=arguments[e];if(R(n)){const e=t.length||0,s=n.length||0;t.length=e+s;for(let r=0;r<s;r++)t[e+r]=n[r]}else t.push(n)}}function Q(t,e){this.type=t,this.g=this.target=e,this.defaultPrevented=!1}Q.prototype.h=function(){this.defaultPrevented=!0};var z=function(){if(!N.addEventListener||!Object.defineProperty)return!1;var t=!1,e=Object.defineProperty({},"passive",{get:function(){t=!0}});try{N.addEventListener("test",k,e),N.removeEventListener("test",k,e)}catch(t){}return t}();function H(t){return/^[\s\xa0]*$/.test(t)}var W=String.prototype.trim?function(t){return t.trim()}:function(t){return/^[\s\xa0]*([\s\S]*?)[\s\xa0]*$/.exec(t)[1]};function Y(t,e){return t<e?-1:t>e?1:0}function X(){var t=N.navigator;return t&&(t=t.userAgent)?t:""}function J(t){return-1!=X().indexOf(t)}function Z(t){return Z[" "](t),t}Z[" "]=k;var tt,et,nt=J("Opera"),st=J("Trident")||J("MSIE"),rt=J("Edge"),it=rt||st,ot=J("Gecko")&&!(-1!=X().toLowerCase().indexOf("webkit")&&!J("Edge"))&&!(J("Trident")||J("MSIE"))&&!J("Edge"),at=-1!=X().toLowerCase().indexOf("webkit")&&!J("Edge");function ut(){var t=N.document;return t?t.documentMode:void 0}t:{var ct="",ht=(et=X(),ot?/rv:([^\);]+)(\)|;)/.exec(et):rt?/Edge\/([\d\.]+)/.exec(et):st?/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(et):at?/WebKit\/(\S+)/.exec(et):nt?/(?:Version)[ \/]?(\S+)/.exec(et):void 0);if(ht&&(ct=ht?ht[1]:""),st){var lt=ut();if(null!=lt&&lt>parseFloat(ct)){tt=String(lt);break t}}tt=ct}var dt,ft={};function mt(){return function(t){var e=ft;return Object.prototype.hasOwnProperty.call(e,9)?e[9]:e[9]=t(9)}((function(){let t=0;const e=W(String(tt)).split("."),n=W("9").split("."),s=Math.max(e.length,n.length);for(let o=0;0==t&&o<s;o++){var r=e[o]||"",i=n[o]||"";do{if(r=/(\d*)(\D*)(.*)/.exec(r)||["","","",""],i=/(\d*)(\D*)(.*)/.exec(i)||["","","",""],0==r[0].length&&0==i[0].length)break;t=Y(0==r[1].length?0:parseInt(r[1],10),0==i[1].length?0:parseInt(i[1],10))||Y(0==r[2].length,0==i[2].length)||Y(r[2],i[2]),r=r[3],i=i[3]}while(0==t)}return 0<=t}))}if(N.document&&st){var gt=ut();dt=gt||(parseInt(tt,10)||void 0)}else dt=void 0;var pt=dt;function yt(t,e){if(Q.call(this,t?t.type:""),this.relatedTarget=this.g=this.target=null,this.button=this.screenY=this.screenX=this.clientY=this.clientX=0,this.key="",this.metaKey=this.shiftKey=this.altKey=this.ctrlKey=!1,this.state=null,this.pointerId=0,this.pointerType="",this.i=null,t){var n=this.type=t.type,s=t.changedTouches&&t.changedTouches.length?t.changedTouches[0]:null;if(this.target=t.target||t.srcElement,this.g=e,e=t.relatedTarget){if(ot){t:{try{Z(e.nodeName);var r=!0;break t}catch(t){}r=!1}r||(e=null)}}else"mouseover"==n?e=t.fromElement:"mouseout"==n&&(e=t.toElement);this.relatedTarget=e,s?(this.clientX=void 0!==s.clientX?s.clientX:s.pageX,this.clientY=void 0!==s.clientY?s.clientY:s.pageY,this.screenX=s.screenX||0,this.screenY=s.screenY||0):(this.clientX=void 0!==t.clientX?t.clientX:t.pageX,this.clientY=void 0!==t.clientY?t.clientY:t.pageY,this.screenX=t.screenX||0,this.screenY=t.screenY||0),this.button=t.button,this.key=t.key||"",this.ctrlKey=t.ctrlKey,this.altKey=t.altKey,this.shiftKey=t.shiftKey,this.metaKey=t.metaKey,this.pointerId=t.pointerId||0,this.pointerType="string"==typeof t.pointerType?t.pointerType:wt[t.pointerType]||"",this.state=t.state,this.i=t,t.defaultPrevented&&yt.X.h.call(this)}}B(yt,Q);var wt={2:"touch",3:"pen",4:"mouse"};yt.prototype.h=function(){yt.X.h.call(this);var t=this.i;t.preventDefault?t.preventDefault():t.returnValue=!1};var vt="closure_listenable_"+(1e6*Math.random()|0),It=0;function bt(t,e,n,s,r){this.listener=t,this.proxy=null,this.src=e,this.type=n,this.capture=!!s,this.ha=r,this.key=++It,this.ba=this.ea=!1}function Et(t){t.ba=!0,t.listener=null,t.proxy=null,t.src=null,t.ha=null}function Tt(t,e,n){for(const s in t)e.call(n,t[s],s,t)}function St(t){const e={};for(const n in t)e[n]=t[n];return e}const _t="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");function Dt(t,e){let n,s;for(let e=1;e<arguments.length;e++){for(n in s=arguments[e],s)t[n]=s[n];for(let e=0;e<_t.length;e++)n=_t[e],Object.prototype.hasOwnProperty.call(s,n)&&(t[n]=s[n])}}function xt(t){this.src=t,this.g={},this.h=0}function At(t,e){var n=e.type;if(n in t.g){var s,r=t.g[n],i=K(r,e);(s=0<=i)&&Array.prototype.splice.call(r,i,1),s&&(Et(e),0==t.g[n].length&&(delete t.g[n],t.h--))}}function Ct(t,e,n,s){for(var r=0;r<t.length;++r){var i=t[r];if(!i.ba&&i.listener==e&&i.capture==!!n&&i.ha==s)return r}return-1}xt.prototype.add=function(t,e,n,s,r){var i=t.toString();(t=this.g[i])||(t=this.g[i]=[],this.h++);var o=Ct(t,e,s,r);return-1<o?(e=t[o],n||(e.ea=!1)):((e=new bt(e,this.src,i,!!s,r)).ea=n,t.push(e)),e};var Nt="closure_lm_"+(1e6*Math.random()|0),kt={};function Rt(t,e,n,s,r){if(s&&s.once)return Mt(t,e,n,s,r);if(Array.isArray(e)){for(var i=0;i<e.length;i++)Rt(t,e[i],n,s,r);return null}return n=qt(n),t&&t[vt]?t.N(e,n,L(s)?!!s.capture:!!s,r):Lt(t,e,n,!1,s,r)}function Lt(t,e,n,s,r,i){if(!e)throw Error("Invalid event type");var o=L(r)?!!r.capture:!!r,a=Ut(t);if(a||(t[Nt]=a=new xt(t)),(n=a.add(e,n,s,o,i)).proxy)return n;if(s=function(){function t(n){return e.call(t.src,t.listener,n)}const e=Pt;return t}(),n.proxy=s,s.src=t,s.listener=n,t.addEventListener)z||(r=o),void 0===r&&(r=!1),t.addEventListener(e.toString(),s,r);else if(t.attachEvent)t.attachEvent(Ft(e.toString()),s);else{if(!t.addListener||!t.removeListener)throw Error("addEventListener and attachEvent are unavailable.");t.addListener(s)}return n}function Mt(t,e,n,s,r){if(Array.isArray(e)){for(var i=0;i<e.length;i++)Mt(t,e[i],n,s,r);return null}return n=qt(n),t&&t[vt]?t.O(e,n,L(s)?!!s.capture:!!s,r):Lt(t,e,n,!0,s,r)}function Ot(t,e,n,s,r){if(Array.isArray(e))for(var i=0;i<e.length;i++)Ot(t,e[i],n,s,r);else s=L(s)?!!s.capture:!!s,n=qt(n),t&&t[vt]?(t=t.i,(e=String(e).toString())in t.g&&(-1<(n=Ct(i=t.g[e],n,s,r))&&(Et(i[n]),Array.prototype.splice.call(i,n,1),0==i.length&&(delete t.g[e],t.h--)))):t&&(t=Ut(t))&&(e=t.g[e.toString()],t=-1,e&&(t=Ct(e,n,s,r)),(n=-1<t?e[t]:null)&&Vt(n))}function Vt(t){if("number"!=typeof t&&t&&!t.ba){var e=t.src;if(e&&e[vt])At(e.i,t);else{var n=t.type,s=t.proxy;e.removeEventListener?e.removeEventListener(n,s,t.capture):e.detachEvent?e.detachEvent(Ft(n),s):e.addListener&&e.removeListener&&e.removeListener(s),(n=Ut(e))?(At(n,t),0==n.h&&(n.src=null,e[Nt]=null)):Et(t)}}}function Ft(t){return t in kt?kt[t]:kt[t]="on"+t}function Pt(t,e){if(t.ba)t=!0;else{e=new yt(e,this);var n=t.listener,s=t.ha||t.src;t.ea&&Vt(t),t=n.call(s,e)}return t}function Ut(t){return(t=t[Nt])instanceof xt?t:null}var Bt="__closure_events_fn_"+(1e9*Math.random()>>>0);function qt(t){return"function"==typeof t?t:(t[Bt]||(t[Bt]=function(e){return t.handleEvent(e)}),t[Bt])}function Gt(){q.call(this),this.i=new xt(this),this.P=this,this.I=null}function Kt(t,e){var n,s=t.I;if(s)for(n=[];s;s=s.I)n.push(s);if(t=t.P,s=e.type||e,"string"==typeof e)e=new Q(e,t);else if(e instanceof Q)e.target=e.target||t;else{var r=e;Dt(e=new Q(s,t),r)}if(r=!0,n)for(var i=n.length-1;0<=i;i--){var o=e.g=n[i];r=jt(o,s,!0,e)&&r}if(r=jt(o=e.g=t,s,!0,e)&&r,r=jt(o,s,!1,e)&&r,n)for(i=0;i<n.length;i++)r=jt(o=e.g=n[i],s,!1,e)&&r}function jt(t,e,n,s){if(!(e=t.i.g[String(e)]))return!0;e=e.concat();for(var r=!0,i=0;i<e.length;++i){var o=e[i];if(o&&!o.ba&&o.capture==n){var a=o.listener,u=o.ha||o.src;o.ea&&At(t.i,o),r=!1!==a.call(u,s)&&r}}return r&&!s.defaultPrevented}B(Gt,q),Gt.prototype[vt]=!0,Gt.prototype.removeEventListener=function(t,e,n,s){Ot(this,t,e,n,s)},Gt.prototype.M=function(){if(Gt.X.M.call(this),this.i){var t,e=this.i;for(t in e.g){for(var n=e.g[t],s=0;s<n.length;s++)Et(n[s]);delete e.g[t],e.h--}}this.I=null},Gt.prototype.N=function(t,e,n,s){return this.i.add(String(t),e,!1,n,s)},Gt.prototype.O=function(t,e,n,s){return this.i.add(String(t),e,!0,n,s)};var $t=N.JSON.stringify;function Qt(){var t=Zt;let e=null;return t.g&&(e=t.g,t.g=t.g.next,t.g||(t.h=null),e.next=null),e}var zt,Ht=new class{constructor(t,e){this.i=t,this.j=e,this.h=0,this.g=null}get(){let t;return 0<this.h?(this.h--,t=this.g,this.g=t.next,t.next=null):t=this.i(),t}}((()=>new Wt),(t=>t.reset()));class Wt{constructor(){this.next=this.g=this.h=null}set(t,e){this.h=t,this.g=e,this.next=null}reset(){this.next=this.g=this.h=null}}function Yt(t){N.setTimeout((()=>{throw t}),0)}function Xt(t,e){zt||function(){var t=N.Promise.resolve(void 0);zt=function(){t.then(te)}}(),Jt||(zt(),Jt=!0),Zt.add(t,e)}var Jt=!1,Zt=new class{constructor(){this.h=this.g=null}add(t,e){const n=Ht.get();n.set(t,e),this.h?this.h.next=n:this.g=n,this.h=n}};function te(){for(var t;t=Qt();){try{t.h.call(t.g)}catch(t){Yt(t)}var e=Ht;e.j(t),100>e.h&&(e.h++,t.next=e.g,e.g=t)}Jt=!1}function ee(t,e){Gt.call(this),this.h=t||1,this.g=e||N,this.j=P(this.lb,this),this.l=Date.now()}function ne(t){t.ca=!1,t.R&&(t.g.clearTimeout(t.R),t.R=null)}function se(t,e,n){if("function"==typeof t)n&&(t=P(t,n));else{if(!t||"function"!=typeof t.handleEvent)throw Error("Invalid listener argument");t=P(t.handleEvent,t)}return 2147483647<Number(e)?-1:N.setTimeout(t,e||0)}function re(t){t.g=se((()=>{t.g=null,t.i&&(t.i=!1,re(t))}),t.j);const e=t.h;t.h=null,t.m.apply(null,e)}B(ee,Gt),(x=ee.prototype).ca=!1,x.R=null,x.lb=function(){if(this.ca){var t=Date.now()-this.l;0<t&&t<.8*this.h?this.R=this.g.setTimeout(this.j,this.h-t):(this.R&&(this.g.clearTimeout(this.R),this.R=null),Kt(this,"tick"),this.ca&&(ne(this),this.start()))}},x.start=function(){this.ca=!0,this.R||(this.R=this.g.setTimeout(this.j,this.h),this.l=Date.now())},x.M=function(){ee.X.M.call(this),ne(this),delete this.g};class ie extends q{constructor(t,e){super(),this.m=t,this.j=e,this.h=null,this.i=!1,this.g=null}l(t){this.h=arguments,this.g?this.i=!0:re(this)}M(){super.M(),this.g&&(N.clearTimeout(this.g),this.g=null,this.i=!1,this.h=null)}}function oe(t){q.call(this),this.h=t,this.g={}}B(oe,q);var ae=[];function ue(t,e,n,s){Array.isArray(n)||(n&&(ae[0]=n.toString()),n=ae);for(var r=0;r<n.length;r++){var i=Rt(e,n[r],s||t.handleEvent,!1,t.h||t);if(!i)break;t.g[i.key]=i}}function ce(t){Tt(t.g,(function(t,e){this.g.hasOwnProperty(e)&&Vt(t)}),t),t.g={}}function he(){this.g=!0}function le(t,e,n,s){t.info((function(){return"XMLHTTP TEXT ("+e+"): "+function(t,e){if(!t.g)return e;if(!e)return null;try{var n=JSON.parse(e);if(n)for(t=0;t<n.length;t++)if(Array.isArray(n[t])){var s=n[t];if(!(2>s.length)){var r=s[1];if(Array.isArray(r)&&!(1>r.length)){var i=r[0];if("noop"!=i&&"stop"!=i&&"close"!=i)for(var o=1;o<r.length;o++)r[o]=""}}}return $t(n)}catch(t){return e}}(t,n)+(s?" "+s:"")}))}oe.prototype.M=function(){oe.X.M.call(this),ce(this)},oe.prototype.handleEvent=function(){throw Error("EventHandler.handleEvent not implemented")},he.prototype.Aa=function(){this.g=!1},he.prototype.info=function(){};var de={},fe=null;function me(){return fe=fe||new Gt}function ge(t){Q.call(this,de.Pa,t)}function pe(t){const e=me();Kt(e,new ge(e,t))}function ye(t,e){Q.call(this,de.STAT_EVENT,t),this.stat=e}function we(t){const e=me();Kt(e,new ye(e,t))}function ve(t,e){Q.call(this,de.Qa,t),this.size=e}function Ie(t,e){if("function"!=typeof t)throw Error("Fn must not be null and must be a function");return N.setTimeout((function(){t()}),e)}de.Pa="serverreachability",B(ge,Q),de.STAT_EVENT="statevent",B(ye,Q),de.Qa="timingevent",B(ve,Q);var be={NO_ERROR:0,mb:1,zb:2,yb:3,tb:4,xb:5,Ab:6,Ma:7,TIMEOUT:8,Db:9},Ee={rb:"complete",Nb:"success",Na:"error",Ma:"abort",Fb:"ready",Gb:"readystatechange",TIMEOUT:"timeout",Bb:"incrementaldata",Eb:"progress",ub:"downloadprogress",Vb:"uploadprogress"};function Te(){}function Se(t){return t.h||(t.h=t.i())}function _e(){}Te.prototype.h=null;var De,xe={OPEN:"a",qb:"b",Na:"c",Cb:"d"};function Ae(){Q.call(this,"d")}function Ce(){Q.call(this,"c")}function Ne(){}function ke(t,e,n,s){this.l=t,this.j=e,this.m=n,this.U=s||1,this.S=new oe(this),this.O=Le,t=it?125:void 0,this.T=new ee(t),this.H=null,this.i=!1,this.s=this.A=this.v=this.K=this.F=this.V=this.B=null,this.D=[],this.g=null,this.C=0,this.o=this.u=null,this.Y=-1,this.I=!1,this.N=0,this.L=null,this.$=this.J=this.Z=this.P=!1,this.h=new Re}function Re(){this.i=null,this.g="",this.h=!1}B(Ae,Q),B(Ce,Q),B(Ne,Te),Ne.prototype.g=function(){return new XMLHttpRequest},Ne.prototype.i=function(){return{}},De=new Ne;var Le=45e3,Me={},Oe={};function Ve(t,e,n){t.K=1,t.v=en(Ye(e)),t.s=n,t.P=!0,Fe(t,null)}function Fe(t,e){t.F=Date.now(),qe(t),t.A=Ye(t.v);var n=t.A,s=t.U;Array.isArray(s)||(s=[String(s)]),gn(n.i,"t",s),t.C=0,n=t.l.H,t.h=new Re,t.g=ms(t.l,n?e:null,!t.s),0<t.N&&(t.L=new ie(P(t.La,t,t.g),t.N)),ue(t.S,t.g,"readystatechange",t.ib),e=t.H?St(t.H):{},t.s?(t.u||(t.u="POST"),e["Content-Type"]="application/x-www-form-urlencoded",t.g.da(t.A,t.u,t.s,e)):(t.u="GET",t.g.da(t.A,t.u,null,e)),pe(1),function(t,e,n,s,r,i){t.info((function(){if(t.g)if(i)for(var o="",a=i.split("&"),u=0;u<a.length;u++){var c=a[u].split("=");if(1<c.length){var h=c[0];c=c[1];var l=h.split("_");o=2<=l.length&&"type"==l[1]?o+(h+"=")+c+"&":o+(h+"=redacted&")}}else o=null;else o=i;return"XMLHTTP REQ ("+s+") [attempt "+r+"]: "+e+"\n"+n+"\n"+o}))}(t.j,t.u,t.A,t.m,t.U,t.s)}function Pe(t){return!!t.g&&("GET"==t.u&&2!=t.K&&t.l.Da)}function Ue(t,e,n){let s,r=!0;for(;!t.I&&t.C<n.length;){if(s=Be(t,n),s==Oe){4==e&&(t.o=4,we(14),r=!1),le(t.j,t.m,null,"[Incomplete Response]");break}if(s==Me){t.o=4,we(15),le(t.j,t.m,n,"[Invalid Chunk]"),r=!1;break}le(t.j,t.m,s,null),Qe(t,s)}Pe(t)&&s!=Oe&&s!=Me&&(t.h.g="",t.C=0),4!=e||0!=n.length||t.h.h||(t.o=1,we(16),r=!1),t.i=t.i&&r,r?0<n.length&&!t.$&&(t.$=!0,(e=t.l).g==t&&e.$&&!e.K&&(e.j.info("Great, no buffering proxy detected. Bytes received: "+n.length),os(e),e.K=!0,we(11))):(le(t.j,t.m,n,"[Invalid Chunked Response]"),$e(t),je(t))}function Be(t,e){var n=t.C,s=e.indexOf("\n",n);return-1==s?Oe:(n=Number(e.substring(n,s)),isNaN(n)?Me:(s+=1)+n>e.length?Oe:(e=e.substr(s,n),t.C=s+n,e))}function qe(t){t.V=Date.now()+t.O,Ge(t,t.O)}function Ge(t,e){if(null!=t.B)throw Error("WatchDog timer not null");t.B=Ie(P(t.gb,t),e)}function Ke(t){t.B&&(N.clearTimeout(t.B),t.B=null)}function je(t){0==t.l.G||t.I||cs(t.l,t)}function $e(t){Ke(t);var e=t.L;e&&"function"==typeof e.na&&e.na(),t.L=null,ne(t.T),ce(t.S),t.g&&(e=t.g,t.g=null,e.abort(),e.na())}function Qe(t,e){try{var n=t.l;if(0!=n.G&&(n.g==t||bn(n.h,t)))if(!t.J&&bn(n.h,t)&&3==n.G){try{var s=n.Fa.g.parse(e)}catch(t){s=null}if(Array.isArray(s)&&3==s.length){var r=s;if(0==r[0]){t:if(!n.u){if(n.g){if(!(n.g.F+3e3<t.F))break t;us(n),Jn(n)}is(n),we(18)}}else n.Ba=r[1],0<n.Ba-n.T&&37500>r[2]&&n.L&&0==n.A&&!n.v&&(n.v=Ie(P(n.cb,n),6e3));if(1>=In(n.h)&&n.ja){try{n.ja()}catch(t){}n.ja=void 0}}else ls(n,11)}else if((t.J||n.g==t)&&us(n),!H(e))for(r=n.Fa.g.parse(e),e=0;e<r.length;e++){let c=r[e];if(n.T=c[0],c=c[1],2==n.G)if("c"==c[0]){n.I=c[1],n.ka=c[2];const e=c[3];null!=e&&(n.ma=e,n.j.info("VER="+n.ma));const r=c[4];null!=r&&(n.Ca=r,n.j.info("SVER="+n.Ca));const h=c[5];null!=h&&"number"==typeof h&&0<h&&(s=1.5*h,n.J=s,n.j.info("backChannelRequestTimeoutMs_="+s)),s=n;const l=t.g;if(l){const t=l.g?l.g.getResponseHeader("X-Client-Wire-Protocol"):null;if(t){var i=s.h;i.g||-1==t.indexOf("spdy")&&-1==t.indexOf("quic")&&-1==t.indexOf("h2")||(i.j=i.l,i.g=new Set,i.h&&(En(i,i.h),i.h=null))}if(s.D){const t=l.g?l.g.getResponseHeader("X-HTTP-Session-Id"):null;t&&(s.za=t,tn(s.F,s.D,t))}}n.G=3,n.l&&n.l.xa(),n.$&&(n.P=Date.now()-t.F,n.j.info("Handshake RTT: "+n.P+"ms"));var o=t;if((s=n).sa=fs(s,s.H?s.ka:null,s.V),o.J){Tn(s.h,o);var a=o,u=s.J;u&&a.setTimeout(u),a.B&&(Ke(a),qe(a)),s.g=o}else rs(s);0<n.i.length&&ts(n)}else"stop"!=c[0]&&"close"!=c[0]||ls(n,7);else 3==n.G&&("stop"==c[0]||"close"==c[0]?"stop"==c[0]?ls(n,7):Xn(n):"noop"!=c[0]&&n.l&&n.l.wa(c),n.A=0)}pe(4)}catch(t){}}function ze(t,e){if(t.forEach&&"function"==typeof t.forEach)t.forEach(e,void 0);else if(R(t)||"string"==typeof t)Array.prototype.forEach.call(t,e,void 0);else for(var n=function(t){if(t.oa&&"function"==typeof t.oa)return t.oa();if(!t.W||"function"!=typeof t.W){if("undefined"!=typeof Map&&t instanceof Map)return Array.from(t.keys());if(!("undefined"!=typeof Set&&t instanceof Set)){if(R(t)||"string"==typeof t){var e=[];t=t.length;for(var n=0;n<t;n++)e.push(n);return e}e=[],n=0;for(const s in t)e[n++]=s;return e}}}(t),s=function(t){if(t.W&&"function"==typeof t.W)return t.W();if("undefined"!=typeof Map&&t instanceof Map||"undefined"!=typeof Set&&t instanceof Set)return Array.from(t.values());if("string"==typeof t)return t.split("");if(R(t)){for(var e=[],n=t.length,s=0;s<n;s++)e.push(t[s]);return e}for(s in e=[],n=0,t)e[n++]=t[s];return e}(t),r=s.length,i=0;i<r;i++)e.call(void 0,s[i],n&&n[i],t)}(x=ke.prototype).setTimeout=function(t){this.O=t},x.ib=function(t){t=t.target;const e=this.L;e&&3==$n(t)?e.l():this.La(t)},x.La=function(t){try{if(t==this.g)t:{const h=$n(this.g);var e=this.g.Ea();const l=this.g.aa();if(!(3>h)&&(3!=h||it||this.g&&(this.h.h||this.g.fa()||Qn(this.g)))){this.I||4!=h||7==e||pe(8==e||0>=l?3:2),Ke(this);var n=this.g.aa();this.Y=n;e:if(Pe(this)){var s=Qn(this.g);t="";var r=s.length,i=4==$n(this.g);if(!this.h.i){if("undefined"==typeof TextDecoder){$e(this),je(this);var o="";break e}this.h.i=new N.TextDecoder}for(e=0;e<r;e++)this.h.h=!0,t+=this.h.i.decode(s[e],{stream:i&&e==r-1});s.splice(0,r),this.h.g+=t,this.C=0,o=this.h.g}else o=this.g.fa();if(this.i=200==n,function(t,e,n,s,r,i,o){t.info((function(){return"XMLHTTP RESP ("+s+") [ attempt "+r+"]: "+e+"\n"+n+"\n"+i+" "+o}))}(this.j,this.u,this.A,this.m,this.U,h,n),this.i){if(this.Z&&!this.J){e:{if(this.g){var a,u=this.g;if((a=u.g?u.g.getResponseHeader("X-HTTP-Initial-Response"):null)&&!H(a)){var c=a;break e}}c=null}if(!(n=c)){this.i=!1,this.o=3,we(12),$e(this),je(this);break t}le(this.j,this.m,n,"Initial handshake response via X-HTTP-Initial-Response"),this.J=!0,Qe(this,n)}this.P?(Ue(this,h,o),it&&this.i&&3==h&&(ue(this.S,this.T,"tick",this.hb),this.T.start())):(le(this.j,this.m,o,null),Qe(this,o)),4==h&&$e(this),this.i&&!this.I&&(4==h?cs(this.l,this):(this.i=!1,qe(this)))}else 400==n&&0<o.indexOf("Unknown SID")?(this.o=3,we(12)):(this.o=0,we(13)),$e(this),je(this)}}}catch(t){}},x.hb=function(){if(this.g){var t=$n(this.g),e=this.g.fa();this.C<e.length&&(Ke(this),Ue(this,t,e),this.i&&4!=t&&qe(this))}},x.cancel=function(){this.I=!0,$e(this)},x.gb=function(){this.B=null;const t=Date.now();0<=t-this.V?(function(t,e){t.info((function(){return"TIMEOUT: "+e}))}(this.j,this.A),2!=this.K&&(pe(3),we(17)),$e(this),this.o=2,je(this)):Ge(this,this.V-t)};var He=RegExp("^(?:([^:/?#.]+):)?(?://(?:([^\\\\/?#]*)@)?([^\\\\/?#]*?)(?::([0-9]+))?(?=[\\\\/?#]|$))?([^?#]+)?(?:\\?([^#]*))?(?:#([\\s\\S]*))?$");function We(t,e){if(this.g=this.s=this.j="",this.m=null,this.o=this.l="",this.h=!1,t instanceof We){this.h=void 0!==e?e:t.h,Xe(this,t.j),this.s=t.s,this.g=t.g,Je(this,t.m),this.l=t.l,e=t.i;var n=new ln;n.i=e.i,e.g&&(n.g=new Map(e.g),n.h=e.h),Ze(this,n),this.o=t.o}else t&&(n=String(t).match(He))?(this.h=!!e,Xe(this,n[1]||"",!0),this.s=nn(n[2]||""),this.g=nn(n[3]||"",!0),Je(this,n[4]),this.l=nn(n[5]||"",!0),Ze(this,n[6]||"",!0),this.o=nn(n[7]||"")):(this.h=!!e,this.i=new ln(null,this.h))}function Ye(t){return new We(t)}function Xe(t,e,n){t.j=n?nn(e,!0):e,t.j&&(t.j=t.j.replace(/:$/,""))}function Je(t,e){if(e){if(e=Number(e),isNaN(e)||0>e)throw Error("Bad port number "+e);t.m=e}else t.m=null}function Ze(t,e,n){e instanceof ln?(t.i=e,function(t,e){e&&!t.j&&(dn(t),t.i=null,t.g.forEach((function(t,e){var n=e.toLowerCase();e!=n&&(fn(this,e),gn(this,n,t))}),t)),t.j=e}(t.i,t.h)):(n||(e=sn(e,cn)),t.i=new ln(e,t.h))}function tn(t,e,n){t.i.set(e,n)}function en(t){return tn(t,"zx",Math.floor(2147483648*Math.random()).toString(36)+Math.abs(Math.floor(2147483648*Math.random())^Date.now()).toString(36)),t}function nn(t,e){return t?e?decodeURI(t.replace(/%25/g,"%2525")):decodeURIComponent(t):""}function sn(t,e,n){return"string"==typeof t?(t=encodeURI(t).replace(e,rn),n&&(t=t.replace(/%25([0-9a-fA-F]{2})/g,"%$1")),t):null}function rn(t){return"%"+((t=t.charCodeAt(0))>>4&15).toString(16)+(15&t).toString(16)}We.prototype.toString=function(){var t=[],e=this.j;e&&t.push(sn(e,on,!0),":");var n=this.g;return(n||"file"==e)&&(t.push("//"),(e=this.s)&&t.push(sn(e,on,!0),"@"),t.push(encodeURIComponent(String(n)).replace(/%25([0-9a-fA-F]{2})/g,"%$1")),null!=(n=this.m)&&t.push(":",String(n))),(n=this.l)&&(this.g&&"/"!=n.charAt(0)&&t.push("/"),t.push(sn(n,"/"==n.charAt(0)?un:an,!0))),(n=this.i.toString())&&t.push("?",n),(n=this.o)&&t.push("#",sn(n,hn)),t.join("")};var on=/[#\/\?@]/g,an=/[#\?:]/g,un=/[#\?]/g,cn=/[#\?@]/g,hn=/#/g;function ln(t,e){this.h=this.g=null,this.i=t||null,this.j=!!e}function dn(t){t.g||(t.g=new Map,t.h=0,t.i&&function(t,e){if(t){t=t.split("&");for(var n=0;n<t.length;n++){var s=t[n].indexOf("="),r=null;if(0<=s){var i=t[n].substring(0,s);r=t[n].substring(s+1)}else i=t[n];e(i,r?decodeURIComponent(r.replace(/\+/g," ")):"")}}}(t.i,(function(e,n){t.add(decodeURIComponent(e.replace(/\+/g," ")),n)})))}function fn(t,e){dn(t),e=pn(t,e),t.g.has(e)&&(t.i=null,t.h-=t.g.get(e).length,t.g.delete(e))}function mn(t,e){return dn(t),e=pn(t,e),t.g.has(e)}function gn(t,e,n){fn(t,e),0<n.length&&(t.i=null,t.g.set(pn(t,e),j(n)),t.h+=n.length)}function pn(t,e){return e=String(e),t.j&&(e=e.toLowerCase()),e}(x=ln.prototype).add=function(t,e){dn(this),this.i=null,t=pn(this,t);var n=this.g.get(t);return n||this.g.set(t,n=[]),n.push(e),this.h+=1,this},x.forEach=function(t,e){dn(this),this.g.forEach((function(n,s){n.forEach((function(n){t.call(e,n,s,this)}),this)}),this)},x.oa=function(){dn(this);const t=Array.from(this.g.values()),e=Array.from(this.g.keys()),n=[];for(let s=0;s<e.length;s++){const r=t[s];for(let t=0;t<r.length;t++)n.push(e[s])}return n},x.W=function(t){dn(this);let e=[];if("string"==typeof t)mn(this,t)&&(e=e.concat(this.g.get(pn(this,t))));else{t=Array.from(this.g.values());for(let n=0;n<t.length;n++)e=e.concat(t[n])}return e},x.set=function(t,e){return dn(this),this.i=null,mn(this,t=pn(this,t))&&(this.h-=this.g.get(t).length),this.g.set(t,[e]),this.h+=1,this},x.get=function(t,e){return t&&0<(t=this.W(t)).length?String(t[0]):e},x.toString=function(){if(this.i)return this.i;if(!this.g)return"";const t=[],e=Array.from(this.g.keys());for(var n=0;n<e.length;n++){var s=e[n];const i=encodeURIComponent(String(s)),o=this.W(s);for(s=0;s<o.length;s++){var r=i;""!==o[s]&&(r+="="+encodeURIComponent(String(o[s]))),t.push(r)}}return this.i=t.join("&")};function yn(t){this.l=t||wn,N.PerformanceNavigationTiming?t=0<(t=N.performance.getEntriesByType("navigation")).length&&("hq"==t[0].nextHopProtocol||"h2"==t[0].nextHopProtocol):t=!!(N.g&&N.g.Ga&&N.g.Ga()&&N.g.Ga().$b),this.j=t?this.l:1,this.g=null,1<this.j&&(this.g=new Set),this.h=null,this.i=[]}var wn=10;function vn(t){return!!t.h||!!t.g&&t.g.size>=t.j}function In(t){return t.h?1:t.g?t.g.size:0}function bn(t,e){return t.h?t.h==e:!!t.g&&t.g.has(e)}function En(t,e){t.g?t.g.add(e):t.h=e}function Tn(t,e){t.h&&t.h==e?t.h=null:t.g&&t.g.has(e)&&t.g.delete(e)}function Sn(t){if(null!=t.h)return t.i.concat(t.h.D);if(null!=t.g&&0!==t.g.size){let e=t.i;for(const n of t.g.values())e=e.concat(n.D);return e}return j(t.i)}function _n(){}function Dn(){this.g=new _n}function xn(t,e,n){const s=n||"";try{ze(t,(function(t,n){let r=t;L(t)&&(r=$t(t)),e.push(s+n+"="+encodeURIComponent(r))}))}catch(t){throw e.push(s+"type="+encodeURIComponent("_badmap")),t}}function An(t,e,n,s,r){try{e.onload=null,e.onerror=null,e.onabort=null,e.ontimeout=null,r(s)}catch(t){}}function Cn(t){this.l=t.ac||null,this.j=t.jb||!1}function Nn(t,e){Gt.call(this),this.D=t,this.u=e,this.m=void 0,this.readyState=kn,this.status=0,this.responseType=this.responseText=this.response=this.statusText="",this.onreadystatechange=null,this.v=new Headers,this.h=null,this.C="GET",this.B="",this.g=!1,this.A=this.j=this.l=null}yn.prototype.cancel=function(){if(this.i=Sn(this),this.h)this.h.cancel(),this.h=null;else if(this.g&&0!==this.g.size){for(const t of this.g.values())t.cancel();this.g.clear()}},_n.prototype.stringify=function(t){return N.JSON.stringify(t,void 0)},_n.prototype.parse=function(t){return N.JSON.parse(t,void 0)},B(Cn,Te),Cn.prototype.g=function(){return new Nn(this.l,this.j)},Cn.prototype.i=function(t){return function(){return t}}({}),B(Nn,Gt);var kn=0;function Rn(t){t.j.read().then(t.Ta.bind(t)).catch(t.ga.bind(t))}function Ln(t){t.readyState=4,t.l=null,t.j=null,t.A=null,Mn(t)}function Mn(t){t.onreadystatechange&&t.onreadystatechange.call(t)}(x=Nn.prototype).open=function(t,e){if(this.readyState!=kn)throw this.abort(),Error("Error reopening a connection");this.C=t,this.B=e,this.readyState=1,Mn(this)},x.send=function(t){if(1!=this.readyState)throw this.abort(),Error("need to call open() first. ");this.g=!0;const e={headers:this.v,method:this.C,credentials:this.m,cache:void 0};t&&(e.body=t),(this.D||N).fetch(new Request(this.B,e)).then(this.Wa.bind(this),this.ga.bind(this))},x.abort=function(){this.response=this.responseText="",this.v=new Headers,this.status=0,this.j&&this.j.cancel("Request was aborted.").catch((()=>{})),1<=this.readyState&&this.g&&4!=this.readyState&&(this.g=!1,Ln(this)),this.readyState=kn},x.Wa=function(t){if(this.g&&(this.l=t,this.h||(this.status=this.l.status,this.statusText=this.l.statusText,this.h=t.headers,this.readyState=2,Mn(this)),this.g&&(this.readyState=3,Mn(this),this.g)))if("arraybuffer"===this.responseType)t.arrayBuffer().then(this.Ua.bind(this),this.ga.bind(this));else if(void 0!==N.ReadableStream&&"body"in t){if(this.j=t.body.getReader(),this.u){if(this.responseType)throw Error('responseType must be empty for "streamBinaryChunks" mode responses.');this.response=[]}else this.response=this.responseText="",this.A=new TextDecoder;Rn(this)}else t.text().then(this.Va.bind(this),this.ga.bind(this))},x.Ta=function(t){if(this.g){if(this.u&&t.value)this.response.push(t.value);else if(!this.u){var e=t.value?t.value:new Uint8Array(0);(e=this.A.decode(e,{stream:!t.done}))&&(this.response=this.responseText+=e)}t.done?Ln(this):Mn(this),3==this.readyState&&Rn(this)}},x.Va=function(t){this.g&&(this.response=this.responseText=t,Ln(this))},x.Ua=function(t){this.g&&(this.response=t,Ln(this))},x.ga=function(){this.g&&Ln(this)},x.setRequestHeader=function(t,e){this.v.append(t,e)},x.getResponseHeader=function(t){return this.h&&this.h.get(t.toLowerCase())||""},x.getAllResponseHeaders=function(){if(!this.h)return"";const t=[],e=this.h.entries();for(var n=e.next();!n.done;)n=n.value,t.push(n[0]+": "+n[1]),n=e.next();return t.join("\r\n")},Object.defineProperty(Nn.prototype,"withCredentials",{get:function(){return"include"===this.m},set:function(t){this.m=t?"include":"same-origin"}});var On=N.JSON.parse;function Vn(t){Gt.call(this),this.headers=new Map,this.u=t||null,this.h=!1,this.C=this.g=null,this.H="",this.m=0,this.j="",this.l=this.F=this.v=this.D=!1,this.B=0,this.A=null,this.J=Fn,this.K=this.L=!1}B(Vn,Gt);var Fn="",Pn=/^https?$/i,Un=["POST","PUT"];function Bn(t,e){t.h=!1,t.g&&(t.l=!0,t.g.abort(),t.l=!1),t.j=e,t.m=5,qn(t),Kn(t)}function qn(t){t.D||(t.D=!0,Kt(t,"complete"),Kt(t,"error"))}function Gn(t){if(t.h&&void 0!==C&&(!t.C[1]||4!=$n(t)||2!=t.aa()))if(t.v&&4==$n(t))se(t.Ha,0,t);else if(Kt(t,"readystatechange"),4==$n(t)){t.h=!1;try{const a=t.aa();t:switch(a){case 200:case 201:case 202:case 204:case 206:case 304:case 1223:var e=!0;break t;default:e=!1}var n;if(!(n=e)){var s;if(s=0===a){var r=String(t.H).match(He)[1]||null;if(!r&&N.self&&N.self.location){var i=N.self.location.protocol;r=i.substr(0,i.length-1)}s=!Pn.test(r?r.toLowerCase():"")}n=s}if(n)Kt(t,"complete"),Kt(t,"success");else{t.m=6;try{var o=2<$n(t)?t.g.statusText:""}catch(t){o=""}t.j=o+" ["+t.aa()+"]",qn(t)}}finally{Kn(t)}}}function Kn(t,e){if(t.g){jn(t);const n=t.g,s=t.C[0]?k:null;t.g=null,t.C=null,e||Kt(t,"ready");try{n.onreadystatechange=s}catch(t){}}}function jn(t){t.g&&t.K&&(t.g.ontimeout=null),t.A&&(N.clearTimeout(t.A),t.A=null)}function $n(t){return t.g?t.g.readyState:0}function Qn(t){try{if(!t.g)return null;if("response"in t.g)return t.g.response;switch(t.J){case Fn:case"text":return t.g.responseText;case"arraybuffer":if("mozResponseArrayBuffer"in t.g)return t.g.mozResponseArrayBuffer}return null}catch(t){return null}}function zn(t){let e="";return Tt(t,(function(t,n){e+=n,e+=":",e+=t,e+="\r\n"})),e}function Hn(t,e,n){t:{for(s in n){var s=!1;break t}s=!0}s||(n=zn(n),"string"==typeof t?null!=n&&encodeURIComponent(String(n)):tn(t,e,n))}function Wn(t,e,n){return n&&n.internalChannelParams&&n.internalChannelParams[t]||e}function Yn(t){this.Ca=0,this.i=[],this.j=new he,this.ka=this.sa=this.F=this.V=this.g=this.za=this.D=this.ia=this.o=this.S=this.s=null,this.ab=this.U=0,this.Za=Wn("failFast",!1,t),this.L=this.v=this.u=this.m=this.l=null,this.Y=!0,this.pa=this.Ba=this.T=-1,this.Z=this.A=this.C=0,this.Xa=Wn("baseRetryDelayMs",5e3,t),this.bb=Wn("retryDelaySeedMs",1e4,t),this.$a=Wn("forwardChannelMaxRetries",2,t),this.ta=Wn("forwardChannelRequestTimeoutMs",2e4,t),this.ra=t&&t.xmlHttpFactory||void 0,this.Da=t&&t.Zb||!1,this.J=void 0,this.H=t&&t.supportsCrossDomainXhr||!1,this.I="",this.h=new yn(t&&t.concurrentRequestLimit),this.Fa=new Dn,this.O=t&&t.fastHandshake||!1,this.N=t&&t.encodeInitMessageHeaders||!1,this.O&&this.N&&(this.N=!1),this.Ya=t&&t.Xb||!1,t&&t.Aa&&this.j.Aa(),t&&t.forceLongPolling&&(this.Y=!1),this.$=!this.O&&this.Y&&t&&t.detectBufferingProxy||!1,this.ja=void 0,this.P=0,this.K=!1,this.la=this.B=null}function Xn(t){if(Zn(t),3==t.G){var e=t.U++,n=Ye(t.F);tn(n,"SID",t.I),tn(n,"RID",e),tn(n,"TYPE","terminate"),ns(t,n),(e=new ke(t,t.j,e,void 0)).K=2,e.v=en(Ye(n)),n=!1,N.navigator&&N.navigator.sendBeacon&&(n=N.navigator.sendBeacon(e.v.toString(),"")),!n&&N.Image&&((new Image).src=e.v,n=!0),n||(e.g=ms(e.l,null),e.g.da(e.v)),e.F=Date.now(),qe(e)}ds(t)}function Jn(t){t.g&&(os(t),t.g.cancel(),t.g=null)}function Zn(t){Jn(t),t.u&&(N.clearTimeout(t.u),t.u=null),us(t),t.h.cancel(),t.m&&("number"==typeof t.m&&N.clearTimeout(t.m),t.m=null)}function ts(t){vn(t.h)||t.m||(t.m=!0,Xt(t.Ja,t),t.C=0)}function es(t,e){var n;n=e?e.m:t.U++;const s=Ye(t.F);tn(s,"SID",t.I),tn(s,"RID",n),tn(s,"AID",t.T),ns(t,s),t.o&&t.s&&Hn(s,t.o,t.s),n=new ke(t,t.j,n,t.C+1),null===t.o&&(n.H=t.s),e&&(t.i=e.D.concat(t.i)),e=ss(t,n,1e3),n.setTimeout(Math.round(.5*t.ta)+Math.round(.5*t.ta*Math.random())),En(t.h,n),Ve(n,s,e)}function ns(t,e){t.ia&&Tt(t.ia,(function(t,n){tn(e,n,t)})),t.l&&ze({},(function(t,n){tn(e,n,t)}))}function ss(t,e,n){n=Math.min(t.i.length,n);var s=t.l?P(t.l.Ra,t.l,t):null;t:{var r=t.i;let e=-1;for(;;){const t=["count="+n];-1==e?0<n?(e=r[0].h,t.push("ofs="+e)):e=0:t.push("ofs="+e);let i=!0;for(let o=0;o<n;o++){let n=r[o].h;const a=r[o].g;if(n-=e,0>n)e=Math.max(0,r[o].h-100),i=!1;else try{xn(a,t,"req"+n+"_")}catch(t){s&&s(a)}}if(i){s=t.join("&");break t}}}return t=t.i.splice(0,n),e.D=t,s}function rs(t){t.g||t.u||(t.Z=1,Xt(t.Ia,t),t.A=0)}function is(t){return!(t.g||t.u||3<=t.A)&&(t.Z++,t.u=Ie(P(t.Ia,t),hs(t,t.A)),t.A++,!0)}function os(t){null!=t.B&&(N.clearTimeout(t.B),t.B=null)}function as(t){t.g=new ke(t,t.j,"rpc",t.Z),null===t.o&&(t.g.H=t.s),t.g.N=0;var e=Ye(t.sa);tn(e,"RID","rpc"),tn(e,"SID",t.I),tn(e,"CI",t.L?"0":"1"),tn(e,"AID",t.T),tn(e,"TYPE","xmlhttp"),ns(t,e),t.o&&t.s&&Hn(e,t.o,t.s),t.J&&t.g.setTimeout(t.J);var n=t.g;t=t.ka,n.K=1,n.v=en(Ye(e)),n.s=null,n.P=!0,Fe(n,t)}function us(t){null!=t.v&&(N.clearTimeout(t.v),t.v=null)}function cs(t,e){var n=null;if(t.g==e){us(t),os(t),t.g=null;var s=2}else{if(!bn(t.h,e))return;n=e.D,Tn(t.h,e),s=1}if(0!=t.G)if(t.pa=e.Y,e.i)if(1==s){n=e.s?e.s.length:0,e=Date.now()-e.F;var r=t.C;Kt(s=me(),new ve(s,n,e,r)),ts(t)}else rs(t);else if(3==(r=e.o)||0==r&&0<t.pa||!(1==s&&function(t,e){return!(In(t.h)>=t.h.j-(t.m?1:0)||(t.m?(t.i=e.D.concat(t.i),0):1==t.G||2==t.G||t.C>=(t.Za?0:t.$a)||(t.m=Ie(P(t.Ja,t,e),hs(t,t.C)),t.C++,0)))}(t,e)||2==s&&is(t)))switch(n&&0<n.length&&(e=t.h,e.i=e.i.concat(n)),r){case 1:ls(t,5);break;case 4:ls(t,10);break;case 3:ls(t,6);break;default:ls(t,2)}}function hs(t,e){let n=t.Xa+Math.floor(Math.random()*t.bb);return t.l||(n*=2),n*e}function ls(t,e){if(t.j.info("Error code "+e),2==e){var n=null;t.l&&(n=null);var s=P(t.kb,t);n||(n=new We("//www.google.com/images/cleardot.gif"),N.location&&"http"==N.location.protocol||Xe(n,"https"),en(n)),function(t,e){const n=new he;if(N.Image){const s=new Image;s.onload=U(An,n,s,"TestLoadImage: loaded",!0,e),s.onerror=U(An,n,s,"TestLoadImage: error",!1,e),s.onabort=U(An,n,s,"TestLoadImage: abort",!1,e),s.ontimeout=U(An,n,s,"TestLoadImage: timeout",!1,e),N.setTimeout((function(){s.ontimeout&&s.ontimeout()}),1e4),s.src=t}else e(!1)}(n.toString(),s)}else we(2);t.G=0,t.l&&t.l.va(e),ds(t),Zn(t)}function ds(t){if(t.G=0,t.la=[],t.l){const e=Sn(t.h);0==e.length&&0==t.i.length||($(t.la,e),$(t.la,t.i),t.h.i.length=0,j(t.i),t.i.length=0),t.l.ua()}}function fs(t,e,n){var s=n instanceof We?Ye(n):new We(n,void 0);if(""!=s.g)e&&(s.g=e+"."+s.g),Je(s,s.m);else{var r=N.location;s=r.protocol,e=e?e+"."+r.hostname:r.hostname,r=+r.port;var i=new We(null,void 0);s&&Xe(i,s),e&&(i.g=e),r&&Je(i,r),n&&(i.l=n),s=i}return n=t.D,e=t.za,n&&e&&tn(s,n,e),tn(s,"VER",t.ma),ns(t,s),s}function ms(t,e,n){if(e&&!t.H)throw Error("Can't create secondary domain capable XhrIo object.");return(e=n&&t.Da&&!t.ra?new Vn(new Cn({jb:!0})):new Vn(t.ra)).Ka(t.H),e}function gs(){}function ps(){if(st&&!(10<=Number(pt)))throw Error("Environmental error: no available transport.")}function ys(t,e){Gt.call(this),this.g=new Yn(e),this.l=t,this.h=e&&e.messageUrlParams||null,t=e&&e.messageHeaders||null,e&&e.clientProtocolHeaderRequired&&(t?t["X-Client-Protocol"]="webchannel":t={"X-Client-Protocol":"webchannel"}),this.g.s=t,t=e&&e.initMessageHeaders||null,e&&e.messageContentType&&(t?t["X-WebChannel-Content-Type"]=e.messageContentType:t={"X-WebChannel-Content-Type":e.messageContentType}),e&&e.ya&&(t?t["X-WebChannel-Client-Profile"]=e.ya:t={"X-WebChannel-Client-Profile":e.ya}),this.g.S=t,(t=e&&e.Yb)&&!H(t)&&(this.g.o=t),this.A=e&&e.supportsCrossDomainXhr||!1,this.v=e&&e.sendRawJson||!1,(e=e&&e.httpSessionIdParam)&&!H(e)&&(this.g.D=e,null!==(t=this.h)&&e in t&&(e in(t=this.h)&&delete t[e])),this.j=new Is(this)}function ws(t){Ae.call(this);var e=t.__sm__;if(e){t:{for(const n in e){t=n;break t}t=void 0}(this.i=t)&&(t=this.i,e=null!==e&&t in e?e[t]:void 0),this.data=e}else this.data=t}function vs(){Ce.call(this),this.status=1}function Is(t){this.g=t}(x=Vn.prototype).Ka=function(t){this.L=t},x.da=function(t,e,n,s){if(this.g)throw Error("[goog.net.XhrIo] Object is active with another request="+this.H+"; newUri="+t);e=e?e.toUpperCase():"GET",this.H=t,this.j="",this.m=0,this.D=!1,this.h=!0,this.g=this.u?this.u.g():De.g(),this.C=this.u?Se(this.u):Se(De),this.g.onreadystatechange=P(this.Ha,this);try{this.F=!0,this.g.open(e,String(t),!0),this.F=!1}catch(t){return void Bn(this,t)}if(t=n||"",n=new Map(this.headers),s)if(Object.getPrototypeOf(s)===Object.prototype)for(var r in s)n.set(r,s[r]);else{if("function"!=typeof s.keys||"function"!=typeof s.get)throw Error("Unknown input type for opt_headers: "+String(s));for(const t of s.keys())n.set(t,s.get(t))}s=Array.from(n.keys()).find((t=>"content-type"==t.toLowerCase())),r=N.FormData&&t instanceof N.FormData,!(0<=K(Un,e))||s||r||n.set("Content-Type","application/x-www-form-urlencoded;charset=utf-8");for(const[t,e]of n)this.g.setRequestHeader(t,e);this.J&&(this.g.responseType=this.J),"withCredentials"in this.g&&this.g.withCredentials!==this.L&&(this.g.withCredentials=this.L);try{jn(this),0<this.B&&((this.K=function(t){return st&&mt()&&"number"==typeof t.timeout&&void 0!==t.ontimeout}(this.g))?(this.g.timeout=this.B,this.g.ontimeout=P(this.qa,this)):this.A=se(this.qa,this.B,this)),this.v=!0,this.g.send(t),this.v=!1}catch(t){Bn(this,t)}},x.qa=function(){void 0!==C&&this.g&&(this.j="Timed out after "+this.B+"ms, aborting",this.m=8,Kt(this,"timeout"),this.abort(8))},x.abort=function(t){this.g&&this.h&&(this.h=!1,this.l=!0,this.g.abort(),this.l=!1,this.m=t||7,Kt(this,"complete"),Kt(this,"abort"),Kn(this))},x.M=function(){this.g&&(this.h&&(this.h=!1,this.l=!0,this.g.abort(),this.l=!1),Kn(this,!0)),Vn.X.M.call(this)},x.Ha=function(){this.s||(this.F||this.v||this.l?Gn(this):this.fb())},x.fb=function(){Gn(this)},x.aa=function(){try{return 2<$n(this)?this.g.status:-1}catch(t){return-1}},x.fa=function(){try{return this.g?this.g.responseText:""}catch(t){return""}},x.Sa=function(t){if(this.g){var e=this.g.responseText;return t&&0==e.indexOf(t)&&(e=e.substring(t.length)),On(e)}},x.Ea=function(){return this.m},x.Oa=function(){return"string"==typeof this.j?this.j:String(this.j)},(x=Yn.prototype).ma=8,x.G=1,x.Ja=function(t){if(this.m)if(this.m=null,1==this.G){if(!t){this.U=Math.floor(1e5*Math.random()),t=this.U++;const r=new ke(this,this.j,t,void 0);let i=this.s;if(this.S&&(i?(i=St(i),Dt(i,this.S)):i=this.S),null!==this.o||this.N||(r.H=i,i=null),this.O)t:{for(var e=0,n=0;n<this.i.length;n++){var s=this.i[n];if(void 0===(s="__data__"in s.g&&"string"==typeof(s=s.g.__data__)?s.length:void 0))break;if(4096<(e+=s)){e=n;break t}if(4096===e||n===this.i.length-1){e=n+1;break t}}e=1e3}else e=1e3;e=ss(this,r,e),tn(n=Ye(this.F),"RID",t),tn(n,"CVER",22),this.D&&tn(n,"X-HTTP-Session-Id",this.D),ns(this,n),i&&(this.N?e="headers="+encodeURIComponent(String(zn(i)))+"&"+e:this.o&&Hn(n,this.o,i)),En(this.h,r),this.Ya&&tn(n,"TYPE","init"),this.O?(tn(n,"$req",e),tn(n,"SID","null"),r.Z=!0,Ve(r,n,null)):Ve(r,n,e),this.G=2}}else 3==this.G&&(t?es(this,t):0==this.i.length||vn(this.h)||es(this))},x.Ia=function(){if(this.u=null,as(this),this.$&&!(this.K||null==this.g||0>=this.P)){var t=2*this.P;this.j.info("BP detection timer enabled: "+t),this.B=Ie(P(this.eb,this),t)}},x.eb=function(){this.B&&(this.B=null,this.j.info("BP detection timeout reached."),this.j.info("Buffering proxy detected and switch to long-polling!"),this.L=!1,this.K=!0,we(10),Jn(this),as(this))},x.cb=function(){null!=this.v&&(this.v=null,Jn(this),is(this),we(19))},x.kb=function(t){t?(this.j.info("Successfully pinged google.com"),we(2)):(this.j.info("Failed to ping google.com"),we(1))},(x=gs.prototype).xa=function(){},x.wa=function(){},x.va=function(){},x.ua=function(){},x.Ra=function(){},ps.prototype.g=function(t,e){return new ys(t,e)},B(ys,Gt),ys.prototype.m=function(){this.g.l=this.j,this.A&&(this.g.H=!0);var t=this.g,e=this.l,n=this.h||void 0;we(0),t.V=e,t.ia=n||{},t.L=t.Y,t.F=fs(t,null,t.V),ts(t)},ys.prototype.close=function(){Xn(this.g)},ys.prototype.u=function(t){var e=this.g;if("string"==typeof t){var n={};n.__data__=t,t=n}else this.v&&((n={}).__data__=$t(t),t=n);e.i.push(new class{constructor(t,e){this.h=t,this.g=e}}(e.ab++,t)),3==e.G&&ts(e)},ys.prototype.M=function(){this.g.l=null,delete this.j,Xn(this.g),delete this.g,ys.X.M.call(this)},B(ws,Ae),B(vs,Ce),B(Is,gs),Is.prototype.xa=function(){Kt(this.g,"a")},Is.prototype.wa=function(t){Kt(this.g,new ws(t))},Is.prototype.va=function(t){Kt(this.g,new vs(t))},Is.prototype.ua=function(){Kt(this.g,"b")},ps.prototype.createWebChannel=ps.prototype.g,ys.prototype.send=ys.prototype.u,ys.prototype.open=ys.prototype.m,ys.prototype.close=ys.prototype.close,be.NO_ERROR=0,be.TIMEOUT=8,be.HTTP_ERROR=6,Ee.COMPLETE="complete",_e.EventType=xe,xe.OPEN="a",xe.CLOSE="b",xe.ERROR="c",xe.MESSAGE="d",Gt.prototype.listen=Gt.prototype.N,Vn.prototype.listenOnce=Vn.prototype.O,Vn.prototype.getLastError=Vn.prototype.Oa,Vn.prototype.getLastErrorCode=Vn.prototype.Ea,Vn.prototype.getStatus=Vn.prototype.aa,Vn.prototype.getResponseJson=Vn.prototype.Sa,Vn.prototype.getResponseText=Vn.prototype.fa,Vn.prototype.send=Vn.prototype.da,Vn.prototype.setWithCredentials=Vn.prototype.Ka;var bs=be,Es=Ee,Ts=de,Ss=10,_s=11,Ds=Cn,xs=_e,As=Vn;const Cs="@firebase/firestore";class Ns{constructor(t){this.uid=t}isAuthenticated(){return null!=this.uid}toKey(){return this.isAuthenticated()?"uid:"+this.uid:"anonymous-user"}isEqual(t){return t.uid===this.uid}}Ns.UNAUTHENTICATED=new Ns(null),Ns.GOOGLE_CREDENTIALS=new Ns("google-credentials-uid"),Ns.FIRST_PARTY=new Ns("first-party-uid"),Ns.MOCK_USER=new Ns("mock-user");let ks="9.12.1";const Rs=new class{constructor(t){this.name=t,this._logLevel=S,this._logHandler=D,this._userLogHandler=null}get logLevel(){return this._logLevel}set logLevel(t){if(!(t in E))throw new TypeError(`Invalid value "${t}" assigned to \`logLevel\``);this._logLevel=t}setLogLevel(t){this._logLevel="string"==typeof t?T[t]:t}get logHandler(){return this._logHandler}set logHandler(t){if("function"!=typeof t)throw new TypeError("Value assigned to `logHandler` must be a function");this._logHandler=t}get userLogHandler(){return this._userLogHandler}set userLogHandler(t){this._userLogHandler=t}debug(...t){this._userLogHandler&&this._userLogHandler(this,E.DEBUG,...t),this._logHandler(this,E.DEBUG,...t)}log(...t){this._userLogHandler&&this._userLogHandler(this,E.VERBOSE,...t),this._logHandler(this,E.VERBOSE,...t)}info(...t){this._userLogHandler&&this._userLogHandler(this,E.INFO,...t),this._logHandler(this,E.INFO,...t)}warn(...t){this._userLogHandler&&this._userLogHandler(this,E.WARN,...t),this._logHandler(this,E.WARN,...t)}error(...t){this._userLogHandler&&this._userLogHandler(this,E.ERROR,...t),this._logHandler(this,E.ERROR,...t)}}("@firebase/firestore");function Ls(){return Rs.logLevel}function Ms(t){Rs.setLogLevel(t)}function Os(t,...e){if(Rs.logLevel<=E.DEBUG){const n=e.map(Ps);Rs.debug(`Firestore (${ks}): ${t}`,...n)}}function Vs(t,...e){if(Rs.logLevel<=E.ERROR){const n=e.map(Ps);Rs.error(`Firestore (${ks}): ${t}`,...n)}}function Fs(t,...e){if(Rs.logLevel<=E.WARN){const n=e.map(Ps);Rs.warn(`Firestore (${ks}): ${t}`,...n)}}function Ps(t){if("string"==typeof t)return t;try{return e=t,JSON.stringify(e)}catch(e){return t}var e}function Us(t="Unexpected state"){const e=`FIRESTORE (${ks}) INTERNAL ASSERTION FAILED: `+t;throw Vs(e),new Error(e)}function Bs(t,e){t||Us()}function qs(t,e){t||Us()}function Gs(t,e){return t}const Ks={OK:"ok",CANCELLED:"cancelled",UNKNOWN:"unknown",INVALID_ARGUMENT:"invalid-argument",DEADLINE_EXCEEDED:"deadline-exceeded",NOT_FOUND:"not-found",ALREADY_EXISTS:"already-exists",PERMISSION_DENIED:"permission-denied",UNAUTHENTICATED:"unauthenticated",RESOURCE_EXHAUSTED:"resource-exhausted",FAILED_PRECONDITION:"failed-precondition",ABORTED:"aborted",OUT_OF_RANGE:"out-of-range",UNIMPLEMENTED:"unimplemented",INTERNAL:"internal",UNAVAILABLE:"unavailable",DATA_LOSS:"data-loss"};class js extends g{constructor(t,e){super(t,e),this.code=t,this.message=e,this.toString=()=>`${this.name}: [code=${this.code}]: ${this.message}`}}class $s{constructor(){this.promise=new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}}class Qs{constructor(t,e){this.user=e,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization",`Bearer ${t}`)}}class zs{getToken(){return Promise.resolve(null)}invalidateToken(){}start(t,e){t.enqueueRetryable((()=>e(Ns.UNAUTHENTICATED)))}shutdown(){}}class Hs{constructor(t){this.token=t,this.changeListener=null}getToken(){return Promise.resolve(this.token)}invalidateToken(){}start(t,e){this.changeListener=e,t.enqueueRetryable((()=>e(this.token.user)))}shutdown(){this.changeListener=null}}class Ws{constructor(t){this.t=t,this.currentUser=Ns.UNAUTHENTICATED,this.i=0,this.forceRefresh=!1,this.auth=null}start(t,e){let n=this.i;const s=t=>this.i!==n?(n=this.i,e(t)):Promise.resolve();let r=new $s;this.o=()=>{this.i++,this.currentUser=this.u(),r.resolve(),r=new $s,t.enqueueRetryable((()=>s(this.currentUser)))};const i=()=>{const e=r;t.enqueueRetryable((async()=>{await e.promise,await s(this.currentUser)}))},o=t=>{Os("FirebaseAuthCredentialsProvider","Auth detected"),this.auth=t,this.auth.addAuthTokenListener(this.o),i()};this.t.onInit((t=>o(t))),setTimeout((()=>{if(!this.auth){const t=this.t.getImmediate({optional:!0});t?o(t):(Os("FirebaseAuthCredentialsProvider","Auth not yet detected"),r.resolve(),r=new $s)}}),0),i()}getToken(){const t=this.i,e=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(e).then((e=>this.i!==t?(Os("FirebaseAuthCredentialsProvider","getToken aborted due to token change."),this.getToken()):e?(Bs("string"==typeof e.accessToken),new Qs(e.accessToken,this.currentUser)):null)):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.auth&&this.auth.removeAuthTokenListener(this.o)}u(){const t=this.auth&&this.auth.getUid();return Bs(null===t||"string"==typeof t),new Ns(t)}}class Ys{constructor(t,e,n,s){this.h=t,this.l=e,this.m=n,this.g=s,this.type="FirstParty",this.user=Ns.FIRST_PARTY,this.p=new Map}I(){return this.g?this.g():(Bs(!("object"!=typeof this.h||null===this.h||!this.h.auth||!this.h.auth.getAuthHeaderValueForFirstParty)),this.h.auth.getAuthHeaderValueForFirstParty([]))}get headers(){this.p.set("X-Goog-AuthUser",this.l);const t=this.I();return t&&this.p.set("Authorization",t),this.m&&this.p.set("X-Goog-Iam-Authorization-Token",this.m),this.p}}class Xs{constructor(t,e,n,s){this.h=t,this.l=e,this.m=n,this.g=s}getToken(){return Promise.resolve(new Ys(this.h,this.l,this.m,this.g))}start(t,e){t.enqueueRetryable((()=>e(Ns.FIRST_PARTY)))}shutdown(){}invalidateToken(){}}class Js{constructor(t){this.value=t,this.type="AppCheck",this.headers=new Map,t&&t.length>0&&this.headers.set("x-firebase-appcheck",this.value)}}class Zs{constructor(t){this.T=t,this.forceRefresh=!1,this.appCheck=null,this.A=null}start(t,e){const n=t=>{null!=t.error&&Os("FirebaseAppCheckTokenProvider",`Error getting App Check token; using placeholder token instead. Error: ${t.error.message}`);const n=t.token!==this.A;return this.A=t.token,Os("FirebaseAppCheckTokenProvider",`Received ${n?"new":"existing"} token.`),n?e(t.token):Promise.resolve()};this.o=e=>{t.enqueueRetryable((()=>n(e)))};const s=t=>{Os("FirebaseAppCheckTokenProvider","AppCheck detected"),this.appCheck=t,this.appCheck.addTokenListener(this.o)};this.T.onInit((t=>s(t))),setTimeout((()=>{if(!this.appCheck){const t=this.T.getImmediate({optional:!0});t?s(t):Os("FirebaseAppCheckTokenProvider","AppCheck not yet detected")}}),0)}getToken(){const t=this.forceRefresh;return this.forceRefresh=!1,this.appCheck?this.appCheck.getToken(t).then((t=>t?(Bs("string"==typeof t.token),this.A=t.token,new Js(t.token)):null)):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.appCheck&&this.appCheck.removeTokenListener(this.o)}}class tr{getToken(){return Promise.resolve(new Js(""))}invalidateToken(){}start(t,e){}shutdown(){}}function er(t){const e="undefined"!=typeof self&&(self.crypto||self.msCrypto),n=new Uint8Array(t);if(e&&"function"==typeof e.getRandomValues)e.getRandomValues(n);else for(let e=0;e<t;e++)n[e]=Math.floor(256*Math.random());return n}class nr{static R(){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=Math.floor(256/t.length)*t.length;let n="";for(;n.length<20;){const s=er(40);for(let r=0;r<s.length;++r)n.length<20&&s[r]<e&&(n+=t.charAt(s[r]%t.length))}return n}}function sr(t,e){return t<e?-1:t>e?1:0}function rr(t,e,n){return t.length===e.length&&t.every(((t,s)=>n(t,e[s])))}function ir(t){return t+"\0"}class or{constructor(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new js(Ks.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new js(Ks.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new js(Ks.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new js(Ks.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t)}static now(){return or.fromMillis(Date.now())}static fromDate(t){return or.fromMillis(t.getTime())}static fromMillis(t){const e=Math.floor(t/1e3),n=Math.floor(1e6*(t-1e3*e));return new or(e,n)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(t){return this.seconds===t.seconds?sr(this.nanoseconds,t.nanoseconds):sr(this.seconds,t.seconds)}isEqual(t){return t.seconds===this.seconds&&t.nanoseconds===this.nanoseconds}toString(){return"Timestamp(seconds="+this.seconds+", nanoseconds="+this.nanoseconds+")"}toJSON(){return{seconds:this.seconds,nanoseconds:this.nanoseconds}}valueOf(){const t=this.seconds- -62135596800;return String(t).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")}}class ar{constructor(t){this.timestamp=t}static fromTimestamp(t){return new ar(t)}static min(){return new ar(new or(0,0))}static max(){return new ar(new or(253402300799,999999999))}compareTo(t){return this.timestamp._compareTo(t.timestamp)}isEqual(t){return this.timestamp.isEqual(t.timestamp)}toMicroseconds(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3}toString(){return"SnapshotVersion("+this.timestamp.toString()+")"}toTimestamp(){return this.timestamp}}class ur{constructor(t,e,n){void 0===e?e=0:e>t.length&&Us(),void 0===n?n=t.length-e:n>t.length-e&&Us(),this.segments=t,this.offset=e,this.len=n}get length(){return this.len}isEqual(t){return 0===ur.comparator(this,t)}child(t){const e=this.segments.slice(this.offset,this.limit());return t instanceof ur?t.forEach((t=>{e.push(t)})):e.push(t),this.construct(e)}limit(){return this.offset+this.length}popFirst(t){return t=void 0===t?1:t,this.construct(this.segments,this.offset+t,this.length-t)}popLast(){return this.construct(this.segments,this.offset,this.length-1)}firstSegment(){return this.segments[this.offset]}lastSegment(){return this.get(this.length-1)}get(t){return this.segments[this.offset+t]}isEmpty(){return 0===this.length}isPrefixOf(t){if(t.length<this.length)return!1;for(let e=0;e<this.length;e++)if(this.get(e)!==t.get(e))return!1;return!0}isImmediateParentOf(t){if(this.length+1!==t.length)return!1;for(let e=0;e<this.length;e++)if(this.get(e)!==t.get(e))return!1;return!0}forEach(t){for(let e=this.offset,n=this.limit();e<n;e++)t(this.segments[e])}toArray(){return this.segments.slice(this.offset,this.limit())}static comparator(t,e){const n=Math.min(t.length,e.length);for(let s=0;s<n;s++){const n=t.get(s),r=e.get(s);if(n<r)return-1;if(n>r)return 1}return t.length<e.length?-1:t.length>e.length?1:0}}class cr extends ur{construct(t,e,n){return new cr(t,e,n)}canonicalString(){return this.toArray().join("/")}toString(){return this.canonicalString()}static fromString(...t){const e=[];for(const n of t){if(n.indexOf("//")>=0)throw new js(Ks.INVALID_ARGUMENT,`Invalid segment (${n}). Paths must not contain // in them.`);e.push(...n.split("/").filter((t=>t.length>0)))}return new cr(e)}static emptyPath(){return new cr([])}}const hr=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class lr extends ur{construct(t,e,n){return new lr(t,e,n)}static isValidIdentifier(t){return hr.test(t)}canonicalString(){return this.toArray().map((t=>(t=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),lr.isValidIdentifier(t)||(t="`"+t+"`"),t))).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&"__name__"===this.get(0)}static keyField(){return new lr(["__name__"])}static fromServerFormat(t){const e=[];let n="",s=0;const r=()=>{if(0===n.length)throw new js(Ks.INVALID_ARGUMENT,`Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`);e.push(n),n=""};let i=!1;for(;s<t.length;){const e=t[s];if("\\"===e){if(s+1===t.length)throw new js(Ks.INVALID_ARGUMENT,"Path has trailing escape character: "+t);const e=t[s+1];if("\\"!==e&&"."!==e&&"`"!==e)throw new js(Ks.INVALID_ARGUMENT,"Path has invalid escape sequence: "+t);n+=e,s+=2}else"`"===e?(i=!i,s++):"."!==e||i?(n+=e,s++):(r(),s++)}if(r(),i)throw new js(Ks.INVALID_ARGUMENT,"Unterminated ` in path: "+t);return new lr(e)}static emptyPath(){return new lr([])}}class dr{constructor(t){this.path=t}static fromPath(t){return new dr(cr.fromString(t))}static fromName(t){return new dr(cr.fromString(t).popFirst(5))}static empty(){return new dr(cr.emptyPath())}get collectionGroup(){return this.path.popLast().lastSegment()}hasCollectionId(t){return this.path.length>=2&&this.path.get(this.path.length-2)===t}getCollectionGroup(){return this.path.get(this.path.length-2)}getCollectionPath(){return this.path.popLast()}isEqual(t){return null!==t&&0===cr.comparator(this.path,t.path)}toString(){return this.path.toString()}static comparator(t,e){return cr.comparator(t.path,e.path)}static isDocumentKey(t){return t.length%2==0}static fromSegments(t){return new dr(new cr(t.slice()))}}class fr{constructor(t,e,n,s){this.indexId=t,this.collectionGroup=e,this.fields=n,this.indexState=s}}function mr(t){return t.fields.find((t=>2===t.kind))}function gr(t){return t.fields.filter((t=>2!==t.kind))}function pr(t,e){let n=sr(t.collectionGroup,e.collectionGroup);if(0!==n)return n;for(let s=0;s<Math.min(t.fields.length,e.fields.length);++s)if(n=wr(t.fields[s],e.fields[s]),0!==n)return n;return sr(t.fields.length,e.fields.length)}fr.UNKNOWN_ID=-1;class yr{constructor(t,e){this.fieldPath=t,this.kind=e}}function wr(t,e){const n=lr.comparator(t.fieldPath,e.fieldPath);return 0!==n?n:sr(t.kind,e.kind)}class vr{constructor(t,e){this.sequenceNumber=t,this.offset=e}static empty(){return new vr(0,Er.min())}}function Ir(t,e){const n=t.toTimestamp().seconds,s=t.toTimestamp().nanoseconds+1,r=ar.fromTimestamp(1e9===s?new or(n+1,0):new or(n,s));return new Er(r,dr.empty(),e)}function br(t){return new Er(t.readTime,t.key,-1)}class Er{constructor(t,e,n){this.readTime=t,this.documentKey=e,this.largestBatchId=n}static min(){return new Er(ar.min(),dr.empty(),-1)}static max(){return new Er(ar.max(),dr.empty(),-1)}}function Tr(t,e){let n=t.readTime.compareTo(e.readTime);return 0!==n?n:(n=dr.comparator(t.documentKey,e.documentKey),0!==n?n:sr(t.largestBatchId,e.largestBatchId))}const Sr="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.";class _r{constructor(){this.onCommittedListeners=[]}addOnCommittedListener(t){this.onCommittedListeners.push(t)}raiseOnCommittedEvent(){this.onCommittedListeners.forEach((t=>t()))}}async function Dr(t){if(t.code!==Ks.FAILED_PRECONDITION||t.message!==Sr)throw t;Os("LocalStore","Unexpectedly lost primary lease")}class xr{constructor(t){this.nextCallback=null,this.catchCallback=null,this.result=void 0,this.error=void 0,this.isDone=!1,this.callbackAttached=!1,t((t=>{this.isDone=!0,this.result=t,this.nextCallback&&this.nextCallback(t)}),(t=>{this.isDone=!0,this.error=t,this.catchCallback&&this.catchCallback(t)}))}catch(t){return this.next(void 0,t)}next(t,e){return this.callbackAttached&&Us(),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(e,this.error):this.wrapSuccess(t,this.result):new xr(((n,s)=>{this.nextCallback=e=>{this.wrapSuccess(t,e).next(n,s)},this.catchCallback=t=>{this.wrapFailure(e,t).next(n,s)}}))}toPromise(){return new Promise(((t,e)=>{this.next(t,e)}))}wrapUserFunction(t){try{const e=t();return e instanceof xr?e:xr.resolve(e)}catch(t){return xr.reject(t)}}wrapSuccess(t,e){return t?this.wrapUserFunction((()=>t(e))):xr.resolve(e)}wrapFailure(t,e){return t?this.wrapUserFunction((()=>t(e))):xr.reject(e)}static resolve(t){return new xr(((e,n)=>{e(t)}))}static reject(t){return new xr(((e,n)=>{n(t)}))}static waitFor(t){return new xr(((e,n)=>{let s=0,r=0,i=!1;t.forEach((t=>{++s,t.next((()=>{++r,i&&r===s&&e()}),(t=>n(t)))})),i=!0,r===s&&e()}))}static or(t){let e=xr.resolve(!1);for(const n of t)e=e.next((t=>t?xr.resolve(t):n()));return e}static forEach(t,e){const n=[];return t.forEach(((t,s)=>{n.push(e.call(this,t,s))})),this.waitFor(n)}static mapArray(t,e){return new xr(((n,s)=>{const r=t.length,i=new Array(r);let o=0;for(let a=0;a<r;a++){const u=a;e(t[u]).next((t=>{i[u]=t,++o,o===r&&n(i)}),(t=>s(t)))}}))}static doWhile(t,e){return new xr(((n,s)=>{const r=()=>{!0===t()?e().next((()=>{r()}),s):n()};r()}))}}class Ar{constructor(t,e){this.action=t,this.transaction=e,this.aborted=!1,this.P=new $s,this.transaction.oncomplete=()=>{this.P.resolve()},this.transaction.onabort=()=>{e.error?this.P.reject(new kr(t,e.error)):this.P.resolve()},this.transaction.onerror=e=>{const n=Vr(e.target.error);this.P.reject(new kr(t,n))}}static open(t,e,n,s){try{return new Ar(e,t.transaction(s,n))}catch(t){throw new kr(e,t)}}get v(){return this.P.promise}abort(t){t&&this.P.reject(t),this.aborted||(Os("SimpleDb","Aborting transaction:",t?t.message:"Client-initiated abort"),this.aborted=!0,this.transaction.abort())}V(){const t=this.transaction;this.aborted||"function"!=typeof t.commit||t.commit()}store(t){const e=this.transaction.objectStore(t);return new Lr(e)}}class Cr{constructor(t,e,n){this.name=t,this.version=e,this.S=n,12.2===Cr.D(c())&&Vs("Firestore persistence suffers from a bug in iOS 12.2 Safari that may cause your app to stop working. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.")}static delete(t){return Os("SimpleDb","Removing database:",t),Mr(window.indexedDB.deleteDatabase(t)).toPromise()}static C(){if("object"!=typeof indexedDB)return!1;if(Cr.N())return!0;const t=c(),e=Cr.D(t),n=0<e&&e<10,s=Cr.k(t),r=0<s&&s<4.5;return!(t.indexOf("MSIE ")>0||t.indexOf("Trident/")>0||t.indexOf("Edge/")>0||n||r)}static N(){var t;return"undefined"!=typeof process&&"YES"===(null===(t=process.env)||void 0===t?void 0:t.O)}static M(t,e){return t.store(e)}static D(t){const e=t.match(/i(?:phone|pad|pod) os ([\d_]+)/i),n=e?e[1].split("_").slice(0,2).join("."):"-1";return Number(n)}static k(t){const e=t.match(/Android ([\d.]+)/i),n=e?e[1].split(".").slice(0,2).join("."):"-1";return Number(n)}async F(t){return this.db||(Os("SimpleDb","Opening database:",this.name),this.db=await new Promise(((e,n)=>{const s=indexedDB.open(this.name,this.version);s.onsuccess=t=>{const n=t.target.result;e(n)},s.onblocked=()=>{n(new kr(t,"Cannot upgrade IndexedDB schema while another tab is open. Close all tabs that access Firestore and reload this page to proceed."))},s.onerror=e=>{const s=e.target.error;"VersionError"===s.name?n(new js(Ks.FAILED_PRECONDITION,"A newer version of the Firestore SDK was previously used and so the persisted data is not compatible with the version of the SDK you are now using. The SDK will operate with persistence disabled. If you need persistence, please re-upgrade to a newer version of the SDK or else clear the persisted IndexedDB data for your app to start fresh.")):"InvalidStateError"===s.name?n(new js(Ks.FAILED_PRECONDITION,"Unable to open an IndexedDB connection. This could be due to running in a private browsing session on a browser whose private browsing sessions do not support IndexedDB: "+s)):n(new kr(t,s))},s.onupgradeneeded=t=>{Os("SimpleDb",'Database "'+this.name+'" requires upgrade from version:',t.oldVersion);const e=t.target.result;this.S.$(e,s.transaction,t.oldVersion,this.version).next((()=>{Os("SimpleDb","Database upgrade to version "+this.version+" complete")}))}}))),this.B&&(this.db.onversionchange=t=>this.B(t)),this.db}L(t){this.B=t,this.db&&(this.db.onversionchange=e=>t(e))}async runTransaction(t,e,n,s){const r="readonly"===e;let i=0;for(;;){++i;try{this.db=await this.F(t);const e=Ar.open(this.db,t,r?"readonly":"readwrite",n),i=s(e).next((t=>(e.V(),t))).catch((t=>(e.abort(t),xr.reject(t)))).toPromise();return i.catch((()=>{})),await e.v,i}catch(t){const e=t,n="FirebaseError"!==e.name&&i<3;if(Os("SimpleDb","Transaction failed with error:",e.message,"Retrying:",n),this.close(),!n)return Promise.reject(e)}}}close(){this.db&&this.db.close(),this.db=void 0}}class Nr{constructor(t){this.U=t,this.q=!1,this.K=null}get isDone(){return this.q}get G(){return this.K}set cursor(t){this.U=t}done(){this.q=!0}j(t){this.K=t}delete(){return Mr(this.U.delete())}}class kr extends js{constructor(t,e){super(Ks.UNAVAILABLE,`IndexedDB transaction '${t}' failed: ${e}`),this.name="IndexedDbTransactionError"}}function Rr(t){return"IndexedDbTransactionError"===t.name}class Lr{constructor(t){this.store=t}put(t,e){let n;return void 0!==e?(Os("SimpleDb","PUT",this.store.name,t,e),n=this.store.put(e,t)):(Os("SimpleDb","PUT",this.store.name,"<auto-key>",t),n=this.store.put(t)),Mr(n)}add(t){return Os("SimpleDb","ADD",this.store.name,t,t),Mr(this.store.add(t))}get(t){return Mr(this.store.get(t)).next((e=>(void 0===e&&(e=null),Os("SimpleDb","GET",this.store.name,t,e),e)))}delete(t){return Os("SimpleDb","DELETE",this.store.name,t),Mr(this.store.delete(t))}count(){return Os("SimpleDb","COUNT",this.store.name),Mr(this.store.count())}W(t,e){const n=this.options(t,e);if(n.index||"function"!=typeof this.store.getAll){const t=this.cursor(n),e=[];return this.H(t,((t,n)=>{e.push(n)})).next((()=>e))}{const t=this.store.getAll(n.range);return new xr(((e,n)=>{t.onerror=t=>{n(t.target.error)},t.onsuccess=t=>{e(t.target.result)}}))}}J(t,e){const n=this.store.getAll(t,null===e?void 0:e);return new xr(((t,e)=>{n.onerror=t=>{e(t.target.error)},n.onsuccess=e=>{t(e.target.result)}}))}Y(t,e){Os("SimpleDb","DELETE ALL",this.store.name);const n=this.options(t,e);n.X=!1;const s=this.cursor(n);return this.H(s,((t,e,n)=>n.delete()))}Z(t,e){let n;e?n=t:(n={},e=t);const s=this.cursor(n);return this.H(s,e)}tt(t){const e=this.cursor({});return new xr(((n,s)=>{e.onerror=t=>{const e=Vr(t.target.error);s(e)},e.onsuccess=e=>{const s=e.target.result;s?t(s.primaryKey,s.value).next((t=>{t?s.continue():n()})):n()}}))}H(t,e){const n=[];return new xr(((s,r)=>{t.onerror=t=>{r(t.target.error)},t.onsuccess=t=>{const r=t.target.result;if(!r)return void s();const i=new Nr(r),o=e(r.primaryKey,r.value,i);if(o instanceof xr){const t=o.catch((t=>(i.done(),xr.reject(t))));n.push(t)}i.isDone?s():null===i.G?r.continue():r.continue(i.G)}})).next((()=>xr.waitFor(n)))}options(t,e){let n;return void 0!==t&&("string"==typeof t?n=t:e=t),{index:n,range:e}}cursor(t){let e="next";if(t.reverse&&(e="prev"),t.index){const n=this.store.index(t.index);return t.X?n.openKeyCursor(t.range,e):n.openCursor(t.range,e)}return this.store.openCursor(t.range,e)}}function Mr(t){return new xr(((e,n)=>{t.onsuccess=t=>{const n=t.target.result;e(n)},t.onerror=t=>{const e=Vr(t.target.error);n(e)}}))}let Or=!1;function Vr(t){const e=Cr.D(c());if(e>=12.2&&e<13){const e="An internal error was encountered in the Indexed Database server";if(t.message.indexOf(e)>=0){const t=new js("internal",`IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${e}'. This is likely due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.`);return Or||(Or=!0,setTimeout((()=>{throw t}),0)),t}}return t}class Fr{constructor(t,e){this.asyncQueue=t,this.et=e,this.task=null}start(){this.nt(15e3)}stop(){this.task&&(this.task.cancel(),this.task=null)}get started(){return null!==this.task}nt(t){Os("IndexBackiller",`Scheduled in ${t}ms`),this.task=this.asyncQueue.enqueueAfterDelay("index_backfill",t,(async()=>{this.task=null;try{Os("IndexBackiller",`Documents written: ${await this.et.st()}`)}catch(t){Rr(t)?Os("IndexBackiller","Ignoring IndexedDB error during index backfill: ",t):await Dr(t)}await this.nt(6e4)}))}}class Pr{constructor(t,e){this.localStore=t,this.persistence=e}async st(t=50){return this.persistence.runTransaction("Backfill Indexes","readwrite-primary",(e=>this.it(e,t)))}it(t,e){const n=new Set;let s=e,r=!0;return xr.doWhile((()=>!0===r&&s>0),(()=>this.localStore.indexManager.getNextCollectionGroupToUpdate(t).next((e=>{if(null!==e&&!n.has(e))return Os("IndexBackiller",`Processing collection: ${e}`),this.rt(t,e,s).next((t=>{s-=t,n.add(e)}));r=!1})))).next((()=>e-s))}rt(t,e,n){return this.localStore.indexManager.getMinOffsetFromCollectionGroup(t,e).next((s=>this.localStore.localDocuments.getNextDocuments(t,e,s,n).next((n=>{const r=n.changes;return this.localStore.indexManager.updateIndexEntries(t,r).next((()=>this.ot(s,n))).next((n=>(Os("IndexBackiller",`Updating offset: ${n}`),this.localStore.indexManager.updateCollectionGroup(t,e,n)))).next((()=>r.size))}))))}ot(t,e){let n=t;return e.changes.forEach(((t,e)=>{const s=br(e);Tr(s,n)>0&&(n=s)})),new Er(n.readTime,n.documentKey,Math.max(e.batchId,t.largestBatchId))}}class Ur{constructor(t,e){this.previousValue=t,e&&(e.sequenceNumberHandler=t=>this.ut(t),this.ct=t=>e.writeSequenceNumber(t))}ut(t){return this.previousValue=Math.max(t,this.previousValue),this.previousValue}next(){const t=++this.previousValue;return this.ct&&this.ct(t),t}}function Br(t){let e=0;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e++;return e}function qr(t,e){for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}function Gr(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}Ur.at=-1;class Kr{constructor(t,e){this.comparator=t,this.root=e||$r.EMPTY}insert(t,e){return new Kr(this.comparator,this.root.insert(t,e,this.comparator).copy(null,null,$r.BLACK,null,null))}remove(t){return new Kr(this.comparator,this.root.remove(t,this.comparator).copy(null,null,$r.BLACK,null,null))}get(t){let e=this.root;for(;!e.isEmpty();){const n=this.comparator(t,e.key);if(0===n)return e.value;n<0?e=e.left:n>0&&(e=e.right)}return null}indexOf(t){let e=0,n=this.root;for(;!n.isEmpty();){const s=this.comparator(t,n.key);if(0===s)return e+n.left.size;s<0?n=n.left:(e+=n.left.size+1,n=n.right)}return-1}isEmpty(){return this.root.isEmpty()}get size(){return this.root.size}minKey(){return this.root.minKey()}maxKey(){return this.root.maxKey()}inorderTraversal(t){return this.root.inorderTraversal(t)}forEach(t){this.inorderTraversal(((e,n)=>(t(e,n),!1)))}toString(){const t=[];return this.inorderTraversal(((e,n)=>(t.push(`${e}:${n}`),!1))),`{${t.join(", ")}}`}reverseTraversal(t){return this.root.reverseTraversal(t)}getIterator(){return new jr(this.root,null,this.comparator,!1)}getIteratorFrom(t){return new jr(this.root,t,this.comparator,!1)}getReverseIterator(){return new jr(this.root,null,this.comparator,!0)}getReverseIteratorFrom(t){return new jr(this.root,t,this.comparator,!0)}}class jr{constructor(t,e,n,s){this.isReverse=s,this.nodeStack=[];let r=1;for(;!t.isEmpty();)if(r=e?n(t.key,e):1,e&&s&&(r*=-1),r<0)t=this.isReverse?t.left:t.right;else{if(0===r){this.nodeStack.push(t);break}this.nodeStack.push(t),t=this.isReverse?t.right:t.left}}getNext(){let t=this.nodeStack.pop();const e={key:t.key,value:t.value};if(this.isReverse)for(t=t.left;!t.isEmpty();)this.nodeStack.push(t),t=t.right;else for(t=t.right;!t.isEmpty();)this.nodeStack.push(t),t=t.left;return e}hasNext(){return this.nodeStack.length>0}peek(){if(0===this.nodeStack.length)return null;const t=this.nodeStack[this.nodeStack.length-1];return{key:t.key,value:t.value}}}class $r{constructor(t,e,n,s,r){this.key=t,this.value=e,this.color=null!=n?n:$r.RED,this.left=null!=s?s:$r.EMPTY,this.right=null!=r?r:$r.EMPTY,this.size=this.left.size+1+this.right.size}copy(t,e,n,s,r){return new $r(null!=t?t:this.key,null!=e?e:this.value,null!=n?n:this.color,null!=s?s:this.left,null!=r?r:this.right)}isEmpty(){return!1}inorderTraversal(t){return this.left.inorderTraversal(t)||t(this.key,this.value)||this.right.inorderTraversal(t)}reverseTraversal(t){return this.right.reverseTraversal(t)||t(this.key,this.value)||this.left.reverseTraversal(t)}min(){return this.left.isEmpty()?this:this.left.min()}minKey(){return this.min().key}maxKey(){return this.right.isEmpty()?this.key:this.right.maxKey()}insert(t,e,n){let s=this;const r=n(t,s.key);return s=r<0?s.copy(null,null,null,s.left.insert(t,e,n),null):0===r?s.copy(null,e,null,null,null):s.copy(null,null,null,null,s.right.insert(t,e,n)),s.fixUp()}removeMin(){if(this.left.isEmpty())return $r.EMPTY;let t=this;return t.left.isRed()||t.left.left.isRed()||(t=t.moveRedLeft()),t=t.copy(null,null,null,t.left.removeMin(),null),t.fixUp()}remove(t,e){let n,s=this;if(e(t,s.key)<0)s.left.isEmpty()||s.left.isRed()||s.left.left.isRed()||(s=s.moveRedLeft()),s=s.copy(null,null,null,s.left.remove(t,e),null);else{if(s.left.isRed()&&(s=s.rotateRight()),s.right.isEmpty()||s.right.isRed()||s.right.left.isRed()||(s=s.moveRedRight()),0===e(t,s.key)){if(s.right.isEmpty())return $r.EMPTY;n=s.right.min(),s=s.copy(n.key,n.value,null,null,s.right.removeMin())}s=s.copy(null,null,null,null,s.right.remove(t,e))}return s.fixUp()}isRed(){return this.color}fixUp(){let t=this;return t.right.isRed()&&!t.left.isRed()&&(t=t.rotateLeft()),t.left.isRed()&&t.left.left.isRed()&&(t=t.rotateRight()),t.left.isRed()&&t.right.isRed()&&(t=t.colorFlip()),t}moveRedLeft(){let t=this.colorFlip();return t.right.left.isRed()&&(t=t.copy(null,null,null,null,t.right.rotateRight()),t=t.rotateLeft(),t=t.colorFlip()),t}moveRedRight(){let t=this.colorFlip();return t.left.left.isRed()&&(t=t.rotateRight(),t=t.colorFlip()),t}rotateLeft(){const t=this.copy(null,null,$r.RED,null,this.right.left);return this.right.copy(null,null,this.color,t,null)}rotateRight(){const t=this.copy(null,null,$r.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,t)}colorFlip(){const t=this.left.copy(null,null,!this.left.color,null,null),e=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,t,e)}checkMaxDepth(){const t=this.check();return Math.pow(2,t)<=this.size+1}check(){if(this.isRed()&&this.left.isRed())throw Us();if(this.right.isRed())throw Us();const t=this.left.check();if(t!==this.right.check())throw Us();return t+(this.isRed()?0:1)}}$r.EMPTY=null,$r.RED=!0,$r.BLACK=!1,$r.EMPTY=new class{constructor(){this.size=0}get key(){throw Us()}get value(){throw Us()}get color(){throw Us()}get left(){throw Us()}get right(){throw Us()}copy(t,e,n,s,r){return this}insert(t,e,n){return new $r(t,e)}remove(t,e){return this}isEmpty(){return!0}inorderTraversal(t){return!1}reverseTraversal(t){return!1}minKey(){return null}maxKey(){return null}isRed(){return!1}checkMaxDepth(){return!0}check(){return 0}};class Qr{constructor(t){this.comparator=t,this.data=new Kr(this.comparator)}has(t){return null!==this.data.get(t)}first(){return this.data.minKey()}last(){return this.data.maxKey()}get size(){return this.data.size}indexOf(t){return this.data.indexOf(t)}forEach(t){this.data.inorderTraversal(((e,n)=>(t(e),!1)))}forEachInRange(t,e){const n=this.data.getIteratorFrom(t[0]);for(;n.hasNext();){const s=n.getNext();if(this.comparator(s.key,t[1])>=0)return;e(s.key)}}forEachWhile(t,e){let n;for(n=void 0!==e?this.data.getIteratorFrom(e):this.data.getIterator();n.hasNext();)if(!t(n.getNext().key))return}firstAfterOrEqual(t){const e=this.data.getIteratorFrom(t);return e.hasNext()?e.getNext().key:null}getIterator(){return new zr(this.data.getIterator())}getIteratorFrom(t){return new zr(this.data.getIteratorFrom(t))}add(t){return this.copy(this.data.remove(t).insert(t,!0))}delete(t){return this.has(t)?this.copy(this.data.remove(t)):this}isEmpty(){return this.data.isEmpty()}unionWith(t){let e=this;return e.size<t.size&&(e=t,t=this),t.forEach((t=>{e=e.add(t)})),e}isEqual(t){if(!(t instanceof Qr))return!1;if(this.size!==t.size)return!1;const e=this.data.getIterator(),n=t.data.getIterator();for(;e.hasNext();){const t=e.getNext().key,s=n.getNext().key;if(0!==this.comparator(t,s))return!1}return!0}toArray(){const t=[];return this.forEach((e=>{t.push(e)})),t}toString(){const t=[];return this.forEach((e=>t.push(e))),"SortedSet("+t.toString()+")"}copy(t){const e=new Qr(this.comparator);return e.data=t,e}}class zr{constructor(t){this.iter=t}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}}function Hr(t){return t.hasNext()?t.getNext():void 0}class Wr{constructor(t){this.fields=t,t.sort(lr.comparator)}static empty(){return new Wr([])}unionWith(t){let e=new Qr(lr.comparator);for(const t of this.fields)e=e.add(t);for(const n of t)e=e.add(n);return new Wr(e.toArray())}covers(t){for(const e of this.fields)if(e.isPrefixOf(t))return!0;return!1}isEqual(t){return rr(this.fields,t.fields,((t,e)=>t.isEqual(e)))}}function Yr(){return"undefined"!=typeof atob}class Xr{constructor(t){this.binaryString=t}static fromBase64String(t){const e=atob(t);return new Xr(e)}static fromUint8Array(t){const e=function(t){let e="";for(let n=0;n<t.length;++n)e+=String.fromCharCode(t[n]);return e}(t);return new Xr(e)}[Symbol.iterator](){let t=0;return{next:()=>t<this.binaryString.length?{value:this.binaryString.charCodeAt(t++),done:!1}:{value:void 0,done:!0}}}toBase64(){return t=this.binaryString,btoa(t);var t}toUint8Array(){return function(t){const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}(this.binaryString)}approximateByteSize(){return 2*this.binaryString.length}compareTo(t){return sr(this.binaryString,t.binaryString)}isEqual(t){return this.binaryString===t.binaryString}}Xr.EMPTY_BYTE_STRING=new Xr("");const Jr=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function Zr(t){if(Bs(!!t),"string"==typeof t){let e=0;const n=Jr.exec(t);if(Bs(!!n),n[1]){let t=n[1];t=(t+"000000000").substr(0,9),e=Number(t)}const s=new Date(t);return{seconds:Math.floor(s.getTime()/1e3),nanos:e}}return{seconds:ti(t.seconds),nanos:ti(t.nanos)}}function ti(t){return"number"==typeof t?t:"string"==typeof t?Number(t):0}function ei(t){return"string"==typeof t?Xr.fromBase64String(t):Xr.fromUint8Array(t)}function ni(t){var e,n;return"server_timestamp"===(null===(n=((null===(e=null==t?void 0:t.mapValue)||void 0===e?void 0:e.fields)||{}).__type__)||void 0===n?void 0:n.stringValue)}function si(t){const e=t.mapValue.fields.__previous_value__;return ni(e)?si(e):e}function ri(t){const e=Zr(t.mapValue.fields.__local_write_time__.timestampValue);return new or(e.seconds,e.nanos)}class ii{constructor(t,e,n,s,r,i,o,a){this.databaseId=t,this.appId=e,this.persistenceKey=n,this.host=s,this.ssl=r,this.forceLongPolling=i,this.autoDetectLongPolling=o,this.useFetchStreams=a}}class oi{constructor(t,e){this.projectId=t,this.database=e||"(default)"}static empty(){return new oi("","")}get isDefaultDatabase(){return"(default)"===this.database}isEqual(t){return t instanceof oi&&t.projectId===this.projectId&&t.database===this.database}}function ai(t){return null==t}function ui(t){return 0===t&&1/t==-1/0}function ci(t){return"number"==typeof t&&Number.isInteger(t)&&!ui(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}const hi={mapValue:{fields:{__type__:{stringValue:"__max__"}}}},li={nullValue:"NULL_VALUE"};function di(t){return"nullValue"in t?0:"booleanValue"in t?1:"integerValue"in t||"doubleValue"in t?2:"timestampValue"in t?3:"stringValue"in t?5:"bytesValue"in t?6:"referenceValue"in t?7:"geoPointValue"in t?8:"arrayValue"in t?9:"mapValue"in t?ni(t)?4:Di(t)?9007199254740991:10:Us()}function fi(t,e){if(t===e)return!0;const n=di(t);if(n!==di(e))return!1;switch(n){case 0:case 9007199254740991:return!0;case 1:return t.booleanValue===e.booleanValue;case 4:return ri(t).isEqual(ri(e));case 3:return function(t,e){if("string"==typeof t.timestampValue&&"string"==typeof e.timestampValue&&t.timestampValue.length===e.timestampValue.length)return t.timestampValue===e.timestampValue;const n=Zr(t.timestampValue),s=Zr(e.timestampValue);return n.seconds===s.seconds&&n.nanos===s.nanos}(t,e);case 5:return t.stringValue===e.stringValue;case 6:return function(t,e){return ei(t.bytesValue).isEqual(ei(e.bytesValue))}(t,e);case 7:return t.referenceValue===e.referenceValue;case 8:return function(t,e){return ti(t.geoPointValue.latitude)===ti(e.geoPointValue.latitude)&&ti(t.geoPointValue.longitude)===ti(e.geoPointValue.longitude)}(t,e);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return ti(t.integerValue)===ti(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){const n=ti(t.doubleValue),s=ti(e.doubleValue);return n===s?ui(n)===ui(s):isNaN(n)&&isNaN(s)}return!1}(t,e);case 9:return rr(t.arrayValue.values||[],e.arrayValue.values||[],fi);case 10:return function(t,e){const n=t.mapValue.fields||{},s=e.mapValue.fields||{};if(Br(n)!==Br(s))return!1;for(const t in n)if(n.hasOwnProperty(t)&&(void 0===s[t]||!fi(n[t],s[t])))return!1;return!0}(t,e);default:return Us()}}function mi(t,e){return void 0!==(t.values||[]).find((t=>fi(t,e)))}function gi(t,e){if(t===e)return 0;const n=di(t),s=di(e);if(n!==s)return sr(n,s);switch(n){case 0:case 9007199254740991:return 0;case 1:return sr(t.booleanValue,e.booleanValue);case 2:return function(t,e){const n=ti(t.integerValue||t.doubleValue),s=ti(e.integerValue||e.doubleValue);return n<s?-1:n>s?1:n===s?0:isNaN(n)?isNaN(s)?0:-1:1}(t,e);case 3:return pi(t.timestampValue,e.timestampValue);case 4:return pi(ri(t),ri(e));case 5:return sr(t.stringValue,e.stringValue);case 6:return function(t,e){const n=ei(t),s=ei(e);return n.compareTo(s)}(t.bytesValue,e.bytesValue);case 7:return function(t,e){const n=t.split("/"),s=e.split("/");for(let t=0;t<n.length&&t<s.length;t++){const e=sr(n[t],s[t]);if(0!==e)return e}return sr(n.length,s.length)}(t.referenceValue,e.referenceValue);case 8:return function(t,e){const n=sr(ti(t.latitude),ti(e.latitude));return 0!==n?n:sr(ti(t.longitude),ti(e.longitude))}(t.geoPointValue,e.geoPointValue);case 9:return function(t,e){const n=t.values||[],s=e.values||[];for(let t=0;t<n.length&&t<s.length;++t){const e=gi(n[t],s[t]);if(e)return e}return sr(n.length,s.length)}(t.arrayValue,e.arrayValue);case 10:return function(t,e){if(t===hi.mapValue&&e===hi.mapValue)return 0;if(t===hi.mapValue)return 1;if(e===hi.mapValue)return-1;const n=t.fields||{},s=Object.keys(n),r=e.fields||{},i=Object.keys(r);s.sort(),i.sort();for(let t=0;t<s.length&&t<i.length;++t){const e=sr(s[t],i[t]);if(0!==e)return e;const o=gi(n[s[t]],r[i[t]]);if(0!==o)return o}return sr(s.length,i.length)}(t.mapValue,e.mapValue);default:throw Us()}}function pi(t,e){if("string"==typeof t&&"string"==typeof e&&t.length===e.length)return sr(t,e);const n=Zr(t),s=Zr(e),r=sr(n.seconds,s.seconds);return 0!==r?r:sr(n.nanos,s.nanos)}function yi(t){return wi(t)}function wi(t){return"nullValue"in t?"null":"booleanValue"in t?""+t.booleanValue:"integerValue"in t?""+t.integerValue:"doubleValue"in t?""+t.doubleValue:"timestampValue"in t?function(t){const e=Zr(t);return`time(${e.seconds},${e.nanos})`}(t.timestampValue):"stringValue"in t?t.stringValue:"bytesValue"in t?ei(t.bytesValue).toBase64():"referenceValue"in t?(n=t.referenceValue,dr.fromName(n).toString()):"geoPointValue"in t?`geo(${(e=t.geoPointValue).latitude},${e.longitude})`:"arrayValue"in t?function(t){let e="[",n=!0;for(const s of t.values||[])n?n=!1:e+=",",e+=wi(s);return e+"]"}(t.arrayValue):"mapValue"in t?function(t){const e=Object.keys(t.fields||{}).sort();let n="{",s=!0;for(const r of e)s?s=!1:n+=",",n+=`${r}:${wi(t.fields[r])}`;return n+"}"}(t.mapValue):Us();var e,n}function vi(t,e){return{referenceValue:`projects/${t.projectId}/databases/${t.database}/documents/${e.path.canonicalString()}`}}function Ii(t){return!!t&&"integerValue"in t}function bi(t){return!!t&&"arrayValue"in t}function Ei(t){return!!t&&"nullValue"in t}function Ti(t){return!!t&&"doubleValue"in t&&isNaN(Number(t.doubleValue))}function Si(t){return!!t&&"mapValue"in t}function _i(t){if(t.geoPointValue)return{geoPointValue:Object.assign({},t.geoPointValue)};if(t.timestampValue&&"object"==typeof t.timestampValue)return{timestampValue:Object.assign({},t.timestampValue)};if(t.mapValue){const e={mapValue:{fields:{}}};return qr(t.mapValue.fields,((t,n)=>e.mapValue.fields[t]=_i(n))),e}if(t.arrayValue){const e={arrayValue:{values:[]}};for(let n=0;n<(t.arrayValue.values||[]).length;++n)e.arrayValue.values[n]=_i(t.arrayValue.values[n]);return e}return Object.assign({},t)}function Di(t){return"__max__"===(((t.mapValue||{}).fields||{}).__type__||{}).stringValue}function xi(t){return"nullValue"in t?li:"booleanValue"in t?{booleanValue:!1}:"integerValue"in t||"doubleValue"in t?{doubleValue:NaN}:"timestampValue"in t?{timestampValue:{seconds:Number.MIN_SAFE_INTEGER}}:"stringValue"in t?{stringValue:""}:"bytesValue"in t?{bytesValue:""}:"referenceValue"in t?vi(oi.empty(),dr.empty()):"geoPointValue"in t?{geoPointValue:{latitude:-90,longitude:-180}}:"arrayValue"in t?{arrayValue:{}}:"mapValue"in t?{mapValue:{}}:Us()}function Ai(t){return"nullValue"in t?{booleanValue:!1}:"booleanValue"in t?{doubleValue:NaN}:"integerValue"in t||"doubleValue"in t?{timestampValue:{seconds:Number.MIN_SAFE_INTEGER}}:"timestampValue"in t?{stringValue:""}:"stringValue"in t?{bytesValue:""}:"bytesValue"in t?vi(oi.empty(),dr.empty()):"referenceValue"in t?{geoPointValue:{latitude:-90,longitude:-180}}:"geoPointValue"in t?{arrayValue:{}}:"arrayValue"in t?{mapValue:{}}:"mapValue"in t?hi:Us()}function Ci(t,e){const n=gi(t.value,e.value);return 0!==n?n:t.inclusive&&!e.inclusive?-1:!t.inclusive&&e.inclusive?1:0}function Ni(t,e){const n=gi(t.value,e.value);return 0!==n?n:t.inclusive&&!e.inclusive?1:!t.inclusive&&e.inclusive?-1:0}class ki{constructor(t){this.value=t}static empty(){return new ki({mapValue:{}})}field(t){if(t.isEmpty())return this.value;{let e=this.value;for(let n=0;n<t.length-1;++n)if(e=(e.mapValue.fields||{})[t.get(n)],!Si(e))return null;return e=(e.mapValue.fields||{})[t.lastSegment()],e||null}}set(t,e){this.getFieldsMap(t.popLast())[t.lastSegment()]=_i(e)}setAll(t){let e=lr.emptyPath(),n={},s=[];t.forEach(((t,r)=>{if(!e.isImmediateParentOf(r)){const t=this.getFieldsMap(e);this.applyChanges(t,n,s),n={},s=[],e=r.popLast()}t?n[r.lastSegment()]=_i(t):s.push(r.lastSegment())}));const r=this.getFieldsMap(e);this.applyChanges(r,n,s)}delete(t){const e=this.field(t.popLast());Si(e)&&e.mapValue.fields&&delete e.mapValue.fields[t.lastSegment()]}isEqual(t){return fi(this.value,t.value)}getFieldsMap(t){let e=this.value;e.mapValue.fields||(e.mapValue={fields:{}});for(let n=0;n<t.length;++n){let s=e.mapValue.fields[t.get(n)];Si(s)&&s.mapValue.fields||(s={mapValue:{fields:{}}},e.mapValue.fields[t.get(n)]=s),e=s}return e.mapValue.fields}applyChanges(t,e,n){qr(e,((e,n)=>t[e]=n));for(const e of n)delete t[e]}clone(){return new ki(_i(this.value))}}function Ri(t){const e=[];return qr(t.fields,((t,n)=>{const s=new lr([t]);if(Si(n)){const t=Ri(n.mapValue).fields;if(0===t.length)e.push(s);else for(const n of t)e.push(s.child(n))}else e.push(s)})),new Wr(e)}class Li{constructor(t,e,n,s,r,i){this.key=t,this.documentType=e,this.version=n,this.readTime=s,this.data=r,this.documentState=i}static newInvalidDocument(t){return new Li(t,0,ar.min(),ar.min(),ki.empty(),0)}static newFoundDocument(t,e,n){return new Li(t,1,e,ar.min(),n,0)}static newNoDocument(t,e){return new Li(t,2,e,ar.min(),ki.empty(),0)}static newUnknownDocument(t,e){return new Li(t,3,e,ar.min(),ki.empty(),2)}convertToFoundDocument(t,e){return this.version=t,this.documentType=1,this.data=e,this.documentState=0,this}convertToNoDocument(t){return this.version=t,this.documentType=2,this.data=ki.empty(),this.documentState=0,this}convertToUnknownDocument(t){return this.version=t,this.documentType=3,this.data=ki.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=ar.min(),this}setReadTime(t){return this.readTime=t,this}get hasLocalMutations(){return 1===this.documentState}get hasCommittedMutations(){return 2===this.documentState}get hasPendingWrites(){return this.hasLocalMutations||this.hasCommittedMutations}isValidDocument(){return 0!==this.documentType}isFoundDocument(){return 1===this.documentType}isNoDocument(){return 2===this.documentType}isUnknownDocument(){return 3===this.documentType}isEqual(t){return t instanceof Li&&this.key.isEqual(t.key)&&this.version.isEqual(t.version)&&this.documentType===t.documentType&&this.documentState===t.documentState&&this.data.isEqual(t.data)}mutableCopy(){return new Li(this.key,this.documentType,this.version,this.readTime,this.data.clone(),this.documentState)}toString(){return`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, {documentType: ${this.documentType}}), {documentState: ${this.documentState}})`}}class Mi{constructor(t,e=null,n=[],s=[],r=null,i=null,o=null){this.path=t,this.collectionGroup=e,this.orderBy=n,this.filters=s,this.limit=r,this.startAt=i,this.endAt=o,this.ht=null}}function Oi(t,e=null,n=[],s=[],r=null,i=null,o=null){return new Mi(t,e,n,s,r,i,o)}function Vi(t){const e=Gs(t);if(null===e.ht){let t=e.path.canonicalString();null!==e.collectionGroup&&(t+="|cg:"+e.collectionGroup),t+="|f:",t+=e.filters.map((t=>{return(e=t).field.canonicalString()+e.op.toString()+yi(e.value);var e})).join(","),t+="|ob:",t+=e.orderBy.map((t=>function(t){return t.field.canonicalString()+t.dir}(t))).join(","),ai(e.limit)||(t+="|l:",t+=e.limit),e.startAt&&(t+="|lb:",t+=e.startAt.inclusive?"b:":"a:",t+=e.startAt.position.map((t=>yi(t))).join(",")),e.endAt&&(t+="|ub:",t+=e.endAt.inclusive?"a:":"b:",t+=e.endAt.position.map((t=>yi(t))).join(",")),e.ht=t}return e.ht}function Fi(t,e){if(t.limit!==e.limit)return!1;if(t.orderBy.length!==e.orderBy.length)return!1;for(let n=0;n<t.orderBy.length;n++)if(!Zi(t.orderBy[n],e.orderBy[n]))return!1;if(t.filters.length!==e.filters.length)return!1;for(let r=0;r<t.filters.length;r++)if(n=t.filters[r],s=e.filters[r],n.op!==s.op||!n.field.isEqual(s.field)||!fi(n.value,s.value))return!1;var n,s;return t.collectionGroup===e.collectionGroup&&!!t.path.isEqual(e.path)&&!!eo(t.startAt,e.startAt)&&eo(t.endAt,e.endAt)}function Pi(t){return dr.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}function Ui(t,e){return t.filters.filter((t=>t instanceof Gi&&t.field.isEqual(e)))}function Bi(t,e,n){let s=li,r=!0;for(const n of Ui(t,e)){let t=li,e=!0;switch(n.op){case"<":case"<=":t=xi(n.value);break;case"==":case"in":case">=":t=n.value;break;case">":t=n.value,e=!1;break;case"!=":case"not-in":t=li}Ci({value:s,inclusive:r},{value:t,inclusive:e})<0&&(s=t,r=e)}if(null!==n)for(let i=0;i<t.orderBy.length;++i)if(t.orderBy[i].field.isEqual(e)){const t=n.position[i];Ci({value:s,inclusive:r},{value:t,inclusive:n.inclusive})<0&&(s=t,r=n.inclusive);break}return{value:s,inclusive:r}}function qi(t,e,n){let s=hi,r=!0;for(const n of Ui(t,e)){let t=hi,e=!0;switch(n.op){case">=":case">":t=Ai(n.value),e=!1;break;case"==":case"in":case"<=":t=n.value;break;case"<":t=n.value,e=!1;break;case"!=":case"not-in":t=hi}Ni({value:s,inclusive:r},{value:t,inclusive:e})>0&&(s=t,r=e)}if(null!==n)for(let i=0;i<t.orderBy.length;++i)if(t.orderBy[i].field.isEqual(e)){const t=n.position[i];Ni({value:s,inclusive:r},{value:t,inclusive:n.inclusive})>0&&(s=t,r=n.inclusive);break}return{value:s,inclusive:r}}class Gi extends class{}{constructor(t,e,n){super(),this.field=t,this.op=e,this.value=n}static create(t,e,n){return t.isKeyField()?"in"===e||"not-in"===e?this.lt(t,e,n):new Ki(t,e,n):"array-contains"===e?new zi(t,n):"in"===e?new Hi(t,n):"not-in"===e?new Wi(t,n):"array-contains-any"===e?new Yi(t,n):new Gi(t,e,n)}static lt(t,e,n){return"in"===e?new ji(t,n):new $i(t,n)}matches(t){const e=t.data.field(this.field);return"!="===this.op?null!==e&&this.ft(gi(e,this.value)):null!==e&&di(this.value)===di(e)&&this.ft(gi(e,this.value))}ft(t){switch(this.op){case"<":return t<0;case"<=":return t<=0;case"==":return 0===t;case"!=":return 0!==t;case">":return t>0;case">=":return t>=0;default:return Us()}}dt(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}}class Ki extends Gi{constructor(t,e,n){super(t,e,n),this.key=dr.fromName(n.referenceValue)}matches(t){const e=dr.comparator(t.key,this.key);return this.ft(e)}}class ji extends Gi{constructor(t,e){super(t,"in",e),this.keys=Qi("in",e)}matches(t){return this.keys.some((e=>e.isEqual(t.key)))}}class $i extends Gi{constructor(t,e){super(t,"not-in",e),this.keys=Qi("not-in",e)}matches(t){return!this.keys.some((e=>e.isEqual(t.key)))}}function Qi(t,e){var n;return((null===(n=e.arrayValue)||void 0===n?void 0:n.values)||[]).map((t=>dr.fromName(t.referenceValue)))}class zi extends Gi{constructor(t,e){super(t,"array-contains",e)}matches(t){const e=t.data.field(this.field);return bi(e)&&mi(e.arrayValue,this.value)}}class Hi extends Gi{constructor(t,e){super(t,"in",e)}matches(t){const e=t.data.field(this.field);return null!==e&&mi(this.value.arrayValue,e)}}class Wi extends Gi{constructor(t,e){super(t,"not-in",e)}matches(t){if(mi(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;const e=t.data.field(this.field);return null!==e&&!mi(this.value.arrayValue,e)}}class Yi extends Gi{constructor(t,e){super(t,"array-contains-any",e)}matches(t){const e=t.data.field(this.field);return!(!bi(e)||!e.arrayValue.values)&&e.arrayValue.values.some((t=>mi(this.value.arrayValue,t)))}}class Xi{constructor(t,e){this.position=t,this.inclusive=e}}class Ji{constructor(t,e="asc"){this.field=t,this.dir=e}}function Zi(t,e){return t.dir===e.dir&&t.field.isEqual(e.field)}function to(t,e,n){let s=0;for(let r=0;r<t.position.length;r++){const i=e[r],o=t.position[r];if(s=i.field.isKeyField()?dr.comparator(dr.fromName(o.referenceValue),n.key):gi(o,n.data.field(i.field)),"desc"===i.dir&&(s*=-1),0!==s)break}return s}function eo(t,e){if(null===t)return null===e;if(null===e)return!1;if(t.inclusive!==e.inclusive||t.position.length!==e.position.length)return!1;for(let n=0;n<t.position.length;n++)if(!fi(t.position[n],e.position[n]))return!1;return!0}class no{constructor(t,e=null,n=[],s=[],r=null,i="F",o=null,a=null){this.path=t,this.collectionGroup=e,this.explicitOrderBy=n,this.filters=s,this.limit=r,this.limitType=i,this.startAt=o,this.endAt=a,this._t=null,this.wt=null,this.startAt,this.endAt}}function so(t,e,n,s,r,i,o,a){return new no(t,e,n,s,r,i,o,a)}function ro(t){return new no(t)}function io(t){return 0===t.filters.length&&null===t.limit&&null==t.startAt&&null==t.endAt&&(0===t.explicitOrderBy.length||1===t.explicitOrderBy.length&&t.explicitOrderBy[0].field.isKeyField())}function oo(t){return t.explicitOrderBy.length>0?t.explicitOrderBy[0].field:null}function ao(t){for(const e of t.filters)if(e.dt())return e.field;return null}function uo(t){return null!==t.collectionGroup}function co(t){const e=Gs(t);if(null===e._t){e._t=[];const t=ao(e),n=oo(e);if(null!==t&&null===n)t.isKeyField()||e._t.push(new Ji(t)),e._t.push(new Ji(lr.keyField(),"asc"));else{let t=!1;for(const n of e.explicitOrderBy)e._t.push(n),n.field.isKeyField()&&(t=!0);if(!t){const t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e._t.push(new Ji(lr.keyField(),t))}}}return e._t}function ho(t){const e=Gs(t);if(!e.wt)if("F"===e.limitType)e.wt=Oi(e.path,e.collectionGroup,co(e),e.filters,e.limit,e.startAt,e.endAt);else{const t=[];for(const n of co(e)){const e="desc"===n.dir?"asc":"desc";t.push(new Ji(n.field,e))}const n=e.endAt?new Xi(e.endAt.position,e.endAt.inclusive):null,s=e.startAt?new Xi(e.startAt.position,e.startAt.inclusive):null;e.wt=Oi(e.path,e.collectionGroup,t,e.filters,e.limit,n,s)}return e.wt}function lo(t,e,n){return new no(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),e,n,t.startAt,t.endAt)}function fo(t,e){return Fi(ho(t),ho(e))&&t.limitType===e.limitType}function mo(t){return`${Vi(ho(t))}|lt:${t.limitType}`}function go(t){return`Query(target=${function(t){let e=t.path.canonicalString();return null!==t.collectionGroup&&(e+=" collectionGroup="+t.collectionGroup),t.filters.length>0&&(e+=`, filters: [${t.filters.map((t=>{return`${(e=t).field.canonicalString()} ${e.op} ${yi(e.value)}`;var e})).join(", ")}]`),ai(t.limit)||(e+=", limit: "+t.limit),t.orderBy.length>0&&(e+=`, orderBy: [${t.orderBy.map((t=>function(t){return`${t.field.canonicalString()} (${t.dir})`}(t))).join(", ")}]`),t.startAt&&(e+=", startAt: ",e+=t.startAt.inclusive?"b:":"a:",e+=t.startAt.position.map((t=>yi(t))).join(",")),t.endAt&&(e+=", endAt: ",e+=t.endAt.inclusive?"a:":"b:",e+=t.endAt.position.map((t=>yi(t))).join(",")),`Target(${e})`}(ho(t))}; limitType=${t.limitType})`}function po(t,e){return e.isFoundDocument()&&function(t,e){const n=e.key.path;return null!==t.collectionGroup?e.key.hasCollectionId(t.collectionGroup)&&t.path.isPrefixOf(n):dr.isDocumentKey(t.path)?t.path.isEqual(n):t.path.isImmediateParentOf(n)}(t,e)&&function(t,e){for(const n of t.explicitOrderBy)if(!n.field.isKeyField()&&null===e.data.field(n.field))return!1;return!0}(t,e)&&function(t,e){for(const n of t.filters)if(!n.matches(e))return!1;return!0}(t,e)&&function(t,e){return!(t.startAt&&!function(t,e,n){const s=to(t,e,n);return t.inclusive?s<=0:s<0}(t.startAt,co(t),e))&&!(t.endAt&&!function(t,e,n){const s=to(t,e,n);return t.inclusive?s>=0:s>0}(t.endAt,co(t),e))}(t,e)}function yo(t){return t.collectionGroup||(t.path.length%2==1?t.path.lastSegment():t.path.get(t.path.length-2))}function wo(t){return(e,n)=>{let s=!1;for(const r of co(t)){const t=vo(r,e,n);if(0!==t)return t;s=s||r.field.isKeyField()}return 0}}function vo(t,e,n){const s=t.field.isKeyField()?dr.comparator(e.key,n.key):function(t,e,n){const s=e.data.field(t),r=n.data.field(t);return null!==s&&null!==r?gi(s,r):Us()}(t.field,e,n);switch(t.dir){case"asc":return s;case"desc":return-1*s;default:return Us()}}function Io(t,e){if(t.gt){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:ui(e)?"-0":e}}function bo(t){return{integerValue:""+t}}function Eo(t,e){return ci(e)?bo(e):Io(t,e)}class To{constructor(){this._=void 0}}function So(t,e,n){return t instanceof xo?function(t,e){const n={fields:{__type__:{stringValue:"server_timestamp"},__local_write_time__:{timestampValue:{seconds:t.seconds,nanos:t.nanoseconds}}}};return e&&(n.fields.__previous_value__=e),{mapValue:n}}(n,e):t instanceof Ao?Co(t,e):t instanceof No?ko(t,e):function(t,e){const n=Do(t,e),s=Lo(n)+Lo(t.yt);return Ii(n)&&Ii(t.yt)?bo(s):Io(t.It,s)}(t,e)}function _o(t,e,n){return t instanceof Ao?Co(t,e):t instanceof No?ko(t,e):n}function Do(t,e){return t instanceof Ro?Ii(n=e)||function(t){return!!t&&"doubleValue"in t}(n)?e:{integerValue:0}:null;var n}class xo extends To{}class Ao extends To{constructor(t){super(),this.elements=t}}function Co(t,e){const n=Mo(e);for(const e of t.elements)n.some((t=>fi(t,e)))||n.push(e);return{arrayValue:{values:n}}}class No extends To{constructor(t){super(),this.elements=t}}function ko(t,e){let n=Mo(e);for(const e of t.elements)n=n.filter((t=>!fi(t,e)));return{arrayValue:{values:n}}}class Ro extends To{constructor(t,e){super(),this.It=t,this.yt=e}}function Lo(t){return ti(t.integerValue||t.doubleValue)}function Mo(t){return bi(t)&&t.arrayValue.values?t.arrayValue.values.slice():[]}class Oo{constructor(t,e){this.field=t,this.transform=e}}class Vo{constructor(t,e){this.version=t,this.transformResults=e}}class Fo{constructor(t,e){this.updateTime=t,this.exists=e}static none(){return new Fo}static exists(t){return new Fo(void 0,t)}static updateTime(t){return new Fo(t)}get isNone(){return void 0===this.updateTime&&void 0===this.exists}isEqual(t){return this.exists===t.exists&&(this.updateTime?!!t.updateTime&&this.updateTime.isEqual(t.updateTime):!t.updateTime)}}function Po(t,e){return void 0!==t.updateTime?e.isFoundDocument()&&e.version.isEqual(t.updateTime):void 0===t.exists||t.exists===e.isFoundDocument()}class Uo{}function Bo(t,e){if(!t.hasLocalMutations||e&&0===e.fields.length)return null;if(null===e)return t.isNoDocument()?new Yo(t.key,Fo.none()):new $o(t.key,t.data,Fo.none());{const n=t.data,s=ki.empty();let r=new Qr(lr.comparator);for(let t of e.fields)if(!r.has(t)){let e=n.field(t);null===e&&t.length>1&&(t=t.popLast(),e=n.field(t)),null===e?s.delete(t):s.set(t,e),r=r.add(t)}return new Qo(t.key,s,new Wr(r.toArray()),Fo.none())}}function qo(t,e,n){t instanceof $o?function(t,e,n){const s=t.value.clone(),r=Ho(t.fieldTransforms,e,n.transformResults);s.setAll(r),e.convertToFoundDocument(n.version,s).setHasCommittedMutations()}(t,e,n):t instanceof Qo?function(t,e,n){if(!Po(t.precondition,e))return void e.convertToUnknownDocument(n.version);const s=Ho(t.fieldTransforms,e,n.transformResults),r=e.data;r.setAll(zo(t)),r.setAll(s),e.convertToFoundDocument(n.version,r).setHasCommittedMutations()}(t,e,n):function(t,e,n){e.convertToNoDocument(n.version).setHasCommittedMutations()}(0,e,n)}function Go(t,e,n,s){return t instanceof $o?function(t,e,n,s){if(!Po(t.precondition,e))return n;const r=t.value.clone(),i=Wo(t.fieldTransforms,s,e);return r.setAll(i),e.convertToFoundDocument(e.version,r).setHasLocalMutations(),null}(t,e,n,s):t instanceof Qo?function(t,e,n,s){if(!Po(t.precondition,e))return n;const r=Wo(t.fieldTransforms,s,e),i=e.data;return i.setAll(zo(t)),i.setAll(r),e.convertToFoundDocument(e.version,i).setHasLocalMutations(),null===n?null:n.unionWith(t.fieldMask.fields).unionWith(t.fieldTransforms.map((t=>t.field)))}(t,e,n,s):function(t,e,n){return Po(t.precondition,e)?(e.convertToNoDocument(e.version).setHasLocalMutations(),null):n}(t,e,n)}function Ko(t,e){let n=null;for(const s of t.fieldTransforms){const t=e.data.field(s.field),r=Do(s.transform,t||null);null!=r&&(null===n&&(n=ki.empty()),n.set(s.field,r))}return n||null}function jo(t,e){return t.type===e.type&&!!t.key.isEqual(e.key)&&!!t.precondition.isEqual(e.precondition)&&!!function(t,e){return void 0===t&&void 0===e||!(!t||!e)&&rr(t,e,((t,e)=>function(t,e){return t.field.isEqual(e.field)&&function(t,e){return t instanceof Ao&&e instanceof Ao||t instanceof No&&e instanceof No?rr(t.elements,e.elements,fi):t instanceof Ro&&e instanceof Ro?fi(t.yt,e.yt):t instanceof xo&&e instanceof xo}(t.transform,e.transform)}(t,e)))}(t.fieldTransforms,e.fieldTransforms)&&(0===t.type?t.value.isEqual(e.value):1!==t.type||t.data.isEqual(e.data)&&t.fieldMask.isEqual(e.fieldMask))}class $o extends Uo{constructor(t,e,n,s=[]){super(),this.key=t,this.value=e,this.precondition=n,this.fieldTransforms=s,this.type=0}getFieldMask(){return null}}class Qo extends Uo{constructor(t,e,n,s,r=[]){super(),this.key=t,this.data=e,this.fieldMask=n,this.precondition=s,this.fieldTransforms=r,this.type=1}getFieldMask(){return this.fieldMask}}function zo(t){const e=new Map;return t.fieldMask.fields.forEach((n=>{if(!n.isEmpty()){const s=t.data.field(n);e.set(n,s)}})),e}function Ho(t,e,n){const s=new Map;Bs(t.length===n.length);for(let r=0;r<n.length;r++){const i=t[r],o=i.transform,a=e.data.field(i.field);s.set(i.field,_o(o,a,n[r]))}return s}function Wo(t,e,n){const s=new Map;for(const r of t){const t=r.transform,i=n.data.field(r.field);s.set(r.field,So(t,i,e))}return s}class Yo extends Uo{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class Xo extends Uo{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}class Jo{constructor(t){this.count=t}}var Zo,ta;function ea(t){switch(t){default:return Us();case Ks.CANCELLED:case Ks.UNKNOWN:case Ks.DEADLINE_EXCEEDED:case Ks.RESOURCE_EXHAUSTED:case Ks.INTERNAL:case Ks.UNAVAILABLE:case Ks.UNAUTHENTICATED:return!1;case Ks.INVALID_ARGUMENT:case Ks.NOT_FOUND:case Ks.ALREADY_EXISTS:case Ks.PERMISSION_DENIED:case Ks.FAILED_PRECONDITION:case Ks.ABORTED:case Ks.OUT_OF_RANGE:case Ks.UNIMPLEMENTED:case Ks.DATA_LOSS:return!0}}function na(t){if(void 0===t)return Vs("GRPC error has no .code"),Ks.UNKNOWN;switch(t){case Zo.OK:return Ks.OK;case Zo.CANCELLED:return Ks.CANCELLED;case Zo.UNKNOWN:return Ks.UNKNOWN;case Zo.DEADLINE_EXCEEDED:return Ks.DEADLINE_EXCEEDED;case Zo.RESOURCE_EXHAUSTED:return Ks.RESOURCE_EXHAUSTED;case Zo.INTERNAL:return Ks.INTERNAL;case Zo.UNAVAILABLE:return Ks.UNAVAILABLE;case Zo.UNAUTHENTICATED:return Ks.UNAUTHENTICATED;case Zo.INVALID_ARGUMENT:return Ks.INVALID_ARGUMENT;case Zo.NOT_FOUND:return Ks.NOT_FOUND;case Zo.ALREADY_EXISTS:return Ks.ALREADY_EXISTS;case Zo.PERMISSION_DENIED:return Ks.PERMISSION_DENIED;case Zo.FAILED_PRECONDITION:return Ks.FAILED_PRECONDITION;case Zo.ABORTED:return Ks.ABORTED;case Zo.OUT_OF_RANGE:return Ks.OUT_OF_RANGE;case Zo.UNIMPLEMENTED:return Ks.UNIMPLEMENTED;case Zo.DATA_LOSS:return Ks.DATA_LOSS;default:return Us()}}(ta=Zo||(Zo={}))[ta.OK=0]="OK",ta[ta.CANCELLED=1]="CANCELLED",ta[ta.UNKNOWN=2]="UNKNOWN",ta[ta.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",ta[ta.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",ta[ta.NOT_FOUND=5]="NOT_FOUND",ta[ta.ALREADY_EXISTS=6]="ALREADY_EXISTS",ta[ta.PERMISSION_DENIED=7]="PERMISSION_DENIED",ta[ta.UNAUTHENTICATED=16]="UNAUTHENTICATED",ta[ta.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",ta[ta.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",ta[ta.ABORTED=10]="ABORTED",ta[ta.OUT_OF_RANGE=11]="OUT_OF_RANGE",ta[ta.UNIMPLEMENTED=12]="UNIMPLEMENTED",ta[ta.INTERNAL=13]="INTERNAL",ta[ta.UNAVAILABLE=14]="UNAVAILABLE",ta[ta.DATA_LOSS=15]="DATA_LOSS";class sa{constructor(t,e){this.mapKeyFn=t,this.equalsFn=e,this.inner={},this.innerSize=0}get(t){const e=this.mapKeyFn(t),n=this.inner[e];if(void 0!==n)for(const[e,s]of n)if(this.equalsFn(e,t))return s}has(t){return void 0!==this.get(t)}set(t,e){const n=this.mapKeyFn(t),s=this.inner[n];if(void 0===s)return this.inner[n]=[[t,e]],void this.innerSize++;for(let n=0;n<s.length;n++)if(this.equalsFn(s[n][0],t))return void(s[n]=[t,e]);s.push([t,e]),this.innerSize++}delete(t){const e=this.mapKeyFn(t),n=this.inner[e];if(void 0===n)return!1;for(let s=0;s<n.length;s++)if(this.equalsFn(n[s][0],t))return 1===n.length?delete this.inner[e]:n.splice(s,1),this.innerSize--,!0;return!1}forEach(t){qr(this.inner,((e,n)=>{for(const[e,s]of n)t(e,s)}))}isEmpty(){return Gr(this.inner)}size(){return this.innerSize}}const ra=new Kr(dr.comparator);function ia(){return ra}const oa=new Kr(dr.comparator);function aa(...t){let e=oa;for(const n of t)e=e.insert(n.key,n);return e}function ua(t){let e=oa;return t.forEach(((t,n)=>e=e.insert(t,n.overlayedDocument))),e}function ca(){return la()}function ha(){return la()}function la(){return new sa((t=>t.toString()),((t,e)=>t.isEqual(e)))}const da=new Kr(dr.comparator),fa=new Qr(dr.comparator);function ma(...t){let e=fa;for(const n of t)e=e.add(n);return e}const ga=new Qr(sr);function pa(){return ga}class ya{constructor(t,e,n,s,r){this.snapshotVersion=t,this.targetChanges=e,this.targetMismatches=n,this.documentUpdates=s,this.resolvedLimboDocuments=r}static createSynthesizedRemoteEventForCurrentChange(t,e,n){const s=new Map;return s.set(t,wa.createSynthesizedTargetChangeForCurrentChange(t,e,n)),new ya(ar.min(),s,pa(),ia(),ma())}}class wa{constructor(t,e,n,s,r){this.resumeToken=t,this.current=e,this.addedDocuments=n,this.modifiedDocuments=s,this.removedDocuments=r}static createSynthesizedTargetChangeForCurrentChange(t,e,n){return new wa(n,e,ma(),ma(),ma())}}class va{constructor(t,e,n,s){this.Tt=t,this.removedTargetIds=e,this.key=n,this.Et=s}}class Ia{constructor(t,e){this.targetId=t,this.At=e}}class ba{constructor(t,e,n=Xr.EMPTY_BYTE_STRING,s=null){this.state=t,this.targetIds=e,this.resumeToken=n,this.cause=s}}class Ea{constructor(){this.Rt=0,this.bt=_a(),this.Pt=Xr.EMPTY_BYTE_STRING,this.vt=!1,this.Vt=!0}get current(){return this.vt}get resumeToken(){return this.Pt}get St(){return 0!==this.Rt}get Dt(){return this.Vt}Ct(t){t.approximateByteSize()>0&&(this.Vt=!0,this.Pt=t)}xt(){let t=ma(),e=ma(),n=ma();return this.bt.forEach(((s,r)=>{switch(r){case 0:t=t.add(s);break;case 2:e=e.add(s);break;case 1:n=n.add(s);break;default:Us()}})),new wa(this.Pt,this.vt,t,e,n)}Nt(){this.Vt=!1,this.bt=_a()}kt(t,e){this.Vt=!0,this.bt=this.bt.insert(t,e)}Ot(t){this.Vt=!0,this.bt=this.bt.remove(t)}Mt(){this.Rt+=1}Ft(){this.Rt-=1}$t(){this.Vt=!0,this.vt=!0}}class Ta{constructor(t){this.Bt=t,this.Lt=new Map,this.Ut=ia(),this.qt=Sa(),this.Kt=new Qr(sr)}Gt(t){for(const e of t.Tt)t.Et&&t.Et.isFoundDocument()?this.Qt(e,t.Et):this.jt(e,t.key,t.Et);for(const e of t.removedTargetIds)this.jt(e,t.key,t.Et)}Wt(t){this.forEachTarget(t,(e=>{const n=this.zt(e);switch(t.state){case 0:this.Ht(e)&&n.Ct(t.resumeToken);break;case 1:n.Ft(),n.St||n.Nt(),n.Ct(t.resumeToken);break;case 2:n.Ft(),n.St||this.removeTarget(e);break;case 3:this.Ht(e)&&(n.$t(),n.Ct(t.resumeToken));break;case 4:this.Ht(e)&&(this.Jt(e),n.Ct(t.resumeToken));break;default:Us()}}))}forEachTarget(t,e){t.targetIds.length>0?t.targetIds.forEach(e):this.Lt.forEach(((t,n)=>{this.Ht(n)&&e(n)}))}Yt(t){const e=t.targetId,n=t.At.count,s=this.Xt(e);if(s){const t=s.target;if(Pi(t))if(0===n){const n=new dr(t.path);this.jt(e,n,Li.newNoDocument(n,ar.min()))}else Bs(1===n);else this.Zt(e)!==n&&(this.Jt(e),this.Kt=this.Kt.add(e))}}te(t){const e=new Map;this.Lt.forEach(((n,s)=>{const r=this.Xt(s);if(r){if(n.current&&Pi(r.target)){const e=new dr(r.target.path);null!==this.Ut.get(e)||this.ee(s,e)||this.jt(s,e,Li.newNoDocument(e,t))}n.Dt&&(e.set(s,n.xt()),n.Nt())}}));let n=ma();this.qt.forEach(((t,e)=>{let s=!0;e.forEachWhile((t=>{const e=this.Xt(t);return!e||2===e.purpose||(s=!1,!1)})),s&&(n=n.add(t))})),this.Ut.forEach(((e,n)=>n.setReadTime(t)));const s=new ya(t,e,this.Kt,this.Ut,n);return this.Ut=ia(),this.qt=Sa(),this.Kt=new Qr(sr),s}Qt(t,e){if(!this.Ht(t))return;const n=this.ee(t,e.key)?2:0;this.zt(t).kt(e.key,n),this.Ut=this.Ut.insert(e.key,e),this.qt=this.qt.insert(e.key,this.ne(e.key).add(t))}jt(t,e,n){if(!this.Ht(t))return;const s=this.zt(t);this.ee(t,e)?s.kt(e,1):s.Ot(e),this.qt=this.qt.insert(e,this.ne(e).delete(t)),n&&(this.Ut=this.Ut.insert(e,n))}removeTarget(t){this.Lt.delete(t)}Zt(t){const e=this.zt(t).xt();return this.Bt.getRemoteKeysForTarget(t).size+e.addedDocuments.size-e.removedDocuments.size}Mt(t){this.zt(t).Mt()}zt(t){let e=this.Lt.get(t);return e||(e=new Ea,this.Lt.set(t,e)),e}ne(t){let e=this.qt.get(t);return e||(e=new Qr(sr),this.qt=this.qt.insert(t,e)),e}Ht(t){const e=null!==this.Xt(t);return e||Os("WatchChangeAggregator","Detected inactive target",t),e}Xt(t){const e=this.Lt.get(t);return e&&e.St?null:this.Bt.se(t)}Jt(t){this.Lt.set(t,new Ea),this.Bt.getRemoteKeysForTarget(t).forEach((e=>{this.jt(t,e,null)}))}ee(t,e){return this.Bt.getRemoteKeysForTarget(t).has(e)}}function Sa(){return new Kr(dr.comparator)}function _a(){return new Kr(dr.comparator)}const Da={asc:"ASCENDING",desc:"DESCENDING"},xa={"<":"LESS_THAN","<=":"LESS_THAN_OR_EQUAL",">":"GREATER_THAN",">=":"GREATER_THAN_OR_EQUAL","==":"EQUAL","!=":"NOT_EQUAL","array-contains":"ARRAY_CONTAINS",in:"IN","not-in":"NOT_IN","array-contains-any":"ARRAY_CONTAINS_ANY"};class Aa{constructor(t,e){this.databaseId=t,this.gt=e}}function Ca(t,e){return t.gt?`${new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+e.nanoseconds).slice(-9)}Z`:{seconds:""+e.seconds,nanos:e.nanoseconds}}function Na(t,e){return t.gt?e.toBase64():e.toUint8Array()}function ka(t,e){return Ca(t,e.toTimestamp())}function Ra(t){return Bs(!!t),ar.fromTimestamp(function(t){const e=Zr(t);return new or(e.seconds,e.nanos)}(t))}function La(t,e){return function(t){return new cr(["projects",t.projectId,"databases",t.database])}(t).child("documents").child(e).canonicalString()}function Ma(t){const e=cr.fromString(t);return Bs(nu(e)),e}function Oa(t,e){return La(t.databaseId,e.path)}function Va(t,e){const n=Ma(e);if(n.get(1)!==t.databaseId.projectId)throw new js(Ks.INVALID_ARGUMENT,"Tried to deserialize key from different project: "+n.get(1)+" vs "+t.databaseId.projectId);if(n.get(3)!==t.databaseId.database)throw new js(Ks.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new dr(Ba(n))}function Fa(t,e){return La(t.databaseId,e)}function Pa(t){const e=Ma(t);return 4===e.length?cr.emptyPath():Ba(e)}function Ua(t){return new cr(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function Ba(t){return Bs(t.length>4&&"documents"===t.get(4)),t.popFirst(5)}function qa(t,e,n){return{name:Oa(t,e),fields:n.value.mapValue.fields}}function Ga(t,e,n){const s=Va(t,e.name),r=Ra(e.updateTime),i=new ki({mapValue:{fields:e.fields}}),o=Li.newFoundDocument(s,r,i);return n&&o.setHasCommittedMutations(),n?o.setHasCommittedMutations():o}function Ka(t,e){let n;if(e instanceof $o)n={update:qa(t,e.key,e.value)};else if(e instanceof Yo)n={delete:Oa(t,e.key)};else if(e instanceof Qo)n={update:qa(t,e.key,e.data),updateMask:eu(e.fieldMask)};else{if(!(e instanceof Xo))return Us();n={verify:Oa(t,e.key)}}return e.fieldTransforms.length>0&&(n.updateTransforms=e.fieldTransforms.map((t=>function(t,e){const n=e.transform;if(n instanceof xo)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof Ao)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof No)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof Ro)return{fieldPath:e.field.canonicalString(),increment:n.yt};throw Us()}(0,t)))),e.precondition.isNone||(n.currentDocument=function(t,e){return void 0!==e.updateTime?{updateTime:ka(t,e.updateTime)}:void 0!==e.exists?{exists:e.exists}:Us()}(t,e.precondition)),n}function ja(t,e){const n=e.currentDocument?function(t){return void 0!==t.updateTime?Fo.updateTime(Ra(t.updateTime)):void 0!==t.exists?Fo.exists(t.exists):Fo.none()}(e.currentDocument):Fo.none(),s=e.updateTransforms?e.updateTransforms.map((e=>function(t,e){let n=null;if("setToServerValue"in e)Bs("REQUEST_TIME"===e.setToServerValue),n=new xo;else if("appendMissingElements"in e){const t=e.appendMissingElements.values||[];n=new Ao(t)}else if("removeAllFromArray"in e){const t=e.removeAllFromArray.values||[];n=new No(t)}else"increment"in e?n=new Ro(t,e.increment):Us();const s=lr.fromServerFormat(e.fieldPath);return new Oo(s,n)}(t,e))):[];if(e.update){e.update.name;const r=Va(t,e.update.name),i=new ki({mapValue:{fields:e.update.fields}});if(e.updateMask){const t=function(t){const e=t.fieldPaths||[];return new Wr(e.map((t=>lr.fromServerFormat(t))))}(e.updateMask);return new Qo(r,i,t,n,s)}return new $o(r,i,n,s)}if(e.delete){const s=Va(t,e.delete);return new Yo(s,n)}if(e.verify){const s=Va(t,e.verify);return new Xo(s,n)}return Us()}function $a(t,e){return{documents:[Fa(t,e.path)]}}function Qa(t,e){const n={structuredQuery:{}},s=e.path;null!==e.collectionGroup?(n.parent=Fa(t,s),n.structuredQuery.from=[{collectionId:e.collectionGroup,allDescendants:!0}]):(n.parent=Fa(t,s.popLast()),n.structuredQuery.from=[{collectionId:s.lastSegment()}]);const r=function(t){if(0===t.length)return;const e=t.map((t=>function(t){if("=="===t.op){if(Ti(t.value))return{unaryFilter:{field:Xa(t.field),op:"IS_NAN"}};if(Ei(t.value))return{unaryFilter:{field:Xa(t.field),op:"IS_NULL"}}}else if("!="===t.op){if(Ti(t.value))return{unaryFilter:{field:Xa(t.field),op:"IS_NOT_NAN"}};if(Ei(t.value))return{unaryFilter:{field:Xa(t.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:Xa(t.field),op:Ya(t.op),value:t.value}}}(t)));return 1===e.length?e[0]:{compositeFilter:{op:"AND",filters:e}}}(e.filters);r&&(n.structuredQuery.where=r);const i=function(t){if(0!==t.length)return t.map((t=>function(t){return{field:Xa(t.field),direction:Wa(t.dir)}}(t)))}(e.orderBy);i&&(n.structuredQuery.orderBy=i);const o=function(t,e){return t.gt||ai(e)?e:{value:e}}(t,e.limit);var a;return null!==o&&(n.structuredQuery.limit=o),e.startAt&&(n.structuredQuery.startAt={before:(a=e.startAt).inclusive,values:a.position}),e.endAt&&(n.structuredQuery.endAt=function(t){return{before:!t.inclusive,values:t.position}}(e.endAt)),n}function za(t){let e=Pa(t.parent);const n=t.structuredQuery,s=n.from?n.from.length:0;let r=null;if(s>0){Bs(1===s);const t=n.from[0];t.allDescendants?r=t.collectionId:e=e.child(t.collectionId)}let i=[];n.where&&(i=Ha(n.where));let o=[];n.orderBy&&(o=n.orderBy.map((t=>function(t){return new Ji(Ja(t.field),function(t){switch(t){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}}(t.direction))}(t))));let a=null;n.limit&&(a=function(t){let e;return e="object"==typeof t?t.value:t,ai(e)?null:e}(n.limit));let u=null;n.startAt&&(u=function(t){const e=!!t.before,n=t.values||[];return new Xi(n,e)}(n.startAt));let c=null;return n.endAt&&(c=function(t){const e=!t.before,n=t.values||[];return new Xi(n,e)}(n.endAt)),so(e,r,o,i,a,"F",u,c)}function Ha(t){return t?void 0!==t.unaryFilter?[tu(t)]:void 0!==t.fieldFilter?[Za(t)]:void 0!==t.compositeFilter?t.compositeFilter.filters.map((t=>Ha(t))).reduce(((t,e)=>t.concat(e))):Us():[]}function Wa(t){return Da[t]}function Ya(t){return xa[t]}function Xa(t){return{fieldPath:t.canonicalString()}}function Ja(t){return lr.fromServerFormat(t.fieldPath)}function Za(t){return Gi.create(Ja(t.fieldFilter.field),function(t){switch(t){case"EQUAL":return"==";case"NOT_EQUAL":return"!=";case"GREATER_THAN":return">";case"GREATER_THAN_OR_EQUAL":return">=";case"LESS_THAN":return"<";case"LESS_THAN_OR_EQUAL":return"<=";case"ARRAY_CONTAINS":return"array-contains";case"IN":return"in";case"NOT_IN":return"not-in";case"ARRAY_CONTAINS_ANY":return"array-contains-any";default:return Us()}}(t.fieldFilter.op),t.fieldFilter.value)}function tu(t){switch(t.unaryFilter.op){case"IS_NAN":const e=Ja(t.unaryFilter.field);return Gi.create(e,"==",{doubleValue:NaN});case"IS_NULL":const n=Ja(t.unaryFilter.field);return Gi.create(n,"==",{nullValue:"NULL_VALUE"});case"IS_NOT_NAN":const s=Ja(t.unaryFilter.field);return Gi.create(s,"!=",{doubleValue:NaN});case"IS_NOT_NULL":const r=Ja(t.unaryFilter.field);return Gi.create(r,"!=",{nullValue:"NULL_VALUE"});default:return Us()}}function eu(t){const e=[];return t.fields.forEach((t=>e.push(t.canonicalString()))),{fieldPaths:e}}function nu(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)}function su(t){let e="";for(let n=0;n<t.length;n++)e.length>0&&(e=iu(e)),e=ru(t.get(n),e);return iu(e)}function ru(t,e){let n=e;const s=t.length;for(let e=0;e<s;e++){const s=t.charAt(e);switch(s){case"\0":n+="";break;case"":n+="";break;default:n+=s}}return n}function iu(t){return t+""}function ou(t){const e=t.length;if(Bs(e>=2),2===e)return Bs(""===t.charAt(0)&&""===t.charAt(1)),cr.emptyPath();const n=e-2,s=[];let r="";for(let i=0;i<e;){const e=t.indexOf("",i);switch((e<0||e>n)&&Us(),t.charAt(e+1)){case"":const n=t.substring(i,e);let o;0===r.length?o=n:(r+=n,o=r,r=""),s.push(o);break;case"":r+=t.substring(i,e),r+="\0";break;case"":r+=t.substring(i,e+1);break;default:Us()}i=e+2}return new cr(s)}const au=["userId","batchId"];function uu(t,e){return[t,su(e)]}function cu(t,e,n){return[t,su(e),n]}const hu={},lu=["prefixPath","collectionGroup","readTime","documentId"],du=["prefixPath","collectionGroup","documentId"],fu=["collectionGroup","readTime","prefixPath","documentId"],mu=["canonicalId","targetId"],gu=["targetId","path"],pu=["path","targetId"],yu=["collectionId","parent"],wu=["indexId","uid"],vu=["uid","sequenceNumber"],Iu=["indexId","uid","arrayValue","directionalValue","orderedDocumentKey","documentKey"],bu=["indexId","uid","orderedDocumentKey"],Eu=["userId","collectionPath","documentId"],Tu=["userId","collectionPath","largestBatchId"],Su=["userId","collectionGroup","largestBatchId"],_u=["mutationQueues","mutations","documentMutations","remoteDocuments","targets","owner","targetGlobal","targetDocuments","clientMetadata","remoteDocumentGlobal","collectionParents","bundles","namedQueries"],Du=[..._u,"documentOverlays"],xu=["mutationQueues","mutations","documentMutations","remoteDocumentsV14","targets","owner","targetGlobal","targetDocuments","clientMetadata","remoteDocumentGlobal","collectionParents","bundles","namedQueries","documentOverlays"],Au=xu,Cu=[...Au,"indexConfiguration","indexState","indexEntries"];class Nu extends _r{constructor(t,e){super(),this.ie=t,this.currentSequenceNumber=e}}function ku(t,e){const n=Gs(t);return Cr.M(n.ie,e)}class Ru{constructor(t,e,n,s){this.batchId=t,this.localWriteTime=e,this.baseMutations=n,this.mutations=s}applyToRemoteDocument(t,e){const n=e.mutationResults;for(let e=0;e<this.mutations.length;e++){const s=this.mutations[e];s.key.isEqual(t.key)&&qo(s,t,n[e])}}applyToLocalView(t,e){for(const n of this.baseMutations)n.key.isEqual(t.key)&&(e=Go(n,t,e,this.localWriteTime));for(const n of this.mutations)n.key.isEqual(t.key)&&(e=Go(n,t,e,this.localWriteTime));return e}applyToLocalDocumentSet(t,e){const n=ha();return this.mutations.forEach((s=>{const r=t.get(s.key),i=r.overlayedDocument;let o=this.applyToLocalView(i,r.mutatedFields);o=e.has(s.key)?null:o;const a=Bo(i,o);null!==a&&n.set(s.key,a),i.isValidDocument()||i.convertToNoDocument(ar.min())})),n}keys(){return this.mutations.reduce(((t,e)=>t.add(e.key)),ma())}isEqual(t){return this.batchId===t.batchId&&rr(this.mutations,t.mutations,((t,e)=>jo(t,e)))&&rr(this.baseMutations,t.baseMutations,((t,e)=>jo(t,e)))}}class Lu{constructor(t,e,n,s){this.batch=t,this.commitVersion=e,this.mutationResults=n,this.docVersions=s}static from(t,e,n){Bs(t.mutations.length===n.length);let s=da;const r=t.mutations;for(let t=0;t<r.length;t++)s=s.insert(r[t].key,n[t].version);return new Lu(t,e,n,s)}}class Mu{constructor(t,e){this.largestBatchId=t,this.mutation=e}getKey(){return this.mutation.key}isEqual(t){return null!==t&&this.mutation===t.mutation}toString(){return`Overlay{\n largestBatchId: ${this.largestBatchId},\n mutation: ${this.mutation.toString()}\n }`}}class Ou{constructor(t,e,n,s,r=ar.min(),i=ar.min(),o=Xr.EMPTY_BYTE_STRING){this.target=t,this.targetId=e,this.purpose=n,this.sequenceNumber=s,this.snapshotVersion=r,this.lastLimboFreeSnapshotVersion=i,this.resumeToken=o}withSequenceNumber(t){return new Ou(this.target,this.targetId,this.purpose,t,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken)}withResumeToken(t,e){return new Ou(this.target,this.targetId,this.purpose,this.sequenceNumber,e,this.lastLimboFreeSnapshotVersion,t)}withLastLimboFreeSnapshotVersion(t){return new Ou(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,t,this.resumeToken)}}class Vu{constructor(t){this.re=t}}function Fu(t,e){const n=e.key,s={prefixPath:n.getCollectionPath().popLast().toArray(),collectionGroup:n.collectionGroup,documentId:n.path.lastSegment(),readTime:Pu(e.readTime),hasCommittedMutations:e.hasCommittedMutations};if(e.isFoundDocument())s.document=function(t,e){return{name:Oa(t,e.key),fields:e.data.value.mapValue.fields,updateTime:Ca(t,e.version.toTimestamp())}}(t.re,e);else if(e.isNoDocument())s.noDocument={path:n.path.toArray(),readTime:Uu(e.version)};else{if(!e.isUnknownDocument())return Us();s.unknownDocument={path:n.path.toArray(),version:Uu(e.version)}}return s}function Pu(t){const e=t.toTimestamp();return[e.seconds,e.nanoseconds]}function Uu(t){const e=t.toTimestamp();return{seconds:e.seconds,nanoseconds:e.nanoseconds}}function Bu(t){const e=new or(t.seconds,t.nanoseconds);return ar.fromTimestamp(e)}function qu(t,e){const n=(e.baseMutations||[]).map((e=>ja(t.re,e)));for(let t=0;t<e.mutations.length-1;++t){const n=e.mutations[t];if(t+1<e.mutations.length&&void 0!==e.mutations[t+1].transform){const s=e.mutations[t+1];n.updateTransforms=s.transform.fieldTransforms,e.mutations.splice(t+1,1),++t}}const s=e.mutations.map((e=>ja(t.re,e))),r=or.fromMillis(e.localWriteTimeMs);return new Ru(e.batchId,r,n,s)}function Gu(t){const e=Bu(t.readTime),n=void 0!==t.lastLimboFreeSnapshotVersion?Bu(t.lastLimboFreeSnapshotVersion):ar.min();let s;var r;return void 0!==t.query.documents?(Bs(1===(r=t.query).documents.length),s=ho(ro(Pa(r.documents[0])))):s=function(t){return ho(za(t))}(t.query),new Ou(s,t.targetId,0,t.lastListenSequenceNumber,e,n,Xr.fromBase64String(t.resumeToken))}function Ku(t,e){const n=Uu(e.snapshotVersion),s=Uu(e.lastLimboFreeSnapshotVersion);let r;r=Pi(e.target)?$a(t.re,e.target):Qa(t.re,e.target);const i=e.resumeToken.toBase64();return{targetId:e.targetId,canonicalId:Vi(e.target),readTime:n,resumeToken:i,lastListenSequenceNumber:e.sequenceNumber,lastLimboFreeSnapshotVersion:s,query:r}}function ju(t){const e=za({parent:t.parent,structuredQuery:t.structuredQuery});return"LAST"===t.limitType?lo(e,e.limit,"L"):e}function $u(t,e){return new Mu(e.largestBatchId,ja(t.re,e.overlayMutation))}function Qu(t,e){const n=e.path.lastSegment();return[t,su(e.path.popLast()),n]}function zu(t,e,n,s){return{indexId:t,uid:e.uid||"",sequenceNumber:n,readTime:Uu(s.readTime),documentKey:su(s.documentKey.path),largestBatchId:s.largestBatchId}}class Hu{getBundleMetadata(t,e){return Wu(t).get(e).next((t=>{if(t)return{id:(e=t).bundleId,createTime:Bu(e.createTime),version:e.version};var e}))}saveBundleMetadata(t,e){return Wu(t).put({bundleId:(n=e).id,createTime:Uu(Ra(n.createTime)),version:n.version});var n}getNamedQuery(t,e){return Yu(t).get(e).next((t=>{if(t)return{name:(e=t).name,query:ju(e.bundledQuery),readTime:Bu(e.readTime)};var e}))}saveNamedQuery(t,e){return Yu(t).put(function(t){return{name:t.name,readTime:Uu(Ra(t.readTime)),bundledQuery:t.bundledQuery}}(e))}}function Wu(t){return ku(t,"bundles")}function Yu(t){return ku(t,"namedQueries")}class Xu{constructor(t,e){this.It=t,this.userId=e}static oe(t,e){const n=e.uid||"";return new Xu(t,n)}getOverlay(t,e){return Ju(t).get(Qu(this.userId,e)).next((t=>t?$u(this.It,t):null))}getOverlays(t,e){const n=ca();return xr.forEach(e,(e=>this.getOverlay(t,e).next((t=>{null!==t&&n.set(e,t)})))).next((()=>n))}saveOverlays(t,e,n){const s=[];return n.forEach(((n,r)=>{const i=new Mu(e,r);s.push(this.ue(t,i))})),xr.waitFor(s)}removeOverlaysForBatchId(t,e,n){const s=new Set;e.forEach((t=>s.add(su(t.getCollectionPath()))));const r=[];return s.forEach((e=>{const s=IDBKeyRange.bound([this.userId,e,n],[this.userId,e,n+1],!1,!0);r.push(Ju(t).Y("collectionPathOverlayIndex",s))})),xr.waitFor(r)}getOverlaysForCollection(t,e,n){const s=ca(),r=su(e),i=IDBKeyRange.bound([this.userId,r,n],[this.userId,r,Number.POSITIVE_INFINITY],!0);return Ju(t).W("collectionPathOverlayIndex",i).next((t=>{for(const e of t){const t=$u(this.It,e);s.set(t.getKey(),t)}return s}))}getOverlaysForCollectionGroup(t,e,n,s){const r=ca();let i;const o=IDBKeyRange.bound([this.userId,e,n],[this.userId,e,Number.POSITIVE_INFINITY],!0);return Ju(t).Z({index:"collectionGroupOverlayIndex",range:o},((t,e,n)=>{const o=$u(this.It,e);r.size()<s||o.largestBatchId===i?(r.set(o.getKey(),o),i=o.largestBatchId):n.done()})).next((()=>r))}ue(t,e){return Ju(t).put(function(t,e,n){const[s,r,i]=Qu(e,n.mutation.key);return{userId:e,collectionPath:r,documentId:i,collectionGroup:n.mutation.key.getCollectionGroup(),largestBatchId:n.largestBatchId,overlayMutation:Ka(t.re,n.mutation)}}(this.It,this.userId,e))}}function Ju(t){return ku(t,"documentOverlays")}class Zu{constructor(){}ce(t,e){this.ae(t,e),e.he()}ae(t,e){if("nullValue"in t)this.le(e,5);else if("booleanValue"in t)this.le(e,10),e.fe(t.booleanValue?1:0);else if("integerValue"in t)this.le(e,15),e.fe(ti(t.integerValue));else if("doubleValue"in t){const n=ti(t.doubleValue);isNaN(n)?this.le(e,13):(this.le(e,15),ui(n)?e.fe(0):e.fe(n))}else if("timestampValue"in t){const n=t.timestampValue;this.le(e,20),"string"==typeof n?e.de(n):(e.de(`${n.seconds||""}`),e.fe(n.nanos||0))}else if("stringValue"in t)this._e(t.stringValue,e),this.we(e);else if("bytesValue"in t)this.le(e,30),e.me(ei(t.bytesValue)),this.we(e);else if("referenceValue"in t)this.ge(t.referenceValue,e);else if("geoPointValue"in t){const n=t.geoPointValue;this.le(e,45),e.fe(n.latitude||0),e.fe(n.longitude||0)}else"mapValue"in t?Di(t)?this.le(e,Number.MAX_SAFE_INTEGER):(this.ye(t.mapValue,e),this.we(e)):"arrayValue"in t?(this.pe(t.arrayValue,e),this.we(e)):Us()}_e(t,e){this.le(e,25),this.Ie(t,e)}Ie(t,e){e.de(t)}ye(t,e){const n=t.fields||{};this.le(e,55);for(const t of Object.keys(n))this._e(t,e),this.ae(n[t],e)}pe(t,e){const n=t.values||[];this.le(e,50);for(const t of n)this.ae(t,e)}ge(t,e){this.le(e,37),dr.fromName(t).path.forEach((t=>{this.le(e,60),this.Ie(t,e)}))}le(t,e){t.fe(e)}we(t){t.fe(2)}}function tc(t){if(0===t)return 8;let e=0;return t>>4==0&&(e+=4,t<<=4),t>>6==0&&(e+=2,t<<=2),t>>7==0&&(e+=1),e}function ec(t){const e=64-function(t){let e=0;for(let n=0;n<8;++n){const s=tc(255&t[n]);if(e+=s,8!==s)break}return e}(t);return Math.ceil(e/8)}Zu.Te=new Zu;class nc{constructor(){this.buffer=new Uint8Array(1024),this.position=0}Ee(t){const e=t[Symbol.iterator]();let n=e.next();for(;!n.done;)this.Ae(n.value),n=e.next();this.Re()}be(t){const e=t[Symbol.iterator]();let n=e.next();for(;!n.done;)this.Pe(n.value),n=e.next();this.ve()}Ve(t){for(const e of t){const t=e.charCodeAt(0);if(t<128)this.Ae(t);else if(t<2048)this.Ae(960|t>>>6),this.Ae(128|63&t);else if(e<"\ud800"||"\udbff"<e)this.Ae(480|t>>>12),this.Ae(128|63&t>>>6),this.Ae(128|63&t);else{const t=e.codePointAt(0);this.Ae(240|t>>>18),this.Ae(128|63&t>>>12),this.Ae(128|63&t>>>6),this.Ae(128|63&t)}}this.Re()}Se(t){for(const e of t){const t=e.charCodeAt(0);if(t<128)this.Pe(t);else if(t<2048)this.Pe(960|t>>>6),this.Pe(128|63&t);else if(e<"\ud800"||"\udbff"<e)this.Pe(480|t>>>12),this.Pe(128|63&t>>>6),this.Pe(128|63&t);else{const t=e.codePointAt(0);this.Pe(240|t>>>18),this.Pe(128|63&t>>>12),this.Pe(128|63&t>>>6),this.Pe(128|63&t)}}this.ve()}De(t){const e=this.Ce(t),n=ec(e);this.xe(1+n),this.buffer[this.position++]=255&n;for(let t=e.length-n;t<e.length;++t)this.buffer[this.position++]=255&e[t]}Ne(t){const e=this.Ce(t),n=ec(e);this.xe(1+n),this.buffer[this.position++]=~(255&n);for(let t=e.length-n;t<e.length;++t)this.buffer[this.position++]=~(255&e[t])}ke(){this.Oe(255),this.Oe(255)}Me(){this.Fe(255),this.Fe(255)}reset(){this.position=0}seed(t){this.xe(t.length),this.buffer.set(t,this.position),this.position+=t.length}$e(){return this.buffer.slice(0,this.position)}Ce(t){const e=function(t){const e=new DataView(new ArrayBuffer(8));return e.setFloat64(0,t,!1),new Uint8Array(e.buffer)}(t),n=0!=(128&e[0]);e[0]^=n?255:128;for(let t=1;t<e.length;++t)e[t]^=n?255:0;return e}Ae(t){const e=255&t;0===e?(this.Oe(0),this.Oe(255)):255===e?(this.Oe(255),this.Oe(0)):this.Oe(e)}Pe(t){const e=255&t;0===e?(this.Fe(0),this.Fe(255)):255===e?(this.Fe(255),this.Fe(0)):this.Fe(t)}Re(){this.Oe(0),this.Oe(1)}ve(){this.Fe(0),this.Fe(1)}Oe(t){this.xe(1),this.buffer[this.position++]=t}Fe(t){this.xe(1),this.buffer[this.position++]=~t}xe(t){const e=t+this.position;if(e<=this.buffer.length)return;let n=2*this.buffer.length;n<e&&(n=e);const s=new Uint8Array(n);s.set(this.buffer),this.buffer=s}}class sc{constructor(t){this.Be=t}me(t){this.Be.Ee(t)}de(t){this.Be.Ve(t)}fe(t){this.Be.De(t)}he(){this.Be.ke()}}class rc{constructor(t){this.Be=t}me(t){this.Be.be(t)}de(t){this.Be.Se(t)}fe(t){this.Be.Ne(t)}he(){this.Be.Me()}}class ic{constructor(){this.Be=new nc,this.Le=new sc(this.Be),this.Ue=new rc(this.Be)}seed(t){this.Be.seed(t)}qe(t){return 0===t?this.Le:this.Ue}$e(){return this.Be.$e()}reset(){this.Be.reset()}}class oc{constructor(t,e,n,s){this.indexId=t,this.documentKey=e,this.arrayValue=n,this.directionalValue=s}Ke(){const t=this.directionalValue.length,e=0===t||255===this.directionalValue[t-1]?t+1:t,n=new Uint8Array(e);return n.set(this.directionalValue,0),e!==t?n.set([0],this.directionalValue.length):++n[n.length-1],new oc(this.indexId,this.documentKey,this.arrayValue,n)}}function ac(t,e){let n=t.indexId-e.indexId;return 0!==n?n:(n=uc(t.arrayValue,e.arrayValue),0!==n?n:(n=uc(t.directionalValue,e.directionalValue),0!==n?n:dr.comparator(t.documentKey,e.documentKey)))}function uc(t,e){for(let n=0;n<t.length&&n<e.length;++n){const s=t[n]-e[n];if(0!==s)return s}return t.length-e.length}class cc{constructor(t){this.collectionId=null!=t.collectionGroup?t.collectionGroup:t.path.lastSegment(),this.Ge=t.orderBy,this.Qe=[];for(const e of t.filters){const t=e;t.dt()?this.je=t:this.Qe.push(t)}}We(t){const e=mr(t);if(void 0!==e&&!this.ze(e))return!1;const n=gr(t);let s=0,r=0;for(;s<n.length&&this.ze(n[s]);++s);if(s===n.length)return!0;if(void 0!==this.je){const t=n[s];if(!this.He(this.je,t)||!this.Je(this.Ge[r++],t))return!1;++s}for(;s<n.length;++s){const t=n[s];if(r>=this.Ge.length||!this.Je(this.Ge[r++],t))return!1}return!0}ze(t){for(const e of this.Qe)if(this.He(e,t))return!0;return!1}He(t,e){if(void 0===t||!t.field.isEqual(e.fieldPath))return!1;const n="array-contains"===t.op||"array-contains-any"===t.op;return 2===e.kind===n}Je(t,e){return!!t.field.isEqual(e.fieldPath)&&(0===e.kind&&"asc"===t.dir||1===e.kind&&"desc"===t.dir)}}class hc{constructor(){this.Ye=new lc}addToCollectionParentIndex(t,e){return this.Ye.add(e),xr.resolve()}getCollectionParents(t,e){return xr.resolve(this.Ye.getEntries(e))}addFieldIndex(t,e){return xr.resolve()}deleteFieldIndex(t,e){return xr.resolve()}getDocumentsMatchingTarget(t,e){return xr.resolve(null)}getIndexType(t,e){return xr.resolve(0)}getFieldIndexes(t,e){return xr.resolve([])}getNextCollectionGroupToUpdate(t){return xr.resolve(null)}getMinOffset(t,e){return xr.resolve(Er.min())}getMinOffsetFromCollectionGroup(t,e){return xr.resolve(Er.min())}updateCollectionGroup(t,e,n){return xr.resolve()}updateIndexEntries(t,e){return xr.resolve()}}class lc{constructor(){this.index={}}add(t){const e=t.lastSegment(),n=t.popLast(),s=this.index[e]||new Qr(cr.comparator),r=!s.has(n);return this.index[e]=s.add(n),r}has(t){const e=t.lastSegment(),n=t.popLast(),s=this.index[e];return s&&s.has(n)}getEntries(t){return(this.index[t]||new Qr(cr.comparator)).toArray()}}const dc=new Uint8Array(0);class fc{constructor(t,e){this.user=t,this.databaseId=e,this.Xe=new lc,this.Ze=new sa((t=>Vi(t)),((t,e)=>Fi(t,e))),this.uid=t.uid||""}addToCollectionParentIndex(t,e){if(!this.Xe.has(e)){const n=e.lastSegment(),s=e.popLast();t.addOnCommittedListener((()=>{this.Xe.add(e)}));const r={collectionId:n,parent:su(s)};return mc(t).put(r)}return xr.resolve()}getCollectionParents(t,e){const n=[],s=IDBKeyRange.bound([e,""],[ir(e),""],!1,!0);return mc(t).W(s).next((t=>{for(const s of t){if(s.collectionId!==e)break;n.push(ou(s.parent))}return n}))}addFieldIndex(t,e){const n=pc(t),s=function(t){return{indexId:t.indexId,collectionGroup:t.collectionGroup,fields:t.fields.map((t=>[t.fieldPath.canonicalString(),t.kind]))}}(e);delete s.indexId;const r=n.add(s);if(e.indexState){const n=yc(t);return r.next((t=>{n.put(zu(t,this.user,e.indexState.sequenceNumber,e.indexState.offset))}))}return r.next()}deleteFieldIndex(t,e){const n=pc(t),s=yc(t),r=gc(t);return n.delete(e.indexId).next((()=>s.delete(IDBKeyRange.bound([e.indexId],[e.indexId+1],!1,!0)))).next((()=>r.delete(IDBKeyRange.bound([e.indexId],[e.indexId+1],!1,!0))))}getDocumentsMatchingTarget(t,e){const n=gc(t);let s=!0;const r=new Map;return xr.forEach(this.tn(e),(e=>this.en(t,e).next((t=>{s&&(s=!!t),r.set(e,t)})))).next((()=>{if(s){let t=ma();const s=[];return xr.forEach(r,((r,i)=>{var o;Os("IndexedDbIndexManager",`Using index ${o=r,`id=${o.indexId}|cg=${o.collectionGroup}|f=${o.fields.map((t=>`${t.fieldPath}:${t.kind}`)).join(",")}`} to execute ${Vi(e)}`);const a=function(t,e){const n=mr(e);if(void 0===n)return null;for(const e of Ui(t,n.fieldPath))switch(e.op){case"array-contains-any":return e.value.arrayValue.values||[];case"array-contains":return[e.value]}return null}(i,r),u=function(t,e){const n=new Map;for(const s of gr(e))for(const e of Ui(t,s.fieldPath))switch(e.op){case"==":case"in":n.set(s.fieldPath.canonicalString(),e.value);break;case"not-in":case"!=":return n.set(s.fieldPath.canonicalString(),e.value),Array.from(n.values())}return null}(i,r),c=function(t,e){const n=[];let s=!0;for(const r of gr(e)){const e=0===r.kind?Bi(t,r.fieldPath,t.startAt):qi(t,r.fieldPath,t.startAt);n.push(e.value),s&&(s=e.inclusive)}return new Xi(n,s)}(i,r),h=function(t,e){const n=[];let s=!0;for(const r of gr(e)){const e=0===r.kind?qi(t,r.fieldPath,t.endAt):Bi(t,r.fieldPath,t.endAt);n.push(e.value),s&&(s=e.inclusive)}return new Xi(n,s)}(i,r),l=this.nn(r,i,c),d=this.nn(r,i,h),f=this.sn(r,i,u),m=this.rn(r.indexId,a,l,c.inclusive,d,h.inclusive,f);return xr.forEach(m,(r=>n.J(r,e.limit).next((e=>{e.forEach((e=>{const n=dr.fromSegments(e.documentKey);t.has(n)||(t=t.add(n),s.push(n))}))}))))})).next((()=>s))}return xr.resolve(null)}))}tn(t){let e=this.Ze.get(t);return e||(e=[t],this.Ze.set(t,e),e)}rn(t,e,n,s,r,i,o){const a=(null!=e?e.length:1)*Math.max(n.length,r.length),u=a/(null!=e?e.length:1),c=[];for(let h=0;h<a;++h){const a=e?this.on(e[h/u]):dc,l=this.un(t,a,n[h%u],s),d=this.cn(t,a,r[h%u],i),f=o.map((e=>this.un(t,a,e,!0)));c.push(...this.createRange(l,d,f))}return c}un(t,e,n,s){const r=new oc(t,dr.empty(),e,n);return s?r:r.Ke()}cn(t,e,n,s){const r=new oc(t,dr.empty(),e,n);return s?r.Ke():r}en(t,e){const n=new cc(e),s=null!=e.collectionGroup?e.collectionGroup:e.path.lastSegment();return this.getFieldIndexes(t,s).next((t=>{let e=null;for(const s of t)n.We(s)&&(!e||s.fields.length>e.fields.length)&&(e=s);return e}))}getIndexType(t,e){let n=2;return xr.forEach(this.tn(e),(e=>this.en(t,e).next((t=>{t?0!==n&&t.fields.length<function(t){let e=new Qr(lr.comparator),n=!1;for(const s of t.filters){const t=s;t.field.isKeyField()||("array-contains"===t.op||"array-contains-any"===t.op?n=!0:e=e.add(t.field))}for(const n of t.orderBy)n.field.isKeyField()||(e=e.add(n.field));return e.size+(n?1:0)}(e)&&(n=1):n=0})))).next((()=>n))}an(t,e){const n=new ic;for(const s of gr(t)){const t=e.data.field(s.fieldPath);if(null==t)return null;const r=n.qe(s.kind);Zu.Te.ce(t,r)}return n.$e()}on(t){const e=new ic;return Zu.Te.ce(t,e.qe(0)),e.$e()}hn(t,e){const n=new ic;return Zu.Te.ce(vi(this.databaseId,e),n.qe(function(t){const e=gr(t);return 0===e.length?0:e[e.length-1].kind}(t))),n.$e()}sn(t,e,n){if(null===n)return[];let s=[];s.push(new ic);let r=0;for(const i of gr(t)){const t=n[r++];for(const n of s)if(this.ln(e,i.fieldPath)&&bi(t))s=this.fn(s,i,t);else{const e=n.qe(i.kind);Zu.Te.ce(t,e)}}return this.dn(s)}nn(t,e,n){return this.sn(t,e,n.position)}dn(t){const e=[];for(let n=0;n<t.length;++n)e[n]=t[n].$e();return e}fn(t,e,n){const s=[...t],r=[];for(const t of n.arrayValue.values||[])for(const n of s){const s=new ic;s.seed(n.$e()),Zu.Te.ce(t,s.qe(e.kind)),r.push(s)}return r}ln(t,e){return!!t.filters.find((t=>t instanceof Gi&&t.field.isEqual(e)&&("in"===t.op||"not-in"===t.op)))}getFieldIndexes(t,e){const n=pc(t),s=yc(t);return(e?n.W("collectionGroupIndex",IDBKeyRange.bound(e,e)):n.W()).next((t=>{const e=[];return xr.forEach(t,(t=>s.get([t.indexId,this.uid]).next((n=>{e.push(function(t,e){const n=e?new vr(e.sequenceNumber,new Er(Bu(e.readTime),new dr(ou(e.documentKey)),e.largestBatchId)):vr.empty(),s=t.fields.map((([t,e])=>new yr(lr.fromServerFormat(t),e)));return new fr(t.indexId,t.collectionGroup,s,n)}(t,n))})))).next((()=>e))}))}getNextCollectionGroupToUpdate(t){return this.getFieldIndexes(t).next((t=>0===t.length?null:(t.sort(((t,e)=>{const n=t.indexState.sequenceNumber-e.indexState.sequenceNumber;return 0!==n?n:sr(t.collectionGroup,e.collectionGroup)})),t[0].collectionGroup)))}updateCollectionGroup(t,e,n){const s=pc(t),r=yc(t);return this._n(t).next((t=>s.W("collectionGroupIndex",IDBKeyRange.bound(e,e)).next((e=>xr.forEach(e,(e=>r.put(zu(e.indexId,this.user,t,n))))))))}updateIndexEntries(t,e){const n=new Map;return xr.forEach(e,((e,s)=>{const r=n.get(e.collectionGroup);return(r?xr.resolve(r):this.getFieldIndexes(t,e.collectionGroup)).next((r=>(n.set(e.collectionGroup,r),xr.forEach(r,(n=>this.wn(t,e,n).next((e=>{const r=this.mn(s,n);return e.isEqual(r)?xr.resolve():this.gn(t,s,n,e,r)})))))))}))}yn(t,e,n,s){return gc(t).put({indexId:s.indexId,uid:this.uid,arrayValue:s.arrayValue,directionalValue:s.directionalValue,orderedDocumentKey:this.hn(n,e.key),documentKey:e.key.path.toArray()})}pn(t,e,n,s){return gc(t).delete([s.indexId,this.uid,s.arrayValue,s.directionalValue,this.hn(n,e.key),e.key.path.toArray()])}wn(t,e,n){const s=gc(t);let r=new Qr(ac);return s.Z({index:"documentKeyIndex",range:IDBKeyRange.only([n.indexId,this.uid,this.hn(n,e)])},((t,s)=>{r=r.add(new oc(n.indexId,e,s.arrayValue,s.directionalValue))})).next((()=>r))}mn(t,e){let n=new Qr(ac);const s=this.an(e,t);if(null==s)return n;const r=mr(e);if(null!=r){const i=t.data.field(r.fieldPath);if(bi(i))for(const r of i.arrayValue.values||[])n=n.add(new oc(e.indexId,t.key,this.on(r),s))}else n=n.add(new oc(e.indexId,t.key,dc,s));return n}gn(t,e,n,s,r){Os("IndexedDbIndexManager","Updating index entries for document '%s'",e.key);const i=[];return function(t,e,n,s,r){const i=t.getIterator(),o=e.getIterator();let a=Hr(i),u=Hr(o);for(;a||u;){let t=!1,e=!1;if(a&&u){const s=n(a,u);s<0?e=!0:s>0&&(t=!0)}else null!=a?e=!0:t=!0;t?(s(u),u=Hr(o)):e?(r(a),a=Hr(i)):(a=Hr(i),u=Hr(o))}}(s,r,ac,(s=>{i.push(this.yn(t,e,n,s))}),(s=>{i.push(this.pn(t,e,n,s))})),xr.waitFor(i)}_n(t){let e=1;return yc(t).Z({index:"sequenceNumberIndex",reverse:!0,range:IDBKeyRange.upperBound([this.uid,Number.MAX_SAFE_INTEGER])},((t,n,s)=>{s.done(),e=n.sequenceNumber+1})).next((()=>e))}createRange(t,e,n){n=n.sort(((t,e)=>ac(t,e))).filter(((t,e,n)=>!e||0!==ac(t,n[e-1])));const s=[];s.push(t);for(const r of n){const n=ac(r,t),i=ac(r,e);if(0===n)s[0]=t.Ke();else if(n>0&&i<0)s.push(r),s.push(r.Ke());else if(i>0)break}s.push(e);const r=[];for(let t=0;t<s.length;t+=2)r.push(IDBKeyRange.bound([s[t].indexId,this.uid,s[t].arrayValue,s[t].directionalValue,dc,[]],[s[t+1].indexId,this.uid,s[t+1].arrayValue,s[t+1].directionalValue,dc,[]]));return r}getMinOffsetFromCollectionGroup(t,e){return this.getFieldIndexes(t,e).next(wc)}getMinOffset(t,e){return xr.mapArray(this.tn(e),(e=>this.en(t,e).next((t=>t||Us())))).next(wc)}}function mc(t){return ku(t,"collectionParents")}function gc(t){return ku(t,"indexEntries")}function pc(t){return ku(t,"indexConfiguration")}function yc(t){return ku(t,"indexState")}function wc(t){Bs(0!==t.length);let e=t[0].indexState.offset,n=e.largestBatchId;for(let s=1;s<t.length;s++){const r=t[s].indexState.offset;Tr(r,e)<0&&(e=r),n<r.largestBatchId&&(n=r.largestBatchId)}return new Er(e.readTime,e.documentKey,n)}const vc={didRun:!1,sequenceNumbersCollected:0,targetsRemoved:0,documentsRemoved:0};class Ic{constructor(t,e,n){this.cacheSizeCollectionThreshold=t,this.percentileToCollect=e,this.maximumSequenceNumbersToCollect=n}static withCacheSize(t){return new Ic(t,Ic.DEFAULT_COLLECTION_PERCENTILE,Ic.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)}}function bc(t,e,n){const s=t.store("mutations"),r=t.store("documentMutations"),i=[],o=IDBKeyRange.only(n.batchId);let a=0;const u=s.Z({range:o},((t,e,n)=>(a++,n.delete())));i.push(u.next((()=>{Bs(1===a)})));const c=[];for(const t of n.mutations){const s=cu(e,t.key.path,n.batchId);i.push(r.delete(s)),c.push(t.key)}return xr.waitFor(i).next((()=>c))}function Ec(t){if(!t)return 0;let e;if(t.document)e=t.document;else if(t.unknownDocument)e=t.unknownDocument;else{if(!t.noDocument)throw Us();e=t.noDocument}return JSON.stringify(e).length}Ic.DEFAULT_COLLECTION_PERCENTILE=10,Ic.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,Ic.DEFAULT=new Ic(41943040,Ic.DEFAULT_COLLECTION_PERCENTILE,Ic.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),Ic.DISABLED=new Ic(-1,0,0);class Tc{constructor(t,e,n,s){this.userId=t,this.It=e,this.indexManager=n,this.referenceDelegate=s,this.In={}}static oe(t,e,n,s){Bs(""!==t.uid);const r=t.isAuthenticated()?t.uid:"";return new Tc(r,e,n,s)}checkEmpty(t){let e=!0;const n=IDBKeyRange.bound([this.userId,Number.NEGATIVE_INFINITY],[this.userId,Number.POSITIVE_INFINITY]);return _c(t).Z({index:"userMutationsIndex",range:n},((t,n,s)=>{e=!1,s.done()})).next((()=>e))}addMutationBatch(t,e,n,s){const r=Dc(t),i=_c(t);return i.add({}).next((o=>{Bs("number"==typeof o);const a=new Ru(o,e,n,s),u=function(t,e,n){const s=n.baseMutations.map((e=>Ka(t.re,e))),r=n.mutations.map((e=>Ka(t.re,e)));return{userId:e,batchId:n.batchId,localWriteTimeMs:n.localWriteTime.toMillis(),baseMutations:s,mutations:r}}(this.It,this.userId,a),c=[];let h=new Qr(((t,e)=>sr(t.canonicalString(),e.canonicalString())));for(const t of s){const e=cu(this.userId,t.key.path,o);h=h.add(t.key.path.popLast()),c.push(i.put(u)),c.push(r.put(e,hu))}return h.forEach((e=>{c.push(this.indexManager.addToCollectionParentIndex(t,e))})),t.addOnCommittedListener((()=>{this.In[o]=a.keys()})),xr.waitFor(c).next((()=>a))}))}lookupMutationBatch(t,e){return _c(t).get(e).next((t=>t?(Bs(t.userId===this.userId),qu(this.It,t)):null))}Tn(t,e){return this.In[e]?xr.resolve(this.In[e]):this.lookupMutationBatch(t,e).next((t=>{if(t){const n=t.keys();return this.In[e]=n,n}return null}))}getNextMutationBatchAfterBatchId(t,e){const n=e+1,s=IDBKeyRange.lowerBound([this.userId,n]);let r=null;return _c(t).Z({index:"userMutationsIndex",range:s},((t,e,s)=>{e.userId===this.userId&&(Bs(e.batchId>=n),r=qu(this.It,e)),s.done()})).next((()=>r))}getHighestUnacknowledgedBatchId(t){const e=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]);let n=-1;return _c(t).Z({index:"userMutationsIndex",range:e,reverse:!0},((t,e,s)=>{n=e.batchId,s.done()})).next((()=>n))}getAllMutationBatches(t){const e=IDBKeyRange.bound([this.userId,-1],[this.userId,Number.POSITIVE_INFINITY]);return _c(t).W("userMutationsIndex",e).next((t=>t.map((t=>qu(this.It,t)))))}getAllMutationBatchesAffectingDocumentKey(t,e){const n=uu(this.userId,e.path),s=IDBKeyRange.lowerBound(n),r=[];return Dc(t).Z({range:s},((n,s,i)=>{const[o,a,u]=n,c=ou(a);if(o===this.userId&&e.path.isEqual(c))return _c(t).get(u).next((t=>{if(!t)throw Us();Bs(t.userId===this.userId),r.push(qu(this.It,t))}));i.done()})).next((()=>r))}getAllMutationBatchesAffectingDocumentKeys(t,e){let n=new Qr(sr);const s=[];return e.forEach((e=>{const r=uu(this.userId,e.path),i=IDBKeyRange.lowerBound(r),o=Dc(t).Z({range:i},((t,s,r)=>{const[i,o,a]=t,u=ou(o);i===this.userId&&e.path.isEqual(u)?n=n.add(a):r.done()}));s.push(o)})),xr.waitFor(s).next((()=>this.En(t,n)))}getAllMutationBatchesAffectingQuery(t,e){const n=e.path,s=n.length+1,r=uu(this.userId,n),i=IDBKeyRange.lowerBound(r);let o=new Qr(sr);return Dc(t).Z({range:i},((t,e,r)=>{const[i,a,u]=t,c=ou(a);i===this.userId&&n.isPrefixOf(c)?c.length===s&&(o=o.add(u)):r.done()})).next((()=>this.En(t,o)))}En(t,e){const n=[],s=[];return e.forEach((e=>{s.push(_c(t).get(e).next((t=>{if(null===t)throw Us();Bs(t.userId===this.userId),n.push(qu(this.It,t))})))})),xr.waitFor(s).next((()=>n))}removeMutationBatch(t,e){return bc(t.ie,this.userId,e).next((n=>(t.addOnCommittedListener((()=>{this.An(e.batchId)})),xr.forEach(n,(e=>this.referenceDelegate.markPotentiallyOrphaned(t,e))))))}An(t){delete this.In[t]}performConsistencyCheck(t){return this.checkEmpty(t).next((e=>{if(!e)return xr.resolve();const n=IDBKeyRange.lowerBound([this.userId]),s=[];return Dc(t).Z({range:n},((t,e,n)=>{if(t[0]===this.userId){const e=ou(t[1]);s.push(e)}else n.done()})).next((()=>{Bs(0===s.length)}))}))}containsKey(t,e){return Sc(t,this.userId,e)}Rn(t){return xc(t).get(this.userId).next((t=>t||{userId:this.userId,lastAcknowledgedBatchId:-1,lastStreamToken:""}))}}function Sc(t,e,n){const s=uu(e,n.path),r=s[1],i=IDBKeyRange.lowerBound(s);let o=!1;return Dc(t).Z({range:i,X:!0},((t,n,s)=>{const[i,a,u]=t;i===e&&a===r&&(o=!0),s.done()})).next((()=>o))}function _c(t){return ku(t,"mutations")}function Dc(t){return ku(t,"documentMutations")}function xc(t){return ku(t,"mutationQueues")}class Ac{constructor(t){this.bn=t}next(){return this.bn+=2,this.bn}static Pn(){return new Ac(0)}static vn(){return new Ac(-1)}}class Cc{constructor(t,e){this.referenceDelegate=t,this.It=e}allocateTargetId(t){return this.Vn(t).next((e=>{const n=new Ac(e.highestTargetId);return e.highestTargetId=n.next(),this.Sn(t,e).next((()=>e.highestTargetId))}))}getLastRemoteSnapshotVersion(t){return this.Vn(t).next((t=>ar.fromTimestamp(new or(t.lastRemoteSnapshotVersion.seconds,t.lastRemoteSnapshotVersion.nanoseconds))))}getHighestSequenceNumber(t){return this.Vn(t).next((t=>t.highestListenSequenceNumber))}setTargetsMetadata(t,e,n){return this.Vn(t).next((s=>(s.highestListenSequenceNumber=e,n&&(s.lastRemoteSnapshotVersion=n.toTimestamp()),e>s.highestListenSequenceNumber&&(s.highestListenSequenceNumber=e),this.Sn(t,s))))}addTargetData(t,e){return this.Dn(t,e).next((()=>this.Vn(t).next((n=>(n.targetCount+=1,this.Cn(e,n),this.Sn(t,n))))))}updateTargetData(t,e){return this.Dn(t,e)}removeTargetData(t,e){return this.removeMatchingKeysForTargetId(t,e.targetId).next((()=>Nc(t).delete(e.targetId))).next((()=>this.Vn(t))).next((e=>(Bs(e.targetCount>0),e.targetCount-=1,this.Sn(t,e))))}removeTargets(t,e,n){let s=0;const r=[];return Nc(t).Z(((i,o)=>{const a=Gu(o);a.sequenceNumber<=e&&null===n.get(a.targetId)&&(s++,r.push(this.removeTargetData(t,a)))})).next((()=>xr.waitFor(r))).next((()=>s))}forEachTarget(t,e){return Nc(t).Z(((t,n)=>{const s=Gu(n);e(s)}))}Vn(t){return kc(t).get("targetGlobalKey").next((t=>(Bs(null!==t),t)))}Sn(t,e){return kc(t).put("targetGlobalKey",e)}Dn(t,e){return Nc(t).put(Ku(this.It,e))}Cn(t,e){let n=!1;return t.targetId>e.highestTargetId&&(e.highestTargetId=t.targetId,n=!0),t.sequenceNumber>e.highestListenSequenceNumber&&(e.highestListenSequenceNumber=t.sequenceNumber,n=!0),n}getTargetCount(t){return this.Vn(t).next((t=>t.targetCount))}getTargetData(t,e){const n=Vi(e),s=IDBKeyRange.bound([n,Number.NEGATIVE_INFINITY],[n,Number.POSITIVE_INFINITY]);let r=null;return Nc(t).Z({range:s,index:"queryTargetsIndex"},((t,n,s)=>{const i=Gu(n);Fi(e,i.target)&&(r=i,s.done())})).next((()=>r))}addMatchingKeys(t,e,n){const s=[],r=Rc(t);return e.forEach((e=>{const i=su(e.path);s.push(r.put({targetId:n,path:i})),s.push(this.referenceDelegate.addReference(t,n,e))})),xr.waitFor(s)}removeMatchingKeys(t,e,n){const s=Rc(t);return xr.forEach(e,(e=>{const r=su(e.path);return xr.waitFor([s.delete([n,r]),this.referenceDelegate.removeReference(t,n,e)])}))}removeMatchingKeysForTargetId(t,e){const n=Rc(t),s=IDBKeyRange.bound([e],[e+1],!1,!0);return n.delete(s)}getMatchingKeysForTargetId(t,e){const n=IDBKeyRange.bound([e],[e+1],!1,!0),s=Rc(t);let r=ma();return s.Z({range:n,X:!0},((t,e,n)=>{const s=ou(t[1]),i=new dr(s);r=r.add(i)})).next((()=>r))}containsKey(t,e){const n=su(e.path),s=IDBKeyRange.bound([n],[ir(n)],!1,!0);let r=0;return Rc(t).Z({index:"documentTargetsIndex",X:!0,range:s},(([t,e],n,s)=>{0!==t&&(r++,s.done())})).next((()=>r>0))}se(t,e){return Nc(t).get(e).next((t=>t?Gu(t):null))}}function Nc(t){return ku(t,"targets")}function kc(t){return ku(t,"targetGlobal")}function Rc(t){return ku(t,"targetDocuments")}function Lc([t,e],[n,s]){const r=sr(t,n);return 0===r?sr(e,s):r}class Mc{constructor(t){this.xn=t,this.buffer=new Qr(Lc),this.Nn=0}kn(){return++this.Nn}On(t){const e=[t,this.kn()];if(this.buffer.size<this.xn)this.buffer=this.buffer.add(e);else{const t=this.buffer.last();Lc(e,t)<0&&(this.buffer=this.buffer.delete(t).add(e))}}get maxValue(){return this.buffer.last()[0]}}class Oc{constructor(t,e,n){this.garbageCollector=t,this.asyncQueue=e,this.localStore=n,this.Mn=null}start(){-1!==this.garbageCollector.params.cacheSizeCollectionThreshold&&this.Fn(6e4)}stop(){this.Mn&&(this.Mn.cancel(),this.Mn=null)}get started(){return null!==this.Mn}Fn(t){Os("LruGarbageCollector",`Garbage collection scheduled in ${t}ms`),this.Mn=this.asyncQueue.enqueueAfterDelay("lru_garbage_collection",t,(async()=>{this.Mn=null;try{await this.localStore.collectGarbage(this.garbageCollector)}catch(t){Rr(t)?Os("LruGarbageCollector","Ignoring IndexedDB error during garbage collection: ",t):await Dr(t)}await this.Fn(3e5)}))}}class Vc{constructor(t,e){this.$n=t,this.params=e}calculateTargetCount(t,e){return this.$n.Bn(t).next((t=>Math.floor(e/100*t)))}nthSequenceNumber(t,e){if(0===e)return xr.resolve(Ur.at);const n=new Mc(e);return this.$n.forEachTarget(t,(t=>n.On(t.sequenceNumber))).next((()=>this.$n.Ln(t,(t=>n.On(t))))).next((()=>n.maxValue))}removeTargets(t,e,n){return this.$n.removeTargets(t,e,n)}removeOrphanedDocuments(t,e){return this.$n.removeOrphanedDocuments(t,e)}collect(t,e){return-1===this.params.cacheSizeCollectionThreshold?(Os("LruGarbageCollector","Garbage collection skipped; disabled"),xr.resolve(vc)):this.getCacheSize(t).next((n=>n<this.params.cacheSizeCollectionThreshold?(Os("LruGarbageCollector",`Garbage collection skipped; Cache size ${n} is lower than threshold ${this.params.cacheSizeCollectionThreshold}`),vc):this.Un(t,e)))}getCacheSize(t){return this.$n.getCacheSize(t)}Un(t,e){let n,s,r,i,o,a,u;const c=Date.now();return this.calculateTargetCount(t,this.params.percentileToCollect).next((e=>(e>this.params.maximumSequenceNumbersToCollect?(Os("LruGarbageCollector",`Capping sequence numbers to collect down to the maximum of ${this.params.maximumSequenceNumbersToCollect} from ${e}`),s=this.params.maximumSequenceNumbersToCollect):s=e,i=Date.now(),this.nthSequenceNumber(t,s)))).next((s=>(n=s,o=Date.now(),this.removeTargets(t,n,e)))).next((e=>(r=e,a=Date.now(),this.removeOrphanedDocuments(t,n)))).next((t=>(u=Date.now(),Ls()<=E.DEBUG&&Os("LruGarbageCollector",`LRU Garbage Collection\n\tCounted targets in ${i-c}ms\n\tDetermined least recently used ${s} in `+(o-i)+"ms\n"+`\tRemoved ${r} targets in `+(a-o)+"ms\n"+`\tRemoved ${t} documents in `+(u-a)+"ms\n"+`Total Duration: ${u-c}ms`),xr.resolve({didRun:!0,sequenceNumbersCollected:s,targetsRemoved:r,documentsRemoved:t}))))}}class Fc{constructor(t,e){this.db=t,this.garbageCollector=function(t,e){return new Vc(t,e)}(this,e)}Bn(t){const e=this.qn(t);return this.db.getTargetCache().getTargetCount(t).next((t=>e.next((e=>t+e))))}qn(t){let e=0;return this.Ln(t,(t=>{e++})).next((()=>e))}forEachTarget(t,e){return this.db.getTargetCache().forEachTarget(t,e)}Ln(t,e){return this.Kn(t,((t,n)=>e(n)))}addReference(t,e,n){return Pc(t,n)}removeReference(t,e,n){return Pc(t,n)}removeTargets(t,e,n){return this.db.getTargetCache().removeTargets(t,e,n)}markPotentiallyOrphaned(t,e){return Pc(t,e)}Gn(t,e){return function(t,e){let n=!1;return xc(t).tt((s=>Sc(t,s,e).next((t=>(t&&(n=!0),xr.resolve(!t)))))).next((()=>n))}(t,e)}removeOrphanedDocuments(t,e){const n=this.db.getRemoteDocumentCache().newChangeBuffer(),s=[];let r=0;return this.Kn(t,((i,o)=>{if(o<=e){const e=this.Gn(t,i).next((e=>{if(!e)return r++,n.getEntry(t,i).next((()=>(n.removeEntry(i,ar.min()),Rc(t).delete([0,su(i.path)]))))}));s.push(e)}})).next((()=>xr.waitFor(s))).next((()=>n.apply(t))).next((()=>r))}removeTarget(t,e){const n=e.withSequenceNumber(t.currentSequenceNumber);return this.db.getTargetCache().updateTargetData(t,n)}updateLimboDocument(t,e){return Pc(t,e)}Kn(t,e){const n=Rc(t);let s,r=Ur.at;return n.Z({index:"documentTargetsIndex"},(([t,n],{path:i,sequenceNumber:o})=>{0===t?(r!==Ur.at&&e(new dr(ou(s)),r),r=o,s=i):r=Ur.at})).next((()=>{r!==Ur.at&&e(new dr(ou(s)),r)}))}getCacheSize(t){return this.db.getRemoteDocumentCache().getSize(t)}}function Pc(t,e){return Rc(t).put(function(t,e){return{targetId:0,path:su(t.path),sequenceNumber:e}}(e,t.currentSequenceNumber))}class Uc{constructor(){this.changes=new sa((t=>t.toString()),((t,e)=>t.isEqual(e))),this.changesApplied=!1}addEntry(t){this.assertNotApplied(),this.changes.set(t.key,t)}removeEntry(t,e){this.assertNotApplied(),this.changes.set(t,Li.newInvalidDocument(t).setReadTime(e))}getEntry(t,e){this.assertNotApplied();const n=this.changes.get(e);return void 0!==n?xr.resolve(n):this.getFromCache(t,e)}getEntries(t,e){return this.getAllFromCache(t,e)}apply(t){return this.assertNotApplied(),this.changesApplied=!0,this.applyChanges(t)}assertNotApplied(){}}class Bc{constructor(t){this.It=t}setIndexManager(t){this.indexManager=t}addEntry(t,e,n){return jc(t).put(n)}removeEntry(t,e,n){return jc(t).delete(function(t,e){const n=t.path.toArray();return[n.slice(0,n.length-2),n[n.length-2],Pu(e),n[n.length-1]]}(e,n))}updateMetadata(t,e){return this.getMetadata(t).next((n=>(n.byteSize+=e,this.Qn(t,n))))}getEntry(t,e){let n=Li.newInvalidDocument(e);return jc(t).Z({index:"documentKeyIndex",range:IDBKeyRange.only($c(e))},((t,s)=>{n=this.jn(e,s)})).next((()=>n))}Wn(t,e){let n={size:0,document:Li.newInvalidDocument(e)};return jc(t).Z({index:"documentKeyIndex",range:IDBKeyRange.only($c(e))},((t,s)=>{n={document:this.jn(e,s),size:Ec(s)}})).next((()=>n))}getEntries(t,e){let n=ia();return this.zn(t,e,((t,e)=>{const s=this.jn(t,e);n=n.insert(t,s)})).next((()=>n))}Hn(t,e){let n=ia(),s=new Kr(dr.comparator);return this.zn(t,e,((t,e)=>{const r=this.jn(t,e);n=n.insert(t,r),s=s.insert(t,Ec(e))})).next((()=>({documents:n,Jn:s})))}zn(t,e,n){if(e.isEmpty())return xr.resolve();let s=new Qr(zc);e.forEach((t=>s=s.add(t)));const r=IDBKeyRange.bound($c(s.first()),$c(s.last())),i=s.getIterator();let o=i.getNext();return jc(t).Z({index:"documentKeyIndex",range:r},((t,e,s)=>{const r=dr.fromSegments([...e.prefixPath,e.collectionGroup,e.documentId]);for(;o&&zc(o,r)<0;)n(o,null),o=i.getNext();o&&o.isEqual(r)&&(n(o,e),o=i.hasNext()?i.getNext():null),o?s.j($c(o)):s.done()})).next((()=>{for(;o;)n(o,null),o=i.hasNext()?i.getNext():null}))}getAllFromCollection(t,e,n){const s=[e.popLast().toArray(),e.lastSegment(),Pu(n.readTime),n.documentKey.path.isEmpty()?"":n.documentKey.path.lastSegment()],r=[e.popLast().toArray(),e.lastSegment(),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],""];return jc(t).W(IDBKeyRange.bound(s,r,!0)).next((t=>{let e=ia();for(const n of t){const t=this.jn(dr.fromSegments(n.prefixPath.concat(n.collectionGroup,n.documentId)),n);e=e.insert(t.key,t)}return e}))}getAllFromCollectionGroup(t,e,n,s){let r=ia();const i=Qc(e,n),o=Qc(e,Er.max());return jc(t).Z({index:"collectionGroupIndex",range:IDBKeyRange.bound(i,o,!0)},((t,e,n)=>{const i=this.jn(dr.fromSegments(e.prefixPath.concat(e.collectionGroup,e.documentId)),e);r=r.insert(i.key,i),r.size===s&&n.done()})).next((()=>r))}newChangeBuffer(t){return new Gc(this,!!t&&t.trackRemovals)}getSize(t){return this.getMetadata(t).next((t=>t.byteSize))}getMetadata(t){return Kc(t).get("remoteDocumentGlobalKey").next((t=>(Bs(!!t),t)))}Qn(t,e){return Kc(t).put("remoteDocumentGlobalKey",e)}jn(t,e){if(e){const t=function(t,e){let n;if(e.document)n=Ga(t.re,e.document,!!e.hasCommittedMutations);else if(e.noDocument){const t=dr.fromSegments(e.noDocument.path),s=Bu(e.noDocument.readTime);n=Li.newNoDocument(t,s),e.hasCommittedMutations&&n.setHasCommittedMutations()}else{if(!e.unknownDocument)return Us();{const t=dr.fromSegments(e.unknownDocument.path),s=Bu(e.unknownDocument.version);n=Li.newUnknownDocument(t,s)}}return e.readTime&&n.setReadTime(function(t){const e=new or(t[0],t[1]);return ar.fromTimestamp(e)}(e.readTime)),n}(this.It,e);if(!t.isNoDocument()||!t.version.isEqual(ar.min()))return t}return Li.newInvalidDocument(t)}}function qc(t){return new Bc(t)}class Gc extends Uc{constructor(t,e){super(),this.Yn=t,this.trackRemovals=e,this.Xn=new sa((t=>t.toString()),((t,e)=>t.isEqual(e)))}applyChanges(t){const e=[];let n=0,s=new Qr(((t,e)=>sr(t.canonicalString(),e.canonicalString())));return this.changes.forEach(((r,i)=>{const o=this.Xn.get(r);if(e.push(this.Yn.removeEntry(t,r,o.readTime)),i.isValidDocument()){const a=Fu(this.Yn.It,i);s=s.add(r.path.popLast());const u=Ec(a);n+=u-o.size,e.push(this.Yn.addEntry(t,r,a))}else if(n-=o.size,this.trackRemovals){const n=Fu(this.Yn.It,i.convertToNoDocument(ar.min()));e.push(this.Yn.addEntry(t,r,n))}})),s.forEach((n=>{e.push(this.Yn.indexManager.addToCollectionParentIndex(t,n))})),e.push(this.Yn.updateMetadata(t,n)),xr.waitFor(e)}getFromCache(t,e){return this.Yn.Wn(t,e).next((t=>(this.Xn.set(e,{size:t.size,readTime:t.document.readTime}),t.document)))}getAllFromCache(t,e){return this.Yn.Hn(t,e).next((({documents:t,Jn:e})=>(e.forEach(((e,n)=>{this.Xn.set(e,{size:n,readTime:t.get(e).readTime})})),t)))}}function Kc(t){return ku(t,"remoteDocumentGlobal")}function jc(t){return ku(t,"remoteDocumentsV14")}function $c(t){const e=t.path.toArray();return[e.slice(0,e.length-2),e[e.length-2],e[e.length-1]]}function Qc(t,e){const n=e.documentKey.path.toArray();return[t,Pu(e.readTime),n.slice(0,n.length-2),n.length>0?n[n.length-1]:""]}function zc(t,e){const n=t.path.toArray(),s=e.path.toArray();let r=0;for(let t=0;t<n.length-2&&t<s.length-2;++t)if(r=sr(n[t],s[t]),r)return r;return r=sr(n.length,s.length),r||(r=sr(n[n.length-2],s[s.length-2]),r||sr(n[n.length-1],s[s.length-1]))}class Hc{constructor(t,e){this.overlayedDocument=t,this.mutatedFields=e}}class Wc{constructor(t,e,n,s){this.remoteDocumentCache=t,this.mutationQueue=e,this.documentOverlayCache=n,this.indexManager=s}getDocument(t,e){let n=null;return this.documentOverlayCache.getOverlay(t,e).next((s=>(n=s,this.getBaseDocument(t,e,n)))).next((t=>(null!==n&&Go(n.mutation,t,Wr.empty(),or.now()),t)))}getDocuments(t,e){return this.remoteDocumentCache.getEntries(t,e).next((e=>this.getLocalViewOfDocuments(t,e,ma()).next((()=>e))))}getLocalViewOfDocuments(t,e,n=ma()){const s=ca();return this.populateOverlays(t,s,e).next((()=>this.computeViews(t,e,s,n).next((t=>{let e=aa();return t.forEach(((t,n)=>{e=e.insert(t,n.overlayedDocument)})),e}))))}getOverlayedDocuments(t,e){const n=ca();return this.populateOverlays(t,n,e).next((()=>this.computeViews(t,e,n,ma())))}populateOverlays(t,e,n){const s=[];return n.forEach((t=>{e.has(t)||s.push(t)})),this.documentOverlayCache.getOverlays(t,s).next((t=>{t.forEach(((t,n)=>{e.set(t,n)}))}))}computeViews(t,e,n,s){let r=ia();const i=la(),o=la();return e.forEach(((t,e)=>{const o=n.get(e.key);s.has(e.key)&&(void 0===o||o.mutation instanceof Qo)?r=r.insert(e.key,e):void 0!==o&&(i.set(e.key,o.mutation.getFieldMask()),Go(o.mutation,e,o.mutation.getFieldMask(),or.now()))})),this.recalculateAndSaveOverlays(t,r).next((t=>(t.forEach(((t,e)=>i.set(t,e))),e.forEach(((t,e)=>{var n;return o.set(t,new Hc(e,null!==(n=i.get(t))&&void 0!==n?n:null))})),o)))}recalculateAndSaveOverlays(t,e){const n=la();let s=new Kr(((t,e)=>t-e)),r=ma();return this.mutationQueue.getAllMutationBatchesAffectingDocumentKeys(t,e).next((t=>{for(const r of t)r.keys().forEach((t=>{const i=e.get(t);if(null===i)return;let o=n.get(t)||Wr.empty();o=r.applyToLocalView(i,o),n.set(t,o);const a=(s.get(r.batchId)||ma()).add(t);s=s.insert(r.batchId,a)}))})).next((()=>{const i=[],o=s.getReverseIterator();for(;o.hasNext();){const s=o.getNext(),a=s.key,u=s.value,c=ha();u.forEach((t=>{if(!r.has(t)){const s=Bo(e.get(t),n.get(t));null!==s&&c.set(t,s),r=r.add(t)}})),i.push(this.documentOverlayCache.saveOverlays(t,a,c))}return xr.waitFor(i)})).next((()=>n))}recalculateAndSaveOverlaysForDocumentKeys(t,e){return this.remoteDocumentCache.getEntries(t,e).next((e=>this.recalculateAndSaveOverlays(t,e)))}getDocumentsMatchingQuery(t,e,n){return function(t){return dr.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}(e)?this.getDocumentsMatchingDocumentQuery(t,e.path):uo(e)?this.getDocumentsMatchingCollectionGroupQuery(t,e,n):this.getDocumentsMatchingCollectionQuery(t,e,n)}getNextDocuments(t,e,n,s){return this.remoteDocumentCache.getAllFromCollectionGroup(t,e,n,s).next((r=>{const i=s-r.size>0?this.documentOverlayCache.getOverlaysForCollectionGroup(t,e,n.largestBatchId,s-r.size):xr.resolve(ca());let o=-1,a=r;return i.next((e=>xr.forEach(e,((e,n)=>(o<n.largestBatchId&&(o=n.largestBatchId),r.get(e)?xr.resolve():this.getBaseDocument(t,e,n).next((t=>{a=a.insert(e,t)}))))).next((()=>this.populateOverlays(t,e,r))).next((()=>this.computeViews(t,a,e,ma()))).next((t=>({batchId:o,changes:ua(t)})))))}))}getDocumentsMatchingDocumentQuery(t,e){return this.getDocument(t,new dr(e)).next((t=>{let e=aa();return t.isFoundDocument()&&(e=e.insert(t.key,t)),e}))}getDocumentsMatchingCollectionGroupQuery(t,e,n){const s=e.collectionGroup;let r=aa();return this.indexManager.getCollectionParents(t,s).next((i=>xr.forEach(i,(i=>{const o=function(t,e){return new no(e,null,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(e,i.child(s));return this.getDocumentsMatchingCollectionQuery(t,o,n).next((t=>{t.forEach(((t,e)=>{r=r.insert(t,e)}))}))})).next((()=>r))))}getDocumentsMatchingCollectionQuery(t,e,n){let s;return this.remoteDocumentCache.getAllFromCollection(t,e.path,n).next((r=>(s=r,this.documentOverlayCache.getOverlaysForCollection(t,e.path,n.largestBatchId)))).next((t=>{t.forEach(((t,e)=>{const n=e.getKey();null===s.get(n)&&(s=s.insert(n,Li.newInvalidDocument(n)))}));let n=aa();return s.forEach(((s,r)=>{const i=t.get(s);void 0!==i&&Go(i.mutation,r,Wr.empty(),or.now()),po(e,r)&&(n=n.insert(s,r))})),n}))}getBaseDocument(t,e,n){return null===n||1===n.mutation.type?this.remoteDocumentCache.getEntry(t,e):xr.resolve(Li.newInvalidDocument(e))}}class Yc{constructor(t){this.It=t,this.Zn=new Map,this.ts=new Map}getBundleMetadata(t,e){return xr.resolve(this.Zn.get(e))}saveBundleMetadata(t,e){var n;return this.Zn.set(e.id,{id:(n=e).id,version:n.version,createTime:Ra(n.createTime)}),xr.resolve()}getNamedQuery(t,e){return xr.resolve(this.ts.get(e))}saveNamedQuery(t,e){return this.ts.set(e.name,function(t){return{name:t.name,query:ju(t.bundledQuery),readTime:Ra(t.readTime)}}(e)),xr.resolve()}}class Xc{constructor(){this.overlays=new Kr(dr.comparator),this.es=new Map}getOverlay(t,e){return xr.resolve(this.overlays.get(e))}getOverlays(t,e){const n=ca();return xr.forEach(e,(e=>this.getOverlay(t,e).next((t=>{null!==t&&n.set(e,t)})))).next((()=>n))}saveOverlays(t,e,n){return n.forEach(((n,s)=>{this.ue(t,e,s)})),xr.resolve()}removeOverlaysForBatchId(t,e,n){const s=this.es.get(n);return void 0!==s&&(s.forEach((t=>this.overlays=this.overlays.remove(t))),this.es.delete(n)),xr.resolve()}getOverlaysForCollection(t,e,n){const s=ca(),r=e.length+1,i=new dr(e.child("")),o=this.overlays.getIteratorFrom(i);for(;o.hasNext();){const t=o.getNext().value,i=t.getKey();if(!e.isPrefixOf(i.path))break;i.path.length===r&&t.largestBatchId>n&&s.set(t.getKey(),t)}return xr.resolve(s)}getOverlaysForCollectionGroup(t,e,n,s){let r=new Kr(((t,e)=>t-e));const i=this.overlays.getIterator();for(;i.hasNext();){const t=i.getNext().value;if(t.getKey().getCollectionGroup()===e&&t.largestBatchId>n){let e=r.get(t.largestBatchId);null===e&&(e=ca(),r=r.insert(t.largestBatchId,e)),e.set(t.getKey(),t)}}const o=ca(),a=r.getIterator();for(;a.hasNext()&&(a.getNext().value.forEach(((t,e)=>o.set(t,e))),!(o.size()>=s)););return xr.resolve(o)}ue(t,e,n){const s=this.overlays.get(n.key);if(null!==s){const t=this.es.get(s.largestBatchId).delete(n.key);this.es.set(s.largestBatchId,t)}this.overlays=this.overlays.insert(n.key,new Mu(e,n));let r=this.es.get(e);void 0===r&&(r=ma(),this.es.set(e,r)),this.es.set(e,r.add(n.key))}}class Jc{constructor(){this.ns=new Qr(Zc.ss),this.rs=new Qr(Zc.os)}isEmpty(){return this.ns.isEmpty()}addReference(t,e){const n=new Zc(t,e);this.ns=this.ns.add(n),this.rs=this.rs.add(n)}us(t,e){t.forEach((t=>this.addReference(t,e)))}removeReference(t,e){this.cs(new Zc(t,e))}hs(t,e){t.forEach((t=>this.removeReference(t,e)))}ls(t){const e=new dr(new cr([])),n=new Zc(e,t),s=new Zc(e,t+1),r=[];return this.rs.forEachInRange([n,s],(t=>{this.cs(t),r.push(t.key)})),r}fs(){this.ns.forEach((t=>this.cs(t)))}cs(t){this.ns=this.ns.delete(t),this.rs=this.rs.delete(t)}ds(t){const e=new dr(new cr([])),n=new Zc(e,t),s=new Zc(e,t+1);let r=ma();return this.rs.forEachInRange([n,s],(t=>{r=r.add(t.key)})),r}containsKey(t){const e=new Zc(t,0),n=this.ns.firstAfterOrEqual(e);return null!==n&&t.isEqual(n.key)}}class Zc{constructor(t,e){this.key=t,this._s=e}static ss(t,e){return dr.comparator(t.key,e.key)||sr(t._s,e._s)}static os(t,e){return sr(t._s,e._s)||dr.comparator(t.key,e.key)}}class th{constructor(t,e){this.indexManager=t,this.referenceDelegate=e,this.mutationQueue=[],this.ws=1,this.gs=new Qr(Zc.ss)}checkEmpty(t){return xr.resolve(0===this.mutationQueue.length)}addMutationBatch(t,e,n,s){const r=this.ws;this.ws++,this.mutationQueue.length>0&&this.mutationQueue[this.mutationQueue.length-1];const i=new Ru(r,e,n,s);this.mutationQueue.push(i);for(const e of s)this.gs=this.gs.add(new Zc(e.key,r)),this.indexManager.addToCollectionParentIndex(t,e.key.path.popLast());return xr.resolve(i)}lookupMutationBatch(t,e){return xr.resolve(this.ys(e))}getNextMutationBatchAfterBatchId(t,e){const n=e+1,s=this.ps(n),r=s<0?0:s;return xr.resolve(this.mutationQueue.length>r?this.mutationQueue[r]:null)}getHighestUnacknowledgedBatchId(){return xr.resolve(0===this.mutationQueue.length?-1:this.ws-1)}getAllMutationBatches(t){return xr.resolve(this.mutationQueue.slice())}getAllMutationBatchesAffectingDocumentKey(t,e){const n=new Zc(e,0),s=new Zc(e,Number.POSITIVE_INFINITY),r=[];return this.gs.forEachInRange([n,s],(t=>{const e=this.ys(t._s);r.push(e)})),xr.resolve(r)}getAllMutationBatchesAffectingDocumentKeys(t,e){let n=new Qr(sr);return e.forEach((t=>{const e=new Zc(t,0),s=new Zc(t,Number.POSITIVE_INFINITY);this.gs.forEachInRange([e,s],(t=>{n=n.add(t._s)}))})),xr.resolve(this.Is(n))}getAllMutationBatchesAffectingQuery(t,e){const n=e.path,s=n.length+1;let r=n;dr.isDocumentKey(r)||(r=r.child(""));const i=new Zc(new dr(r),0);let o=new Qr(sr);return this.gs.forEachWhile((t=>{const e=t.key.path;return!!n.isPrefixOf(e)&&(e.length===s&&(o=o.add(t._s)),!0)}),i),xr.resolve(this.Is(o))}Is(t){const e=[];return t.forEach((t=>{const n=this.ys(t);null!==n&&e.push(n)})),e}removeMutationBatch(t,e){Bs(0===this.Ts(e.batchId,"removed")),this.mutationQueue.shift();let n=this.gs;return xr.forEach(e.mutations,(s=>{const r=new Zc(s.key,e.batchId);return n=n.delete(r),this.referenceDelegate.markPotentiallyOrphaned(t,s.key)})).next((()=>{this.gs=n}))}An(t){}containsKey(t,e){const n=new Zc(e,0),s=this.gs.firstAfterOrEqual(n);return xr.resolve(e.isEqual(s&&s.key))}performConsistencyCheck(t){return this.mutationQueue.length,xr.resolve()}Ts(t,e){return this.ps(t)}ps(t){return 0===this.mutationQueue.length?0:t-this.mutationQueue[0].batchId}ys(t){const e=this.ps(t);return e<0||e>=this.mutationQueue.length?null:this.mutationQueue[e]}}class eh{constructor(t){this.Es=t,this.docs=new Kr(dr.comparator),this.size=0}setIndexManager(t){this.indexManager=t}addEntry(t,e){const n=e.key,s=this.docs.get(n),r=s?s.size:0,i=this.Es(e);return this.docs=this.docs.insert(n,{document:e.mutableCopy(),size:i}),this.size+=i-r,this.indexManager.addToCollectionParentIndex(t,n.path.popLast())}removeEntry(t){const e=this.docs.get(t);e&&(this.docs=this.docs.remove(t),this.size-=e.size)}getEntry(t,e){const n=this.docs.get(e);return xr.resolve(n?n.document.mutableCopy():Li.newInvalidDocument(e))}getEntries(t,e){let n=ia();return e.forEach((t=>{const e=this.docs.get(t);n=n.insert(t,e?e.document.mutableCopy():Li.newInvalidDocument(t))})),xr.resolve(n)}getAllFromCollection(t,e,n){let s=ia();const r=new dr(e.child("")),i=this.docs.getIteratorFrom(r);for(;i.hasNext();){const{key:t,value:{document:r}}=i.getNext();if(!e.isPrefixOf(t.path))break;t.path.length>e.length+1||Tr(br(r),n)<=0||(s=s.insert(r.key,r.mutableCopy()))}return xr.resolve(s)}getAllFromCollectionGroup(t,e,n,s){Us()}As(t,e){return xr.forEach(this.docs,(t=>e(t)))}newChangeBuffer(t){return new nh(this)}getSize(t){return xr.resolve(this.size)}}class nh extends Uc{constructor(t){super(),this.Yn=t}applyChanges(t){const e=[];return this.changes.forEach(((n,s)=>{s.isValidDocument()?e.push(this.Yn.addEntry(t,s)):this.Yn.removeEntry(n)})),xr.waitFor(e)}getFromCache(t,e){return this.Yn.getEntry(t,e)}getAllFromCache(t,e){return this.Yn.getEntries(t,e)}}class sh{constructor(t){this.persistence=t,this.Rs=new sa((t=>Vi(t)),Fi),this.lastRemoteSnapshotVersion=ar.min(),this.highestTargetId=0,this.bs=0,this.Ps=new Jc,this.targetCount=0,this.vs=Ac.Pn()}forEachTarget(t,e){return this.Rs.forEach(((t,n)=>e(n))),xr.resolve()}getLastRemoteSnapshotVersion(t){return xr.resolve(this.lastRemoteSnapshotVersion)}getHighestSequenceNumber(t){return xr.resolve(this.bs)}allocateTargetId(t){return this.highestTargetId=this.vs.next(),xr.resolve(this.highestTargetId)}setTargetsMetadata(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.bs&&(this.bs=e),xr.resolve()}Dn(t){this.Rs.set(t.target,t);const e=t.targetId;e>this.highestTargetId&&(this.vs=new Ac(e),this.highestTargetId=e),t.sequenceNumber>this.bs&&(this.bs=t.sequenceNumber)}addTargetData(t,e){return this.Dn(e),this.targetCount+=1,xr.resolve()}updateTargetData(t,e){return this.Dn(e),xr.resolve()}removeTargetData(t,e){return this.Rs.delete(e.target),this.Ps.ls(e.targetId),this.targetCount-=1,xr.resolve()}removeTargets(t,e,n){let s=0;const r=[];return this.Rs.forEach(((i,o)=>{o.sequenceNumber<=e&&null===n.get(o.targetId)&&(this.Rs.delete(i),r.push(this.removeMatchingKeysForTargetId(t,o.targetId)),s++)})),xr.waitFor(r).next((()=>s))}getTargetCount(t){return xr.resolve(this.targetCount)}getTargetData(t,e){const n=this.Rs.get(e)||null;return xr.resolve(n)}addMatchingKeys(t,e,n){return this.Ps.us(e,n),xr.resolve()}removeMatchingKeys(t,e,n){this.Ps.hs(e,n);const s=this.persistence.referenceDelegate,r=[];return s&&e.forEach((e=>{r.push(s.markPotentiallyOrphaned(t,e))})),xr.waitFor(r)}removeMatchingKeysForTargetId(t,e){return this.Ps.ls(e),xr.resolve()}getMatchingKeysForTargetId(t,e){const n=this.Ps.ds(e);return xr.resolve(n)}containsKey(t,e){return xr.resolve(this.Ps.containsKey(e))}}class rh{constructor(t,e){this.Vs={},this.overlays={},this.Ss=new Ur(0),this.Ds=!1,this.Ds=!0,this.referenceDelegate=t(this),this.Cs=new sh(this),this.indexManager=new hc,this.remoteDocumentCache=function(t){return new eh(t)}((t=>this.referenceDelegate.xs(t))),this.It=new Vu(e),this.Ns=new Yc(this.It)}start(){return Promise.resolve()}shutdown(){return this.Ds=!1,Promise.resolve()}get started(){return this.Ds}setDatabaseDeletedListener(){}setNetworkEnabled(){}getIndexManager(t){return this.indexManager}getDocumentOverlayCache(t){let e=this.overlays[t.toKey()];return e||(e=new Xc,this.overlays[t.toKey()]=e),e}getMutationQueue(t,e){let n=this.Vs[t.toKey()];return n||(n=new th(e,this.referenceDelegate),this.Vs[t.toKey()]=n),n}getTargetCache(){return this.Cs}getRemoteDocumentCache(){return this.remoteDocumentCache}getBundleCache(){return this.Ns}runTransaction(t,e,n){Os("MemoryPersistence","Starting transaction:",t);const s=new ih(this.Ss.next());return this.referenceDelegate.ks(),n(s).next((t=>this.referenceDelegate.Os(s).next((()=>t)))).toPromise().then((t=>(s.raiseOnCommittedEvent(),t)))}Ms(t,e){return xr.or(Object.values(this.Vs).map((n=>()=>n.containsKey(t,e))))}}class ih extends _r{constructor(t){super(),this.currentSequenceNumber=t}}class oh{constructor(t){this.persistence=t,this.Fs=new Jc,this.$s=null}static Bs(t){return new oh(t)}get Ls(){if(this.$s)return this.$s;throw Us()}addReference(t,e,n){return this.Fs.addReference(n,e),this.Ls.delete(n.toString()),xr.resolve()}removeReference(t,e,n){return this.Fs.removeReference(n,e),this.Ls.add(n.toString()),xr.resolve()}markPotentiallyOrphaned(t,e){return this.Ls.add(e.toString()),xr.resolve()}removeTarget(t,e){this.Fs.ls(e.targetId).forEach((t=>this.Ls.add(t.toString())));const n=this.persistence.getTargetCache();return n.getMatchingKeysForTargetId(t,e.targetId).next((t=>{t.forEach((t=>this.Ls.add(t.toString())))})).next((()=>n.removeTargetData(t,e)))}ks(){this.$s=new Set}Os(t){const e=this.persistence.getRemoteDocumentCache().newChangeBuffer();return xr.forEach(this.Ls,(n=>{const s=dr.fromPath(n);return this.Us(t,s).next((t=>{t||e.removeEntry(s,ar.min())}))})).next((()=>(this.$s=null,e.apply(t))))}updateLimboDocument(t,e){return this.Us(t,e).next((t=>{t?this.Ls.delete(e.toString()):this.Ls.add(e.toString())}))}xs(t){return 0}Us(t,e){return xr.or([()=>xr.resolve(this.Fs.containsKey(e)),()=>this.persistence.getTargetCache().containsKey(t,e),()=>this.persistence.Ms(t,e)])}}class ah{constructor(t){this.It=t}$(t,e,n,s){const r=new Ar("createOrUpgrade",e);n<1&&s>=1&&(function(t){t.createObjectStore("owner")}(t),function(t){t.createObjectStore("mutationQueues",{keyPath:"userId"}),t.createObjectStore("mutations",{keyPath:"batchId",autoIncrement:!0}).createIndex("userMutationsIndex",au,{unique:!0}),t.createObjectStore("documentMutations")}(t),uh(t),function(t){t.createObjectStore("remoteDocuments")}(t));let i=xr.resolve();return n<3&&s>=3&&(0!==n&&(function(t){t.deleteObjectStore("targetDocuments"),t.deleteObjectStore("targets"),t.deleteObjectStore("targetGlobal")}(t),uh(t)),i=i.next((()=>function(t){const e=t.store("targetGlobal"),n={highestTargetId:0,highestListenSequenceNumber:0,lastRemoteSnapshotVersion:ar.min().toTimestamp(),targetCount:0};return e.put("targetGlobalKey",n)}(r)))),n<4&&s>=4&&(0!==n&&(i=i.next((()=>function(t,e){return e.store("mutations").W().next((n=>{t.deleteObjectStore("mutations"),t.createObjectStore("mutations",{keyPath:"batchId",autoIncrement:!0}).createIndex("userMutationsIndex",au,{unique:!0});const s=e.store("mutations"),r=n.map((t=>s.put(t)));return xr.waitFor(r)}))}(t,r)))),i=i.next((()=>{!function(t){t.createObjectStore("clientMetadata",{keyPath:"clientId"})}(t)}))),n<5&&s>=5&&(i=i.next((()=>this.qs(r)))),n<6&&s>=6&&(i=i.next((()=>(function(t){t.createObjectStore("remoteDocumentGlobal")}(t),this.Ks(r))))),n<7&&s>=7&&(i=i.next((()=>this.Gs(r)))),n<8&&s>=8&&(i=i.next((()=>this.Qs(t,r)))),n<9&&s>=9&&(i=i.next((()=>{!function(t){t.objectStoreNames.contains("remoteDocumentChanges")&&t.deleteObjectStore("remoteDocumentChanges")}(t)}))),n<10&&s>=10&&(i=i.next((()=>this.js(r)))),n<11&&s>=11&&(i=i.next((()=>{!function(t){t.createObjectStore("bundles",{keyPath:"bundleId"})}(t),function(t){t.createObjectStore("namedQueries",{keyPath:"name"})}(t)}))),n<12&&s>=12&&(i=i.next((()=>{!function(t){const e=t.createObjectStore("documentOverlays",{keyPath:Eu});e.createIndex("collectionPathOverlayIndex",Tu,{unique:!1}),e.createIndex("collectionGroupOverlayIndex",Su,{unique:!1})}(t)}))),n<13&&s>=13&&(i=i.next((()=>function(t){const e=t.createObjectStore("remoteDocumentsV14",{keyPath:lu});e.createIndex("documentKeyIndex",du),e.createIndex("collectionGroupIndex",fu)}(t))).next((()=>this.Ws(t,r))).next((()=>t.deleteObjectStore("remoteDocuments")))),n<14&&s>=14&&(i=i.next((()=>this.zs(t,r)))),n<15&&s>=15&&(i=i.next((()=>function(t){t.createObjectStore("indexConfiguration",{keyPath:"indexId",autoIncrement:!0}).createIndex("collectionGroupIndex","collectionGroup",{unique:!1}),t.createObjectStore("indexState",{keyPath:wu}).createIndex("sequenceNumberIndex",vu,{unique:!1}),t.createObjectStore("indexEntries",{keyPath:Iu}).createIndex("documentKeyIndex",bu,{unique:!1})}(t)))),i}Ks(t){let e=0;return t.store("remoteDocuments").Z(((t,n)=>{e+=Ec(n)})).next((()=>{const n={byteSize:e};return t.store("remoteDocumentGlobal").put("remoteDocumentGlobalKey",n)}))}qs(t){const e=t.store("mutationQueues"),n=t.store("mutations");return e.W().next((e=>xr.forEach(e,(e=>{const s=IDBKeyRange.bound([e.userId,-1],[e.userId,e.lastAcknowledgedBatchId]);return n.W("userMutationsIndex",s).next((n=>xr.forEach(n,(n=>{Bs(n.userId===e.userId);const s=qu(this.It,n);return bc(t,e.userId,s).next((()=>{}))}))))}))))}Gs(t){const e=t.store("targetDocuments"),n=t.store("remoteDocuments");return t.store("targetGlobal").get("targetGlobalKey").next((t=>{const s=[];return n.Z(((n,r)=>{const i=new cr(n),o=function(t){return[0,su(t)]}(i);s.push(e.get(o).next((n=>n?xr.resolve():(n=>e.put({targetId:0,path:su(n),sequenceNumber:t.highestListenSequenceNumber}))(i))))})).next((()=>xr.waitFor(s)))}))}Qs(t,e){t.createObjectStore("collectionParents",{keyPath:yu});const n=e.store("collectionParents"),s=new lc,r=t=>{if(s.add(t)){const e=t.lastSegment(),s=t.popLast();return n.put({collectionId:e,parent:su(s)})}};return e.store("remoteDocuments").Z({X:!0},((t,e)=>{const n=new cr(t);return r(n.popLast())})).next((()=>e.store("documentMutations").Z({X:!0},(([t,e,n],s)=>{const i=ou(e);return r(i.popLast())}))))}js(t){const e=t.store("targets");return e.Z(((t,n)=>{const s=Gu(n),r=Ku(this.It,s);return e.put(r)}))}Ws(t,e){const n=e.store("remoteDocuments"),s=[];return n.Z(((t,n)=>{const r=e.store("remoteDocumentsV14"),i=(o=n,o.document?new dr(cr.fromString(o.document.name).popFirst(5)):o.noDocument?dr.fromSegments(o.noDocument.path):o.unknownDocument?dr.fromSegments(o.unknownDocument.path):Us()).path.toArray();var o;const a={prefixPath:i.slice(0,i.length-2),collectionGroup:i[i.length-2],documentId:i[i.length-1],readTime:n.readTime||[0,0],unknownDocument:n.unknownDocument,noDocument:n.noDocument,document:n.document,hasCommittedMutations:!!n.hasCommittedMutations};s.push(r.put(a))})).next((()=>xr.waitFor(s)))}zs(t,e){const n=e.store("mutations"),s=qc(this.It),r=new rh(oh.Bs,this.It.re);return n.W().next((t=>{const n=new Map;return t.forEach((t=>{var e;let s=null!==(e=n.get(t.userId))&&void 0!==e?e:ma();qu(this.It,t).keys().forEach((t=>s=s.add(t))),n.set(t.userId,s)})),xr.forEach(n,((t,n)=>{const i=new Ns(n),o=Xu.oe(this.It,i),a=r.getIndexManager(i),u=Tc.oe(i,this.It,a,r.referenceDelegate);return new Wc(s,u,o,a).recalculateAndSaveOverlaysForDocumentKeys(new Nu(e,Ur.at),t).next()}))}))}}function uh(t){t.createObjectStore("targetDocuments",{keyPath:gu}).createIndex("documentTargetsIndex",pu,{unique:!0}),t.createObjectStore("targets",{keyPath:"targetId"}).createIndex("queryTargetsIndex",mu,{unique:!0}),t.createObjectStore("targetGlobal")}const ch="Failed to obtain exclusive access to the persistence layer. To allow shared access, multi-tab synchronization has to be enabled in all tabs. If you are using `experimentalForceOwningTab:true`, make sure that only one tab has persistence enabled at any given time.";class hh{constructor(t,e,n,s,r,i,o,a,u,c,h=15){if(this.allowTabSynchronization=t,this.persistenceKey=e,this.clientId=n,this.Hs=r,this.window=i,this.document=o,this.Js=u,this.Ys=c,this.Xs=h,this.Ss=null,this.Ds=!1,this.isPrimary=!1,this.networkEnabled=!0,this.Zs=null,this.inForeground=!1,this.ti=null,this.ei=null,this.ni=Number.NEGATIVE_INFINITY,this.si=t=>Promise.resolve(),!hh.C())throw new js(Ks.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");this.referenceDelegate=new Fc(this,s),this.ii=e+"main",this.It=new Vu(a),this.ri=new Cr(this.ii,this.Xs,new ah(this.It)),this.Cs=new Cc(this.referenceDelegate,this.It),this.remoteDocumentCache=qc(this.It),this.Ns=new Hu,this.window&&this.window.localStorage?this.oi=this.window.localStorage:(this.oi=null,!1===c&&Vs("IndexedDbPersistence","LocalStorage is unavailable. As a result, persistence may not work reliably. In particular enablePersistence() could fail immediately after refreshing the page."))}start(){return this.ui().then((()=>{if(!this.isPrimary&&!this.allowTabSynchronization)throw new js(Ks.FAILED_PRECONDITION,ch);return this.ci(),this.ai(),this.hi(),this.runTransaction("getHighestListenSequenceNumber","readonly",(t=>this.Cs.getHighestSequenceNumber(t)))})).then((t=>{this.Ss=new Ur(t,this.Js)})).then((()=>{this.Ds=!0})).catch((t=>(this.ri&&this.ri.close(),Promise.reject(t))))}li(t){return this.si=async e=>{if(this.started)return t(e)},t(this.isPrimary)}setDatabaseDeletedListener(t){this.ri.L((async e=>{null===e.newVersion&&await t()}))}setNetworkEnabled(t){this.networkEnabled!==t&&(this.networkEnabled=t,this.Hs.enqueueAndForget((async()=>{this.started&&await this.ui()})))}ui(){return this.runTransaction("updateClientMetadataAndTryBecomePrimary","readwrite",(t=>dh(t).put({clientId:this.clientId,updateTimeMs:Date.now(),networkEnabled:this.networkEnabled,inForeground:this.inForeground}).next((()=>{if(this.isPrimary)return this.fi(t).next((t=>{t||(this.isPrimary=!1,this.Hs.enqueueRetryable((()=>this.si(!1))))}))})).next((()=>this.di(t))).next((e=>this.isPrimary&&!e?this._i(t).next((()=>!1)):!!e&&this.wi(t).next((()=>!0)))))).catch((t=>{if(Rr(t))return Os("IndexedDbPersistence","Failed to extend owner lease: ",t),this.isPrimary;if(!this.allowTabSynchronization)throw t;return Os("IndexedDbPersistence","Releasing owner lease after error during lease refresh",t),!1})).then((t=>{this.isPrimary!==t&&this.Hs.enqueueRetryable((()=>this.si(t))),this.isPrimary=t}))}fi(t){return lh(t).get("owner").next((t=>xr.resolve(this.mi(t))))}gi(t){return dh(t).delete(this.clientId)}async yi(){if(this.isPrimary&&!this.pi(this.ni,18e5)){this.ni=Date.now();const t=await this.runTransaction("maybeGarbageCollectMultiClientState","readwrite-primary",(t=>{const e=ku(t,"clientMetadata");return e.W().next((t=>{const n=this.Ii(t,18e5),s=t.filter((t=>-1===n.indexOf(t)));return xr.forEach(s,(t=>e.delete(t.clientId))).next((()=>s))}))})).catch((()=>[]));if(this.oi)for(const e of t)this.oi.removeItem(this.Ti(e.clientId))}}hi(){this.ei=this.Hs.enqueueAfterDelay("client_metadata_refresh",4e3,(()=>this.ui().then((()=>this.yi())).then((()=>this.hi()))))}mi(t){return!!t&&t.ownerId===this.clientId}di(t){return this.Ys?xr.resolve(!0):lh(t).get("owner").next((e=>{if(null!==e&&this.pi(e.leaseTimestampMs,5e3)&&!this.Ei(e.ownerId)){if(this.mi(e)&&this.networkEnabled)return!0;if(!this.mi(e)){if(!e.allowTabSynchronization)throw new js(Ks.FAILED_PRECONDITION,ch);return!1}}return!(!this.networkEnabled||!this.inForeground)||dh(t).W().next((t=>void 0===this.Ii(t,5e3).find((t=>{if(this.clientId!==t.clientId){const e=!this.networkEnabled&&t.networkEnabled,n=!this.inForeground&&t.inForeground,s=this.networkEnabled===t.networkEnabled;if(e||n&&s)return!0}return!1}))))})).next((t=>(this.isPrimary!==t&&Os("IndexedDbPersistence",`Client ${t?"is":"is not"} eligible for a primary lease.`),t)))}async shutdown(){this.Ds=!1,this.Ai(),this.ei&&(this.ei.cancel(),this.ei=null),this.Ri(),this.bi(),await this.ri.runTransaction("shutdown","readwrite",["owner","clientMetadata"],(t=>{const e=new Nu(t,Ur.at);return this._i(e).next((()=>this.gi(e)))})),this.ri.close(),this.Pi()}Ii(t,e){return t.filter((t=>this.pi(t.updateTimeMs,e)&&!this.Ei(t.clientId)))}vi(){return this.runTransaction("getActiveClients","readonly",(t=>dh(t).W().next((t=>this.Ii(t,18e5).map((t=>t.clientId))))))}get started(){return this.Ds}getMutationQueue(t,e){return Tc.oe(t,this.It,e,this.referenceDelegate)}getTargetCache(){return this.Cs}getRemoteDocumentCache(){return this.remoteDocumentCache}getIndexManager(t){return new fc(t,this.It.re.databaseId)}getDocumentOverlayCache(t){return Xu.oe(this.It,t)}getBundleCache(){return this.Ns}runTransaction(t,e,n){Os("IndexedDbPersistence","Starting transaction:",t);const s="readonly"===e?"readonly":"readwrite",r=15===(i=this.Xs)?Cu:14===i?Au:13===i?xu:12===i?Du:11===i?_u:void Us();var i;let o;return this.ri.runTransaction(t,s,r,(s=>(o=new Nu(s,this.Ss?this.Ss.next():Ur.at),"readwrite-primary"===e?this.fi(o).next((t=>!!t||this.di(o))).next((e=>{if(!e)throw Vs(`Failed to obtain primary lease for action '${t}'.`),this.isPrimary=!1,this.Hs.enqueueRetryable((()=>this.si(!1))),new js(Ks.FAILED_PRECONDITION,Sr);return n(o)})).next((t=>this.wi(o).next((()=>t)))):this.Vi(o).next((()=>n(o)))))).then((t=>(o.raiseOnCommittedEvent(),t)))}Vi(t){return lh(t).get("owner").next((t=>{if(null!==t&&this.pi(t.leaseTimestampMs,5e3)&&!this.Ei(t.ownerId)&&!this.mi(t)&&!(this.Ys||this.allowTabSynchronization&&t.allowTabSynchronization))throw new js(Ks.FAILED_PRECONDITION,ch)}))}wi(t){const e={ownerId:this.clientId,allowTabSynchronization:this.allowTabSynchronization,leaseTimestampMs:Date.now()};return lh(t).put("owner",e)}static C(){return Cr.C()}_i(t){const e=lh(t);return e.get("owner").next((t=>this.mi(t)?(Os("IndexedDbPersistence","Releasing primary lease."),e.delete("owner")):xr.resolve()))}pi(t,e){const n=Date.now();return!(t<n-e||t>n&&(Vs(`Detected an update time that is in the future: ${t} > ${n}`),1))}ci(){null!==this.document&&"function"==typeof this.document.addEventListener&&(this.ti=()=>{this.Hs.enqueueAndForget((()=>(this.inForeground="visible"===this.document.visibilityState,this.ui())))},this.document.addEventListener("visibilitychange",this.ti),this.inForeground="visible"===this.document.visibilityState)}Ri(){this.ti&&(this.document.removeEventListener("visibilitychange",this.ti),this.ti=null)}ai(){var t;"function"==typeof(null===(t=this.window)||void 0===t?void 0:t.addEventListener)&&(this.Zs=()=>{this.Ai(),h()&&navigator.appVersion.match(/Version\/1[45]/)&&this.Hs.enterRestrictedMode(!0),this.Hs.enqueueAndForget((()=>this.shutdown()))},this.window.addEventListener("pagehide",this.Zs))}bi(){this.Zs&&(this.window.removeEventListener("pagehide",this.Zs),this.Zs=null)}Ei(t){var e;try{const n=null!==(null===(e=this.oi)||void 0===e?void 0:e.getItem(this.Ti(t)));return Os("IndexedDbPersistence",`Client '${t}' ${n?"is":"is not"} zombied in LocalStorage`),n}catch(t){return Vs("IndexedDbPersistence","Failed to get zombied client id.",t),!1}}Ai(){if(this.oi)try{this.oi.setItem(this.Ti(this.clientId),String(Date.now()))}catch(t){Vs("Failed to set zombie client id.",t)}}Pi(){if(this.oi)try{this.oi.removeItem(this.Ti(this.clientId))}catch(t){}}Ti(t){return`firestore_zombie_${this.persistenceKey}_${t}`}}function lh(t){return ku(t,"owner")}function dh(t){return ku(t,"clientMetadata")}function fh(t,e){let n=t.projectId;return t.isDefaultDatabase||(n+="."+t.database),"firestore/"+e+"/"+n+"/"}class mh{constructor(t,e,n,s){this.targetId=t,this.fromCache=e,this.Si=n,this.Di=s}static Ci(t,e){let n=ma(),s=ma();for(const t of e.docChanges)switch(t.type){case 0:n=n.add(t.doc.key);break;case 1:s=s.add(t.doc.key)}return new mh(t,e.fromCache,n,s)}}class gh{constructor(){this.xi=!1}initialize(t,e){this.Ni=t,this.indexManager=e,this.xi=!0}getDocumentsMatchingQuery(t,e,n,s){return this.ki(t,e).next((r=>r||this.Oi(t,e,s,n))).next((n=>n||this.Mi(t,e)))}ki(t,e){if(io(e))return xr.resolve(null);let n=ho(e);return this.indexManager.getIndexType(t,n).next((s=>0===s?null:(null!==e.limit&&1===s&&(e=lo(e,null,"F"),n=ho(e)),this.indexManager.getDocumentsMatchingTarget(t,n).next((s=>{const r=ma(...s);return this.Ni.getDocuments(t,r).next((s=>this.indexManager.getMinOffset(t,n).next((n=>{const i=this.Fi(e,s);return this.$i(e,i,r,n.readTime)?this.ki(t,lo(e,null,"F")):this.Bi(t,i,e,n)}))))})))))}Oi(t,e,n,s){return io(e)||s.isEqual(ar.min())?this.Mi(t,e):this.Ni.getDocuments(t,n).next((r=>{const i=this.Fi(e,r);return this.$i(e,i,n,s)?this.Mi(t,e):(Ls()<=E.DEBUG&&Os("QueryEngine","Re-using previous result from %s to execute query: %s",s.toString(),go(e)),this.Bi(t,i,e,Ir(s,-1)))}))}Fi(t,e){let n=new Qr(wo(t));return e.forEach(((e,s)=>{po(t,s)&&(n=n.add(s))})),n}$i(t,e,n,s){if(null===t.limit)return!1;if(n.size!==e.size)return!0;const r="F"===t.limitType?e.last():e.first();return!!r&&(r.hasPendingWrites||r.version.compareTo(s)>0)}Mi(t,e){return Ls()<=E.DEBUG&&Os("QueryEngine","Using full collection scan to execute query:",go(e)),this.Ni.getDocumentsMatchingQuery(t,e,Er.min())}Bi(t,e,n,s){return this.Ni.getDocumentsMatchingQuery(t,n,s).next((t=>(e.forEach((e=>{t=t.insert(e.key,e)})),t)))}}class ph{constructor(t,e,n,s){this.persistence=t,this.Li=e,this.It=s,this.Ui=new Kr(sr),this.qi=new sa((t=>Vi(t)),Fi),this.Ki=new Map,this.Gi=t.getRemoteDocumentCache(),this.Cs=t.getTargetCache(),this.Ns=t.getBundleCache(),this.Qi(n)}Qi(t){this.documentOverlayCache=this.persistence.getDocumentOverlayCache(t),this.indexManager=this.persistence.getIndexManager(t),this.mutationQueue=this.persistence.getMutationQueue(t,this.indexManager),this.localDocuments=new Wc(this.Gi,this.mutationQueue,this.documentOverlayCache,this.indexManager),this.Gi.setIndexManager(this.indexManager),this.Li.initialize(this.localDocuments,this.indexManager)}collectGarbage(t){return this.persistence.runTransaction("Collect garbage","readwrite-primary",(e=>t.collect(e,this.Ui)))}}function yh(t,e,n,s){return new ph(t,e,n,s)}async function wh(t,e){const n=Gs(t);return await n.persistence.runTransaction("Handle user change","readonly",(t=>{let s;return n.mutationQueue.getAllMutationBatches(t).next((r=>(s=r,n.Qi(e),n.mutationQueue.getAllMutationBatches(t)))).next((e=>{const r=[],i=[];let o=ma();for(const t of s){r.push(t.batchId);for(const e of t.mutations)o=o.add(e.key)}for(const t of e){i.push(t.batchId);for(const e of t.mutations)o=o.add(e.key)}return n.localDocuments.getDocuments(t,o).next((t=>({ji:t,removedBatchIds:r,addedBatchIds:i})))}))}))}function vh(t){const e=Gs(t);return e.persistence.runTransaction("Get last remote snapshot version","readonly",(t=>e.Cs.getLastRemoteSnapshotVersion(t)))}function Ih(t,e,n){let s=ma(),r=ma();return n.forEach((t=>s=s.add(t))),e.getEntries(t,s).next((t=>{let s=ia();return n.forEach(((n,i)=>{const o=t.get(n);i.isFoundDocument()!==o.isFoundDocument()&&(r=r.add(n)),i.isNoDocument()&&i.version.isEqual(ar.min())?(e.removeEntry(n,i.readTime),s=s.insert(n,i)):!o.isValidDocument()||i.version.compareTo(o.version)>0||0===i.version.compareTo(o.version)&&o.hasPendingWrites?(e.addEntry(i),s=s.insert(n,i)):Os("LocalStore","Ignoring outdated watch update for ",n,". Current version:",o.version," Watch version:",i.version)})),{Wi:s,zi:r}}))}function bh(t,e){const n=Gs(t);return n.persistence.runTransaction("Get next mutation batch","readonly",(t=>(void 0===e&&(e=-1),n.mutationQueue.getNextMutationBatchAfterBatchId(t,e))))}function Eh(t,e){const n=Gs(t);return n.persistence.runTransaction("Allocate target","readwrite",(t=>{let s;return n.Cs.getTargetData(t,e).next((r=>r?(s=r,xr.resolve(s)):n.Cs.allocateTargetId(t).next((r=>(s=new Ou(e,r,0,t.currentSequenceNumber),n.Cs.addTargetData(t,s).next((()=>s)))))))})).then((t=>{const s=n.Ui.get(t.targetId);return(null===s||t.snapshotVersion.compareTo(s.snapshotVersion)>0)&&(n.Ui=n.Ui.insert(t.targetId,t),n.qi.set(e,t.targetId)),t}))}async function Th(t,e,n){const s=Gs(t),r=s.Ui.get(e),i=n?"readwrite":"readwrite-primary";try{n||await s.persistence.runTransaction("Release target",i,(t=>s.persistence.referenceDelegate.removeTarget(t,r)))}catch(t){if(!Rr(t))throw t;Os("LocalStore",`Failed to update sequence numbers for target ${e}: ${t}`)}s.Ui=s.Ui.remove(e),s.qi.delete(r.target)}function Sh(t,e,n){const s=Gs(t);let r=ar.min(),i=ma();return s.persistence.runTransaction("Execute query","readonly",(t=>function(t,e,n){const s=Gs(t),r=s.qi.get(n);return void 0!==r?xr.resolve(s.Ui.get(r)):s.Cs.getTargetData(e,n)}(s,t,ho(e)).next((e=>{if(e)return r=e.lastLimboFreeSnapshotVersion,s.Cs.getMatchingKeysForTargetId(t,e.targetId).next((t=>{i=t}))})).next((()=>s.Li.getDocumentsMatchingQuery(t,e,n?r:ar.min(),n?i:ma()))).next((t=>(xh(s,yo(e),t),{documents:t,Hi:i})))))}function _h(t,e){const n=Gs(t),s=Gs(n.Cs),r=n.Ui.get(e);return r?Promise.resolve(r.target):n.persistence.runTransaction("Get target data","readonly",(t=>s.se(t,e).next((t=>t?t.target:null))))}function Dh(t,e){const n=Gs(t),s=n.Ki.get(e)||ar.min();return n.persistence.runTransaction("Get new document changes","readonly",(t=>n.Gi.getAllFromCollectionGroup(t,e,Ir(s,-1),Number.MAX_SAFE_INTEGER))).then((t=>(xh(n,e,t),t)))}function xh(t,e,n){let s=t.Ki.get(e)||ar.min();n.forEach(((t,e)=>{e.readTime.compareTo(s)>0&&(s=e.readTime)})),t.Ki.set(e,s)}async function Ah(t,e,n=ma()){const s=await Eh(t,ho(ju(e.bundledQuery))),r=Gs(t);return r.persistence.runTransaction("Save named query","readwrite",(t=>{const i=Ra(e.readTime);if(s.snapshotVersion.compareTo(i)>=0)return r.Ns.saveNamedQuery(t,e);const o=s.withResumeToken(Xr.EMPTY_BYTE_STRING,i);return r.Ui=r.Ui.insert(o.targetId,o),r.Cs.updateTargetData(t,o).next((()=>r.Cs.removeMatchingKeysForTargetId(t,s.targetId))).next((()=>r.Cs.addMatchingKeys(t,n,s.targetId))).next((()=>r.Ns.saveNamedQuery(t,e)))}))}function Ch(t,e){return`firestore_clients_${t}_${e}`}function Nh(t,e,n){let s=`firestore_mutations_${t}_${n}`;return e.isAuthenticated()&&(s+=`_${e.uid}`),s}function kh(t,e){return`firestore_targets_${t}_${e}`}class Rh{constructor(t,e,n,s){this.user=t,this.batchId=e,this.state=n,this.error=s}static Zi(t,e,n){const s=JSON.parse(n);let r,i="object"==typeof s&&-1!==["pending","acknowledged","rejected"].indexOf(s.state)&&(void 0===s.error||"object"==typeof s.error);return i&&s.error&&(i="string"==typeof s.error.message&&"string"==typeof s.error.code,i&&(r=new js(s.error.code,s.error.message))),i?new Rh(t,e,s.state,r):(Vs("SharedClientState",`Failed to parse mutation state for ID '${e}': ${n}`),null)}tr(){const t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)}}class Lh{constructor(t,e,n){this.targetId=t,this.state=e,this.error=n}static Zi(t,e){const n=JSON.parse(e);let s,r="object"==typeof n&&-1!==["not-current","current","rejected"].indexOf(n.state)&&(void 0===n.error||"object"==typeof n.error);return r&&n.error&&(r="string"==typeof n.error.message&&"string"==typeof n.error.code,r&&(s=new js(n.error.code,n.error.message))),r?new Lh(t,n.state,s):(Vs("SharedClientState",`Failed to parse target state for ID '${t}': ${e}`),null)}tr(){const t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)}}class Mh{constructor(t,e){this.clientId=t,this.activeTargetIds=e}static Zi(t,e){const n=JSON.parse(e);let s="object"==typeof n&&n.activeTargetIds instanceof Array,r=pa();for(let t=0;s&&t<n.activeTargetIds.length;++t)s=ci(n.activeTargetIds[t]),r=r.add(n.activeTargetIds[t]);return s?new Mh(t,r):(Vs("SharedClientState",`Failed to parse client data for instance '${t}': ${e}`),null)}}class Oh{constructor(t,e){this.clientId=t,this.onlineState=e}static Zi(t){const e=JSON.parse(t);return"object"==typeof e&&-1!==["Unknown","Online","Offline"].indexOf(e.onlineState)&&"string"==typeof e.clientId?new Oh(e.clientId,e.onlineState):(Vs("SharedClientState",`Failed to parse online state: ${t}`),null)}}class Vh{constructor(){this.activeTargetIds=pa()}er(t){this.activeTargetIds=this.activeTargetIds.add(t)}nr(t){this.activeTargetIds=this.activeTargetIds.delete(t)}tr(){const t={activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()};return JSON.stringify(t)}}class Fh{constructor(t,e,n,s,r){this.window=t,this.Hs=e,this.persistenceKey=n,this.sr=s,this.syncEngine=null,this.onlineStateHandler=null,this.sequenceNumberHandler=null,this.ir=this.rr.bind(this),this.ur=new Kr(sr),this.started=!1,this.cr=[];const i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");this.storage=this.window.localStorage,this.currentUser=r,this.ar=Ch(this.persistenceKey,this.sr),this.hr=function(t){return`firestore_sequence_number_${t}`}(this.persistenceKey),this.ur=this.ur.insert(this.sr,new Vh),this.lr=new RegExp(`^firestore_clients_${i}_([^_]*)$`),this.dr=new RegExp(`^firestore_mutations_${i}_(\\d+)(?:_(.*))?$`),this._r=new RegExp(`^firestore_targets_${i}_(\\d+)$`),this.wr=function(t){return`firestore_online_state_${t}`}(this.persistenceKey),this.mr=function(t){return`firestore_bundle_loaded_v2_${t}`}(this.persistenceKey),this.window.addEventListener("storage",this.ir)}static C(t){return!(!t||!t.localStorage)}async start(){const t=await this.syncEngine.vi();for(const e of t){if(e===this.sr)continue;const t=this.getItem(Ch(this.persistenceKey,e));if(t){const n=Mh.Zi(e,t);n&&(this.ur=this.ur.insert(n.clientId,n))}}this.gr();const e=this.storage.getItem(this.wr);if(e){const t=this.yr(e);t&&this.pr(t)}for(const t of this.cr)this.rr(t);this.cr=[],this.window.addEventListener("pagehide",(()=>this.shutdown())),this.started=!0}writeSequenceNumber(t){this.setItem(this.hr,JSON.stringify(t))}getAllActiveQueryTargets(){return this.Ir(this.ur)}isActiveQueryTarget(t){let e=!1;return this.ur.forEach(((n,s)=>{s.activeTargetIds.has(t)&&(e=!0)})),e}addPendingMutation(t){this.Tr(t,"pending")}updateMutationState(t,e,n){this.Tr(t,e,n),this.Er(t)}addLocalQueryTarget(t){let e="not-current";if(this.isActiveQueryTarget(t)){const n=this.storage.getItem(kh(this.persistenceKey,t));if(n){const s=Lh.Zi(t,n);s&&(e=s.state)}}return this.Ar.er(t),this.gr(),e}removeLocalQueryTarget(t){this.Ar.nr(t),this.gr()}isLocalQueryTarget(t){return this.Ar.activeTargetIds.has(t)}clearQueryState(t){this.removeItem(kh(this.persistenceKey,t))}updateQueryState(t,e,n){this.Rr(t,e,n)}handleUserChange(t,e,n){e.forEach((t=>{this.Er(t)})),this.currentUser=t,n.forEach((t=>{this.addPendingMutation(t)}))}setOnlineState(t){this.br(t)}notifyBundleLoaded(t){this.Pr(t)}shutdown(){this.started&&(this.window.removeEventListener("storage",this.ir),this.removeItem(this.ar),this.started=!1)}getItem(t){const e=this.storage.getItem(t);return Os("SharedClientState","READ",t,e),e}setItem(t,e){Os("SharedClientState","SET",t,e),this.storage.setItem(t,e)}removeItem(t){Os("SharedClientState","REMOVE",t),this.storage.removeItem(t)}rr(t){const e=t;if(e.storageArea===this.storage){if(Os("SharedClientState","EVENT",e.key,e.newValue),e.key===this.ar)return void Vs("Received WebStorage notification for local change. Another client might have garbage-collected our state");this.Hs.enqueueRetryable((async()=>{if(this.started){if(null!==e.key)if(this.lr.test(e.key)){if(null==e.newValue){const t=this.vr(e.key);return this.Vr(t,null)}{const t=this.Sr(e.key,e.newValue);if(t)return this.Vr(t.clientId,t)}}else if(this.dr.test(e.key)){if(null!==e.newValue){const t=this.Dr(e.key,e.newValue);if(t)return this.Cr(t)}}else if(this._r.test(e.key)){if(null!==e.newValue){const t=this.Nr(e.key,e.newValue);if(t)return this.kr(t)}}else if(e.key===this.wr){if(null!==e.newValue){const t=this.yr(e.newValue);if(t)return this.pr(t)}}else if(e.key===this.hr){const t=function(t){let e=Ur.at;if(null!=t)try{const n=JSON.parse(t);Bs("number"==typeof n),e=n}catch(t){Vs("SharedClientState","Failed to read sequence number from WebStorage",t)}return e}(e.newValue);t!==Ur.at&&this.sequenceNumberHandler(t)}else if(e.key===this.mr){const t=this.Or(e.newValue);await Promise.all(t.map((t=>this.syncEngine.Mr(t))))}}else this.cr.push(e)}))}}get Ar(){return this.ur.get(this.sr)}gr(){this.setItem(this.ar,this.Ar.tr())}Tr(t,e,n){const s=new Rh(this.currentUser,t,e,n),r=Nh(this.persistenceKey,this.currentUser,t);this.setItem(r,s.tr())}Er(t){const e=Nh(this.persistenceKey,this.currentUser,t);this.removeItem(e)}br(t){const e={clientId:this.sr,onlineState:t};this.storage.setItem(this.wr,JSON.stringify(e))}Rr(t,e,n){const s=kh(this.persistenceKey,t),r=new Lh(t,e,n);this.setItem(s,r.tr())}Pr(t){const e=JSON.stringify(Array.from(t));this.setItem(this.mr,e)}vr(t){const e=this.lr.exec(t);return e?e[1]:null}Sr(t,e){const n=this.vr(t);return Mh.Zi(n,e)}Dr(t,e){const n=this.dr.exec(t),s=Number(n[1]),r=void 0!==n[2]?n[2]:null;return Rh.Zi(new Ns(r),s,e)}Nr(t,e){const n=this._r.exec(t),s=Number(n[1]);return Lh.Zi(s,e)}yr(t){return Oh.Zi(t)}Or(t){return JSON.parse(t)}async Cr(t){if(t.user.uid===this.currentUser.uid)return this.syncEngine.Fr(t.batchId,t.state,t.error);Os("SharedClientState",`Ignoring mutation for non-active user ${t.user.uid}`)}kr(t){return this.syncEngine.$r(t.targetId,t.state,t.error)}Vr(t,e){const n=e?this.ur.insert(t,e):this.ur.remove(t),s=this.Ir(this.ur),r=this.Ir(n),i=[],o=[];return r.forEach((t=>{s.has(t)||i.push(t)})),s.forEach((t=>{r.has(t)||o.push(t)})),this.syncEngine.Br(i,o).then((()=>{this.ur=n}))}pr(t){this.ur.get(t.clientId)&&this.onlineStateHandler(t.onlineState)}Ir(t){let e=pa();return t.forEach(((t,n)=>{e=e.unionWith(n.activeTargetIds)})),e}}class Ph{constructor(){this.Lr=new Vh,this.Ur={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}addPendingMutation(t){}updateMutationState(t,e,n){}addLocalQueryTarget(t){return this.Lr.er(t),this.Ur[t]||"not-current"}updateQueryState(t,e,n){this.Ur[t]=e}removeLocalQueryTarget(t){this.Lr.nr(t)}isLocalQueryTarget(t){return this.Lr.activeTargetIds.has(t)}clearQueryState(t){delete this.Ur[t]}getAllActiveQueryTargets(){return this.Lr.activeTargetIds}isActiveQueryTarget(t){return this.Lr.activeTargetIds.has(t)}start(){return this.Lr=new Vh,Promise.resolve()}handleUserChange(t,e,n){}setOnlineState(t){}shutdown(){}writeSequenceNumber(t){}notifyBundleLoaded(t){}}class Uh{qr(t){}shutdown(){}}class Bh{constructor(){this.Kr=()=>this.Gr(),this.Qr=()=>this.jr(),this.Wr=[],this.zr()}qr(t){this.Wr.push(t)}shutdown(){window.removeEventListener("online",this.Kr),window.removeEventListener("offline",this.Qr)}zr(){window.addEventListener("online",this.Kr),window.addEventListener("offline",this.Qr)}Gr(){Os("ConnectivityMonitor","Network connectivity changed: AVAILABLE");for(const t of this.Wr)t(0)}jr(){Os("ConnectivityMonitor","Network connectivity changed: UNAVAILABLE");for(const t of this.Wr)t(1)}static C(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener}}const qh={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery"};class Gh{constructor(t){this.Hr=t.Hr,this.Jr=t.Jr}Yr(t){this.Xr=t}Zr(t){this.eo=t}onMessage(t){this.no=t}close(){this.Jr()}send(t){this.Hr(t)}so(){this.Xr()}io(t){this.eo(t)}ro(t){this.no(t)}}class Kh extends class{constructor(t){this.databaseInfo=t,this.databaseId=t.databaseId;const e=t.ssl?"https":"http";this.oo=e+"://"+t.host,this.uo="projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database+"/documents"}get co(){return!1}ao(t,e,n,s,r){const i=this.ho(t,e);Os("RestConnection","Sending: ",i,n);const o={};return this.lo(o,s,r),this.fo(t,i,o,n).then((t=>(Os("RestConnection","Received: ",t),t)),(e=>{throw Fs("RestConnection",`${t} failed with error: `,e,"url: ",i,"request:",n),e}))}_o(t,e,n,s,r,i){return this.ao(t,e,n,s,r)}lo(t,e,n){t["X-Goog-Api-Client"]="gl-js/ fire/"+ks,t["Content-Type"]="text/plain",this.databaseInfo.appId&&(t["X-Firebase-GMPID"]=this.databaseInfo.appId),e&&e.headers.forEach(((e,n)=>t[n]=e)),n&&n.headers.forEach(((e,n)=>t[n]=e))}ho(t,e){const n=qh[t];return`${this.oo}/v1/${e}:${n}`}}{constructor(t){super(t),this.forceLongPolling=t.forceLongPolling,this.autoDetectLongPolling=t.autoDetectLongPolling,this.useFetchStreams=t.useFetchStreams}fo(t,e,n,s){return new Promise(((r,i)=>{const o=new As;o.setWithCredentials(!0),o.listenOnce(Es.COMPLETE,(()=>{try{switch(o.getLastErrorCode()){case bs.NO_ERROR:const e=o.getResponseJson();Os("Connection","XHR received:",JSON.stringify(e)),r(e);break;case bs.TIMEOUT:Os("Connection",'RPC "'+t+'" timed out'),i(new js(Ks.DEADLINE_EXCEEDED,"Request time out"));break;case bs.HTTP_ERROR:const n=o.getStatus();if(Os("Connection",'RPC "'+t+'" failed with status:',n,"response text:",o.getResponseText()),n>0){const t=o.getResponseJson().error;if(t&&t.status&&t.message){const e=function(t){const e=t.toLowerCase().replace(/_/g,"-");return Object.values(Ks).indexOf(e)>=0?e:Ks.UNKNOWN}(t.status);i(new js(e,t.message))}else i(new js(Ks.UNKNOWN,"Server responded with status "+o.getStatus()))}else i(new js(Ks.UNAVAILABLE,"Connection failed."));break;default:Us()}}finally{Os("Connection",'RPC "'+t+'" completed.')}}));const a=JSON.stringify(s);o.send(e,"POST",a,n,15)}))}wo(t,e,n){const s=[this.oo,"/","google.firestore.v1.Firestore","/",t,"/channel"],r=new ps,i=me(),o={httpSessionIdParam:"gsessionid",initMessageHeaders:{},messageUrlParams:{database:`projects/${this.databaseId.projectId}/databases/${this.databaseId.database}`},sendRawJson:!0,supportsCrossDomainXhr:!0,internalChannelParams:{forwardChannelRequestTimeoutMs:6e5},forceLongPolling:this.forceLongPolling,detectBufferingProxy:this.autoDetectLongPolling};this.useFetchStreams&&(o.xmlHttpFactory=new Ds({})),this.lo(o.initMessageHeaders,e,n),o.encodeInitMessageHeaders=!0;const a=s.join("");Os("Connection","Creating WebChannel: "+a,o);const u=r.createWebChannel(a,o);let c=!1,h=!1;const l=new Gh({Hr:t=>{h?Os("Connection","Not sending because WebChannel is closed:",t):(c||(Os("Connection","Opening WebChannel transport."),u.open(),c=!0),Os("Connection","WebChannel sending:",t),u.send(t))},Jr:()=>u.close()}),d=(t,e,n)=>{t.listen(e,(t=>{try{n(t)}catch(t){setTimeout((()=>{throw t}),0)}}))};return d(u,xs.EventType.OPEN,(()=>{h||Os("Connection","WebChannel transport opened.")})),d(u,xs.EventType.CLOSE,(()=>{h||(h=!0,Os("Connection","WebChannel transport closed"),l.io())})),d(u,xs.EventType.ERROR,(t=>{h||(h=!0,Fs("Connection","WebChannel transport errored:",t),l.io(new js(Ks.UNAVAILABLE,"The operation could not be completed")))})),d(u,xs.EventType.MESSAGE,(t=>{var e;if(!h){const n=t.data[0];Bs(!!n);const s=n,r=s.error||(null===(e=s[0])||void 0===e?void 0:e.error);if(r){Os("Connection","WebChannel received error:",r);const t=r.status;let e=function(t){const e=Zo[t];if(void 0!==e)return na(e)}(t),n=r.message;void 0===e&&(e=Ks.INTERNAL,n="Unknown error status: "+t+" with message "+r.message),h=!0,l.io(new js(e,n)),u.close()}else Os("Connection","WebChannel received:",n),l.ro(n)}})),d(i,Ts.STAT_EVENT,(t=>{t.stat===Ss?Os("Connection","Detected buffering proxy"):t.stat===_s&&Os("Connection","Detected no buffering proxy")})),setTimeout((()=>{l.so()}),0),l}}function jh(){return"undefined"!=typeof window?window:null}function $h(){return"undefined"!=typeof document?document:null}function Qh(t){return new Aa(t,!0)}class zh{constructor(t,e,n=1e3,s=1.5,r=6e4){this.Hs=t,this.timerId=e,this.mo=n,this.yo=s,this.po=r,this.Io=0,this.To=null,this.Eo=Date.now(),this.reset()}reset(){this.Io=0}Ao(){this.Io=this.po}Ro(t){this.cancel();const e=Math.floor(this.Io+this.bo()),n=Math.max(0,Date.now()-this.Eo),s=Math.max(0,e-n);s>0&&Os("ExponentialBackoff",`Backing off for ${s} ms (base delay: ${this.Io} ms, delay with jitter: ${e} ms, last attempt: ${n} ms ago)`),this.To=this.Hs.enqueueAfterDelay(this.timerId,s,(()=>(this.Eo=Date.now(),t()))),this.Io*=this.yo,this.Io<this.mo&&(this.Io=this.mo),this.Io>this.po&&(this.Io=this.po)}Po(){null!==this.To&&(this.To.skipDelay(),this.To=null)}cancel(){null!==this.To&&(this.To.cancel(),this.To=null)}bo(){return(Math.random()-.5)*this.Io}}class Hh{constructor(t,e,n,s,r,i,o,a){this.Hs=t,this.vo=n,this.Vo=s,this.So=r,this.authCredentialsProvider=i,this.appCheckCredentialsProvider=o,this.listener=a,this.state=0,this.Do=0,this.Co=null,this.xo=null,this.stream=null,this.No=new zh(t,e)}ko(){return 1===this.state||5===this.state||this.Oo()}Oo(){return 2===this.state||3===this.state}start(){4!==this.state?this.auth():this.Mo()}async stop(){this.ko()&&await this.close(0)}Fo(){this.state=0,this.No.reset()}$o(){this.Oo()&&null===this.Co&&(this.Co=this.Hs.enqueueAfterDelay(this.vo,6e4,(()=>this.Bo())))}Lo(t){this.Uo(),this.stream.send(t)}async Bo(){if(this.Oo())return this.close(0)}Uo(){this.Co&&(this.Co.cancel(),this.Co=null)}qo(){this.xo&&(this.xo.cancel(),this.xo=null)}async close(t,e){this.Uo(),this.qo(),this.No.cancel(),this.Do++,4!==t?this.No.reset():e&&e.code===Ks.RESOURCE_EXHAUSTED?(Vs(e.toString()),Vs("Using maximum backoff delay to prevent overloading the backend."),this.No.Ao()):e&&e.code===Ks.UNAUTHENTICATED&&3!==this.state&&(this.authCredentialsProvider.invalidateToken(),this.appCheckCredentialsProvider.invalidateToken()),null!==this.stream&&(this.Ko(),this.stream.close(),this.stream=null),this.state=t,await this.listener.Zr(e)}Ko(){}auth(){this.state=1;const t=this.Go(this.Do),e=this.Do;Promise.all([this.authCredentialsProvider.getToken(),this.appCheckCredentialsProvider.getToken()]).then((([t,n])=>{this.Do===e&&this.Qo(t,n)}),(e=>{t((()=>{const t=new js(Ks.UNKNOWN,"Fetching auth token failed: "+e.message);return this.jo(t)}))}))}Qo(t,e){const n=this.Go(this.Do);this.stream=this.Wo(t,e),this.stream.Yr((()=>{n((()=>(this.state=2,this.xo=this.Hs.enqueueAfterDelay(this.Vo,1e4,(()=>(this.Oo()&&(this.state=3),Promise.resolve()))),this.listener.Yr())))})),this.stream.Zr((t=>{n((()=>this.jo(t)))})),this.stream.onMessage((t=>{n((()=>this.onMessage(t)))}))}Mo(){this.state=5,this.No.Ro((async()=>{this.state=0,this.start()}))}jo(t){return Os("PersistentStream",`close with error: ${t}`),this.stream=null,this.close(4,t)}Go(t){return e=>{this.Hs.enqueueAndForget((()=>this.Do===t?e():(Os("PersistentStream","stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())))}}}class Wh extends Hh{constructor(t,e,n,s,r,i){super(t,"listen_stream_connection_backoff","listen_stream_idle","health_check_timeout",e,n,s,i),this.It=r}Wo(t,e){return this.So.wo("Listen",t,e)}onMessage(t){this.No.reset();const e=function(t,e){let n;if("targetChange"in e){e.targetChange;const s=function(t){return"NO_CHANGE"===t?0:"ADD"===t?1:"REMOVE"===t?2:"CURRENT"===t?3:"RESET"===t?4:Us()}(e.targetChange.targetChangeType||"NO_CHANGE"),r=e.targetChange.targetIds||[],i=function(t,e){return t.gt?(Bs(void 0===e||"string"==typeof e),Xr.fromBase64String(e||"")):(Bs(void 0===e||e instanceof Uint8Array),Xr.fromUint8Array(e||new Uint8Array))}(t,e.targetChange.resumeToken),o=e.targetChange.cause,a=o&&function(t){const e=void 0===t.code?Ks.UNKNOWN:na(t.code);return new js(e,t.message||"")}(o);n=new ba(s,r,i,a||null)}else if("documentChange"in e){e.documentChange;const s=e.documentChange;s.document,s.document.name,s.document.updateTime;const r=Va(t,s.document.name),i=Ra(s.document.updateTime),o=new ki({mapValue:{fields:s.document.fields}}),a=Li.newFoundDocument(r,i,o),u=s.targetIds||[],c=s.removedTargetIds||[];n=new va(u,c,a.key,a)}else if("documentDelete"in e){e.documentDelete;const s=e.documentDelete;s.document;const r=Va(t,s.document),i=s.readTime?Ra(s.readTime):ar.min(),o=Li.newNoDocument(r,i),a=s.removedTargetIds||[];n=new va([],a,o.key,o)}else if("documentRemove"in e){e.documentRemove;const s=e.documentRemove;s.document;const r=Va(t,s.document),i=s.removedTargetIds||[];n=new va([],i,r,null)}else{if(!("filter"in e))return Us();{e.filter;const t=e.filter;t.targetId;const s=t.count||0,r=new Jo(s),i=t.targetId;n=new Ia(i,r)}}return n}(this.It,t),n=function(t){if(!("targetChange"in t))return ar.min();const e=t.targetChange;return e.targetIds&&e.targetIds.length?ar.min():e.readTime?Ra(e.readTime):ar.min()}(t);return this.listener.zo(e,n)}Ho(t){const e={};e.database=Ua(this.It),e.addTarget=function(t,e){let n;const s=e.target;return n=Pi(s)?{documents:$a(t,s)}:{query:Qa(t,s)},n.targetId=e.targetId,e.resumeToken.approximateByteSize()>0?n.resumeToken=Na(t,e.resumeToken):e.snapshotVersion.compareTo(ar.min())>0&&(n.readTime=Ca(t,e.snapshotVersion.toTimestamp())),n}(this.It,t);const n=function(t,e){const n=function(t,e){switch(e){case 0:return null;case 1:return"existence-filter-mismatch";case 2:return"limbo-document";default:return Us()}}(0,e.purpose);return null==n?null:{"goog-listen-tags":n}}(this.It,t);n&&(e.labels=n),this.Lo(e)}Jo(t){const e={};e.database=Ua(this.It),e.removeTarget=t,this.Lo(e)}}class Yh extends Hh{constructor(t,e,n,s,r,i){super(t,"write_stream_connection_backoff","write_stream_idle","health_check_timeout",e,n,s,i),this.It=r,this.Yo=!1}get Xo(){return this.Yo}start(){this.Yo=!1,this.lastStreamToken=void 0,super.start()}Ko(){this.Yo&&this.Zo([])}Wo(t,e){return this.So.wo("Write",t,e)}onMessage(t){if(Bs(!!t.streamToken),this.lastStreamToken=t.streamToken,this.Yo){this.No.reset();const e=function(t,e){return t&&t.length>0?(Bs(void 0!==e),t.map((t=>function(t,e){let n=t.updateTime?Ra(t.updateTime):Ra(e);return n.isEqual(ar.min())&&(n=Ra(e)),new Vo(n,t.transformResults||[])}(t,e)))):[]}(t.writeResults,t.commitTime),n=Ra(t.commitTime);return this.listener.tu(n,e)}return Bs(!t.writeResults||0===t.writeResults.length),this.Yo=!0,this.listener.eu()}nu(){const t={};t.database=Ua(this.It),this.Lo(t)}Zo(t){const e={streamToken:this.lastStreamToken,writes:t.map((t=>Ka(this.It,t)))};this.Lo(e)}}class Xh extends class{}{constructor(t,e,n,s){super(),this.authCredentials=t,this.appCheckCredentials=e,this.So=n,this.It=s,this.su=!1}iu(){if(this.su)throw new js(Ks.FAILED_PRECONDITION,"The client has already been terminated.")}ao(t,e,n){return this.iu(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([s,r])=>this.So.ao(t,e,n,s,r))).catch((t=>{throw"FirebaseError"===t.name?(t.code===Ks.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new js(Ks.UNKNOWN,t.toString())}))}_o(t,e,n,s){return this.iu(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([r,i])=>this.So._o(t,e,n,r,i,s))).catch((t=>{throw"FirebaseError"===t.name?(t.code===Ks.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new js(Ks.UNKNOWN,t.toString())}))}terminate(){this.su=!0}}class Jh{constructor(t,e){this.asyncQueue=t,this.onlineStateHandler=e,this.state="Unknown",this.ru=0,this.ou=null,this.uu=!0}cu(){0===this.ru&&(this.au("Unknown"),this.ou=this.asyncQueue.enqueueAfterDelay("online_state_timeout",1e4,(()=>(this.ou=null,this.hu("Backend didn't respond within 10 seconds."),this.au("Offline"),Promise.resolve()))))}lu(t){"Online"===this.state?this.au("Unknown"):(this.ru++,this.ru>=1&&(this.fu(),this.hu(`Connection failed 1 times. Most recent error: ${t.toString()}`),this.au("Offline")))}set(t){this.fu(),this.ru=0,"Online"===t&&(this.uu=!1),this.au(t)}au(t){t!==this.state&&(this.state=t,this.onlineStateHandler(t))}hu(t){const e=`Could not reach Cloud Firestore backend. ${t}\nThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.`;this.uu?(Vs(e),this.uu=!1):Os("OnlineStateTracker",e)}fu(){null!==this.ou&&(this.ou.cancel(),this.ou=null)}}class Zh{constructor(t,e,n,s,r){this.localStore=t,this.datastore=e,this.asyncQueue=n,this.remoteSyncer={},this.du=[],this._u=new Map,this.wu=new Set,this.mu=[],this.gu=r,this.gu.qr((t=>{n.enqueueAndForget((async()=>{ul(this)&&(Os("RemoteStore","Restarting streams for network reachability change."),await async function(t){const e=Gs(t);e.wu.add(4),await el(e),e.yu.set("Unknown"),e.wu.delete(4),await tl(e)}(this))}))})),this.yu=new Jh(n,s)}}async function tl(t){if(ul(t))for(const e of t.mu)await e(!0)}async function el(t){for(const e of t.mu)await e(!1)}function nl(t,e){const n=Gs(t);n._u.has(e.targetId)||(n._u.set(e.targetId,e),al(n)?ol(n):Dl(n).Oo()&&rl(n,e))}function sl(t,e){const n=Gs(t),s=Dl(n);n._u.delete(e),s.Oo()&&il(n,e),0===n._u.size&&(s.Oo()?s.$o():ul(n)&&n.yu.set("Unknown"))}function rl(t,e){t.pu.Mt(e.targetId),Dl(t).Ho(e)}function il(t,e){t.pu.Mt(e),Dl(t).Jo(e)}function ol(t){t.pu=new Ta({getRemoteKeysForTarget:e=>t.remoteSyncer.getRemoteKeysForTarget(e),se:e=>t._u.get(e)||null}),Dl(t).start(),t.yu.cu()}function al(t){return ul(t)&&!Dl(t).ko()&&t._u.size>0}function ul(t){return 0===Gs(t).wu.size}function cl(t){t.pu=void 0}async function hl(t){t._u.forEach(((e,n)=>{rl(t,e)}))}async function ll(t,e){cl(t),al(t)?(t.yu.lu(e),ol(t)):t.yu.set("Unknown")}async function dl(t,e,n){if(t.yu.set("Online"),e instanceof ba&&2===e.state&&e.cause)try{await async function(t,e){const n=e.cause;for(const s of e.targetIds)t._u.has(s)&&(await t.remoteSyncer.rejectListen(s,n),t._u.delete(s),t.pu.removeTarget(s))}(t,e)}catch(n){Os("RemoteStore","Failed to remove targets %s: %s ",e.targetIds.join(","),n),await fl(t,n)}else if(e instanceof va?t.pu.Gt(e):e instanceof Ia?t.pu.Yt(e):t.pu.Wt(e),!n.isEqual(ar.min()))try{const e=await vh(t.localStore);n.compareTo(e)>=0&&await function(t,e){const n=t.pu.te(e);return n.targetChanges.forEach(((n,s)=>{if(n.resumeToken.approximateByteSize()>0){const r=t._u.get(s);r&&t._u.set(s,r.withResumeToken(n.resumeToken,e))}})),n.targetMismatches.forEach((e=>{const n=t._u.get(e);if(!n)return;t._u.set(e,n.withResumeToken(Xr.EMPTY_BYTE_STRING,n.snapshotVersion)),il(t,e);const s=new Ou(n.target,e,1,n.sequenceNumber);rl(t,s)})),t.remoteSyncer.applyRemoteEvent(n)}(t,n)}catch(e){Os("RemoteStore","Failed to raise snapshot:",e),await fl(t,e)}}async function fl(t,e,n){if(!Rr(e))throw e;t.wu.add(1),await el(t),t.yu.set("Offline"),n||(n=()=>vh(t.localStore)),t.asyncQueue.enqueueRetryable((async()=>{Os("RemoteStore","Retrying IndexedDB access"),await n(),t.wu.delete(1),await tl(t)}))}function ml(t,e){return e().catch((n=>fl(t,n,e)))}async function gl(t){const e=Gs(t),n=xl(e);let s=e.du.length>0?e.du[e.du.length-1].batchId:-1;for(;pl(e);)try{const t=await bh(e.localStore,s);if(null===t){0===e.du.length&&n.$o();break}s=t.batchId,yl(e,t)}catch(t){await fl(e,t)}wl(e)&&vl(e)}function pl(t){return ul(t)&&t.du.length<10}function yl(t,e){t.du.push(e);const n=xl(t);n.Oo()&&n.Xo&&n.Zo(e.mutations)}function wl(t){return ul(t)&&!xl(t).ko()&&t.du.length>0}function vl(t){xl(t).start()}async function Il(t){xl(t).nu()}async function bl(t){const e=xl(t);for(const n of t.du)e.Zo(n.mutations)}async function El(t,e,n){const s=t.du.shift(),r=Lu.from(s,e,n);await ml(t,(()=>t.remoteSyncer.applySuccessfulWrite(r))),await gl(t)}async function Tl(t,e){e&&xl(t).Xo&&await async function(t,e){if(ea(n=e.code)&&n!==Ks.ABORTED){const n=t.du.shift();xl(t).Fo(),await ml(t,(()=>t.remoteSyncer.rejectFailedWrite(n.batchId,e))),await gl(t)}var n}(t,e),wl(t)&&vl(t)}async function Sl(t,e){const n=Gs(t);n.asyncQueue.verifyOperationInProgress(),Os("RemoteStore","RemoteStore received new credentials");const s=ul(n);n.wu.add(3),await el(n),s&&n.yu.set("Unknown"),await n.remoteSyncer.handleCredentialChange(e),n.wu.delete(3),await tl(n)}async function _l(t,e){const n=Gs(t);e?(n.wu.delete(2),await tl(n)):e||(n.wu.add(2),await el(n),n.yu.set("Unknown"))}function Dl(t){return t.Iu||(t.Iu=function(t,e,n){const s=Gs(t);return s.iu(),new Wh(e,s.So,s.authCredentials,s.appCheckCredentials,s.It,n)}(t.datastore,t.asyncQueue,{Yr:hl.bind(null,t),Zr:ll.bind(null,t),zo:dl.bind(null,t)}),t.mu.push((async e=>{e?(t.Iu.Fo(),al(t)?ol(t):t.yu.set("Unknown")):(await t.Iu.stop(),cl(t))}))),t.Iu}function xl(t){return t.Tu||(t.Tu=function(t,e,n){const s=Gs(t);return s.iu(),new Yh(e,s.So,s.authCredentials,s.appCheckCredentials,s.It,n)}(t.datastore,t.asyncQueue,{Yr:Il.bind(null,t),Zr:Tl.bind(null,t),eu:bl.bind(null,t),tu:El.bind(null,t)}),t.mu.push((async e=>{e?(t.Tu.Fo(),await gl(t)):(await t.Tu.stop(),t.du.length>0&&(Os("RemoteStore",`Stopping write stream with ${t.du.length} pending writes`),t.du=[]))}))),t.Tu}class Al{constructor(t,e,n,s,r){this.asyncQueue=t,this.timerId=e,this.targetTimeMs=n,this.op=s,this.removalCallback=r,this.deferred=new $s,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch((t=>{}))}static createAndSchedule(t,e,n,s,r){const i=Date.now()+n,o=new Al(t,e,i,s,r);return o.start(n),o}start(t){this.timerHandle=setTimeout((()=>this.handleDelayElapsed()),t)}skipDelay(){return this.handleDelayElapsed()}cancel(t){null!==this.timerHandle&&(this.clearTimeout(),this.deferred.reject(new js(Ks.CANCELLED,"Operation cancelled"+(t?": "+t:""))))}handleDelayElapsed(){this.asyncQueue.enqueueAndForget((()=>null!==this.timerHandle?(this.clearTimeout(),this.op().then((t=>this.deferred.resolve(t)))):Promise.resolve()))}clearTimeout(){null!==this.timerHandle&&(this.removalCallback(this),clearTimeout(this.timerHandle),this.timerHandle=null)}}function Cl(t,e){if(Vs("AsyncQueue",`${e}: ${t}`),Rr(t))return new js(Ks.UNAVAILABLE,`${e}: ${t}`);throw t}class Nl{constructor(t){this.comparator=t?(e,n)=>t(e,n)||dr.comparator(e.key,n.key):(t,e)=>dr.comparator(t.key,e.key),this.keyedMap=aa(),this.sortedSet=new Kr(this.comparator)}static emptySet(t){return new Nl(t.comparator)}has(t){return null!=this.keyedMap.get(t)}get(t){return this.keyedMap.get(t)}first(){return this.sortedSet.minKey()}last(){return this.sortedSet.maxKey()}isEmpty(){return this.sortedSet.isEmpty()}indexOf(t){const e=this.keyedMap.get(t);return e?this.sortedSet.indexOf(e):-1}get size(){return this.sortedSet.size}forEach(t){this.sortedSet.inorderTraversal(((e,n)=>(t(e),!1)))}add(t){const e=this.delete(t.key);return e.copy(e.keyedMap.insert(t.key,t),e.sortedSet.insert(t,null))}delete(t){const e=this.get(t);return e?this.copy(this.keyedMap.remove(t),this.sortedSet.remove(e)):this}isEqual(t){if(!(t instanceof Nl))return!1;if(this.size!==t.size)return!1;const e=this.sortedSet.getIterator(),n=t.sortedSet.getIterator();for(;e.hasNext();){const t=e.getNext().key,s=n.getNext().key;if(!t.isEqual(s))return!1}return!0}toString(){const t=[];return this.forEach((e=>{t.push(e.toString())})),0===t.length?"DocumentSet ()":"DocumentSet (\n "+t.join(" \n")+"\n)"}copy(t,e){const n=new Nl;return n.comparator=this.comparator,n.keyedMap=t,n.sortedSet=e,n}}class kl{constructor(){this.Eu=new Kr(dr.comparator)}track(t){const e=t.doc.key,n=this.Eu.get(e);n?0!==t.type&&3===n.type?this.Eu=this.Eu.insert(e,t):3===t.type&&1!==n.type?this.Eu=this.Eu.insert(e,{type:n.type,doc:t.doc}):2===t.type&&2===n.type?this.Eu=this.Eu.insert(e,{type:2,doc:t.doc}):2===t.type&&0===n.type?this.Eu=this.Eu.insert(e,{type:0,doc:t.doc}):1===t.type&&0===n.type?this.Eu=this.Eu.remove(e):1===t.type&&2===n.type?this.Eu=this.Eu.insert(e,{type:1,doc:n.doc}):0===t.type&&1===n.type?this.Eu=this.Eu.insert(e,{type:2,doc:t.doc}):Us():this.Eu=this.Eu.insert(e,t)}Au(){const t=[];return this.Eu.inorderTraversal(((e,n)=>{t.push(n)})),t}}class Rl{constructor(t,e,n,s,r,i,o,a,u){this.query=t,this.docs=e,this.oldDocs=n,this.docChanges=s,this.mutatedKeys=r,this.fromCache=i,this.syncStateChanged=o,this.excludesMetadataChanges=a,this.hasCachedResults=u}static fromInitialDocuments(t,e,n,s,r){const i=[];return e.forEach((t=>{i.push({type:0,doc:t})})),new Rl(t,e,Nl.emptySet(e),i,n,s,!0,!1,r)}get hasPendingWrites(){return!this.mutatedKeys.isEmpty()}isEqual(t){if(!(this.fromCache===t.fromCache&&this.hasCachedResults===t.hasCachedResults&&this.syncStateChanged===t.syncStateChanged&&this.mutatedKeys.isEqual(t.mutatedKeys)&&fo(this.query,t.query)&&this.docs.isEqual(t.docs)&&this.oldDocs.isEqual(t.oldDocs)))return!1;const e=this.docChanges,n=t.docChanges;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t].type!==n[t].type||!e[t].doc.isEqual(n[t].doc))return!1;return!0}}class Ll{constructor(){this.Ru=void 0,this.listeners=[]}}class Ml{constructor(){this.queries=new sa((t=>mo(t)),fo),this.onlineState="Unknown",this.bu=new Set}}async function Ol(t,e){const n=Gs(t),s=e.query;let r=!1,i=n.queries.get(s);if(i||(r=!0,i=new Ll),r)try{i.Ru=await n.onListen(s)}catch(t){const n=Cl(t,`Initialization of query '${go(e.query)}' failed`);return void e.onError(n)}n.queries.set(s,i),i.listeners.push(e),e.Pu(n.onlineState),i.Ru&&e.vu(i.Ru)&&Ul(n)}async function Vl(t,e){const n=Gs(t),s=e.query;let r=!1;const i=n.queries.get(s);if(i){const t=i.listeners.indexOf(e);t>=0&&(i.listeners.splice(t,1),r=0===i.listeners.length)}if(r)return n.queries.delete(s),n.onUnlisten(s)}function Fl(t,e){const n=Gs(t);let s=!1;for(const t of e){const e=t.query,r=n.queries.get(e);if(r){for(const e of r.listeners)e.vu(t)&&(s=!0);r.Ru=t}}s&&Ul(n)}function Pl(t,e,n){const s=Gs(t),r=s.queries.get(e);if(r)for(const t of r.listeners)t.onError(n);s.queries.delete(e)}function Ul(t){t.bu.forEach((t=>{t.next()}))}class Bl{constructor(t,e,n){this.query=t,this.Vu=e,this.Su=!1,this.Du=null,this.onlineState="Unknown",this.options=n||{}}vu(t){if(!this.options.includeMetadataChanges){const e=[];for(const n of t.docChanges)3!==n.type&&e.push(n);t=new Rl(t.query,t.docs,t.oldDocs,e,t.mutatedKeys,t.fromCache,t.syncStateChanged,!0,t.hasCachedResults)}let e=!1;return this.Su?this.Cu(t)&&(this.Vu.next(t),e=!0):this.xu(t,this.onlineState)&&(this.Nu(t),e=!0),this.Du=t,e}onError(t){this.Vu.error(t)}Pu(t){this.onlineState=t;let e=!1;return this.Du&&!this.Su&&this.xu(this.Du,t)&&(this.Nu(this.Du),e=!0),e}xu(t,e){if(!t.fromCache)return!0;const n="Offline"!==e;return(!this.options.ku||!n)&&(!t.docs.isEmpty()||t.hasCachedResults||"Offline"===e)}Cu(t){if(t.docChanges.length>0)return!0;const e=this.Du&&this.Du.hasPendingWrites!==t.hasPendingWrites;return!(!t.syncStateChanged&&!e)&&!0===this.options.includeMetadataChanges}Nu(t){t=Rl.fromInitialDocuments(t.query,t.docs,t.mutatedKeys,t.fromCache,t.hasCachedResults),this.Su=!0,this.Vu.next(t)}}class ql{constructor(t,e){this.payload=t,this.byteLength=e}Ou(){return"metadata"in this.payload}}class Gl{constructor(t){this.It=t}Ji(t){return Va(this.It,t)}Yi(t){return t.metadata.exists?Ga(this.It,t.document,!1):Li.newNoDocument(this.Ji(t.metadata.name),this.Xi(t.metadata.readTime))}Xi(t){return Ra(t)}}class Kl{constructor(t,e,n){this.Mu=t,this.localStore=e,this.It=n,this.queries=[],this.documents=[],this.collectionGroups=new Set,this.progress=jl(t)}Fu(t){this.progress.bytesLoaded+=t.byteLength;let e=this.progress.documentsLoaded;if(t.payload.namedQuery)this.queries.push(t.payload.namedQuery);else if(t.payload.documentMetadata){this.documents.push({metadata:t.payload.documentMetadata}),t.payload.documentMetadata.exists||++e;const n=cr.fromString(t.payload.documentMetadata.name);this.collectionGroups.add(n.get(n.length-2))}else t.payload.document&&(this.documents[this.documents.length-1].document=t.payload.document,++e);return e!==this.progress.documentsLoaded?(this.progress.documentsLoaded=e,Object.assign({},this.progress)):null}$u(t){const e=new Map,n=new Gl(this.It);for(const s of t)if(s.metadata.queries){const t=n.Ji(s.metadata.name);for(const n of s.metadata.queries){const s=(e.get(n)||ma()).add(t);e.set(n,s)}}return e}async complete(){const t=await async function(t,e,n,s){const r=Gs(t);let i=ma(),o=ia();for(const t of n){const n=e.Ji(t.metadata.name);t.document&&(i=i.add(n));const s=e.Yi(t);s.setReadTime(e.Xi(t.metadata.readTime)),o=o.insert(n,s)}const a=r.Gi.newChangeBuffer({trackRemovals:!0}),u=await Eh(r,function(t){return ho(ro(cr.fromString(`__bundle__/docs/${t}`)))}(s));return r.persistence.runTransaction("Apply bundle documents","readwrite",(t=>Ih(t,a,o).next((e=>(a.apply(t),e))).next((e=>r.Cs.removeMatchingKeysForTargetId(t,u.targetId).next((()=>r.Cs.addMatchingKeys(t,i,u.targetId))).next((()=>r.localDocuments.getLocalViewOfDocuments(t,e.Wi,e.zi))).next((()=>e.Wi))))))}(this.localStore,new Gl(this.It),this.documents,this.Mu.id),e=this.$u(this.documents);for(const t of this.queries)await Ah(this.localStore,t,e.get(t.name));return this.progress.taskState="Success",{progress:this.progress,Bu:this.collectionGroups,Lu:t}}}function jl(t){return{taskState:"Running",documentsLoaded:0,bytesLoaded:0,totalDocuments:t.totalDocuments,totalBytes:t.totalBytes}}class $l{constructor(t){this.key=t}}class Ql{constructor(t){this.key=t}}class zl{constructor(t,e){this.query=t,this.Uu=e,this.qu=null,this.hasCachedResults=!1,this.current=!1,this.Ku=ma(),this.mutatedKeys=ma(),this.Gu=wo(t),this.Qu=new Nl(this.Gu)}get ju(){return this.Uu}Wu(t,e){const n=e?e.zu:new kl,s=e?e.Qu:this.Qu;let r=e?e.mutatedKeys:this.mutatedKeys,i=s,o=!1;const a="F"===this.query.limitType&&s.size===this.query.limit?s.last():null,u="L"===this.query.limitType&&s.size===this.query.limit?s.first():null;if(t.inorderTraversal(((t,e)=>{const c=s.get(t),h=po(this.query,e)?e:null,l=!!c&&this.mutatedKeys.has(c.key),d=!!h&&(h.hasLocalMutations||this.mutatedKeys.has(h.key)&&h.hasCommittedMutations);let f=!1;c&&h?c.data.isEqual(h.data)?l!==d&&(n.track({type:3,doc:h}),f=!0):this.Hu(c,h)||(n.track({type:2,doc:h}),f=!0,(a&&this.Gu(h,a)>0||u&&this.Gu(h,u)<0)&&(o=!0)):!c&&h?(n.track({type:0,doc:h}),f=!0):c&&!h&&(n.track({type:1,doc:c}),f=!0,(a||u)&&(o=!0)),f&&(h?(i=i.add(h),r=d?r.add(t):r.delete(t)):(i=i.delete(t),r=r.delete(t)))})),null!==this.query.limit)for(;i.size>this.query.limit;){const t="F"===this.query.limitType?i.last():i.first();i=i.delete(t.key),r=r.delete(t.key),n.track({type:1,doc:t})}return{Qu:i,zu:n,$i:o,mutatedKeys:r}}Hu(t,e){return t.hasLocalMutations&&e.hasCommittedMutations&&!e.hasLocalMutations}applyChanges(t,e,n){const s=this.Qu;this.Qu=t.Qu,this.mutatedKeys=t.mutatedKeys;const r=t.zu.Au();r.sort(((t,e)=>function(t,e){const n=t=>{switch(t){case 0:return 1;case 2:case 3:return 2;case 1:return 0;default:return Us()}};return n(t)-n(e)}(t.type,e.type)||this.Gu(t.doc,e.doc))),this.Ju(n);const i=e?this.Yu():[],o=0===this.Ku.size&&this.current?1:0,a=o!==this.qu;return this.qu=o,0!==r.length||a?{snapshot:new Rl(this.query,t.Qu,s,r,t.mutatedKeys,0===o,a,!1,!!n&&n.resumeToken.approximateByteSize()>0),Xu:i}:{Xu:i}}Pu(t){return this.current&&"Offline"===t?(this.current=!1,this.applyChanges({Qu:this.Qu,zu:new kl,mutatedKeys:this.mutatedKeys,$i:!1},!1)):{Xu:[]}}Zu(t){return!this.Uu.has(t)&&!!this.Qu.has(t)&&!this.Qu.get(t).hasLocalMutations}Ju(t){t&&(t.addedDocuments.forEach((t=>this.Uu=this.Uu.add(t))),t.modifiedDocuments.forEach((t=>{})),t.removedDocuments.forEach((t=>this.Uu=this.Uu.delete(t))),this.current=t.current)}Yu(){if(!this.current)return[];const t=this.Ku;this.Ku=ma(),this.Qu.forEach((t=>{this.Zu(t.key)&&(this.Ku=this.Ku.add(t.key))}));const e=[];return t.forEach((t=>{this.Ku.has(t)||e.push(new Ql(t))})),this.Ku.forEach((n=>{t.has(n)||e.push(new $l(n))})),e}tc(t){this.Uu=t.Hi,this.Ku=ma();const e=this.Wu(t.documents);return this.applyChanges(e,!0)}ec(){return Rl.fromInitialDocuments(this.query,this.Qu,this.mutatedKeys,0===this.qu,this.hasCachedResults)}}class Hl{constructor(t,e,n){this.query=t,this.targetId=e,this.view=n}}class Wl{constructor(t){this.key=t,this.nc=!1}}class Yl{constructor(t,e,n,s,r,i){this.localStore=t,this.remoteStore=e,this.eventManager=n,this.sharedClientState=s,this.currentUser=r,this.maxConcurrentLimboResolutions=i,this.sc={},this.ic=new sa((t=>mo(t)),fo),this.rc=new Map,this.oc=new Set,this.uc=new Kr(dr.comparator),this.cc=new Map,this.ac=new Jc,this.hc={},this.lc=new Map,this.fc=Ac.vn(),this.onlineState="Unknown",this.dc=void 0}get isPrimaryClient(){return!0===this.dc}}async function Xl(t,e){const n=Td(t);let s,r;const i=n.ic.get(e);if(i)s=i.targetId,n.sharedClientState.addLocalQueryTarget(s),r=i.view.ec();else{const t=await Eh(n.localStore,ho(e));n.isPrimaryClient&&nl(n.remoteStore,t);const i=n.sharedClientState.addLocalQueryTarget(t.targetId);s=t.targetId,r=await Jl(n,e,s,"current"===i,t.resumeToken)}return r}async function Jl(t,e,n,s,r){t._c=(e,n,s)=>async function(t,e,n,s){let r=e.view.Wu(n);r.$i&&(r=await Sh(t.localStore,e.query,!1).then((({documents:t})=>e.view.Wu(t,r))));const i=s&&s.targetChanges.get(e.targetId),o=e.view.applyChanges(r,t.isPrimaryClient,i);return cd(t,e.targetId,o.Xu),o.snapshot}(t,e,n,s);const i=await Sh(t.localStore,e,!0),o=new zl(e,i.Hi),a=o.Wu(i.documents),u=wa.createSynthesizedTargetChangeForCurrentChange(n,s&&"Offline"!==t.onlineState,r),c=o.applyChanges(a,t.isPrimaryClient,u);cd(t,n,c.Xu);const h=new Hl(e,n,o);return t.ic.set(e,h),t.rc.has(n)?t.rc.get(n).push(e):t.rc.set(n,[e]),c.snapshot}async function Zl(t,e){const n=Gs(t),s=n.ic.get(e),r=n.rc.get(s.targetId);if(r.length>1)return n.rc.set(s.targetId,r.filter((t=>!fo(t,e)))),void n.ic.delete(e);n.isPrimaryClient?(n.sharedClientState.removeLocalQueryTarget(s.targetId),n.sharedClientState.isActiveQueryTarget(s.targetId)||await Th(n.localStore,s.targetId,!1).then((()=>{n.sharedClientState.clearQueryState(s.targetId),sl(n.remoteStore,s.targetId),ad(n,s.targetId)})).catch(Dr)):(ad(n,s.targetId),await Th(n.localStore,s.targetId,!0))}async function td(t,e){const n=Gs(t);try{const t=await function(t,e){const n=Gs(t),s=e.snapshotVersion;let r=n.Ui;return n.persistence.runTransaction("Apply remote event","readwrite-primary",(t=>{const i=n.Gi.newChangeBuffer({trackRemovals:!0});r=n.Ui;const o=[];e.targetChanges.forEach(((i,a)=>{const u=r.get(a);if(!u)return;o.push(n.Cs.removeMatchingKeys(t,i.removedDocuments,a).next((()=>n.Cs.addMatchingKeys(t,i.addedDocuments,a))));let c=u.withSequenceNumber(t.currentSequenceNumber);e.targetMismatches.has(a)?c=c.withResumeToken(Xr.EMPTY_BYTE_STRING,ar.min()).withLastLimboFreeSnapshotVersion(ar.min()):i.resumeToken.approximateByteSize()>0&&(c=c.withResumeToken(i.resumeToken,s)),r=r.insert(a,c),function(t,e,n){return 0===t.resumeToken.approximateByteSize()||e.snapshotVersion.toMicroseconds()-t.snapshotVersion.toMicroseconds()>=3e8||n.addedDocuments.size+n.modifiedDocuments.size+n.removedDocuments.size>0}(u,c,i)&&o.push(n.Cs.updateTargetData(t,c))}));let a=ia(),u=ma();if(e.documentUpdates.forEach((s=>{e.resolvedLimboDocuments.has(s)&&o.push(n.persistence.referenceDelegate.updateLimboDocument(t,s))})),o.push(Ih(t,i,e.documentUpdates).next((t=>{a=t.Wi,u=t.zi}))),!s.isEqual(ar.min())){const e=n.Cs.getLastRemoteSnapshotVersion(t).next((e=>n.Cs.setTargetsMetadata(t,t.currentSequenceNumber,s)));o.push(e)}return xr.waitFor(o).next((()=>i.apply(t))).next((()=>n.localDocuments.getLocalViewOfDocuments(t,a,u))).next((()=>a))})).then((t=>(n.Ui=r,t)))}(n.localStore,e);e.targetChanges.forEach(((t,e)=>{const s=n.cc.get(e);s&&(Bs(t.addedDocuments.size+t.modifiedDocuments.size+t.removedDocuments.size<=1),t.addedDocuments.size>0?s.nc=!0:t.modifiedDocuments.size>0?Bs(s.nc):t.removedDocuments.size>0&&(Bs(s.nc),s.nc=!1))})),await dd(n,t,e)}catch(t){await Dr(t)}}function ed(t,e,n){const s=Gs(t);if(s.isPrimaryClient&&0===n||!s.isPrimaryClient&&1===n){const t=[];s.ic.forEach(((n,s)=>{const r=s.view.Pu(e);r.snapshot&&t.push(r.snapshot)})),function(t,e){const n=Gs(t);n.onlineState=e;let s=!1;n.queries.forEach(((t,n)=>{for(const t of n.listeners)t.Pu(e)&&(s=!0)})),s&&Ul(n)}(s.eventManager,e),t.length&&s.sc.zo(t),s.onlineState=e,s.isPrimaryClient&&s.sharedClientState.setOnlineState(e)}}async function nd(t,e,n){const s=Gs(t);s.sharedClientState.updateQueryState(e,"rejected",n);const r=s.cc.get(e),i=r&&r.key;if(i){let t=new Kr(dr.comparator);t=t.insert(i,Li.newNoDocument(i,ar.min()));const n=ma().add(i),r=new ya(ar.min(),new Map,new Qr(sr),t,n);await td(s,r),s.uc=s.uc.remove(i),s.cc.delete(e),ld(s)}else await Th(s.localStore,e,!1).then((()=>ad(s,e,n))).catch(Dr)}async function sd(t,e){const n=Gs(t),s=e.batch.batchId;try{const t=await function(t,e){const n=Gs(t);return n.persistence.runTransaction("Acknowledge batch","readwrite-primary",(t=>{const s=e.batch.keys(),r=n.Gi.newChangeBuffer({trackRemovals:!0});return function(t,e,n,s){const r=n.batch,i=r.keys();let o=xr.resolve();return i.forEach((t=>{o=o.next((()=>s.getEntry(e,t))).next((e=>{const i=n.docVersions.get(t);Bs(null!==i),e.version.compareTo(i)<0&&(r.applyToRemoteDocument(e,n),e.isValidDocument()&&(e.setReadTime(n.commitVersion),s.addEntry(e)))}))})),o.next((()=>t.mutationQueue.removeMutationBatch(e,r)))}(n,t,e,r).next((()=>r.apply(t))).next((()=>n.mutationQueue.performConsistencyCheck(t))).next((()=>n.documentOverlayCache.removeOverlaysForBatchId(t,s,e.batch.batchId))).next((()=>n.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(t,function(t){let e=ma();for(let n=0;n<t.mutationResults.length;++n)t.mutationResults[n].transformResults.length>0&&(e=e.add(t.batch.mutations[n].key));return e}(e)))).next((()=>n.localDocuments.getDocuments(t,s)))}))}(n.localStore,e);od(n,s,null),id(n,s),n.sharedClientState.updateMutationState(s,"acknowledged"),await dd(n,t)}catch(t){await Dr(t)}}async function rd(t,e,n){const s=Gs(t);try{const t=await function(t,e){const n=Gs(t);return n.persistence.runTransaction("Reject batch","readwrite-primary",(t=>{let s;return n.mutationQueue.lookupMutationBatch(t,e).next((e=>(Bs(null!==e),s=e.keys(),n.mutationQueue.removeMutationBatch(t,e)))).next((()=>n.mutationQueue.performConsistencyCheck(t))).next((()=>n.documentOverlayCache.removeOverlaysForBatchId(t,s,e))).next((()=>n.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(t,s))).next((()=>n.localDocuments.getDocuments(t,s)))}))}(s.localStore,e);od(s,e,n),id(s,e),s.sharedClientState.updateMutationState(e,"rejected",n),await dd(s,t)}catch(n){await Dr(n)}}function id(t,e){(t.lc.get(e)||[]).forEach((t=>{t.resolve()})),t.lc.delete(e)}function od(t,e,n){const s=Gs(t);let r=s.hc[s.currentUser.toKey()];if(r){const t=r.get(e);t&&(n?t.reject(n):t.resolve(),r=r.remove(e)),s.hc[s.currentUser.toKey()]=r}}function ad(t,e,n=null){t.sharedClientState.removeLocalQueryTarget(e);for(const s of t.rc.get(e))t.ic.delete(s),n&&t.sc.wc(s,n);t.rc.delete(e),t.isPrimaryClient&&t.ac.ls(e).forEach((e=>{t.ac.containsKey(e)||ud(t,e)}))}function ud(t,e){t.oc.delete(e.path.canonicalString());const n=t.uc.get(e);null!==n&&(sl(t.remoteStore,n),t.uc=t.uc.remove(e),t.cc.delete(n),ld(t))}function cd(t,e,n){for(const s of n)s instanceof $l?(t.ac.addReference(s.key,e),hd(t,s)):s instanceof Ql?(Os("SyncEngine","Document no longer in limbo: "+s.key),t.ac.removeReference(s.key,e),t.ac.containsKey(s.key)||ud(t,s.key)):Us()}function hd(t,e){const n=e.key,s=n.path.canonicalString();t.uc.get(n)||t.oc.has(s)||(Os("SyncEngine","New document in limbo: "+n),t.oc.add(s),ld(t))}function ld(t){for(;t.oc.size>0&&t.uc.size<t.maxConcurrentLimboResolutions;){const e=t.oc.values().next().value;t.oc.delete(e);const n=new dr(cr.fromString(e)),s=t.fc.next();t.cc.set(s,new Wl(n)),t.uc=t.uc.insert(n,s),nl(t.remoteStore,new Ou(ho(ro(n.path)),s,2,Ur.at))}}async function dd(t,e,n){const s=Gs(t),r=[],i=[],o=[];s.ic.isEmpty()||(s.ic.forEach(((t,a)=>{o.push(s._c(a,e,n).then((t=>{if((t||n)&&s.isPrimaryClient&&s.sharedClientState.updateQueryState(a.targetId,(null==t?void 0:t.fromCache)?"not-current":"current"),t){r.push(t);const e=mh.Ci(a.targetId,t);i.push(e)}})))})),await Promise.all(o),s.sc.zo(r),await async function(t,e){const n=Gs(t);try{await n.persistence.runTransaction("notifyLocalViewChanges","readwrite",(t=>xr.forEach(e,(e=>xr.forEach(e.Si,(s=>n.persistence.referenceDelegate.addReference(t,e.targetId,s))).next((()=>xr.forEach(e.Di,(s=>n.persistence.referenceDelegate.removeReference(t,e.targetId,s)))))))))}catch(t){if(!Rr(t))throw t;Os("LocalStore","Failed to update sequence numbers: "+t)}for(const t of e){const e=t.targetId;if(!t.fromCache){const t=n.Ui.get(e),s=t.snapshotVersion,r=t.withLastLimboFreeSnapshotVersion(s);n.Ui=n.Ui.insert(e,r)}}}(s.localStore,i))}async function fd(t,e){const n=Gs(t);if(!n.currentUser.isEqual(e)){Os("SyncEngine","User change. New user:",e.toKey());const t=await wh(n.localStore,e);n.currentUser=e,function(t,e){t.lc.forEach((t=>{t.forEach((t=>{t.reject(new js(Ks.CANCELLED,"'waitForPendingWrites' promise is rejected due to a user change."))}))})),t.lc.clear()}(n),n.sharedClientState.handleUserChange(e,t.removedBatchIds,t.addedBatchIds),await dd(n,t.ji)}}function md(t,e){const n=Gs(t),s=n.cc.get(e);if(s&&s.nc)return ma().add(s.key);{let t=ma();const s=n.rc.get(e);if(!s)return t;for(const e of s){const s=n.ic.get(e);t=t.unionWith(s.view.ju)}return t}}async function gd(t,e){const n=Gs(t),s=await Sh(n.localStore,e.query,!0),r=e.view.tc(s);return n.isPrimaryClient&&cd(n,e.targetId,r.Xu),r}async function pd(t,e){const n=Gs(t);return Dh(n.localStore,e).then((t=>dd(n,t)))}async function yd(t,e,n,s){const r=Gs(t),i=await function(t,e){const n=Gs(t),s=Gs(n.mutationQueue);return n.persistence.runTransaction("Lookup mutation documents","readonly",(t=>s.Tn(t,e).next((e=>e?n.localDocuments.getDocuments(t,e):xr.resolve(null)))))}(r.localStore,e);null!==i?("pending"===n?await gl(r.remoteStore):"acknowledged"===n||"rejected"===n?(od(r,e,s||null),id(r,e),function(t,e){Gs(Gs(t).mutationQueue).An(e)}(r.localStore,e)):Us(),await dd(r,i)):Os("SyncEngine","Cannot apply mutation batch with id: "+e)}async function wd(t,e,n){const s=Gs(t),r=[],i=[];for(const t of e){let e;const n=s.rc.get(t);if(n&&0!==n.length){e=await Eh(s.localStore,ho(n[0]));for(const t of n){const e=s.ic.get(t),n=await gd(s,e);n.snapshot&&i.push(n.snapshot)}}else{const n=await _h(s.localStore,t);e=await Eh(s.localStore,n),await Jl(s,vd(n),t,!1,e.resumeToken)}r.push(e)}return s.sc.zo(i),r}function vd(t){return so(t.path,t.collectionGroup,t.orderBy,t.filters,t.limit,"F",t.startAt,t.endAt)}function Id(t){const e=Gs(t);return Gs(Gs(e.localStore).persistence).vi()}async function bd(t,e,n,s){const r=Gs(t);if(r.dc)return void Os("SyncEngine","Ignoring unexpected query state notification.");const i=r.rc.get(e);if(i&&i.length>0)switch(n){case"current":case"not-current":{const t=await Dh(r.localStore,yo(i[0])),s=ya.createSynthesizedRemoteEventForCurrentChange(e,"current"===n,Xr.EMPTY_BYTE_STRING);await dd(r,t,s);break}case"rejected":await Th(r.localStore,e,!0),ad(r,e,s);break;default:Us()}}async function Ed(t,e,n){const s=Td(t);if(s.dc){for(const t of e){if(s.rc.has(t)){Os("SyncEngine","Adding an already active target "+t);continue}const e=await _h(s.localStore,t),n=await Eh(s.localStore,e);await Jl(s,vd(e),n.targetId,!1,n.resumeToken),nl(s.remoteStore,n)}for(const t of n)s.rc.has(t)&&await Th(s.localStore,t,!1).then((()=>{sl(s.remoteStore,t),ad(s,t)})).catch(Dr)}}function Td(t){const e=Gs(t);return e.remoteStore.remoteSyncer.applyRemoteEvent=td.bind(null,e),e.remoteStore.remoteSyncer.getRemoteKeysForTarget=md.bind(null,e),e.remoteStore.remoteSyncer.rejectListen=nd.bind(null,e),e.sc.zo=Fl.bind(null,e.eventManager),e.sc.wc=Pl.bind(null,e.eventManager),e}function Sd(t){const e=Gs(t);return e.remoteStore.remoteSyncer.applySuccessfulWrite=sd.bind(null,e),e.remoteStore.remoteSyncer.rejectFailedWrite=rd.bind(null,e),e}class _d{constructor(){this.synchronizeTabs=!1}async initialize(t){this.It=Qh(t.databaseInfo.databaseId),this.sharedClientState=this.gc(t),this.persistence=this.yc(t),await this.persistence.start(),this.localStore=this.Ic(t),this.gcScheduler=this.Tc(t,this.localStore),this.indexBackfillerScheduler=this.Ec(t,this.localStore)}Tc(t,e){return null}Ec(t,e){return null}Ic(t){return yh(this.persistence,new gh,t.initialUser,this.It)}yc(t){return new rh(oh.Bs,this.It)}gc(t){return new Ph}async terminate(){this.gcScheduler&&this.gcScheduler.stop(),await this.sharedClientState.shutdown(),await this.persistence.shutdown()}}class Dd extends _d{constructor(t,e,n){super(),this.Ac=t,this.cacheSizeBytes=e,this.forceOwnership=n,this.synchronizeTabs=!1}async initialize(t){await super.initialize(t),await this.Ac.initialize(this,t),await Sd(this.Ac.syncEngine),await gl(this.Ac.remoteStore),await this.persistence.li((()=>(this.gcScheduler&&!this.gcScheduler.started&&this.gcScheduler.start(),this.indexBackfillerScheduler&&!this.indexBackfillerScheduler.started&&this.indexBackfillerScheduler.start(),Promise.resolve())))}Ic(t){return yh(this.persistence,new gh,t.initialUser,this.It)}Tc(t,e){const n=this.persistence.referenceDelegate.garbageCollector;return new Oc(n,t.asyncQueue,e)}Ec(t,e){const n=new Pr(e,this.persistence);return new Fr(t.asyncQueue,n)}yc(t){const e=fh(t.databaseInfo.databaseId,t.databaseInfo.persistenceKey),n=void 0!==this.cacheSizeBytes?Ic.withCacheSize(this.cacheSizeBytes):Ic.DEFAULT;return new hh(this.synchronizeTabs,e,t.clientId,n,t.asyncQueue,jh(),$h(),this.It,this.sharedClientState,!!this.forceOwnership)}gc(t){return new Ph}}class xd extends Dd{constructor(t,e){super(t,e,!1),this.Ac=t,this.cacheSizeBytes=e,this.synchronizeTabs=!0}async initialize(t){await super.initialize(t);const e=this.Ac.syncEngine;this.sharedClientState instanceof Fh&&(this.sharedClientState.syncEngine={Fr:yd.bind(null,e),$r:bd.bind(null,e),Br:Ed.bind(null,e),vi:Id.bind(null,e),Mr:pd.bind(null,e)},await this.sharedClientState.start()),await this.persistence.li((async t=>{await async function(t,e){const n=Gs(t);if(Td(n),Sd(n),!0===e&&!0!==n.dc){const t=n.sharedClientState.getAllActiveQueryTargets(),e=await wd(n,t.toArray());n.dc=!0,await _l(n.remoteStore,!0);for(const t of e)nl(n.remoteStore,t)}else if(!1===e&&!1!==n.dc){const t=[];let e=Promise.resolve();n.rc.forEach(((s,r)=>{n.sharedClientState.isLocalQueryTarget(r)?t.push(r):e=e.then((()=>(ad(n,r),Th(n.localStore,r,!0)))),sl(n.remoteStore,r)})),await e,await wd(n,t),function(t){const e=Gs(t);e.cc.forEach(((t,n)=>{sl(e.remoteStore,n)})),e.ac.fs(),e.cc=new Map,e.uc=new Kr(dr.comparator)}(n),n.dc=!1,await _l(n.remoteStore,!1)}}(this.Ac.syncEngine,t),this.gcScheduler&&(t&&!this.gcScheduler.started?this.gcScheduler.start():t||this.gcScheduler.stop()),this.indexBackfillerScheduler&&(t&&!this.indexBackfillerScheduler.started?this.indexBackfillerScheduler.start():t||this.indexBackfillerScheduler.stop())}))}gc(t){const e=jh();if(!Fh.C(e))throw new js(Ks.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");const n=fh(t.databaseInfo.databaseId,t.databaseInfo.persistenceKey);return new Fh(e,t.asyncQueue,n,t.clientId,t.initialUser)}}class Ad{async initialize(t,e){this.localStore||(this.localStore=t.localStore,this.sharedClientState=t.sharedClientState,this.datastore=this.createDatastore(e),this.remoteStore=this.createRemoteStore(e),this.eventManager=this.createEventManager(e),this.syncEngine=this.createSyncEngine(e,!t.synchronizeTabs),this.sharedClientState.onlineStateHandler=t=>ed(this.syncEngine,t,1),this.remoteStore.remoteSyncer.handleCredentialChange=fd.bind(null,this.syncEngine),await _l(this.remoteStore,this.syncEngine.isPrimaryClient))}createEventManager(t){return new Ml}createDatastore(t){const e=Qh(t.databaseInfo.databaseId),n=(s=t.databaseInfo,new Kh(s));var s;return function(t,e,n,s){return new Xh(t,e,n,s)}(t.authCredentials,t.appCheckCredentials,n,e)}createRemoteStore(t){return e=this.localStore,n=this.datastore,s=t.asyncQueue,r=t=>ed(this.syncEngine,t,0),i=Bh.C()?new Bh:new Uh,new Zh(e,n,s,r,i);var e,n,s,r,i}createSyncEngine(t,e){return function(t,e,n,s,r,i,o){const a=new Yl(t,e,n,s,r,i);return o&&(a.dc=!0),a}(this.localStore,this.remoteStore,this.eventManager,this.sharedClientState,t.initialUser,t.maxConcurrentLimboResolutions,e)}terminate(){return async function(t){const e=Gs(t);Os("RemoteStore","RemoteStore shutting down."),e.wu.add(5),await el(e),e.gu.shutdown(),e.yu.set("Unknown")}(this.remoteStore)}}function Cd(t,e,n){if(!n)throw new js(Ks.INVALID_ARGUMENT,`Function ${t}() cannot be called with an empty ${e}.`)}function Nd(t,e,n,s){if(!0===e&&!0===s)throw new js(Ks.INVALID_ARGUMENT,`${t} and ${n} cannot be used together.`)}function kd(t){if(!dr.isDocumentKey(t))throw new js(Ks.INVALID_ARGUMENT,`Invalid document reference. Document references must have an even number of segments, but ${t} has ${t.length}.`)}function Rd(t){if(dr.isDocumentKey(t))throw new js(Ks.INVALID_ARGUMENT,`Invalid collection reference. Collection references must have an odd number of segments, but ${t} has ${t.length}.`)}function Ld(t){if(void 0===t)return"undefined";if(null===t)return"null";if("string"==typeof t)return t.length>20&&(t=`${t.substring(0,20)}...`),JSON.stringify(t);if("number"==typeof t||"boolean"==typeof t)return""+t;if("object"==typeof t){if(t instanceof Array)return"an array";{const e=function(t){return t.constructor?t.constructor.name:null}(t);return e?`a custom ${e} object`:"an object"}}return"function"==typeof t?"a function":Us()}function Md(t,e){if("_delegate"in t&&(t=t._delegate),!(t instanceof e)){if(e.name===t.constructor.name)throw new js(Ks.INVALID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{const n=Ld(t);throw new js(Ks.INVALID_ARGUMENT,`Expected type '${e.name}', but it was: ${n}`)}}return t}function Od(t,e){if(e<=0)throw new js(Ks.INVALID_ARGUMENT,`Function ${t}() requires a positive number, but it was: ${e}.`)}const Vd=new Map;class Fd{constructor(t){var e;if(void 0===t.host){if(void 0!==t.ssl)throw new js(Ks.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host="firestore.googleapis.com",this.ssl=!0}else this.host=t.host,this.ssl=null===(e=t.ssl)||void 0===e||e;if(this.credentials=t.credentials,this.ignoreUndefinedProperties=!!t.ignoreUndefinedProperties,void 0===t.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==t.cacheSizeBytes&&t.cacheSizeBytes<1048576)throw new js(Ks.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=t.cacheSizeBytes}this.experimentalForceLongPolling=!!t.experimentalForceLongPolling,this.experimentalAutoDetectLongPolling=!!t.experimentalAutoDetectLongPolling,this.useFetchStreams=!!t.useFetchStreams,Nd("experimentalForceLongPolling",t.experimentalForceLongPolling,"experimentalAutoDetectLongPolling",t.experimentalAutoDetectLongPolling)}isEqual(t){return this.host===t.host&&this.ssl===t.ssl&&this.credentials===t.credentials&&this.cacheSizeBytes===t.cacheSizeBytes&&this.experimentalForceLongPolling===t.experimentalForceLongPolling&&this.experimentalAutoDetectLongPolling===t.experimentalAutoDetectLongPolling&&this.ignoreUndefinedProperties===t.ignoreUndefinedProperties&&this.useFetchStreams===t.useFetchStreams}}class Pd{constructor(t,e,n,s){this._authCredentials=t,this._appCheckCredentials=e,this._databaseId=n,this._app=s,this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new Fd({}),this._settingsFrozen=!1}get app(){if(!this._app)throw new js(Ks.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this._app}get _initialized(){return this._settingsFrozen}get _terminated(){return void 0!==this._terminateTask}_setSettings(t){if(this._settingsFrozen)throw new js(Ks.FAILED_PRECONDITION,"Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.");this._settings=new Fd(t),void 0!==t.credentials&&(this._authCredentials=function(t){if(!t)return new zs;switch(t.type){case"gapi":const e=t.client;return new Xs(e,t.sessionIndex||"0",t.iamToken||null,t.authTokenFactory||null);case"provider":return t.client;default:throw new js(Ks.INVALID_ARGUMENT,"makeAuthCredentialsProvider failed due to invalid credential type")}}(t.credentials))}_getSettings(){return this._settings}_freezeSettings(){return this._settingsFrozen=!0,this._settings}_delete(){return this._terminateTask||(this._terminateTask=this._terminate()),this._terminateTask}toJSON(){return{app:this._app,databaseId:this._databaseId,settings:this._settings}}_terminate(){return function(t){const e=Vd.get(t);e&&(Os("ComponentProvider","Removing Datastore"),Vd.delete(t),e.terminate())}(this),Promise.resolve()}}function Ud(t,e,n,s={}){var r;const i=(t=Md(t,Pd))._getSettings();if("firestore.googleapis.com"!==i.host&&i.host!==e&&Fs("Host has been set in both settings() and useEmulator(), emulator host will be used"),t._setSettings(Object.assign(Object.assign({},i),{host:`${e}:${n}`,ssl:!1})),s.mockUserToken){let e,n;if("string"==typeof s.mockUserToken)e=s.mockUserToken,n=Ns.MOCK_USER;else{e=function(t,e){if(t.uid)throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');const n=e||"demo-project",s=t.iat||0,r=t.sub||t.user_id;if(!r)throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");const i=Object.assign({iss:`https://securetoken.google.com/${n}`,aud:n,iat:s,exp:s+3600,auth_time:s,sub:r,user_id:r,firebase:{sign_in_provider:"custom",identities:{}}},t);return[u(JSON.stringify({alg:"none",type:"JWT"})),u(JSON.stringify(i)),""].join(".")}(s.mockUserToken,null===(r=t._app)||void 0===r?void 0:r.options.projectId);const i=s.mockUserToken.sub||s.mockUserToken.user_id;if(!i)throw new js(Ks.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");n=new Ns(i)}t._authCredentials=new Hs(new Qs(e,n))}}class Bd{constructor(t,e,n){this.converter=e,this._key=n,this.type="document",this.firestore=t}get _path(){return this._key.path}get id(){return this._key.path.lastSegment()}get path(){return this._key.path.canonicalString()}get parent(){return new Gd(this.firestore,this.converter,this._key.path.popLast())}withConverter(t){return new Bd(this.firestore,t,this._key)}}class qd{constructor(t,e,n){this.converter=e,this._query=n,this.type="query",this.firestore=t}withConverter(t){return new qd(this.firestore,t,this._query)}}class Gd extends qd{constructor(t,e,n){super(t,e,ro(n)),this._path=n,this.type="collection"}get id(){return this._query.path.lastSegment()}get path(){return this._query.path.canonicalString()}get parent(){const t=this._path.popLast();return t.isEmpty()?null:new Bd(this.firestore,null,new dr(t))}withConverter(t){return new Gd(this.firestore,t,this._path)}}function Kd(t,e,...n){if(t=I(t),Cd("collection","path",e),t instanceof Pd){const s=cr.fromString(e,...n);return Rd(s),new Gd(t,null,s)}{if(!(t instanceof Bd||t instanceof Gd))throw new js(Ks.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const s=t._path.child(cr.fromString(e,...n));return Rd(s),new Gd(t.firestore,null,s)}}function jd(t,e){if(t=Md(t,Pd),Cd("collectionGroup","collection id",e),e.indexOf("/")>=0)throw new js(Ks.INVALID_ARGUMENT,`Invalid collection ID '${e}' passed to function collectionGroup(). Collection IDs must not contain '/'.`);return new qd(t,null,function(t){return new no(cr.emptyPath(),t)}(e))}function $d(t,e,...n){if(t=I(t),1===arguments.length&&(e=nr.R()),Cd("doc","path",e),t instanceof Pd){const s=cr.fromString(e,...n);return kd(s),new Bd(t,null,new dr(s))}{if(!(t instanceof Bd||t instanceof Gd))throw new js(Ks.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const s=t._path.child(cr.fromString(e,...n));return kd(s),new Bd(t.firestore,t instanceof Gd?t.converter:null,new dr(s))}}function Qd(t,e){return t=I(t),e=I(e),(t instanceof Bd||t instanceof Gd)&&(e instanceof Bd||e instanceof Gd)&&t.firestore===e.firestore&&t.path===e.path&&t.converter===e.converter}function zd(t,e){return t=I(t),e=I(e),t instanceof qd&&e instanceof qd&&t.firestore===e.firestore&&fo(t._query,e._query)&&t.converter===e.converter}function Hd(t,e=10240){let n=0;return{async read(){if(n<t.byteLength){const s={value:t.slice(n,n+e),done:!1};return n+=e,s}return{done:!0}},async cancel(){},releaseLock(){},closed:Promise.reject("unimplemented")}}class Wd{constructor(t){this.observer=t,this.muted=!1}next(t){this.observer.next&&this.Rc(this.observer.next,t)}error(t){this.observer.error?this.Rc(this.observer.error,t):Vs("Uncaught Error in snapshot listener:",t)}bc(){this.muted=!0}Rc(t,e){this.muted||setTimeout((()=>{this.muted||t(e)}),0)}}class Yd{constructor(t,e){this.Pc=t,this.It=e,this.metadata=new $s,this.buffer=new Uint8Array,this.vc=new TextDecoder("utf-8"),this.Vc().then((t=>{t&&t.Ou()?this.metadata.resolve(t.payload.metadata):this.metadata.reject(new Error(`The first element of the bundle is not a metadata, it is\n ${JSON.stringify(null==t?void 0:t.payload)}`))}),(t=>this.metadata.reject(t)))}close(){return this.Pc.cancel()}async getMetadata(){return this.metadata.promise}async mc(){return await this.getMetadata(),this.Vc()}async Vc(){const t=await this.Sc();if(null===t)return null;const e=this.vc.decode(t),n=Number(e);isNaN(n)&&this.Dc(`length string (${e}) is not valid number`);const s=await this.Cc(n);return new ql(JSON.parse(s),t.length+n)}xc(){return this.buffer.findIndex((t=>t==="{".charCodeAt(0)))}async Sc(){for(;this.xc()<0&&!await this.Nc(););if(0===this.buffer.length)return null;const t=this.xc();t<0&&this.Dc("Reached the end of bundle when a length string is expected.");const e=this.buffer.slice(0,t);return this.buffer=this.buffer.slice(t),e}async Cc(t){for(;this.buffer.length<t;)await this.Nc()&&this.Dc("Reached the end of bundle when more is expected.");const e=this.vc.decode(this.buffer.slice(0,t));return this.buffer=this.buffer.slice(t),e}Dc(t){throw this.Pc.cancel(),new Error(`Invalid bundle format: ${t}`)}async Nc(){const t=await this.Pc.read();if(!t.done){const e=new Uint8Array(this.buffer.length+t.value.length);e.set(this.buffer),e.set(t.value,this.buffer.length),this.buffer=e}return t.done}}class Xd{constructor(){this.type="AggregateField"}}class Jd{constructor(t,e){this._data=e,this.type="AggregateQuerySnapshot",this.query=t}data(){return this._data}}class Zd{constructor(t,e,n){this.query=t,this.datastore=e,this.userDataWriter=n}run(){return async function(t,e){const n=Gs(t),s=function(t,e){const n=Qa(t,e);return{structuredAggregationQuery:{aggregations:[{count:{},alias:"count_alias"}],structuredQuery:n.structuredQuery},parent:n.parent}}(n.It,ho(e)),r=s.parent;return n.So.co||delete s.parent,(await n._o("RunAggregationQuery",r,s,1)).filter((t=>!!t.result)).map((t=>t.result.aggregateFields))}(this.datastore,this.query._query).then((t=>{Bs(void 0!==t[0]);const e=Object.entries(t[0]).filter((([t,e])=>"count_alias"===t)).map((([t,e])=>this.userDataWriter.convertValue(e)))[0];return Bs("number"==typeof e),Promise.resolve(new Jd(this.query,{count:e}))}))}}class tf{constructor(t){this.datastore=t,this.readVersions=new Map,this.mutations=[],this.committed=!1,this.lastWriteError=null,this.writtenDocs=new Set}async lookup(t){if(this.ensureCommitNotCalled(),this.mutations.length>0)throw new js(Ks.INVALID_ARGUMENT,"Firestore transactions require all reads to be executed before all writes.");const e=await async function(t,e){const n=Gs(t),s=Ua(n.It)+"/documents",r={documents:e.map((t=>Oa(n.It,t)))},i=await n._o("BatchGetDocuments",s,r,e.length),o=new Map;i.forEach((t=>{const e=function(t,e){return"found"in e?function(t,e){Bs(!!e.found),e.found.name,e.found.updateTime;const n=Va(t,e.found.name),s=Ra(e.found.updateTime),r=new ki({mapValue:{fields:e.found.fields}});return Li.newFoundDocument(n,s,r)}(t,e):"missing"in e?function(t,e){Bs(!!e.missing),Bs(!!e.readTime);const n=Va(t,e.missing),s=Ra(e.readTime);return Li.newNoDocument(n,s)}(t,e):Us()}(n.It,t);o.set(e.key.toString(),e)}));const a=[];return e.forEach((t=>{const e=o.get(t.toString());Bs(!!e),a.push(e)})),a}(this.datastore,t);return e.forEach((t=>this.recordVersion(t))),e}set(t,e){this.write(e.toMutation(t,this.precondition(t))),this.writtenDocs.add(t.toString())}update(t,e){try{this.write(e.toMutation(t,this.preconditionForUpdate(t)))}catch(t){this.lastWriteError=t}this.writtenDocs.add(t.toString())}delete(t){this.write(new Yo(t,this.precondition(t))),this.writtenDocs.add(t.toString())}async commit(){if(this.ensureCommitNotCalled(),this.lastWriteError)throw this.lastWriteError;const t=this.readVersions;this.mutations.forEach((e=>{t.delete(e.key.toString())})),t.forEach(((t,e)=>{const n=dr.fromPath(e);this.mutations.push(new Xo(n,this.precondition(n)))})),await async function(t,e){const n=Gs(t),s=Ua(n.It)+"/documents",r={writes:e.map((t=>Ka(n.It,t)))};await n.ao("Commit",s,r)}(this.datastore,this.mutations),this.committed=!0}recordVersion(t){let e;if(t.isFoundDocument())e=t.version;else{if(!t.isNoDocument())throw Us();e=ar.min()}const n=this.readVersions.get(t.key.toString());if(n){if(!e.isEqual(n))throw new js(Ks.ABORTED,"Document version changed between two reads.")}else this.readVersions.set(t.key.toString(),e)}precondition(t){const e=this.readVersions.get(t.toString());return!this.writtenDocs.has(t.toString())&&e?e.isEqual(ar.min())?Fo.exists(!1):Fo.updateTime(e):Fo.none()}preconditionForUpdate(t){const e=this.readVersions.get(t.toString());if(!this.writtenDocs.has(t.toString())&&e){if(e.isEqual(ar.min()))throw new js(Ks.INVALID_ARGUMENT,"Can't update a document that doesn't exist.");return Fo.updateTime(e)}return Fo.exists(!0)}write(t){this.ensureCommitNotCalled(),this.mutations.push(t)}ensureCommitNotCalled(){}}class ef{constructor(t,e,n,s,r){this.asyncQueue=t,this.datastore=e,this.options=n,this.updateFunction=s,this.deferred=r,this.kc=n.maxAttempts,this.No=new zh(this.asyncQueue,"transaction_retry")}run(){this.kc-=1,this.Oc()}Oc(){this.No.Ro((async()=>{const t=new tf(this.datastore),e=this.Mc(t);e&&e.then((e=>{this.asyncQueue.enqueueAndForget((()=>t.commit().then((()=>{this.deferred.resolve(e)})).catch((t=>{this.Fc(t)}))))})).catch((t=>{this.Fc(t)}))}))}Mc(t){try{const e=this.updateFunction(t);return!ai(e)&&e.catch&&e.then?e:(this.deferred.reject(Error("Transaction callback must return a Promise")),null)}catch(t){return this.deferred.reject(t),null}}Fc(t){this.kc>0&&this.$c(t)?(this.kc-=1,this.asyncQueue.enqueueAndForget((()=>(this.Oc(),Promise.resolve())))):this.deferred.reject(t)}$c(t){if("FirebaseError"===t.name){const e=t.code;return"aborted"===e||"failed-precondition"===e||!ea(e)}return!1}}class nf{constructor(t,e,n,s){this.authCredentials=t,this.appCheckCredentials=e,this.asyncQueue=n,this.databaseInfo=s,this.user=Ns.UNAUTHENTICATED,this.clientId=nr.R(),this.authCredentialListener=()=>Promise.resolve(),this.appCheckCredentialListener=()=>Promise.resolve(),this.authCredentials.start(n,(async t=>{Os("FirestoreClient","Received user=",t.uid),await this.authCredentialListener(t),this.user=t})),this.appCheckCredentials.start(n,(t=>(Os("FirestoreClient","Received new app check token=",t),this.appCheckCredentialListener(t,this.user))))}async getConfiguration(){return{asyncQueue:this.asyncQueue,databaseInfo:this.databaseInfo,clientId:this.clientId,authCredentials:this.authCredentials,appCheckCredentials:this.appCheckCredentials,initialUser:this.user,maxConcurrentLimboResolutions:100}}setCredentialChangeListener(t){this.authCredentialListener=t}setAppCheckTokenChangeListener(t){this.appCheckCredentialListener=t}verifyNotTerminated(){if(this.asyncQueue.isShuttingDown)throw new js(Ks.FAILED_PRECONDITION,"The client has already been terminated.")}terminate(){this.asyncQueue.enterRestrictedMode();const t=new $s;return this.asyncQueue.enqueueAndForgetEvenWhileRestricted((async()=>{try{this.onlineComponents&&await this.onlineComponents.terminate(),this.offlineComponents&&await this.offlineComponents.terminate(),this.authCredentials.shutdown(),this.appCheckCredentials.shutdown(),t.resolve()}catch(e){const n=Cl(e,"Failed to shutdown persistence");t.reject(n)}})),t.promise}}async function sf(t,e){t.asyncQueue.verifyOperationInProgress(),Os("FirestoreClient","Initializing OfflineComponentProvider");const n=await t.getConfiguration();await e.initialize(n);let s=n.initialUser;t.setCredentialChangeListener((async t=>{s.isEqual(t)||(await wh(e.localStore,t),s=t)})),e.persistence.setDatabaseDeletedListener((()=>t.terminate())),t.offlineComponents=e}async function rf(t,e){t.asyncQueue.verifyOperationInProgress();const n=await of(t);Os("FirestoreClient","Initializing OnlineComponentProvider");const s=await t.getConfiguration();await e.initialize(n,s),t.setCredentialChangeListener((t=>Sl(e.remoteStore,t))),t.setAppCheckTokenChangeListener(((t,n)=>Sl(e.remoteStore,n))),t.onlineComponents=e}async function of(t){return t.offlineComponents||(Os("FirestoreClient","Using default OfflineComponentProvider"),await sf(t,new _d)),t.offlineComponents}async function af(t){return t.onlineComponents||(Os("FirestoreClient","Using default OnlineComponentProvider"),await rf(t,new Ad)),t.onlineComponents}function uf(t){return of(t).then((t=>t.persistence))}function cf(t){return of(t).then((t=>t.localStore))}function hf(t){return af(t).then((t=>t.remoteStore))}function lf(t){return af(t).then((t=>t.syncEngine))}function df(t){return af(t).then((t=>t.datastore))}async function ff(t){const e=await af(t),n=e.eventManager;return n.onListen=Xl.bind(null,e.syncEngine),n.onUnlisten=Zl.bind(null,e.syncEngine),n}function mf(t,e,n={}){const s=new $s;return t.asyncQueue.enqueueAndForget((async()=>function(t,e,n,s,r){const i=new Wd({next:i=>{e.enqueueAndForget((()=>Vl(t,o)));const a=i.docs.has(n);!a&&i.fromCache?r.reject(new js(Ks.UNAVAILABLE,"Failed to get document because the client is offline.")):a&&i.fromCache&&s&&"server"===s.source?r.reject(new js(Ks.UNAVAILABLE,'Failed to get document from server. (However, this document does exist in the local cache. Run again without setting source to "server" to retrieve the cached document.)')):r.resolve(i)},error:t=>r.reject(t)}),o=new Bl(ro(n.path),i,{includeMetadataChanges:!0,ku:!0});return Ol(t,o)}(await ff(t),t.asyncQueue,e,n,s))),s.promise}function gf(t,e,n={}){const s=new $s;return t.asyncQueue.enqueueAndForget((async()=>function(t,e,n,s,r){const i=new Wd({next:n=>{e.enqueueAndForget((()=>Vl(t,o))),n.fromCache&&"server"===s.source?r.reject(new js(Ks.UNAVAILABLE,'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')):r.resolve(n)},error:t=>r.reject(t)}),o=new Bl(n,i,{includeMetadataChanges:!0,ku:!0});return Ol(t,o)}(await ff(t),t.asyncQueue,e,n,s))),s.promise}function pf(t,e,n,s){const r=function(t,e){let n;return n="string"==typeof t?(new TextEncoder).encode(t):t,function(t,e){return new Yd(t,e)}(function(t,e){if(t instanceof Uint8Array)return Hd(t,e);if(t instanceof ArrayBuffer)return Hd(new Uint8Array(t),e);if(t instanceof ReadableStream)return t.getReader();throw new Error("Source of `toByteStreamReader` has to be a ArrayBuffer or ReadableStream")}(n),e)}(n,Qh(e));t.asyncQueue.enqueueAndForget((async()=>{!function(t,e,n){const s=Gs(t);(async function(t,e,n){try{const s=await e.getMetadata();if(await function(t,e){const n=Gs(t),s=Ra(e.createTime);return n.persistence.runTransaction("hasNewerBundle","readonly",(t=>n.Ns.getBundleMetadata(t,e.id))).then((t=>!!t&&t.createTime.compareTo(s)>=0))}(t.localStore,s))return await e.close(),n._completeWith(function(t){return{taskState:"Success",documentsLoaded:t.totalDocuments,bytesLoaded:t.totalBytes,totalDocuments:t.totalDocuments,totalBytes:t.totalBytes}}(s)),Promise.resolve(new Set);n._updateProgress(jl(s));const r=new Kl(s,t.localStore,e.It);let i=await e.mc();for(;i;){const t=await r.Fu(i);t&&n._updateProgress(t),i=await e.mc()}const o=await r.complete();return await dd(t,o.Lu,void 0),await function(t,e){const n=Gs(t);return n.persistence.runTransaction("Save bundle","readwrite",(t=>n.Ns.saveBundleMetadata(t,e)))}(t.localStore,s),n._completeWith(o.progress),Promise.resolve(o.Bu)}catch(t){return Fs("SyncEngine",`Loading bundle failed with ${t}`),n._failWith(t),Promise.resolve(new Set)}})(s,e,n).then((t=>{s.sharedClientState.notifyBundleLoaded(t)}))}(await lf(t),r,s)}))}class yf{constructor(){this.Bc=Promise.resolve(),this.Lc=[],this.Uc=!1,this.qc=[],this.Kc=null,this.Gc=!1,this.Qc=!1,this.jc=[],this.No=new zh(this,"async_queue_retry"),this.Wc=()=>{const t=$h();t&&Os("AsyncQueue","Visibility state changed to "+t.visibilityState),this.No.Po()};const t=$h();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.Wc)}get isShuttingDown(){return this.Uc}enqueueAndForget(t){this.enqueue(t)}enqueueAndForgetEvenWhileRestricted(t){this.zc(),this.Hc(t)}enterRestrictedMode(t){if(!this.Uc){this.Uc=!0,this.Qc=t||!1;const e=$h();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("visibilitychange",this.Wc)}}enqueue(t){if(this.zc(),this.Uc)return new Promise((()=>{}));const e=new $s;return this.Hc((()=>this.Uc&&this.Qc?Promise.resolve():(t().then(e.resolve,e.reject),e.promise))).then((()=>e.promise))}enqueueRetryable(t){this.enqueueAndForget((()=>(this.Lc.push(t),this.Jc())))}async Jc(){if(0!==this.Lc.length){try{await this.Lc[0](),this.Lc.shift(),this.No.reset()}catch(t){if(!Rr(t))throw t;Os("AsyncQueue","Operation failed with retryable error: "+t)}this.Lc.length>0&&this.No.Ro((()=>this.Jc()))}}Hc(t){const e=this.Bc.then((()=>(this.Gc=!0,t().catch((t=>{this.Kc=t,this.Gc=!1;const e=function(t){let e=t.message||"";return t.stack&&(e=t.stack.includes(t.message)?t.stack:t.message+"\n"+t.stack),e}(t);throw Vs("INTERNAL UNHANDLED ERROR: ",e),t})).then((t=>(this.Gc=!1,t))))));return this.Bc=e,e}enqueueAfterDelay(t,e,n){this.zc(),this.jc.indexOf(t)>-1&&(e=0);const s=Al.createAndSchedule(this,t,e,n,(t=>this.Yc(t)));return this.qc.push(s),s}zc(){this.Kc&&Us()}verifyOperationInProgress(){}async Xc(){let t;do{t=this.Bc,await t}while(t!==this.Bc)}Zc(t){for(const e of this.qc)if(e.timerId===t)return!0;return!1}ta(t){return this.Xc().then((()=>{this.qc.sort(((t,e)=>t.targetTimeMs-e.targetTimeMs));for(const e of this.qc)if(e.skipDelay(),"all"!==t&&e.timerId===t)break;return this.Xc()}))}ea(t){this.jc.push(t)}Yc(t){const e=this.qc.indexOf(t);this.qc.splice(e,1)}}function wf(t){return function(t,e){if("object"!=typeof t||null===t)return!1;const n=t;for(const t of["next","error","complete"])if(t in n&&"function"==typeof n[t])return!0;return!1}(t)}class vf{constructor(){this._progressObserver={},this._taskCompletionResolver=new $s,this._lastProgress={taskState:"Running",totalBytes:0,totalDocuments:0,bytesLoaded:0,documentsLoaded:0}}onProgress(t,e,n){this._progressObserver={next:t,error:e,complete:n}}catch(t){return this._taskCompletionResolver.promise.catch(t)}then(t,e){return this._taskCompletionResolver.promise.then(t,e)}_completeWith(t){this._updateProgress(t),this._progressObserver.complete&&this._progressObserver.complete(),this._taskCompletionResolver.resolve(t)}_failWith(t){this._lastProgress.taskState="Error",this._progressObserver.next&&this._progressObserver.next(this._lastProgress),this._progressObserver.error&&this._progressObserver.error(t),this._taskCompletionResolver.reject(t)}_updateProgress(t){this._lastProgress=t,this._progressObserver.next&&this._progressObserver.next(t)}}const If=-1;class bf extends Pd{constructor(t,e,n,s){super(t,e,n,s),this.type="firestore",this._queue=new yf,this._persistenceKey=(null==s?void 0:s.name)||"[DEFAULT]"}_terminate(){return this._firestoreClient||_f(this),this._firestoreClient.terminate()}}function Ef(t,e,s){s||(s="(default)");const r=n(t,"firestore");if(r.isInitialized(s)){const t=r.getImmediate({identifier:s});if(w(r.getOptions(s),e))return t;throw new js(Ks.FAILED_PRECONDITION,"initializeFirestore() has already been called with different options. To avoid this error, call initializeFirestore() with the same options as when it was originally called, or call getFirestore() to return the already initialized instance.")}if(void 0!==e.cacheSizeBytes&&-1!==e.cacheSizeBytes&&e.cacheSizeBytes<1048576)throw new js(Ks.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");return r.initialize({options:e,instanceIdentifier:s})}function Tf(t,e){const r="object"==typeof t?t:s(),i="string"==typeof t?t:e||"(default)",o=n(r,"firestore").getImmediate({identifier:i});if(!o._initialized){const t=m("firestore");t&&Ud(o,...t)}return o}function Sf(t){return t._firestoreClient||_f(t),t._firestoreClient.verifyNotTerminated(),t._firestoreClient}function _f(t){var e;const n=t._freezeSettings(),s=function(t,e,n,s){return new ii(t,e,n,s.host,s.ssl,s.experimentalForceLongPolling,s.experimentalAutoDetectLongPolling,s.useFetchStreams)}(t._databaseId,(null===(e=t._app)||void 0===e?void 0:e.options.appId)||"",t._persistenceKey,n);t._firestoreClient=new nf(t._authCredentials,t._appCheckCredentials,t._queue,s)}function Df(t,e){Vf(t=Md(t,bf));const n=Sf(t),s=t._freezeSettings(),r=new Ad;return Af(n,r,new Dd(r,s.cacheSizeBytes,null==e?void 0:e.forceOwnership))}function xf(t){Vf(t=Md(t,bf));const e=Sf(t),n=t._freezeSettings(),s=new Ad;return Af(e,s,new xd(s,n.cacheSizeBytes))}function Af(t,e,n){const s=new $s;return t.asyncQueue.enqueue((async()=>{try{await sf(t,n),await rf(t,e),s.resolve()}catch(t){const e=t;if(!function(t){return"FirebaseError"===t.name?t.code===Ks.FAILED_PRECONDITION||t.code===Ks.UNIMPLEMENTED:!("undefined"!=typeof DOMException&&t instanceof DOMException)||(22===t.code||20===t.code||11===t.code)}(e))throw e;Fs("Error enabling offline persistence. Falling back to persistence disabled: "+e),s.reject(e)}})).then((()=>s.promise))}function Cf(t){if(t._initialized&&!t._terminated)throw new js(Ks.FAILED_PRECONDITION,"Persistence can only be cleared before a Firestore instance is initialized or after it is terminated.");const e=new $s;return t._queue.enqueueAndForgetEvenWhileRestricted((async()=>{try{await async function(t){if(!Cr.C())return Promise.resolve();const e=t+"main";await Cr.delete(e)}(fh(t._databaseId,t._persistenceKey)),e.resolve()}catch(t){e.reject(t)}})),e.promise}function Nf(t){return function(t){const e=new $s;return t.asyncQueue.enqueueAndForget((async()=>async function(t,e){const n=Gs(t);ul(n.remoteStore)||Os("SyncEngine","The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled.");try{const t=await function(t){const e=Gs(t);return e.persistence.runTransaction("Get highest unacknowledged batch id","readonly",(t=>e.mutationQueue.getHighestUnacknowledgedBatchId(t)))}(n.localStore);if(-1===t)return void e.resolve();const s=n.lc.get(t)||[];s.push(e),n.lc.set(t,s)}catch(t){const n=Cl(t,"Initialization of waitForPendingWrites() operation failed");e.reject(n)}}(await lf(t),e))),e.promise}(Sf(t=Md(t,bf)))}function kf(t){return function(t){return t.asyncQueue.enqueue((async()=>{const e=await uf(t),n=await hf(t);return e.setNetworkEnabled(!0),function(t){const e=Gs(t);return e.wu.delete(0),tl(e)}(n)}))}(Sf(t=Md(t,bf)))}function Rf(t){return function(t){return t.asyncQueue.enqueue((async()=>{const e=await uf(t),n=await hf(t);return e.setNetworkEnabled(!1),async function(t){const e=Gs(t);e.wu.add(0),await el(e),e.yu.set("Offline")}(n)}))}(Sf(t=Md(t,bf)))}function Lf(t){return r(t.app,"firestore",t._databaseId.database),t._delete()}function Mf(t,e){const n=Sf(t=Md(t,bf)),s=new vf;return pf(n,t._databaseId,e,s),s}function Of(t,e){return function(t,e){return t.asyncQueue.enqueue((async()=>function(t,e){const n=Gs(t);return n.persistence.runTransaction("Get named query","readonly",(t=>n.Ns.getNamedQuery(t,e)))}(await cf(t),e)))}(Sf(t=Md(t,bf)),e).then((e=>e?new qd(t,null,e.query):null))}function Vf(t){if(t._initialized||t._terminated)throw new js(Ks.FAILED_PRECONDITION,"Firestore has already been started and persistence can no longer be enabled. You can only enable persistence before calling any other methods on a Firestore object.")}class Ff{constructor(t){this._byteString=t}static fromBase64String(t){try{return new Ff(Xr.fromBase64String(t))}catch(t){throw new js(Ks.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+t)}}static fromUint8Array(t){return new Ff(Xr.fromUint8Array(t))}toBase64(){return this._byteString.toBase64()}toUint8Array(){return this._byteString.toUint8Array()}toString(){return"Bytes(base64: "+this.toBase64()+")"}isEqual(t){return this._byteString.isEqual(t._byteString)}}class Pf{constructor(...t){for(let e=0;e<t.length;++e)if(0===t[e].length)throw new js(Ks.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new lr(t)}isEqual(t){return this._internalPath.isEqual(t._internalPath)}}function Uf(){return new Pf("__name__")}class Bf{constructor(t){this._methodName=t}}class qf{constructor(t,e){if(!isFinite(t)||t<-90||t>90)throw new js(Ks.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new js(Ks.INVALID_ARGUMENT,"Longitude must be a number between -180 and 180, but was: "+e);this._lat=t,this._long=e}get latitude(){return this._lat}get longitude(){return this._long}isEqual(t){return this._lat===t._lat&&this._long===t._long}toJSON(){return{latitude:this._lat,longitude:this._long}}_compareTo(t){return sr(this._lat,t._lat)||sr(this._long,t._long)}}const Gf=/^__.*__$/;class Kf{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return null!==this.fieldMask?new Qo(t,this.data,this.fieldMask,e,this.fieldTransforms):new $o(t,this.data,e,this.fieldTransforms)}}class jf{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return new Qo(t,this.data,this.fieldMask,e,this.fieldTransforms)}}function $f(t){switch(t){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw Us()}}class Qf{constructor(t,e,n,s,r,i){this.settings=t,this.databaseId=e,this.It=n,this.ignoreUndefinedProperties=s,void 0===r&&this.na(),this.fieldTransforms=r||[],this.fieldMask=i||[]}get path(){return this.settings.path}get sa(){return this.settings.sa}ia(t){return new Qf(Object.assign(Object.assign({},this.settings),t),this.databaseId,this.It,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}ra(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),s=this.ia({path:n,oa:!1});return s.ua(t),s}ca(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),s=this.ia({path:n,oa:!1});return s.na(),s}aa(t){return this.ia({path:void 0,oa:!0})}ha(t){return dm(t,this.settings.methodName,this.settings.la||!1,this.path,this.settings.fa)}contains(t){return void 0!==this.fieldMask.find((e=>t.isPrefixOf(e)))||void 0!==this.fieldTransforms.find((e=>t.isPrefixOf(e.field)))}na(){if(this.path)for(let t=0;t<this.path.length;t++)this.ua(this.path.get(t))}ua(t){if(0===t.length)throw this.ha("Document fields must not be empty");if($f(this.sa)&&Gf.test(t))throw this.ha('Document fields cannot begin and end with "__"')}}class zf{constructor(t,e,n){this.databaseId=t,this.ignoreUndefinedProperties=e,this.It=n||Qh(t)}da(t,e,n,s=!1){return new Qf({sa:t,methodName:e,fa:n,path:lr.emptyPath(),oa:!1,la:s},this.databaseId,this.It,this.ignoreUndefinedProperties)}}function Hf(t){const e=t._freezeSettings(),n=Qh(t._databaseId);return new zf(t._databaseId,!!e.ignoreUndefinedProperties,n)}function Wf(t,e,n,s,r,i={}){const o=t.da(i.merge||i.mergeFields?2:0,e,n,r);um("Data must be an object, but it was:",o,s);const a=om(s,o);let u,c;if(i.merge)u=new Wr(o.fieldMask),c=o.fieldTransforms;else if(i.mergeFields){const t=[];for(const s of i.mergeFields){const r=cm(e,s,n);if(!o.contains(r))throw new js(Ks.INVALID_ARGUMENT,`Field '${r}' is specified in your field mask but missing from your input data.`);fm(t,r)||t.push(r)}u=new Wr(t),c=o.fieldTransforms.filter((t=>u.covers(t.field)))}else u=null,c=o.fieldTransforms;return new Kf(new ki(a),u,c)}class Yf extends Bf{_toFieldTransform(t){if(2!==t.sa)throw 1===t.sa?t.ha(`${this._methodName}() can only appear at the top level of your update data`):t.ha(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);return t.fieldMask.push(t.path),null}isEqual(t){return t instanceof Yf}}function Xf(t,e,n){return new Qf({sa:3,fa:e.settings.fa,methodName:t._methodName,oa:n},e.databaseId,e.It,e.ignoreUndefinedProperties)}class Jf extends Bf{_toFieldTransform(t){return new Oo(t.path,new xo)}isEqual(t){return t instanceof Jf}}class Zf extends Bf{constructor(t,e){super(t),this._a=e}_toFieldTransform(t){const e=Xf(this,t,!0),n=this._a.map((t=>im(t,e))),s=new Ao(n);return new Oo(t.path,s)}isEqual(t){return this===t}}class tm extends Bf{constructor(t,e){super(t),this._a=e}_toFieldTransform(t){const e=Xf(this,t,!0),n=this._a.map((t=>im(t,e))),s=new No(n);return new Oo(t.path,s)}isEqual(t){return this===t}}class em extends Bf{constructor(t,e){super(t),this.wa=e}_toFieldTransform(t){const e=new Ro(t.It,Eo(t.It,this.wa));return new Oo(t.path,e)}isEqual(t){return this===t}}function nm(t,e,n,s){const r=t.da(1,e,n);um("Data must be an object, but it was:",r,s);const i=[],o=ki.empty();qr(s,((t,s)=>{const a=lm(e,t,n);s=I(s);const u=r.ca(a);if(s instanceof Yf)i.push(a);else{const t=im(s,u);null!=t&&(i.push(a),o.set(a,t))}}));const a=new Wr(i);return new jf(o,a,r.fieldTransforms)}function sm(t,e,n,s,r,i){const o=t.da(1,e,n),a=[cm(e,s,n)],u=[r];if(i.length%2!=0)throw new js(Ks.INVALID_ARGUMENT,`Function ${e}() needs to be called with an even number of arguments that alternate between field names and values.`);for(let t=0;t<i.length;t+=2)a.push(cm(e,i[t])),u.push(i[t+1]);const c=[],h=ki.empty();for(let t=a.length-1;t>=0;--t)if(!fm(c,a[t])){const e=a[t];let n=u[t];n=I(n);const s=o.ca(e);if(n instanceof Yf)c.push(e);else{const t=im(n,s);null!=t&&(c.push(e),h.set(e,t))}}const l=new Wr(c);return new jf(h,l,o.fieldTransforms)}function rm(t,e,n,s=!1){return im(n,t.da(s?4:3,e))}function im(t,e){if(am(t=I(t)))return um("Unsupported field value:",e,t),om(t,e);if(t instanceof Bf)return function(t,e){if(!$f(e.sa))throw e.ha(`${t._methodName}() can only be used with update() and set()`);if(!e.path)throw e.ha(`${t._methodName}() is not currently supported inside arrays`);const n=t._toFieldTransform(e);n&&e.fieldTransforms.push(n)}(t,e),null;if(void 0===t&&e.ignoreUndefinedProperties)return null;if(e.path&&e.fieldMask.push(e.path),t instanceof Array){if(e.settings.oa&&4!==e.sa)throw e.ha("Nested arrays are not supported");return function(t,e){const n=[];let s=0;for(const r of t){let t=im(r,e.aa(s));null==t&&(t={nullValue:"NULL_VALUE"}),n.push(t),s++}return{arrayValue:{values:n}}}(t,e)}return function(t,e){if(null===(t=I(t)))return{nullValue:"NULL_VALUE"};if("number"==typeof t)return Eo(e.It,t);if("boolean"==typeof t)return{booleanValue:t};if("string"==typeof t)return{stringValue:t};if(t instanceof Date){const n=or.fromDate(t);return{timestampValue:Ca(e.It,n)}}if(t instanceof or){const n=new or(t.seconds,1e3*Math.floor(t.nanoseconds/1e3));return{timestampValue:Ca(e.It,n)}}if(t instanceof qf)return{geoPointValue:{latitude:t.latitude,longitude:t.longitude}};if(t instanceof Ff)return{bytesValue:Na(e.It,t._byteString)};if(t instanceof Bd){const n=e.databaseId,s=t.firestore._databaseId;if(!s.isEqual(n))throw e.ha(`Document reference is for database ${s.projectId}/${s.database} but should be for database ${n.projectId}/${n.database}`);return{referenceValue:La(t.firestore._databaseId||e.databaseId,t._key.path)}}throw e.ha(`Unsupported field value: ${Ld(t)}`)}(t,e)}function om(t,e){const n={};return Gr(t)?e.path&&e.path.length>0&&e.fieldMask.push(e.path):qr(t,((t,s)=>{const r=im(s,e.ra(t));null!=r&&(n[t]=r)})),{mapValue:{fields:n}}}function am(t){return!("object"!=typeof t||null===t||t instanceof Array||t instanceof Date||t instanceof or||t instanceof qf||t instanceof Ff||t instanceof Bd||t instanceof Bf)}function um(t,e,n){if(!am(n)||!function(t){return"object"==typeof t&&null!==t&&(Object.getPrototypeOf(t)===Object.prototype||null===Object.getPrototypeOf(t))}(n)){const s=Ld(n);throw"an object"===s?e.ha(t+" a custom object"):e.ha(t+" "+s)}}function cm(t,e,n){if((e=I(e))instanceof Pf)return e._internalPath;if("string"==typeof e)return lm(t,e);throw dm("Field path arguments must be of type string or ",t,!1,void 0,n)}const hm=new RegExp("[~\\*/\\[\\]]");function lm(t,e,n){if(e.search(hm)>=0)throw dm(`Invalid field path (${e}). Paths must not contain '~', '*', '/', '[', or ']'`,t,!1,void 0,n);try{return new Pf(...e.split("."))._internalPath}catch(s){throw dm(`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,t,!1,void 0,n)}}function dm(t,e,n,s,r){const i=s&&!s.isEmpty(),o=void 0!==r;let a=`Function ${e}() called with invalid data`;n&&(a+=" (via `toFirestore()`)"),a+=". ";let u="";return(i||o)&&(u+=" (found",i&&(u+=` in field ${s}`),o&&(u+=` in document ${r}`),u+=")"),new js(Ks.INVALID_ARGUMENT,a+t+u)}function fm(t,e){return t.some((t=>t.isEqual(e)))}class mm{constructor(t,e,n,s,r){this._firestore=t,this._userDataWriter=e,this._key=n,this._document=s,this._converter=r}get id(){return this._key.path.lastSegment()}get ref(){return new Bd(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){if(this._document){if(this._converter){const t=new gm(this._firestore,this._userDataWriter,this._key,this._document,null);return this._converter.fromFirestore(t)}return this._userDataWriter.convertValue(this._document.data.value)}}get(t){if(this._document){const e=this._document.data.field(pm("DocumentSnapshot.get",t));if(null!==e)return this._userDataWriter.convertValue(e)}}}class gm extends mm{data(){return super.data()}}function pm(t,e){return"string"==typeof e?lm(t,e):e instanceof Pf?e._internalPath:e._delegate._internalPath}function ym(t){if("L"===t.limitType&&0===t.explicitOrderBy.length)throw new js(Ks.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")}class wm{}function vm(t,...e){for(const n of e)t=n._apply(t);return t}class Im extends wm{constructor(t,e,n){super(),this.ma=t,this.ga=e,this.ya=n,this.type="where"}_apply(t){const e=Hf(t.firestore),n=function(t,e,n,s,r,i,o){let a;if(r.isKeyField()){if("array-contains"===i||"array-contains-any"===i)throw new js(Ks.INVALID_ARGUMENT,`Invalid Query. You can't perform '${i}' queries on documentId().`);if("in"===i||"not-in"===i){Om(o,i);const e=[];for(const n of o)e.push(Mm(s,t,n));a={arrayValue:{values:e}}}else a=Mm(s,t,o)}else"in"!==i&&"not-in"!==i&&"array-contains-any"!==i||Om(o,i),a=rm(n,"where",o,"in"===i||"not-in"===i);const u=Gi.create(r,i,a);return function(t,e){if(e.dt()){const n=ao(t);if(null!==n&&!n.isEqual(e.field))throw new js(Ks.INVALID_ARGUMENT,`Invalid query. All where filters with an inequality (<, <=, !=, not-in, >, or >=) must be on the same field. But you have inequality filters on '${n.toString()}' and '${e.field.toString()}'`);const s=oo(t);null!==s&&Vm(t,e.field,s)}const n=function(t,e){for(const n of t.filters)if(e.indexOf(n.op)>=0)return n.op;return null}(t,function(t){switch(t){case"!=":return["!=","not-in"];case"array-contains":return["array-contains","array-contains-any","not-in"];case"in":return["array-contains-any","in","not-in"];case"array-contains-any":return["array-contains","array-contains-any","in","not-in"];case"not-in":return["array-contains","array-contains-any","in","not-in","!="];default:return[]}}(e.op));if(null!==n)throw n===e.op?new js(Ks.INVALID_ARGUMENT,`Invalid query. You cannot use more than one '${e.op.toString()}' filter.`):new js(Ks.INVALID_ARGUMENT,`Invalid query. You cannot use '${e.op.toString()}' filters with '${n.toString()}' filters.`)}(t,u),u}(t._query,0,e,t.firestore._databaseId,this.ma,this.ga,this.ya);return new qd(t.firestore,t.converter,function(t,e){const n=t.filters.concat([e]);return new no(t.path,t.collectionGroup,t.explicitOrderBy.slice(),n,t.limit,t.limitType,t.startAt,t.endAt)}(t._query,n))}}function bm(t,e,n){const s=e,r=pm("where",t);return new Im(r,s,n)}class Em extends wm{constructor(t,e){super(),this.ma=t,this.pa=e,this.type="orderBy"}_apply(t){const e=function(t,e,n){if(null!==t.startAt)throw new js(Ks.INVALID_ARGUMENT,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==t.endAt)throw new js(Ks.INVALID_ARGUMENT,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");const s=new Ji(e,n);return function(t,e){if(null===oo(t)){const n=ao(t);null!==n&&Vm(t,n,e.field)}}(t,s),s}(t._query,this.ma,this.pa);return new qd(t.firestore,t.converter,function(t,e){const n=t.explicitOrderBy.concat([e]);return new no(t.path,t.collectionGroup,n,t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(t._query,e))}}function Tm(t,e="asc"){const n=e,s=pm("orderBy",t);return new Em(s,n)}class Sm extends wm{constructor(t,e,n){super(),this.type=t,this.Ia=e,this.Ta=n}_apply(t){return new qd(t.firestore,t.converter,lo(t._query,this.Ia,this.Ta))}}function _m(t){return Od("limit",t),new Sm("limit",t,"F")}function Dm(t){return Od("limitToLast",t),new Sm("limitToLast",t,"L")}class xm extends wm{constructor(t,e,n){super(),this.type=t,this.Ea=e,this.Aa=n}_apply(t){const e=Lm(t,this.type,this.Ea,this.Aa);return new qd(t.firestore,t.converter,function(t,e){return new no(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,e,t.endAt)}(t._query,e))}}function Am(...t){return new xm("startAt",t,!0)}function Cm(...t){return new xm("startAfter",t,!1)}class Nm extends wm{constructor(t,e,n){super(),this.type=t,this.Ea=e,this.Aa=n}_apply(t){const e=Lm(t,this.type,this.Ea,this.Aa);return new qd(t.firestore,t.converter,function(t,e){return new no(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,e)}(t._query,e))}}function km(...t){return new Nm("endBefore",t,!1)}function Rm(...t){return new Nm("endAt",t,!0)}function Lm(t,e,n,s){if(n[0]=I(n[0]),n[0]instanceof mm)return function(t,e,n,s,r){if(!s)throw new js(Ks.NOT_FOUND,`Can't use a DocumentSnapshot that doesn't exist for ${n}().`);const i=[];for(const n of co(t))if(n.field.isKeyField())i.push(vi(e,s.key));else{const t=s.data.field(n.field);if(ni(t))throw new js(Ks.INVALID_ARGUMENT,'Invalid query. You are trying to start or end a query using a document for which the field "'+n.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===t){const t=n.field.canonicalString();throw new js(Ks.INVALID_ARGUMENT,`Invalid query. You are trying to start or end a query using a document for which the field '${t}' (used as the orderBy) does not exist.`)}i.push(t)}return new Xi(i,r)}(t._query,t.firestore._databaseId,e,n[0]._document,s);{const r=Hf(t.firestore);return function(t,e,n,s,r,i){const o=t.explicitOrderBy;if(r.length>o.length)throw new js(Ks.INVALID_ARGUMENT,`Too many arguments provided to ${s}(). The number of arguments must be less than or equal to the number of orderBy() clauses`);const a=[];for(let i=0;i<r.length;i++){const u=r[i];if(o[i].field.isKeyField()){if("string"!=typeof u)throw new js(Ks.INVALID_ARGUMENT,`Invalid query. Expected a string for document ID in ${s}(), but got a ${typeof u}`);if(!uo(t)&&-1!==u.indexOf("/"))throw new js(Ks.INVALID_ARGUMENT,`Invalid query. When querying a collection and ordering by documentId(), the value passed to ${s}() must be a plain document ID, but '${u}' contains a slash.`);const n=t.path.child(cr.fromString(u));if(!dr.isDocumentKey(n))throw new js(Ks.INVALID_ARGUMENT,`Invalid query. When querying a collection group and ordering by documentId(), the value passed to ${s}() must result in a valid document path, but '${n}' is not because it contains an odd number of segments.`);const r=new dr(n);a.push(vi(e,r))}else{const t=rm(n,s,u);a.push(t)}}return new Xi(a,i)}(t._query,t.firestore._databaseId,r,e,n,s)}}function Mm(t,e,n){if("string"==typeof(n=I(n))){if(""===n)throw new js(Ks.INVALID_ARGUMENT,"Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");if(!uo(e)&&-1!==n.indexOf("/"))throw new js(Ks.INVALID_ARGUMENT,`Invalid query. When querying a collection by documentId(), you must provide a plain document ID, but '${n}' contains a '/' character.`);const s=e.path.child(cr.fromString(n));if(!dr.isDocumentKey(s))throw new js(Ks.INVALID_ARGUMENT,`Invalid query. When querying a collection group by documentId(), the value provided must result in a valid document path, but '${s}' is not because it has an odd number of segments (${s.length}).`);return vi(t,new dr(s))}if(n instanceof Bd)return vi(t,n._key);throw new js(Ks.INVALID_ARGUMENT,`Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${Ld(n)}.`)}function Om(t,e){if(!Array.isArray(t)||0===t.length)throw new js(Ks.INVALID_ARGUMENT,`Invalid Query. A non-empty array is required for '${e.toString()}' filters.`);if(t.length>10)throw new js(Ks.INVALID_ARGUMENT,`Invalid Query. '${e.toString()}' filters support a maximum of 10 elements in the value array.`)}function Vm(t,e,n){if(!n.isEqual(e))throw new js(Ks.INVALID_ARGUMENT,`Invalid query. You have a where filter with an inequality (<, <=, !=, not-in, >, or >=) on field '${e.toString()}' and so you must also use '${e.toString()}' as your first argument to orderBy(), but your first orderBy() is on field '${n.toString()}' instead.`)}class Fm{convertValue(t,e="none"){switch(di(t)){case 0:return null;case 1:return t.booleanValue;case 2:return ti(t.integerValue||t.doubleValue);case 3:return this.convertTimestamp(t.timestampValue);case 4:return this.convertServerTimestamp(t,e);case 5:return t.stringValue;case 6:return this.convertBytes(ei(t.bytesValue));case 7:return this.convertReference(t.referenceValue);case 8:return this.convertGeoPoint(t.geoPointValue);case 9:return this.convertArray(t.arrayValue,e);case 10:return this.convertObject(t.mapValue,e);default:throw Us()}}convertObject(t,e){const n={};return qr(t.fields,((t,s)=>{n[t]=this.convertValue(s,e)})),n}convertGeoPoint(t){return new qf(ti(t.latitude),ti(t.longitude))}convertArray(t,e){return(t.values||[]).map((t=>this.convertValue(t,e)))}convertServerTimestamp(t,e){switch(e){case"previous":const n=si(t);return null==n?null:this.convertValue(n,e);case"estimate":return this.convertTimestamp(ri(t));default:return null}}convertTimestamp(t){const e=Zr(t);return new or(e.seconds,e.nanos)}convertDocumentKey(t,e){const n=cr.fromString(t);Bs(nu(n));const s=new oi(n.get(1),n.get(3)),r=new dr(n.popFirst(5));return s.isEqual(e)||Vs(`Document ${r} contains a document reference within a different database (${s.projectId}/${s.database}) which is not supported. It will be treated as a reference in the current database (${e.projectId}/${e.database}) instead.`),r}}function Pm(t,e,n){let s;return s=t?n&&(n.merge||n.mergeFields)?t.toFirestore(e,n):t.toFirestore(e):e,s}class Um extends Fm{constructor(t){super(),this.firestore=t}convertBytes(t){return new Ff(t)}convertReference(t){const e=this.convertDocumentKey(t,this.firestore._databaseId);return new Bd(this.firestore,null,e)}}class Bm{constructor(t,e){this.hasPendingWrites=t,this.fromCache=e}isEqual(t){return this.hasPendingWrites===t.hasPendingWrites&&this.fromCache===t.fromCache}}class qm extends mm{constructor(t,e,n,s,r,i){super(t,e,n,s,i),this._firestore=t,this._firestoreImpl=t,this.metadata=r}exists(){return super.exists()}data(t={}){if(this._document){if(this._converter){const e=new Gm(this._firestore,this._userDataWriter,this._key,this._document,this.metadata,null);return this._converter.fromFirestore(e,t)}return this._userDataWriter.convertValue(this._document.data.value,t.serverTimestamps)}}get(t,e={}){if(this._document){const n=this._document.data.field(pm("DocumentSnapshot.get",t));if(null!==n)return this._userDataWriter.convertValue(n,e.serverTimestamps)}}}class Gm extends qm{data(t={}){return super.data(t)}}class Km{constructor(t,e,n,s){this._firestore=t,this._userDataWriter=e,this._snapshot=s,this.metadata=new Bm(s.hasPendingWrites,s.fromCache),this.query=n}get docs(){const t=[];return this.forEach((e=>t.push(e))),t}get size(){return this._snapshot.docs.size}get empty(){return 0===this.size}forEach(t,e){this._snapshot.docs.forEach((n=>{t.call(e,new Gm(this._firestore,this._userDataWriter,n.key,n,new Bm(this._snapshot.mutatedKeys.has(n.key),this._snapshot.fromCache),this.query.converter))}))}docChanges(t={}){const e=!!t.includeMetadataChanges;if(e&&this._snapshot.excludesMetadataChanges)throw new js(Ks.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this._cachedChanges&&this._cachedChangesIncludeMetadataChanges===e||(this._cachedChanges=function(t,e){if(t._snapshot.oldDocs.isEmpty()){let e=0;return t._snapshot.docChanges.map((n=>({type:"added",doc:new Gm(t._firestore,t._userDataWriter,n.doc.key,n.doc,new Bm(t._snapshot.mutatedKeys.has(n.doc.key),t._snapshot.fromCache),t.query.converter),oldIndex:-1,newIndex:e++})))}{let n=t._snapshot.oldDocs;return t._snapshot.docChanges.filter((t=>e||3!==t.type)).map((e=>{const s=new Gm(t._firestore,t._userDataWriter,e.doc.key,e.doc,new Bm(t._snapshot.mutatedKeys.has(e.doc.key),t._snapshot.fromCache),t.query.converter);let r=-1,i=-1;return 0!==e.type&&(r=n.indexOf(e.doc.key),n=n.delete(e.doc.key)),1!==e.type&&(n=n.add(e.doc),i=n.indexOf(e.doc.key)),{type:jm(e.type),doc:s,oldIndex:r,newIndex:i}}))}}(this,e),this._cachedChangesIncludeMetadataChanges=e),this._cachedChanges}}function jm(t){switch(t){case 0:return"added";case 2:case 3:return"modified";case 1:return"removed";default:return Us()}}function $m(t,e){return t instanceof qm&&e instanceof qm?t._firestore===e._firestore&&t._key.isEqual(e._key)&&(null===t._document?null===e._document:t._document.isEqual(e._document))&&t._converter===e._converter:t instanceof Km&&e instanceof Km&&t._firestore===e._firestore&&zd(t.query,e.query)&&t.metadata.isEqual(e.metadata)&&t._snapshot.isEqual(e._snapshot)}function Qm(t){t=Md(t,Bd);const e=Md(t.firestore,bf);return mf(Sf(e),t._key).then((n=>og(e,t,n)))}class zm extends Fm{constructor(t){super(),this.firestore=t}convertBytes(t){return new Ff(t)}convertReference(t){const e=this.convertDocumentKey(t,this.firestore._databaseId);return new Bd(this.firestore,null,e)}}function Hm(t){t=Md(t,Bd);const e=Md(t.firestore,bf),n=Sf(e),s=new zm(e);return function(t,e){const n=new $s;return t.asyncQueue.enqueueAndForget((async()=>async function(t,e,n){try{const s=await function(t,e){const n=Gs(t);return n.persistence.runTransaction("read document","readonly",(t=>n.localDocuments.getDocument(t,e)))}(t,e);s.isFoundDocument()?n.resolve(s):s.isNoDocument()?n.resolve(null):n.reject(new js(Ks.UNAVAILABLE,"Failed to get document from cache. (However, this document may exist on the server. Run again without setting 'source' in the GetOptions to attempt to retrieve the document from the server.)"))}catch(t){const s=Cl(t,`Failed to get document '${e} from cache`);n.reject(s)}}(await cf(t),e,n))),n.promise}(n,t._key).then((n=>new qm(e,s,t._key,n,new Bm(null!==n&&n.hasLocalMutations,!0),t.converter)))}function Wm(t){t=Md(t,Bd);const e=Md(t.firestore,bf);return mf(Sf(e),t._key,{source:"server"}).then((n=>og(e,t,n)))}function Ym(t){t=Md(t,qd);const e=Md(t.firestore,bf),n=Sf(e),s=new zm(e);return ym(t._query),gf(n,t._query).then((n=>new Km(e,s,t,n)))}function Xm(t){t=Md(t,qd);const e=Md(t.firestore,bf),n=Sf(e),s=new zm(e);return function(t,e){const n=new $s;return t.asyncQueue.enqueueAndForget((async()=>async function(t,e,n){try{const s=await Sh(t,e,!0),r=new zl(e,s.Hi),i=r.Wu(s.documents),o=r.applyChanges(i,!1);n.resolve(o.snapshot)}catch(t){const s=Cl(t,`Failed to execute query '${e} against cache`);n.reject(s)}}(await cf(t),e,n))),n.promise}(n,t._query).then((n=>new Km(e,s,t,n)))}function Jm(t){t=Md(t,qd);const e=Md(t.firestore,bf),n=Sf(e),s=new zm(e);return gf(n,t._query,{source:"server"}).then((n=>new Km(e,s,t,n)))}function Zm(t,e,n){t=Md(t,Bd);const s=Md(t.firestore,bf),r=Pm(t.converter,e,n);return ig(s,[Wf(Hf(s),"setDoc",t._key,r,null!==t.converter,n).toMutation(t._key,Fo.none())])}function tg(t,e,n,...s){t=Md(t,Bd);const r=Md(t.firestore,bf),i=Hf(r);let o;return o="string"==typeof(e=I(e))||e instanceof Pf?sm(i,"updateDoc",t._key,e,n,s):nm(i,"updateDoc",t._key,e),ig(r,[o.toMutation(t._key,Fo.exists(!0))])}function eg(t){return ig(Md(t.firestore,bf),[new Yo(t._key,Fo.none())])}function ng(t,e){const n=Md(t.firestore,bf),s=$d(t),r=Pm(t.converter,e);return ig(n,[Wf(Hf(t.firestore),"addDoc",s._key,r,null!==t.converter,{}).toMutation(s._key,Fo.exists(!1))]).then((()=>s))}function sg(t,...e){var n,s,r;t=I(t);let i={includeMetadataChanges:!1},o=0;"object"!=typeof e[o]||wf(e[o])||(i=e[o],o++);const a={includeMetadataChanges:i.includeMetadataChanges};if(wf(e[o])){const t=e[o];e[o]=null===(n=t.next)||void 0===n?void 0:n.bind(t),e[o+1]=null===(s=t.error)||void 0===s?void 0:s.bind(t),e[o+2]=null===(r=t.complete)||void 0===r?void 0:r.bind(t)}let u,c,h;if(t instanceof Bd)c=Md(t.firestore,bf),h=ro(t._key.path),u={next:n=>{e[o]&&e[o](og(c,t,n))},error:e[o+1],complete:e[o+2]};else{const n=Md(t,qd);c=Md(n.firestore,bf),h=n._query;const s=new zm(c);u={next:t=>{e[o]&&e[o](new Km(c,s,n,t))},error:e[o+1],complete:e[o+2]},ym(t._query)}return function(t,e,n,s){const r=new Wd(s),i=new Bl(e,r,n);return t.asyncQueue.enqueueAndForget((async()=>Ol(await ff(t),i))),()=>{r.bc(),t.asyncQueue.enqueueAndForget((async()=>Vl(await ff(t),i)))}}(Sf(c),h,a,u)}function rg(t,e){return function(t,e){const n=new Wd(e);return t.asyncQueue.enqueueAndForget((async()=>function(t,e){Gs(t).bu.add(e),e.next()}(await ff(t),n))),()=>{n.bc(),t.asyncQueue.enqueueAndForget((async()=>function(t,e){Gs(t).bu.delete(e)}(await ff(t),n)))}}(Sf(t=Md(t,bf)),wf(e)?e:{next:e})}function ig(t,e){return function(t,e){const n=new $s;return t.asyncQueue.enqueueAndForget((async()=>async function(t,e,n){const s=Sd(t);try{const t=await function(t,e){const n=Gs(t),s=or.now(),r=e.reduce(((t,e)=>t.add(e.key)),ma());let i,o;return n.persistence.runTransaction("Locally write mutations","readwrite",(t=>{let a=ia(),u=ma();return n.Gi.getEntries(t,r).next((t=>{a=t,a.forEach(((t,e)=>{e.isValidDocument()||(u=u.add(t))}))})).next((()=>n.localDocuments.getOverlayedDocuments(t,a))).next((r=>{i=r;const o=[];for(const t of e){const e=Ko(t,i.get(t.key).overlayedDocument);null!=e&&o.push(new Qo(t.key,e,Ri(e.value.mapValue),Fo.exists(!0)))}return n.mutationQueue.addMutationBatch(t,s,o,e)})).next((e=>{o=e;const s=e.applyToLocalDocumentSet(i,u);return n.documentOverlayCache.saveOverlays(t,e.batchId,s)}))})).then((()=>({batchId:o.batchId,changes:ua(i)})))}(s.localStore,e);s.sharedClientState.addPendingMutation(t.batchId),function(t,e,n){let s=t.hc[t.currentUser.toKey()];s||(s=new Kr(sr)),s=s.insert(e,n),t.hc[t.currentUser.toKey()]=s}(s,t.batchId,n),await dd(s,t.changes),await gl(s.remoteStore)}catch(t){const e=Cl(t,"Failed to persist write");n.reject(e)}}(await lf(t),e,n))),n.promise}(Sf(t),e)}function og(t,e,n){const s=n.docs.get(e._key),r=new zm(t);return new qm(t,r,e._key,s,new Bm(n.hasPendingWrites,n.fromCache),e.converter)}function ag(t,e){return zd(t.query,e.query)&&w(t.data(),e.data())}function ug(t){const e=Md(t.firestore,bf);return function(t,e,n){const s=new $s;return t.asyncQueue.enqueueAndForget((async()=>{try{if(ul(await hf(t))){const r=await df(t),i=new Zd(e,r,n).run();s.resolve(i)}else s.reject(new js(Ks.UNAVAILABLE,"Failed to get count result because the client is offline."))}catch(t){s.reject(t)}})),s.promise}(Sf(e),t,new zm(e))}const cg={maxAttempts:5};class hg{constructor(t,e){this._firestore=t,this._commitHandler=e,this._mutations=[],this._committed=!1,this._dataReader=Hf(t)}set(t,e,n){this._verifyNotCommitted();const s=lg(t,this._firestore),r=Pm(s.converter,e,n),i=Wf(this._dataReader,"WriteBatch.set",s._key,r,null!==s.converter,n);return this._mutations.push(i.toMutation(s._key,Fo.none())),this}update(t,e,n,...s){this._verifyNotCommitted();const r=lg(t,this._firestore);let i;return i="string"==typeof(e=I(e))||e instanceof Pf?sm(this._dataReader,"WriteBatch.update",r._key,e,n,s):nm(this._dataReader,"WriteBatch.update",r._key,e),this._mutations.push(i.toMutation(r._key,Fo.exists(!0))),this}delete(t){this._verifyNotCommitted();const e=lg(t,this._firestore);return this._mutations=this._mutations.concat(new Yo(e._key,Fo.none())),this}commit(){return this._verifyNotCommitted(),this._committed=!0,this._mutations.length>0?this._commitHandler(this._mutations):Promise.resolve()}_verifyNotCommitted(){if(this._committed)throw new js(Ks.FAILED_PRECONDITION,"A write batch can no longer be used after commit() has been called.")}}function lg(t,e){if((t=I(t)).firestore!==e)throw new js(Ks.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return t}class dg extends class{constructor(t,e){this._firestore=t,this._transaction=e,this._dataReader=Hf(t)}get(t){const e=lg(t,this._firestore),n=new Um(this._firestore);return this._transaction.lookup([e._key]).then((t=>{if(!t||1!==t.length)return Us();const s=t[0];if(s.isFoundDocument())return new mm(this._firestore,n,s.key,s,e.converter);if(s.isNoDocument())return new mm(this._firestore,n,e._key,null,e.converter);throw Us()}))}set(t,e,n){const s=lg(t,this._firestore),r=Pm(s.converter,e,n),i=Wf(this._dataReader,"Transaction.set",s._key,r,null!==s.converter,n);return this._transaction.set(s._key,i),this}update(t,e,n,...s){const r=lg(t,this._firestore);let i;return i="string"==typeof(e=I(e))||e instanceof Pf?sm(this._dataReader,"Transaction.update",r._key,e,n,s):nm(this._dataReader,"Transaction.update",r._key,e),this._transaction.update(r._key,i),this}delete(t){const e=lg(t,this._firestore);return this._transaction.delete(e._key),this}}{constructor(t,e){super(t,e),this._firestore=t}get(t){const e=lg(t,this._firestore),n=new zm(this._firestore);return super.get(t).then((t=>new qm(this._firestore,n,e._key,t._document,new Bm(!1,!1),e.converter)))}}function fg(t,e,n){t=Md(t,bf);const s=Object.assign(Object.assign({},cg),n);return function(t){if(t.maxAttempts<1)throw new js(Ks.INVALID_ARGUMENT,"Max attempts must be at least 1")}(s),function(t,e,n){const s=new $s;return t.asyncQueue.enqueueAndForget((async()=>{const r=await df(t);new ef(t.asyncQueue,r,n,e,s).run()})),s.promise}(Sf(t),(n=>e(new dg(t,n))),s)}function mg(){return new Yf("deleteField")}function gg(){return new Jf("serverTimestamp")}function pg(...t){return new Zf("arrayUnion",t)}function yg(...t){return new tm("arrayRemove",t)}function wg(t){return new em("increment",t)}function vg(t){return Sf(t=Md(t,bf)),new hg(t,(e=>ig(t,e)))}function Ig(t,e){var n;const s=Sf(t=Md(t,bf));if(!(null===(n=s.offlineComponents)||void 0===n?void 0:n.indexBackfillerScheduler))return Fs("Cannot enable indexes when persistence is disabled"),Promise.resolve();const r=function(t){const e="string"==typeof t?function(t){var e;try{return JSON.parse(t)}catch(t){throw new js(Ks.INVALID_ARGUMENT,"Failed to parse JSON: "+(null===(e=t)||void 0===e?void 0:e.message))}}(t):t,n=[];if(Array.isArray(e.indexes))for(const t of e.indexes){const e=bg(t,"collectionGroup"),s=[];if(Array.isArray(t.fields))for(const e of t.fields){const t=lm("setIndexConfiguration",bg(e,"fieldPath"));"CONTAINS"===e.arrayConfig?s.push(new yr(t,2)):"ASCENDING"===e.order?s.push(new yr(t,0)):"DESCENDING"===e.order&&s.push(new yr(t,1))}n.push(new fr(fr.UNKNOWN_ID,e,s,vr.empty()))}return n}(e);return cf(s).then((t=>async function(t,e){const n=Gs(t),s=n.indexManager,r=[];return n.persistence.runTransaction("Configure indexes","readwrite",(t=>s.getFieldIndexes(t).next((n=>function(t,e,n,s,r){t=[...t],e=[...e],t.sort(n),e.sort(n);const i=t.length,o=e.length;let a=0,u=0;for(;a<o&&u<i;){const i=n(t[u],e[a]);i<0?r(t[u++]):i>0?s(e[a++]):(a++,u++)}for(;a<o;)s(e[a++]);for(;u<i;)r(t[u++])}(n,e,pr,(e=>{r.push(s.addFieldIndex(t,e))}),(e=>{r.push(s.deleteFieldIndex(t,e))})))).next((()=>xr.waitFor(r)))))}(t,r)))}function bg(t,e){if("string"!=typeof t[e])throw new js(Ks.INVALID_ARGUMENT,"Missing string value for: "+e);return t[e]}!function(n,s=!0){ks=i,t(new b("firestore",((t,{instanceIdentifier:e,options:n})=>{const r=t.getProvider("app").getImmediate(),i=new bf(new Ws(t.getProvider("auth-internal")),new Zs(t.getProvider("app-check-internal")),function(t,e){if(!Object.prototype.hasOwnProperty.apply(t.options,["projectId"]))throw new js(Ks.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');return new oi(t.options.projectId,e)}(r,e),r);return n=Object.assign({useFetchStreams:s},n),i._setSettings(n),i}),"PUBLIC").setMultipleInstances(!0)),e(Cs,"3.7.1",n),e(Cs,"3.7.1","esm2017")}();export{Fm as AbstractUserDataWriter,Xd as AggregateField,Jd as AggregateQuerySnapshot,Ff as Bytes,If as CACHE_SIZE_UNLIMITED,Gd as CollectionReference,Bd as DocumentReference,qm as DocumentSnapshot,Pf as FieldPath,Bf as FieldValue,bf as Firestore,js as FirestoreError,qf as GeoPoint,vf as LoadBundleTask,qd as Query,wm as QueryConstraint,Gm as QueryDocumentSnapshot,Km as QuerySnapshot,Bm as SnapshotMetadata,or as Timestamp,dg as Transaction,hg as WriteBatch,oi as _DatabaseId,dr as _DocumentKey,tr as _EmptyAppCheckTokenProvider,zs as _EmptyAuthCredentialsProvider,lr as _FieldPath,Md as _cast,qs as _debugAssert,Yr as _isBase64Available,Fs as _logWarn,Nd as _validateIsNotUsedTogether,ng as addDoc,ag as aggregateQuerySnapshotEqual,yg as arrayRemove,pg as arrayUnion,Cf as clearIndexedDbPersistence,Kd as collection,jd as collectionGroup,Ud as connectFirestoreEmulator,eg as deleteDoc,mg as deleteField,Rf as disableNetwork,$d as doc,Uf as documentId,Df as enableIndexedDbPersistence,xf as enableMultiTabIndexedDbPersistence,kf as enableNetwork,Rm as endAt,km as endBefore,Sf as ensureFirestoreConfigured,ig as executeWrite,ug as getCountFromServer,Qm as getDoc,Hm as getDocFromCache,Wm as getDocFromServer,Ym as getDocs,Xm as getDocsFromCache,Jm as getDocsFromServer,Tf as getFirestore,wg as increment,Ef as initializeFirestore,_m as limit,Dm as limitToLast,Mf as loadBundle,Of as namedQuery,sg as onSnapshot,rg as onSnapshotsInSync,Tm as orderBy,vm as query,zd as queryEqual,Qd as refEqual,fg as runTransaction,gg as serverTimestamp,Zm as setDoc,Ig as setIndexConfiguration,Ms as setLogLevel,$m as snapshotEqual,Cm as startAfter,Am as startAt,Lf as terminate,tg as updateDoc,Nf as waitForPendingWrites,bm as where,vg as writeBatch};
1
+ import{_registerComponent as t,registerVersion as e,_getProvider as n,getApp as s,_removeServiceInstance as r,SDK_VERSION as i}from"https://www.gstatic.com/firebasejs/9.13.0/firebase-app.js";const o=function(t){const e=[];let n=0;for(let s=0;s<t.length;s++){let r=t.charCodeAt(s);r<128?e[n++]=r:r<2048?(e[n++]=r>>6|192,e[n++]=63&r|128):55296==(64512&r)&&s+1<t.length&&56320==(64512&t.charCodeAt(s+1))?(r=65536+((1023&r)<<10)+(1023&t.charCodeAt(++s)),e[n++]=r>>18|240,e[n++]=r>>12&63|128,e[n++]=r>>6&63|128,e[n++]=63&r|128):(e[n++]=r>>12|224,e[n++]=r>>6&63|128,e[n++]=63&r|128)}return e},a={byteToCharMap_:null,charToByteMap_:null,byteToCharMapWebSafe_:null,charToByteMapWebSafe_:null,ENCODED_VALS_BASE:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",get ENCODED_VALS(){return this.ENCODED_VALS_BASE+"+/="},get ENCODED_VALS_WEBSAFE(){return this.ENCODED_VALS_BASE+"-_."},HAS_NATIVE_SUPPORT:"function"==typeof atob,encodeByteArray(t,e){if(!Array.isArray(t))throw Error("encodeByteArray takes an array as a parameter");this.init_();const n=e?this.byteToCharMapWebSafe_:this.byteToCharMap_,s=[];for(let e=0;e<t.length;e+=3){const r=t[e],i=e+1<t.length,o=i?t[e+1]:0,a=e+2<t.length,u=a?t[e+2]:0,c=r>>2,h=(3&r)<<4|o>>4;let l=(15&o)<<2|u>>6,d=63&u;a||(d=64,i||(l=64)),s.push(n[c],n[h],n[l],n[d])}return s.join("")},encodeString(t,e){return this.HAS_NATIVE_SUPPORT&&!e?btoa(t):this.encodeByteArray(o(t),e)},decodeString(t,e){return this.HAS_NATIVE_SUPPORT&&!e?atob(t):function(t){const e=[];let n=0,s=0;for(;n<t.length;){const r=t[n++];if(r<128)e[s++]=String.fromCharCode(r);else if(r>191&&r<224){const i=t[n++];e[s++]=String.fromCharCode((31&r)<<6|63&i)}else if(r>239&&r<365){const i=((7&r)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536;e[s++]=String.fromCharCode(55296+(i>>10)),e[s++]=String.fromCharCode(56320+(1023&i))}else{const i=t[n++],o=t[n++];e[s++]=String.fromCharCode((15&r)<<12|(63&i)<<6|63&o)}}return e.join("")}(this.decodeStringToByteArray(t,e))},decodeStringToByteArray(t,e){this.init_();const n=e?this.charToByteMapWebSafe_:this.charToByteMap_,s=[];for(let e=0;e<t.length;){const r=n[t.charAt(e++)],i=e<t.length?n[t.charAt(e)]:0;++e;const o=e<t.length?n[t.charAt(e)]:64;++e;const a=e<t.length?n[t.charAt(e)]:64;if(++e,null==r||null==i||null==o||null==a)throw Error();const u=r<<2|i>>4;if(s.push(u),64!==o){const t=i<<4&240|o>>2;if(s.push(t),64!==a){const t=o<<6&192|a;s.push(t)}}}return s},init_(){if(!this.byteToCharMap_){this.byteToCharMap_={},this.charToByteMap_={},this.byteToCharMapWebSafe_={},this.charToByteMapWebSafe_={};for(let t=0;t<this.ENCODED_VALS.length;t++)this.byteToCharMap_[t]=this.ENCODED_VALS.charAt(t),this.charToByteMap_[this.byteToCharMap_[t]]=t,this.byteToCharMapWebSafe_[t]=this.ENCODED_VALS_WEBSAFE.charAt(t),this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[t]]=t,t>=this.ENCODED_VALS_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(t)]=t,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(t)]=t)}}},u=function(t){return function(t){const e=o(t);return a.encodeByteArray(e,!0)}(t).replace(/\./g,"")};function c(){return"undefined"!=typeof navigator&&"string"==typeof navigator.userAgent?navigator.userAgent:""}function h(){return!function(){try{return"[object process]"===Object.prototype.toString.call(global.process)}catch(t){return!1}}()&&navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")}const l=()=>function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("Unable to locate global object.")}().__FIREBASE_DEFAULTS__,d=()=>{if("undefined"==typeof document)return;let t;try{t=document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/)}catch(t){return}const e=t&&function(t){try{return a.decodeString(t,!0)}catch(t){console.error("base64Decode failed: ",t)}return null}(t[1]);return e&&JSON.parse(e)},f=()=>{try{return l()||(()=>{if("undefined"==typeof process||void 0===process.env)return;const t=process.env.__FIREBASE_DEFAULTS__;return t?JSON.parse(t):void 0})()||d()}catch(t){return void console.info(`Unable to get __FIREBASE_DEFAULTS__ due to: ${t}`)}},m=t=>{const e=(t=>{var e,n;return null===(n=null===(e=f())||void 0===e?void 0:e.emulatorHosts)||void 0===n?void 0:n[t]})(t);if(!e)return;const n=e.lastIndexOf(":");if(n<=0||n+1===e.length)throw new Error(`Invalid host ${e} with no separate hostname and port!`);const s=parseInt(e.substring(n+1),10);return"["===e[0]?[e.substring(1,n-1),s]:[e.substring(0,n),s]};class g extends Error{constructor(t,e,n){super(e),this.code=t,this.customData=n,this.name="FirebaseError",Object.setPrototypeOf(this,g.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,p.prototype.create)}}class p{constructor(t,e,n){this.service=t,this.serviceName=e,this.errors=n}create(t,...e){const n=e[0]||{},s=`${this.service}/${t}`,r=this.errors[t],i=r?function(t,e){return t.replace(y,((t,n)=>{const s=e[n];return null!=s?String(s):`<${n}?>`}))}(r,n):"Error",o=`${this.serviceName}: ${i} (${s}).`;return new g(s,o,n)}}const y=/\{\$([^}]+)}/g;function w(t,e){if(t===e)return!0;const n=Object.keys(t),s=Object.keys(e);for(const r of n){if(!s.includes(r))return!1;const n=t[r],i=e[r];if(v(n)&&v(i)){if(!w(n,i))return!1}else if(n!==i)return!1}for(const t of s)if(!n.includes(t))return!1;return!0}function v(t){return null!==t&&"object"==typeof t}function I(t){return t&&t._delegate?t._delegate:t}class b{constructor(t,e,n){this.name=t,this.instanceFactory=e,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}setInstantiationMode(t){return this.instantiationMode=t,this}setMultipleInstances(t){return this.multipleInstances=t,this}setServiceProps(t){return this.serviceProps=t,this}setInstanceCreatedCallback(t){return this.onInstanceCreated=t,this}}var E;!function(t){t[t.DEBUG=0]="DEBUG",t[t.VERBOSE=1]="VERBOSE",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR",t[t.SILENT=5]="SILENT"}(E||(E={}));const T={debug:E.DEBUG,verbose:E.VERBOSE,info:E.INFO,warn:E.WARN,error:E.ERROR,silent:E.SILENT},S=E.INFO,_={[E.DEBUG]:"log",[E.VERBOSE]:"log",[E.INFO]:"info",[E.WARN]:"warn",[E.ERROR]:"error"},x=(t,e,...n)=>{if(e<t.logLevel)return;const s=(new Date).toISOString(),r=_[e];if(!r)throw new Error(`Attempted to log a message with an invalid logType (value: ${e})`);console[r](`[${s}] ${t.name}:`,...n)};var A,D="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},C=C||{},N=D||self;function k(){}function R(t){var e=typeof t;return"array"==(e="object"!=e?e:t?Array.isArray(t)?"array":e:"null")||"object"==e&&"number"==typeof t.length}function L(t){var e=typeof t;return"object"==e&&null!=t||"function"==e}var M="closure_uid_"+(1e9*Math.random()>>>0),O=0;function V(t,e,n){return t.call.apply(t.bind,arguments)}function F(t,e,n){if(!t)throw Error();if(2<arguments.length){var s=Array.prototype.slice.call(arguments,2);return function(){var n=Array.prototype.slice.call(arguments);return Array.prototype.unshift.apply(n,s),t.apply(e,n)}}return function(){return t.apply(e,arguments)}}function P(t,e,n){return(P=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?V:F).apply(null,arguments)}function B(t,e){var n=Array.prototype.slice.call(arguments,1);return function(){var e=n.slice();return e.push.apply(e,arguments),t.apply(this,e)}}function U(t,e){function n(){}n.prototype=e.prototype,t.X=e.prototype,t.prototype=new n,t.prototype.constructor=t,t.Wb=function(t,n,s){for(var r=Array(arguments.length-2),i=2;i<arguments.length;i++)r[i-2]=arguments[i];return e.prototype[n].apply(t,r)}}function q(){this.s=this.s,this.o=this.o}q.prototype.s=!1,q.prototype.na=function(){var t;!this.s&&(this.s=!0,this.M(),0)&&(t=this,Object.prototype.hasOwnProperty.call(t,M)&&t[M]||(t[M]=++O))},q.prototype.M=function(){if(this.o)for(;this.o.length;)this.o.shift()()};const G=Array.prototype.indexOf?function(t,e){return Array.prototype.indexOf.call(t,e,void 0)}:function(t,e){if("string"==typeof t)return"string"!=typeof e||1!=e.length?-1:t.indexOf(e,0);for(let n=0;n<t.length;n++)if(n in t&&t[n]===e)return n;return-1};function K(t){const e=t.length;if(0<e){const n=Array(e);for(let s=0;s<e;s++)n[s]=t[s];return n}return[]}function j(t,e){for(let e=1;e<arguments.length;e++){const n=arguments[e];if(R(n)){const e=t.length||0,s=n.length||0;t.length=e+s;for(let r=0;r<s;r++)t[e+r]=n[r]}else t.push(n)}}function $(t,e){this.type=t,this.g=this.target=e,this.defaultPrevented=!1}$.prototype.h=function(){this.defaultPrevented=!0};var Q=function(){if(!N.addEventListener||!Object.defineProperty)return!1;var t=!1,e=Object.defineProperty({},"passive",{get:function(){t=!0}});try{N.addEventListener("test",k,e),N.removeEventListener("test",k,e)}catch(t){}return t}();function z(t){return/^[\s\xa0]*$/.test(t)}var H=String.prototype.trim?function(t){return t.trim()}:function(t){return/^[\s\xa0]*([\s\S]*?)[\s\xa0]*$/.exec(t)[1]};function W(t,e){return t<e?-1:t>e?1:0}function Y(){var t=N.navigator;return t&&(t=t.userAgent)?t:""}function X(t){return-1!=Y().indexOf(t)}function J(t){return J[" "](t),t}J[" "]=k;var Z,tt,et=X("Opera"),nt=X("Trident")||X("MSIE"),st=X("Edge"),rt=st||nt,it=X("Gecko")&&!(-1!=Y().toLowerCase().indexOf("webkit")&&!X("Edge"))&&!(X("Trident")||X("MSIE"))&&!X("Edge"),ot=-1!=Y().toLowerCase().indexOf("webkit")&&!X("Edge");function at(){var t=N.document;return t?t.documentMode:void 0}t:{var ut="",ct=(tt=Y(),it?/rv:([^\);]+)(\)|;)/.exec(tt):st?/Edge\/([\d\.]+)/.exec(tt):nt?/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(tt):ot?/WebKit\/(\S+)/.exec(tt):et?/(?:Version)[ \/]?(\S+)/.exec(tt):void 0);if(ct&&(ut=ct?ct[1]:""),nt){var ht=at();if(null!=ht&&ht>parseFloat(ut)){Z=String(ht);break t}}Z=ut}var lt,dt={};function ft(){return function(t){var e=dt;return Object.prototype.hasOwnProperty.call(e,9)?e[9]:e[9]=t(9)}((function(){let t=0;const e=H(String(Z)).split("."),n=H("9").split("."),s=Math.max(e.length,n.length);for(let o=0;0==t&&o<s;o++){var r=e[o]||"",i=n[o]||"";do{if(r=/(\d*)(\D*)(.*)/.exec(r)||["","","",""],i=/(\d*)(\D*)(.*)/.exec(i)||["","","",""],0==r[0].length&&0==i[0].length)break;t=W(0==r[1].length?0:parseInt(r[1],10),0==i[1].length?0:parseInt(i[1],10))||W(0==r[2].length,0==i[2].length)||W(r[2],i[2]),r=r[3],i=i[3]}while(0==t)}return 0<=t}))}if(N.document&&nt){var mt=at();lt=mt||(parseInt(Z,10)||void 0)}else lt=void 0;var gt=lt;function pt(t,e){if($.call(this,t?t.type:""),this.relatedTarget=this.g=this.target=null,this.button=this.screenY=this.screenX=this.clientY=this.clientX=0,this.key="",this.metaKey=this.shiftKey=this.altKey=this.ctrlKey=!1,this.state=null,this.pointerId=0,this.pointerType="",this.i=null,t){var n=this.type=t.type,s=t.changedTouches&&t.changedTouches.length?t.changedTouches[0]:null;if(this.target=t.target||t.srcElement,this.g=e,e=t.relatedTarget){if(it){t:{try{J(e.nodeName);var r=!0;break t}catch(t){}r=!1}r||(e=null)}}else"mouseover"==n?e=t.fromElement:"mouseout"==n&&(e=t.toElement);this.relatedTarget=e,s?(this.clientX=void 0!==s.clientX?s.clientX:s.pageX,this.clientY=void 0!==s.clientY?s.clientY:s.pageY,this.screenX=s.screenX||0,this.screenY=s.screenY||0):(this.clientX=void 0!==t.clientX?t.clientX:t.pageX,this.clientY=void 0!==t.clientY?t.clientY:t.pageY,this.screenX=t.screenX||0,this.screenY=t.screenY||0),this.button=t.button,this.key=t.key||"",this.ctrlKey=t.ctrlKey,this.altKey=t.altKey,this.shiftKey=t.shiftKey,this.metaKey=t.metaKey,this.pointerId=t.pointerId||0,this.pointerType="string"==typeof t.pointerType?t.pointerType:yt[t.pointerType]||"",this.state=t.state,this.i=t,t.defaultPrevented&&pt.X.h.call(this)}}U(pt,$);var yt={2:"touch",3:"pen",4:"mouse"};pt.prototype.h=function(){pt.X.h.call(this);var t=this.i;t.preventDefault?t.preventDefault():t.returnValue=!1};var wt="closure_listenable_"+(1e6*Math.random()|0),vt=0;function It(t,e,n,s,r){this.listener=t,this.proxy=null,this.src=e,this.type=n,this.capture=!!s,this.ha=r,this.key=++vt,this.ba=this.ea=!1}function bt(t){t.ba=!0,t.listener=null,t.proxy=null,t.src=null,t.ha=null}function Et(t,e,n){for(const s in t)e.call(n,t[s],s,t)}function Tt(t){const e={};for(const n in t)e[n]=t[n];return e}const St="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");function _t(t,e){let n,s;for(let e=1;e<arguments.length;e++){for(n in s=arguments[e],s)t[n]=s[n];for(let e=0;e<St.length;e++)n=St[e],Object.prototype.hasOwnProperty.call(s,n)&&(t[n]=s[n])}}function xt(t){this.src=t,this.g={},this.h=0}function At(t,e){var n=e.type;if(n in t.g){var s,r=t.g[n],i=G(r,e);(s=0<=i)&&Array.prototype.splice.call(r,i,1),s&&(bt(e),0==t.g[n].length&&(delete t.g[n],t.h--))}}function Dt(t,e,n,s){for(var r=0;r<t.length;++r){var i=t[r];if(!i.ba&&i.listener==e&&i.capture==!!n&&i.ha==s)return r}return-1}xt.prototype.add=function(t,e,n,s,r){var i=t.toString();(t=this.g[i])||(t=this.g[i]=[],this.h++);var o=Dt(t,e,s,r);return-1<o?(e=t[o],n||(e.ea=!1)):((e=new It(e,this.src,i,!!s,r)).ea=n,t.push(e)),e};var Ct="closure_lm_"+(1e6*Math.random()|0),Nt={};function kt(t,e,n,s,r){if(s&&s.once)return Lt(t,e,n,s,r);if(Array.isArray(e)){for(var i=0;i<e.length;i++)kt(t,e[i],n,s,r);return null}return n=Ut(n),t&&t[wt]?t.N(e,n,L(s)?!!s.capture:!!s,r):Rt(t,e,n,!1,s,r)}function Rt(t,e,n,s,r,i){if(!e)throw Error("Invalid event type");var o=L(r)?!!r.capture:!!r,a=Pt(t);if(a||(t[Ct]=a=new xt(t)),(n=a.add(e,n,s,o,i)).proxy)return n;if(s=function(){function t(n){return e.call(t.src,t.listener,n)}const e=Ft;return t}(),n.proxy=s,s.src=t,s.listener=n,t.addEventListener)Q||(r=o),void 0===r&&(r=!1),t.addEventListener(e.toString(),s,r);else if(t.attachEvent)t.attachEvent(Vt(e.toString()),s);else{if(!t.addListener||!t.removeListener)throw Error("addEventListener and attachEvent are unavailable.");t.addListener(s)}return n}function Lt(t,e,n,s,r){if(Array.isArray(e)){for(var i=0;i<e.length;i++)Lt(t,e[i],n,s,r);return null}return n=Ut(n),t&&t[wt]?t.O(e,n,L(s)?!!s.capture:!!s,r):Rt(t,e,n,!0,s,r)}function Mt(t,e,n,s,r){if(Array.isArray(e))for(var i=0;i<e.length;i++)Mt(t,e[i],n,s,r);else s=L(s)?!!s.capture:!!s,n=Ut(n),t&&t[wt]?(t=t.i,(e=String(e).toString())in t.g&&(-1<(n=Dt(i=t.g[e],n,s,r))&&(bt(i[n]),Array.prototype.splice.call(i,n,1),0==i.length&&(delete t.g[e],t.h--)))):t&&(t=Pt(t))&&(e=t.g[e.toString()],t=-1,e&&(t=Dt(e,n,s,r)),(n=-1<t?e[t]:null)&&Ot(n))}function Ot(t){if("number"!=typeof t&&t&&!t.ba){var e=t.src;if(e&&e[wt])At(e.i,t);else{var n=t.type,s=t.proxy;e.removeEventListener?e.removeEventListener(n,s,t.capture):e.detachEvent?e.detachEvent(Vt(n),s):e.addListener&&e.removeListener&&e.removeListener(s),(n=Pt(e))?(At(n,t),0==n.h&&(n.src=null,e[Ct]=null)):bt(t)}}}function Vt(t){return t in Nt?Nt[t]:Nt[t]="on"+t}function Ft(t,e){if(t.ba)t=!0;else{e=new pt(e,this);var n=t.listener,s=t.ha||t.src;t.ea&&Ot(t),t=n.call(s,e)}return t}function Pt(t){return(t=t[Ct])instanceof xt?t:null}var Bt="__closure_events_fn_"+(1e9*Math.random()>>>0);function Ut(t){return"function"==typeof t?t:(t[Bt]||(t[Bt]=function(e){return t.handleEvent(e)}),t[Bt])}function qt(){q.call(this),this.i=new xt(this),this.P=this,this.I=null}function Gt(t,e){var n,s=t.I;if(s)for(n=[];s;s=s.I)n.push(s);if(t=t.P,s=e.type||e,"string"==typeof e)e=new $(e,t);else if(e instanceof $)e.target=e.target||t;else{var r=e;_t(e=new $(s,t),r)}if(r=!0,n)for(var i=n.length-1;0<=i;i--){var o=e.g=n[i];r=Kt(o,s,!0,e)&&r}if(r=Kt(o=e.g=t,s,!0,e)&&r,r=Kt(o,s,!1,e)&&r,n)for(i=0;i<n.length;i++)r=Kt(o=e.g=n[i],s,!1,e)&&r}function Kt(t,e,n,s){if(!(e=t.i.g[String(e)]))return!0;e=e.concat();for(var r=!0,i=0;i<e.length;++i){var o=e[i];if(o&&!o.ba&&o.capture==n){var a=o.listener,u=o.ha||o.src;o.ea&&At(t.i,o),r=!1!==a.call(u,s)&&r}}return r&&!s.defaultPrevented}U(qt,q),qt.prototype[wt]=!0,qt.prototype.removeEventListener=function(t,e,n,s){Mt(this,t,e,n,s)},qt.prototype.M=function(){if(qt.X.M.call(this),this.i){var t,e=this.i;for(t in e.g){for(var n=e.g[t],s=0;s<n.length;s++)bt(n[s]);delete e.g[t],e.h--}}this.I=null},qt.prototype.N=function(t,e,n,s){return this.i.add(String(t),e,!1,n,s)},qt.prototype.O=function(t,e,n,s){return this.i.add(String(t),e,!0,n,s)};var jt=N.JSON.stringify;function $t(){var t=Jt;let e=null;return t.g&&(e=t.g,t.g=t.g.next,t.g||(t.h=null),e.next=null),e}var Qt,zt=new class{constructor(t,e){this.i=t,this.j=e,this.h=0,this.g=null}get(){let t;return 0<this.h?(this.h--,t=this.g,this.g=t.next,t.next=null):t=this.i(),t}}((()=>new Ht),(t=>t.reset()));class Ht{constructor(){this.next=this.g=this.h=null}set(t,e){this.h=t,this.g=e,this.next=null}reset(){this.next=this.g=this.h=null}}function Wt(t){N.setTimeout((()=>{throw t}),0)}function Yt(t,e){Qt||function(){var t=N.Promise.resolve(void 0);Qt=function(){t.then(Zt)}}(),Xt||(Qt(),Xt=!0),Jt.add(t,e)}var Xt=!1,Jt=new class{constructor(){this.h=this.g=null}add(t,e){const n=zt.get();n.set(t,e),this.h?this.h.next=n:this.g=n,this.h=n}};function Zt(){for(var t;t=$t();){try{t.h.call(t.g)}catch(t){Wt(t)}var e=zt;e.j(t),100>e.h&&(e.h++,t.next=e.g,e.g=t)}Xt=!1}function te(t,e){qt.call(this),this.h=t||1,this.g=e||N,this.j=P(this.lb,this),this.l=Date.now()}function ee(t){t.ca=!1,t.R&&(t.g.clearTimeout(t.R),t.R=null)}function ne(t,e,n){if("function"==typeof t)n&&(t=P(t,n));else{if(!t||"function"!=typeof t.handleEvent)throw Error("Invalid listener argument");t=P(t.handleEvent,t)}return 2147483647<Number(e)?-1:N.setTimeout(t,e||0)}function se(t){t.g=ne((()=>{t.g=null,t.i&&(t.i=!1,se(t))}),t.j);const e=t.h;t.h=null,t.m.apply(null,e)}U(te,qt),(A=te.prototype).ca=!1,A.R=null,A.lb=function(){if(this.ca){var t=Date.now()-this.l;0<t&&t<.8*this.h?this.R=this.g.setTimeout(this.j,this.h-t):(this.R&&(this.g.clearTimeout(this.R),this.R=null),Gt(this,"tick"),this.ca&&(ee(this),this.start()))}},A.start=function(){this.ca=!0,this.R||(this.R=this.g.setTimeout(this.j,this.h),this.l=Date.now())},A.M=function(){te.X.M.call(this),ee(this),delete this.g};class re extends q{constructor(t,e){super(),this.m=t,this.j=e,this.h=null,this.i=!1,this.g=null}l(t){this.h=arguments,this.g?this.i=!0:se(this)}M(){super.M(),this.g&&(N.clearTimeout(this.g),this.g=null,this.i=!1,this.h=null)}}function ie(t){q.call(this),this.h=t,this.g={}}U(ie,q);var oe=[];function ae(t,e,n,s){Array.isArray(n)||(n&&(oe[0]=n.toString()),n=oe);for(var r=0;r<n.length;r++){var i=kt(e,n[r],s||t.handleEvent,!1,t.h||t);if(!i)break;t.g[i.key]=i}}function ue(t){Et(t.g,(function(t,e){this.g.hasOwnProperty(e)&&Ot(t)}),t),t.g={}}function ce(){this.g=!0}function he(t,e,n,s){t.info((function(){return"XMLHTTP TEXT ("+e+"): "+function(t,e){if(!t.g)return e;if(!e)return null;try{var n=JSON.parse(e);if(n)for(t=0;t<n.length;t++)if(Array.isArray(n[t])){var s=n[t];if(!(2>s.length)){var r=s[1];if(Array.isArray(r)&&!(1>r.length)){var i=r[0];if("noop"!=i&&"stop"!=i&&"close"!=i)for(var o=1;o<r.length;o++)r[o]=""}}}return jt(n)}catch(t){return e}}(t,n)+(s?" "+s:"")}))}ie.prototype.M=function(){ie.X.M.call(this),ue(this)},ie.prototype.handleEvent=function(){throw Error("EventHandler.handleEvent not implemented")},ce.prototype.Aa=function(){this.g=!1},ce.prototype.info=function(){};var le={},de=null;function fe(){return de=de||new qt}function me(t){$.call(this,le.Pa,t)}function ge(t){const e=fe();Gt(e,new me(e))}function pe(t,e){$.call(this,le.STAT_EVENT,t),this.stat=e}function ye(t){const e=fe();Gt(e,new pe(e,t))}function we(t,e){$.call(this,le.Qa,t),this.size=e}function ve(t,e){if("function"!=typeof t)throw Error("Fn must not be null and must be a function");return N.setTimeout((function(){t()}),e)}le.Pa="serverreachability",U(me,$),le.STAT_EVENT="statevent",U(pe,$),le.Qa="timingevent",U(we,$);var Ie={NO_ERROR:0,mb:1,zb:2,yb:3,tb:4,xb:5,Ab:6,Ma:7,TIMEOUT:8,Db:9},be={rb:"complete",Nb:"success",Na:"error",Ma:"abort",Fb:"ready",Gb:"readystatechange",TIMEOUT:"timeout",Bb:"incrementaldata",Eb:"progress",ub:"downloadprogress",Vb:"uploadprogress"};function Ee(){}function Te(t){return t.h||(t.h=t.i())}function Se(){}Ee.prototype.h=null;var _e,xe={OPEN:"a",qb:"b",Na:"c",Cb:"d"};function Ae(){$.call(this,"d")}function De(){$.call(this,"c")}function Ce(){}function Ne(t,e,n,s){this.l=t,this.j=e,this.m=n,this.U=s||1,this.S=new ie(this),this.O=Re,t=rt?125:void 0,this.T=new te(t),this.H=null,this.i=!1,this.s=this.A=this.v=this.K=this.F=this.V=this.B=null,this.D=[],this.g=null,this.C=0,this.o=this.u=null,this.Y=-1,this.I=!1,this.N=0,this.L=null,this.$=this.J=this.Z=this.P=!1,this.h=new ke}function ke(){this.i=null,this.g="",this.h=!1}U(Ae,$),U(De,$),U(Ce,Ee),Ce.prototype.g=function(){return new XMLHttpRequest},Ce.prototype.i=function(){return{}},_e=new Ce;var Re=45e3,Le={},Me={};function Oe(t,e,n){t.K=1,t.v=tn(We(e)),t.s=n,t.P=!0,Ve(t,null)}function Ve(t,e){t.F=Date.now(),Ue(t),t.A=We(t.v);var n=t.A,s=t.U;Array.isArray(s)||(s=[String(s)]),mn(n.i,"t",s),t.C=0,n=t.l.H,t.h=new ke,t.g=fs(t.l,n?e:null,!t.s),0<t.N&&(t.L=new re(P(t.La,t,t.g),t.N)),ae(t.S,t.g,"readystatechange",t.ib),e=t.H?Tt(t.H):{},t.s?(t.u||(t.u="POST"),e["Content-Type"]="application/x-www-form-urlencoded",t.g.da(t.A,t.u,t.s,e)):(t.u="GET",t.g.da(t.A,t.u,null,e)),ge(),function(t,e,n,s,r,i){t.info((function(){if(t.g)if(i)for(var o="",a=i.split("&"),u=0;u<a.length;u++){var c=a[u].split("=");if(1<c.length){var h=c[0];c=c[1];var l=h.split("_");o=2<=l.length&&"type"==l[1]?o+(h+"=")+c+"&":o+(h+"=redacted&")}}else o=null;else o=i;return"XMLHTTP REQ ("+s+") [attempt "+r+"]: "+e+"\n"+n+"\n"+o}))}(t.j,t.u,t.A,t.m,t.U,t.s)}function Fe(t){return!!t.g&&("GET"==t.u&&2!=t.K&&t.l.Da)}function Pe(t,e,n){let s,r=!0;for(;!t.I&&t.C<n.length;){if(s=Be(t,n),s==Me){4==e&&(t.o=4,ye(14),r=!1),he(t.j,t.m,null,"[Incomplete Response]");break}if(s==Le){t.o=4,ye(15),he(t.j,t.m,n,"[Invalid Chunk]"),r=!1;break}he(t.j,t.m,s,null),$e(t,s)}Fe(t)&&s!=Me&&s!=Le&&(t.h.g="",t.C=0),4!=e||0!=n.length||t.h.h||(t.o=1,ye(16),r=!1),t.i=t.i&&r,r?0<n.length&&!t.$&&(t.$=!0,(e=t.l).g==t&&e.$&&!e.K&&(e.j.info("Great, no buffering proxy detected. Bytes received: "+n.length),is(e),e.K=!0,ye(11))):(he(t.j,t.m,n,"[Invalid Chunked Response]"),je(t),Ke(t))}function Be(t,e){var n=t.C,s=e.indexOf("\n",n);return-1==s?Me:(n=Number(e.substring(n,s)),isNaN(n)?Le:(s+=1)+n>e.length?Me:(e=e.substr(s,n),t.C=s+n,e))}function Ue(t){t.V=Date.now()+t.O,qe(t,t.O)}function qe(t,e){if(null!=t.B)throw Error("WatchDog timer not null");t.B=ve(P(t.gb,t),e)}function Ge(t){t.B&&(N.clearTimeout(t.B),t.B=null)}function Ke(t){0==t.l.G||t.I||us(t.l,t)}function je(t){Ge(t);var e=t.L;e&&"function"==typeof e.na&&e.na(),t.L=null,ee(t.T),ue(t.S),t.g&&(e=t.g,t.g=null,e.abort(),e.na())}function $e(t,e){try{var n=t.l;if(0!=n.G&&(n.g==t||In(n.h,t)))if(!t.J&&In(n.h,t)&&3==n.G){try{var s=n.Fa.g.parse(e)}catch(t){s=null}if(Array.isArray(s)&&3==s.length){var r=s;if(0==r[0]){t:if(!n.u){if(n.g){if(!(n.g.F+3e3<t.F))break t;as(n),Xn(n)}rs(n),ye(18)}}else n.Ba=r[1],0<n.Ba-n.T&&37500>r[2]&&n.L&&0==n.A&&!n.v&&(n.v=ve(P(n.cb,n),6e3));if(1>=vn(n.h)&&n.ja){try{n.ja()}catch(t){}n.ja=void 0}}else hs(n,11)}else if((t.J||n.g==t)&&as(n),!z(e))for(r=n.Fa.g.parse(e),e=0;e<r.length;e++){let c=r[e];if(n.T=c[0],c=c[1],2==n.G)if("c"==c[0]){n.I=c[1],n.ka=c[2];const e=c[3];null!=e&&(n.ma=e,n.j.info("VER="+n.ma));const r=c[4];null!=r&&(n.Ca=r,n.j.info("SVER="+n.Ca));const h=c[5];null!=h&&"number"==typeof h&&0<h&&(s=1.5*h,n.J=s,n.j.info("backChannelRequestTimeoutMs_="+s)),s=n;const l=t.g;if(l){const t=l.g?l.g.getResponseHeader("X-Client-Wire-Protocol"):null;if(t){var i=s.h;i.g||-1==t.indexOf("spdy")&&-1==t.indexOf("quic")&&-1==t.indexOf("h2")||(i.j=i.l,i.g=new Set,i.h&&(bn(i,i.h),i.h=null))}if(s.D){const t=l.g?l.g.getResponseHeader("X-HTTP-Session-Id"):null;t&&(s.za=t,Ze(s.F,s.D,t))}}n.G=3,n.l&&n.l.xa(),n.$&&(n.P=Date.now()-t.F,n.j.info("Handshake RTT: "+n.P+"ms"));var o=t;if((s=n).sa=ds(s,s.H?s.ka:null,s.V),o.J){En(s.h,o);var a=o,u=s.J;u&&a.setTimeout(u),a.B&&(Ge(a),Ue(a)),s.g=o}else ss(s);0<n.i.length&&Zn(n)}else"stop"!=c[0]&&"close"!=c[0]||hs(n,7);else 3==n.G&&("stop"==c[0]||"close"==c[0]?"stop"==c[0]?hs(n,7):Yn(n):"noop"!=c[0]&&n.l&&n.l.wa(c),n.A=0)}ge()}catch(t){}}function Qe(t,e){if(t.forEach&&"function"==typeof t.forEach)t.forEach(e,void 0);else if(R(t)||"string"==typeof t)Array.prototype.forEach.call(t,e,void 0);else for(var n=function(t){if(t.oa&&"function"==typeof t.oa)return t.oa();if(!t.W||"function"!=typeof t.W){if("undefined"!=typeof Map&&t instanceof Map)return Array.from(t.keys());if(!("undefined"!=typeof Set&&t instanceof Set)){if(R(t)||"string"==typeof t){var e=[];t=t.length;for(var n=0;n<t;n++)e.push(n);return e}e=[],n=0;for(const s in t)e[n++]=s;return e}}}(t),s=function(t){if(t.W&&"function"==typeof t.W)return t.W();if("undefined"!=typeof Map&&t instanceof Map||"undefined"!=typeof Set&&t instanceof Set)return Array.from(t.values());if("string"==typeof t)return t.split("");if(R(t)){for(var e=[],n=t.length,s=0;s<n;s++)e.push(t[s]);return e}for(s in e=[],n=0,t)e[n++]=t[s];return e}(t),r=s.length,i=0;i<r;i++)e.call(void 0,s[i],n&&n[i],t)}(A=Ne.prototype).setTimeout=function(t){this.O=t},A.ib=function(t){t=t.target;const e=this.L;e&&3==jn(t)?e.l():this.La(t)},A.La=function(t){try{if(t==this.g)t:{const h=jn(this.g);var e=this.g.Ea();this.g.aa();if(!(3>h)&&(3!=h||rt||this.g&&(this.h.h||this.g.fa()||$n(this.g)))){this.I||4!=h||7==e||ge(),Ge(this);var n=this.g.aa();this.Y=n;e:if(Fe(this)){var s=$n(this.g);t="";var r=s.length,i=4==jn(this.g);if(!this.h.i){if("undefined"==typeof TextDecoder){je(this),Ke(this);var o="";break e}this.h.i=new N.TextDecoder}for(e=0;e<r;e++)this.h.h=!0,t+=this.h.i.decode(s[e],{stream:i&&e==r-1});s.splice(0,r),this.h.g+=t,this.C=0,o=this.h.g}else o=this.g.fa();if(this.i=200==n,function(t,e,n,s,r,i,o){t.info((function(){return"XMLHTTP RESP ("+s+") [ attempt "+r+"]: "+e+"\n"+n+"\n"+i+" "+o}))}(this.j,this.u,this.A,this.m,this.U,h,n),this.i){if(this.Z&&!this.J){e:{if(this.g){var a,u=this.g;if((a=u.g?u.g.getResponseHeader("X-HTTP-Initial-Response"):null)&&!z(a)){var c=a;break e}}c=null}if(!(n=c)){this.i=!1,this.o=3,ye(12),je(this),Ke(this);break t}he(this.j,this.m,n,"Initial handshake response via X-HTTP-Initial-Response"),this.J=!0,$e(this,n)}this.P?(Pe(this,h,o),rt&&this.i&&3==h&&(ae(this.S,this.T,"tick",this.hb),this.T.start())):(he(this.j,this.m,o,null),$e(this,o)),4==h&&je(this),this.i&&!this.I&&(4==h?us(this.l,this):(this.i=!1,Ue(this)))}else 400==n&&0<o.indexOf("Unknown SID")?(this.o=3,ye(12)):(this.o=0,ye(13)),je(this),Ke(this)}}}catch(t){}},A.hb=function(){if(this.g){var t=jn(this.g),e=this.g.fa();this.C<e.length&&(Ge(this),Pe(this,t,e),this.i&&4!=t&&Ue(this))}},A.cancel=function(){this.I=!0,je(this)},A.gb=function(){this.B=null;const t=Date.now();0<=t-this.V?(function(t,e){t.info((function(){return"TIMEOUT: "+e}))}(this.j,this.A),2!=this.K&&(ge(),ye(17)),je(this),this.o=2,Ke(this)):qe(this,this.V-t)};var ze=RegExp("^(?:([^:/?#.]+):)?(?://(?:([^\\\\/?#]*)@)?([^\\\\/?#]*?)(?::([0-9]+))?(?=[\\\\/?#]|$))?([^?#]+)?(?:\\?([^#]*))?(?:#([\\s\\S]*))?$");function He(t,e){if(this.g=this.s=this.j="",this.m=null,this.o=this.l="",this.h=!1,t instanceof He){this.h=void 0!==e?e:t.h,Ye(this,t.j),this.s=t.s,this.g=t.g,Xe(this,t.m),this.l=t.l,e=t.i;var n=new hn;n.i=e.i,e.g&&(n.g=new Map(e.g),n.h=e.h),Je(this,n),this.o=t.o}else t&&(n=String(t).match(ze))?(this.h=!!e,Ye(this,n[1]||"",!0),this.s=en(n[2]||""),this.g=en(n[3]||"",!0),Xe(this,n[4]),this.l=en(n[5]||"",!0),Je(this,n[6]||"",!0),this.o=en(n[7]||"")):(this.h=!!e,this.i=new hn(null,this.h))}function We(t){return new He(t)}function Ye(t,e,n){t.j=n?en(e,!0):e,t.j&&(t.j=t.j.replace(/:$/,""))}function Xe(t,e){if(e){if(e=Number(e),isNaN(e)||0>e)throw Error("Bad port number "+e);t.m=e}else t.m=null}function Je(t,e,n){e instanceof hn?(t.i=e,function(t,e){e&&!t.j&&(ln(t),t.i=null,t.g.forEach((function(t,e){var n=e.toLowerCase();e!=n&&(dn(this,e),mn(this,n,t))}),t)),t.j=e}(t.i,t.h)):(n||(e=nn(e,un)),t.i=new hn(e,t.h))}function Ze(t,e,n){t.i.set(e,n)}function tn(t){return Ze(t,"zx",Math.floor(2147483648*Math.random()).toString(36)+Math.abs(Math.floor(2147483648*Math.random())^Date.now()).toString(36)),t}function en(t,e){return t?e?decodeURI(t.replace(/%25/g,"%2525")):decodeURIComponent(t):""}function nn(t,e,n){return"string"==typeof t?(t=encodeURI(t).replace(e,sn),n&&(t=t.replace(/%25([0-9a-fA-F]{2})/g,"%$1")),t):null}function sn(t){return"%"+((t=t.charCodeAt(0))>>4&15).toString(16)+(15&t).toString(16)}He.prototype.toString=function(){var t=[],e=this.j;e&&t.push(nn(e,rn,!0),":");var n=this.g;return(n||"file"==e)&&(t.push("//"),(e=this.s)&&t.push(nn(e,rn,!0),"@"),t.push(encodeURIComponent(String(n)).replace(/%25([0-9a-fA-F]{2})/g,"%$1")),null!=(n=this.m)&&t.push(":",String(n))),(n=this.l)&&(this.g&&"/"!=n.charAt(0)&&t.push("/"),t.push(nn(n,"/"==n.charAt(0)?an:on,!0))),(n=this.i.toString())&&t.push("?",n),(n=this.o)&&t.push("#",nn(n,cn)),t.join("")};var rn=/[#\/\?@]/g,on=/[#\?:]/g,an=/[#\?]/g,un=/[#\?@]/g,cn=/#/g;function hn(t,e){this.h=this.g=null,this.i=t||null,this.j=!!e}function ln(t){t.g||(t.g=new Map,t.h=0,t.i&&function(t,e){if(t){t=t.split("&");for(var n=0;n<t.length;n++){var s=t[n].indexOf("="),r=null;if(0<=s){var i=t[n].substring(0,s);r=t[n].substring(s+1)}else i=t[n];e(i,r?decodeURIComponent(r.replace(/\+/g," ")):"")}}}(t.i,(function(e,n){t.add(decodeURIComponent(e.replace(/\+/g," ")),n)})))}function dn(t,e){ln(t),e=gn(t,e),t.g.has(e)&&(t.i=null,t.h-=t.g.get(e).length,t.g.delete(e))}function fn(t,e){return ln(t),e=gn(t,e),t.g.has(e)}function mn(t,e,n){dn(t,e),0<n.length&&(t.i=null,t.g.set(gn(t,e),K(n)),t.h+=n.length)}function gn(t,e){return e=String(e),t.j&&(e=e.toLowerCase()),e}(A=hn.prototype).add=function(t,e){ln(this),this.i=null,t=gn(this,t);var n=this.g.get(t);return n||this.g.set(t,n=[]),n.push(e),this.h+=1,this},A.forEach=function(t,e){ln(this),this.g.forEach((function(n,s){n.forEach((function(n){t.call(e,n,s,this)}),this)}),this)},A.oa=function(){ln(this);const t=Array.from(this.g.values()),e=Array.from(this.g.keys()),n=[];for(let s=0;s<e.length;s++){const r=t[s];for(let t=0;t<r.length;t++)n.push(e[s])}return n},A.W=function(t){ln(this);let e=[];if("string"==typeof t)fn(this,t)&&(e=e.concat(this.g.get(gn(this,t))));else{t=Array.from(this.g.values());for(let n=0;n<t.length;n++)e=e.concat(t[n])}return e},A.set=function(t,e){return ln(this),this.i=null,fn(this,t=gn(this,t))&&(this.h-=this.g.get(t).length),this.g.set(t,[e]),this.h+=1,this},A.get=function(t,e){return t&&0<(t=this.W(t)).length?String(t[0]):e},A.toString=function(){if(this.i)return this.i;if(!this.g)return"";const t=[],e=Array.from(this.g.keys());for(var n=0;n<e.length;n++){var s=e[n];const i=encodeURIComponent(String(s)),o=this.W(s);for(s=0;s<o.length;s++){var r=i;""!==o[s]&&(r+="="+encodeURIComponent(String(o[s]))),t.push(r)}}return this.i=t.join("&")};function pn(t){this.l=t||yn,N.PerformanceNavigationTiming?t=0<(t=N.performance.getEntriesByType("navigation")).length&&("hq"==t[0].nextHopProtocol||"h2"==t[0].nextHopProtocol):t=!!(N.g&&N.g.Ga&&N.g.Ga()&&N.g.Ga().$b),this.j=t?this.l:1,this.g=null,1<this.j&&(this.g=new Set),this.h=null,this.i=[]}var yn=10;function wn(t){return!!t.h||!!t.g&&t.g.size>=t.j}function vn(t){return t.h?1:t.g?t.g.size:0}function In(t,e){return t.h?t.h==e:!!t.g&&t.g.has(e)}function bn(t,e){t.g?t.g.add(e):t.h=e}function En(t,e){t.h&&t.h==e?t.h=null:t.g&&t.g.has(e)&&t.g.delete(e)}function Tn(t){if(null!=t.h)return t.i.concat(t.h.D);if(null!=t.g&&0!==t.g.size){let e=t.i;for(const n of t.g.values())e=e.concat(n.D);return e}return K(t.i)}function Sn(){}function _n(){this.g=new Sn}function xn(t,e,n){const s=n||"";try{Qe(t,(function(t,n){let r=t;L(t)&&(r=jt(t)),e.push(s+n+"="+encodeURIComponent(r))}))}catch(t){throw e.push(s+"type="+encodeURIComponent("_badmap")),t}}function An(t,e,n,s,r){try{e.onload=null,e.onerror=null,e.onabort=null,e.ontimeout=null,r(s)}catch(t){}}function Dn(t){this.l=t.ac||null,this.j=t.jb||!1}function Cn(t,e){qt.call(this),this.D=t,this.u=e,this.m=void 0,this.readyState=Nn,this.status=0,this.responseType=this.responseText=this.response=this.statusText="",this.onreadystatechange=null,this.v=new Headers,this.h=null,this.C="GET",this.B="",this.g=!1,this.A=this.j=this.l=null}pn.prototype.cancel=function(){if(this.i=Tn(this),this.h)this.h.cancel(),this.h=null;else if(this.g&&0!==this.g.size){for(const t of this.g.values())t.cancel();this.g.clear()}},Sn.prototype.stringify=function(t){return N.JSON.stringify(t,void 0)},Sn.prototype.parse=function(t){return N.JSON.parse(t,void 0)},U(Dn,Ee),Dn.prototype.g=function(){return new Cn(this.l,this.j)},Dn.prototype.i=function(t){return function(){return t}}({}),U(Cn,qt);var Nn=0;function kn(t){t.j.read().then(t.Ta.bind(t)).catch(t.ga.bind(t))}function Rn(t){t.readyState=4,t.l=null,t.j=null,t.A=null,Ln(t)}function Ln(t){t.onreadystatechange&&t.onreadystatechange.call(t)}(A=Cn.prototype).open=function(t,e){if(this.readyState!=Nn)throw this.abort(),Error("Error reopening a connection");this.C=t,this.B=e,this.readyState=1,Ln(this)},A.send=function(t){if(1!=this.readyState)throw this.abort(),Error("need to call open() first. ");this.g=!0;const e={headers:this.v,method:this.C,credentials:this.m,cache:void 0};t&&(e.body=t),(this.D||N).fetch(new Request(this.B,e)).then(this.Wa.bind(this),this.ga.bind(this))},A.abort=function(){this.response=this.responseText="",this.v=new Headers,this.status=0,this.j&&this.j.cancel("Request was aborted.").catch((()=>{})),1<=this.readyState&&this.g&&4!=this.readyState&&(this.g=!1,Rn(this)),this.readyState=Nn},A.Wa=function(t){if(this.g&&(this.l=t,this.h||(this.status=this.l.status,this.statusText=this.l.statusText,this.h=t.headers,this.readyState=2,Ln(this)),this.g&&(this.readyState=3,Ln(this),this.g)))if("arraybuffer"===this.responseType)t.arrayBuffer().then(this.Ua.bind(this),this.ga.bind(this));else if(void 0!==N.ReadableStream&&"body"in t){if(this.j=t.body.getReader(),this.u){if(this.responseType)throw Error('responseType must be empty for "streamBinaryChunks" mode responses.');this.response=[]}else this.response=this.responseText="",this.A=new TextDecoder;kn(this)}else t.text().then(this.Va.bind(this),this.ga.bind(this))},A.Ta=function(t){if(this.g){if(this.u&&t.value)this.response.push(t.value);else if(!this.u){var e=t.value?t.value:new Uint8Array(0);(e=this.A.decode(e,{stream:!t.done}))&&(this.response=this.responseText+=e)}t.done?Rn(this):Ln(this),3==this.readyState&&kn(this)}},A.Va=function(t){this.g&&(this.response=this.responseText=t,Rn(this))},A.Ua=function(t){this.g&&(this.response=t,Rn(this))},A.ga=function(){this.g&&Rn(this)},A.setRequestHeader=function(t,e){this.v.append(t,e)},A.getResponseHeader=function(t){return this.h&&this.h.get(t.toLowerCase())||""},A.getAllResponseHeaders=function(){if(!this.h)return"";const t=[],e=this.h.entries();for(var n=e.next();!n.done;)n=n.value,t.push(n[0]+": "+n[1]),n=e.next();return t.join("\r\n")},Object.defineProperty(Cn.prototype,"withCredentials",{get:function(){return"include"===this.m},set:function(t){this.m=t?"include":"same-origin"}});var Mn=N.JSON.parse;function On(t){qt.call(this),this.headers=new Map,this.u=t||null,this.h=!1,this.C=this.g=null,this.H="",this.m=0,this.j="",this.l=this.F=this.v=this.D=!1,this.B=0,this.A=null,this.J=Vn,this.K=this.L=!1}U(On,qt);var Vn="",Fn=/^https?$/i,Pn=["POST","PUT"];function Bn(t,e){t.h=!1,t.g&&(t.l=!0,t.g.abort(),t.l=!1),t.j=e,t.m=5,Un(t),Gn(t)}function Un(t){t.D||(t.D=!0,Gt(t,"complete"),Gt(t,"error"))}function qn(t){if(t.h&&void 0!==C&&(!t.C[1]||4!=jn(t)||2!=t.aa()))if(t.v&&4==jn(t))ne(t.Ha,0,t);else if(Gt(t,"readystatechange"),4==jn(t)){t.h=!1;try{const a=t.aa();t:switch(a){case 200:case 201:case 202:case 204:case 206:case 304:case 1223:var e=!0;break t;default:e=!1}var n;if(!(n=e)){var s;if(s=0===a){var r=String(t.H).match(ze)[1]||null;if(!r&&N.self&&N.self.location){var i=N.self.location.protocol;r=i.substr(0,i.length-1)}s=!Fn.test(r?r.toLowerCase():"")}n=s}if(n)Gt(t,"complete"),Gt(t,"success");else{t.m=6;try{var o=2<jn(t)?t.g.statusText:""}catch(t){o=""}t.j=o+" ["+t.aa()+"]",Un(t)}}finally{Gn(t)}}}function Gn(t,e){if(t.g){Kn(t);const n=t.g,s=t.C[0]?k:null;t.g=null,t.C=null,e||Gt(t,"ready");try{n.onreadystatechange=s}catch(t){}}}function Kn(t){t.g&&t.K&&(t.g.ontimeout=null),t.A&&(N.clearTimeout(t.A),t.A=null)}function jn(t){return t.g?t.g.readyState:0}function $n(t){try{if(!t.g)return null;if("response"in t.g)return t.g.response;switch(t.J){case Vn:case"text":return t.g.responseText;case"arraybuffer":if("mozResponseArrayBuffer"in t.g)return t.g.mozResponseArrayBuffer}return null}catch(t){return null}}function Qn(t){let e="";return Et(t,(function(t,n){e+=n,e+=":",e+=t,e+="\r\n"})),e}function zn(t,e,n){t:{for(s in n){var s=!1;break t}s=!0}s||(n=Qn(n),"string"==typeof t?null!=n&&encodeURIComponent(String(n)):Ze(t,e,n))}function Hn(t,e,n){return n&&n.internalChannelParams&&n.internalChannelParams[t]||e}function Wn(t){this.Ca=0,this.i=[],this.j=new ce,this.ka=this.sa=this.F=this.V=this.g=this.za=this.D=this.ia=this.o=this.S=this.s=null,this.ab=this.U=0,this.Za=Hn("failFast",!1,t),this.L=this.v=this.u=this.m=this.l=null,this.Y=!0,this.pa=this.Ba=this.T=-1,this.Z=this.A=this.C=0,this.Xa=Hn("baseRetryDelayMs",5e3,t),this.bb=Hn("retryDelaySeedMs",1e4,t),this.$a=Hn("forwardChannelMaxRetries",2,t),this.ta=Hn("forwardChannelRequestTimeoutMs",2e4,t),this.ra=t&&t.xmlHttpFactory||void 0,this.Da=t&&t.Zb||!1,this.J=void 0,this.H=t&&t.supportsCrossDomainXhr||!1,this.I="",this.h=new pn(t&&t.concurrentRequestLimit),this.Fa=new _n,this.O=t&&t.fastHandshake||!1,this.N=t&&t.encodeInitMessageHeaders||!1,this.O&&this.N&&(this.N=!1),this.Ya=t&&t.Xb||!1,t&&t.Aa&&this.j.Aa(),t&&t.forceLongPolling&&(this.Y=!1),this.$=!this.O&&this.Y&&t&&t.detectBufferingProxy||!1,this.ja=void 0,this.P=0,this.K=!1,this.la=this.B=null}function Yn(t){if(Jn(t),3==t.G){var e=t.U++,n=We(t.F);Ze(n,"SID",t.I),Ze(n,"RID",e),Ze(n,"TYPE","terminate"),es(t,n),(e=new Ne(t,t.j,e,void 0)).K=2,e.v=tn(We(n)),n=!1,N.navigator&&N.navigator.sendBeacon&&(n=N.navigator.sendBeacon(e.v.toString(),"")),!n&&N.Image&&((new Image).src=e.v,n=!0),n||(e.g=fs(e.l,null),e.g.da(e.v)),e.F=Date.now(),Ue(e)}ls(t)}function Xn(t){t.g&&(is(t),t.g.cancel(),t.g=null)}function Jn(t){Xn(t),t.u&&(N.clearTimeout(t.u),t.u=null),as(t),t.h.cancel(),t.m&&("number"==typeof t.m&&N.clearTimeout(t.m),t.m=null)}function Zn(t){wn(t.h)||t.m||(t.m=!0,Yt(t.Ja,t),t.C=0)}function ts(t,e){var n;n=e?e.m:t.U++;const s=We(t.F);Ze(s,"SID",t.I),Ze(s,"RID",n),Ze(s,"AID",t.T),es(t,s),t.o&&t.s&&zn(s,t.o,t.s),n=new Ne(t,t.j,n,t.C+1),null===t.o&&(n.H=t.s),e&&(t.i=e.D.concat(t.i)),e=ns(t,n,1e3),n.setTimeout(Math.round(.5*t.ta)+Math.round(.5*t.ta*Math.random())),bn(t.h,n),Oe(n,s,e)}function es(t,e){t.ia&&Et(t.ia,(function(t,n){Ze(e,n,t)})),t.l&&Qe({},(function(t,n){Ze(e,n,t)}))}function ns(t,e,n){n=Math.min(t.i.length,n);var s=t.l?P(t.l.Ra,t.l,t):null;t:{var r=t.i;let e=-1;for(;;){const t=["count="+n];-1==e?0<n?(e=r[0].h,t.push("ofs="+e)):e=0:t.push("ofs="+e);let i=!0;for(let o=0;o<n;o++){let n=r[o].h;const a=r[o].g;if(n-=e,0>n)e=Math.max(0,r[o].h-100),i=!1;else try{xn(a,t,"req"+n+"_")}catch(t){s&&s(a)}}if(i){s=t.join("&");break t}}}return t=t.i.splice(0,n),e.D=t,s}function ss(t){t.g||t.u||(t.Z=1,Yt(t.Ia,t),t.A=0)}function rs(t){return!(t.g||t.u||3<=t.A)&&(t.Z++,t.u=ve(P(t.Ia,t),cs(t,t.A)),t.A++,!0)}function is(t){null!=t.B&&(N.clearTimeout(t.B),t.B=null)}function os(t){t.g=new Ne(t,t.j,"rpc",t.Z),null===t.o&&(t.g.H=t.s),t.g.N=0;var e=We(t.sa);Ze(e,"RID","rpc"),Ze(e,"SID",t.I),Ze(e,"CI",t.L?"0":"1"),Ze(e,"AID",t.T),Ze(e,"TYPE","xmlhttp"),es(t,e),t.o&&t.s&&zn(e,t.o,t.s),t.J&&t.g.setTimeout(t.J);var n=t.g;t=t.ka,n.K=1,n.v=tn(We(e)),n.s=null,n.P=!0,Ve(n,t)}function as(t){null!=t.v&&(N.clearTimeout(t.v),t.v=null)}function us(t,e){var n=null;if(t.g==e){as(t),is(t),t.g=null;var s=2}else{if(!In(t.h,e))return;n=e.D,En(t.h,e),s=1}if(0!=t.G)if(t.pa=e.Y,e.i)if(1==s){n=e.s?e.s.length:0,e=Date.now()-e.F;var r=t.C;Gt(s=fe(),new we(s,n)),Zn(t)}else ss(t);else if(3==(r=e.o)||0==r&&0<t.pa||!(1==s&&function(t,e){return!(vn(t.h)>=t.h.j-(t.m?1:0)||(t.m?(t.i=e.D.concat(t.i),0):1==t.G||2==t.G||t.C>=(t.Za?0:t.$a)||(t.m=ve(P(t.Ja,t,e),cs(t,t.C)),t.C++,0)))}(t,e)||2==s&&rs(t)))switch(n&&0<n.length&&(e=t.h,e.i=e.i.concat(n)),r){case 1:hs(t,5);break;case 4:hs(t,10);break;case 3:hs(t,6);break;default:hs(t,2)}}function cs(t,e){let n=t.Xa+Math.floor(Math.random()*t.bb);return t.l||(n*=2),n*e}function hs(t,e){if(t.j.info("Error code "+e),2==e){var n=null;t.l&&(n=null);var s=P(t.kb,t);n||(n=new He("//www.google.com/images/cleardot.gif"),N.location&&"http"==N.location.protocol||Ye(n,"https"),tn(n)),function(t,e){const n=new ce;if(N.Image){const s=new Image;s.onload=B(An,n,s,"TestLoadImage: loaded",!0,e),s.onerror=B(An,n,s,"TestLoadImage: error",!1,e),s.onabort=B(An,n,s,"TestLoadImage: abort",!1,e),s.ontimeout=B(An,n,s,"TestLoadImage: timeout",!1,e),N.setTimeout((function(){s.ontimeout&&s.ontimeout()}),1e4),s.src=t}else e(!1)}(n.toString(),s)}else ye(2);t.G=0,t.l&&t.l.va(e),ls(t),Jn(t)}function ls(t){if(t.G=0,t.la=[],t.l){const e=Tn(t.h);0==e.length&&0==t.i.length||(j(t.la,e),j(t.la,t.i),t.h.i.length=0,K(t.i),t.i.length=0),t.l.ua()}}function ds(t,e,n){var s=n instanceof He?We(n):new He(n,void 0);if(""!=s.g)e&&(s.g=e+"."+s.g),Xe(s,s.m);else{var r=N.location;s=r.protocol,e=e?e+"."+r.hostname:r.hostname,r=+r.port;var i=new He(null,void 0);s&&Ye(i,s),e&&(i.g=e),r&&Xe(i,r),n&&(i.l=n),s=i}return n=t.D,e=t.za,n&&e&&Ze(s,n,e),Ze(s,"VER",t.ma),es(t,s),s}function fs(t,e,n){if(e&&!t.H)throw Error("Can't create secondary domain capable XhrIo object.");return(e=n&&t.Da&&!t.ra?new On(new Dn({jb:!0})):new On(t.ra)).Ka(t.H),e}function ms(){}function gs(){if(nt&&!(10<=Number(gt)))throw Error("Environmental error: no available transport.")}function ps(t,e){qt.call(this),this.g=new Wn(e),this.l=t,this.h=e&&e.messageUrlParams||null,t=e&&e.messageHeaders||null,e&&e.clientProtocolHeaderRequired&&(t?t["X-Client-Protocol"]="webchannel":t={"X-Client-Protocol":"webchannel"}),this.g.s=t,t=e&&e.initMessageHeaders||null,e&&e.messageContentType&&(t?t["X-WebChannel-Content-Type"]=e.messageContentType:t={"X-WebChannel-Content-Type":e.messageContentType}),e&&e.ya&&(t?t["X-WebChannel-Client-Profile"]=e.ya:t={"X-WebChannel-Client-Profile":e.ya}),this.g.S=t,(t=e&&e.Yb)&&!z(t)&&(this.g.o=t),this.A=e&&e.supportsCrossDomainXhr||!1,this.v=e&&e.sendRawJson||!1,(e=e&&e.httpSessionIdParam)&&!z(e)&&(this.g.D=e,null!==(t=this.h)&&e in t&&(e in(t=this.h)&&delete t[e])),this.j=new vs(this)}function ys(t){Ae.call(this);var e=t.__sm__;if(e){t:{for(const n in e){t=n;break t}t=void 0}(this.i=t)&&(t=this.i,e=null!==e&&t in e?e[t]:void 0),this.data=e}else this.data=t}function ws(){De.call(this),this.status=1}function vs(t){this.g=t}(A=On.prototype).Ka=function(t){this.L=t},A.da=function(t,e,n,s){if(this.g)throw Error("[goog.net.XhrIo] Object is active with another request="+this.H+"; newUri="+t);e=e?e.toUpperCase():"GET",this.H=t,this.j="",this.m=0,this.D=!1,this.h=!0,this.g=this.u?this.u.g():_e.g(),this.C=this.u?Te(this.u):Te(_e),this.g.onreadystatechange=P(this.Ha,this);try{this.F=!0,this.g.open(e,String(t),!0),this.F=!1}catch(t){return void Bn(this,t)}if(t=n||"",n=new Map(this.headers),s)if(Object.getPrototypeOf(s)===Object.prototype)for(var r in s)n.set(r,s[r]);else{if("function"!=typeof s.keys||"function"!=typeof s.get)throw Error("Unknown input type for opt_headers: "+String(s));for(const t of s.keys())n.set(t,s.get(t))}s=Array.from(n.keys()).find((t=>"content-type"==t.toLowerCase())),r=N.FormData&&t instanceof N.FormData,!(0<=G(Pn,e))||s||r||n.set("Content-Type","application/x-www-form-urlencoded;charset=utf-8");for(const[t,e]of n)this.g.setRequestHeader(t,e);this.J&&(this.g.responseType=this.J),"withCredentials"in this.g&&this.g.withCredentials!==this.L&&(this.g.withCredentials=this.L);try{Kn(this),0<this.B&&((this.K=function(t){return nt&&ft()&&"number"==typeof t.timeout&&void 0!==t.ontimeout}(this.g))?(this.g.timeout=this.B,this.g.ontimeout=P(this.qa,this)):this.A=ne(this.qa,this.B,this)),this.v=!0,this.g.send(t),this.v=!1}catch(t){Bn(this,t)}},A.qa=function(){void 0!==C&&this.g&&(this.j="Timed out after "+this.B+"ms, aborting",this.m=8,Gt(this,"timeout"),this.abort(8))},A.abort=function(t){this.g&&this.h&&(this.h=!1,this.l=!0,this.g.abort(),this.l=!1,this.m=t||7,Gt(this,"complete"),Gt(this,"abort"),Gn(this))},A.M=function(){this.g&&(this.h&&(this.h=!1,this.l=!0,this.g.abort(),this.l=!1),Gn(this,!0)),On.X.M.call(this)},A.Ha=function(){this.s||(this.F||this.v||this.l?qn(this):this.fb())},A.fb=function(){qn(this)},A.aa=function(){try{return 2<jn(this)?this.g.status:-1}catch(t){return-1}},A.fa=function(){try{return this.g?this.g.responseText:""}catch(t){return""}},A.Sa=function(t){if(this.g){var e=this.g.responseText;return t&&0==e.indexOf(t)&&(e=e.substring(t.length)),Mn(e)}},A.Ea=function(){return this.m},A.Oa=function(){return"string"==typeof this.j?this.j:String(this.j)},(A=Wn.prototype).ma=8,A.G=1,A.Ja=function(t){if(this.m)if(this.m=null,1==this.G){if(!t){this.U=Math.floor(1e5*Math.random()),t=this.U++;const r=new Ne(this,this.j,t,void 0);let i=this.s;if(this.S&&(i?(i=Tt(i),_t(i,this.S)):i=this.S),null!==this.o||this.N||(r.H=i,i=null),this.O)t:{for(var e=0,n=0;n<this.i.length;n++){var s=this.i[n];if(void 0===(s="__data__"in s.g&&"string"==typeof(s=s.g.__data__)?s.length:void 0))break;if(4096<(e+=s)){e=n;break t}if(4096===e||n===this.i.length-1){e=n+1;break t}}e=1e3}else e=1e3;e=ns(this,r,e),Ze(n=We(this.F),"RID",t),Ze(n,"CVER",22),this.D&&Ze(n,"X-HTTP-Session-Id",this.D),es(this,n),i&&(this.N?e="headers="+encodeURIComponent(String(Qn(i)))+"&"+e:this.o&&zn(n,this.o,i)),bn(this.h,r),this.Ya&&Ze(n,"TYPE","init"),this.O?(Ze(n,"$req",e),Ze(n,"SID","null"),r.Z=!0,Oe(r,n,null)):Oe(r,n,e),this.G=2}}else 3==this.G&&(t?ts(this,t):0==this.i.length||wn(this.h)||ts(this))},A.Ia=function(){if(this.u=null,os(this),this.$&&!(this.K||null==this.g||0>=this.P)){var t=2*this.P;this.j.info("BP detection timer enabled: "+t),this.B=ve(P(this.eb,this),t)}},A.eb=function(){this.B&&(this.B=null,this.j.info("BP detection timeout reached."),this.j.info("Buffering proxy detected and switch to long-polling!"),this.L=!1,this.K=!0,ye(10),Xn(this),os(this))},A.cb=function(){null!=this.v&&(this.v=null,Xn(this),rs(this),ye(19))},A.kb=function(t){t?(this.j.info("Successfully pinged google.com"),ye(2)):(this.j.info("Failed to ping google.com"),ye(1))},(A=ms.prototype).xa=function(){},A.wa=function(){},A.va=function(){},A.ua=function(){},A.Ra=function(){},gs.prototype.g=function(t,e){return new ps(t,e)},U(ps,qt),ps.prototype.m=function(){this.g.l=this.j,this.A&&(this.g.H=!0);var t=this.g,e=this.l,n=this.h||void 0;ye(0),t.V=e,t.ia=n||{},t.L=t.Y,t.F=ds(t,null,t.V),Zn(t)},ps.prototype.close=function(){Yn(this.g)},ps.prototype.u=function(t){var e=this.g;if("string"==typeof t){var n={};n.__data__=t,t=n}else this.v&&((n={}).__data__=jt(t),t=n);e.i.push(new class{constructor(t,e){this.h=t,this.g=e}}(e.ab++,t)),3==e.G&&Zn(e)},ps.prototype.M=function(){this.g.l=null,delete this.j,Yn(this.g),delete this.g,ps.X.M.call(this)},U(ys,Ae),U(ws,De),U(vs,ms),vs.prototype.xa=function(){Gt(this.g,"a")},vs.prototype.wa=function(t){Gt(this.g,new ys(t))},vs.prototype.va=function(t){Gt(this.g,new ws)},vs.prototype.ua=function(){Gt(this.g,"b")},gs.prototype.createWebChannel=gs.prototype.g,ps.prototype.send=ps.prototype.u,ps.prototype.open=ps.prototype.m,ps.prototype.close=ps.prototype.close,Ie.NO_ERROR=0,Ie.TIMEOUT=8,Ie.HTTP_ERROR=6,be.COMPLETE="complete",Se.EventType=xe,xe.OPEN="a",xe.CLOSE="b",xe.ERROR="c",xe.MESSAGE="d",qt.prototype.listen=qt.prototype.N,On.prototype.listenOnce=On.prototype.O,On.prototype.getLastError=On.prototype.Oa,On.prototype.getLastErrorCode=On.prototype.Ea,On.prototype.getStatus=On.prototype.aa,On.prototype.getResponseJson=On.prototype.Sa,On.prototype.getResponseText=On.prototype.fa,On.prototype.send=On.prototype.da,On.prototype.setWithCredentials=On.prototype.Ka;var Is=Ie,bs=be,Es=le,Ts=10,Ss=11,_s=Dn,xs=Se,As=On;const Ds="@firebase/firestore";class Cs{constructor(t){this.uid=t}isAuthenticated(){return null!=this.uid}toKey(){return this.isAuthenticated()?"uid:"+this.uid:"anonymous-user"}isEqual(t){return t.uid===this.uid}}Cs.UNAUTHENTICATED=new Cs(null),Cs.GOOGLE_CREDENTIALS=new Cs("google-credentials-uid"),Cs.FIRST_PARTY=new Cs("first-party-uid"),Cs.MOCK_USER=new Cs("mock-user");let Ns="9.13.0";const ks=new class{constructor(t){this.name=t,this._logLevel=S,this._logHandler=x,this._userLogHandler=null}get logLevel(){return this._logLevel}set logLevel(t){if(!(t in E))throw new TypeError(`Invalid value "${t}" assigned to \`logLevel\``);this._logLevel=t}setLogLevel(t){this._logLevel="string"==typeof t?T[t]:t}get logHandler(){return this._logHandler}set logHandler(t){if("function"!=typeof t)throw new TypeError("Value assigned to `logHandler` must be a function");this._logHandler=t}get userLogHandler(){return this._userLogHandler}set userLogHandler(t){this._userLogHandler=t}debug(...t){this._userLogHandler&&this._userLogHandler(this,E.DEBUG,...t),this._logHandler(this,E.DEBUG,...t)}log(...t){this._userLogHandler&&this._userLogHandler(this,E.VERBOSE,...t),this._logHandler(this,E.VERBOSE,...t)}info(...t){this._userLogHandler&&this._userLogHandler(this,E.INFO,...t),this._logHandler(this,E.INFO,...t)}warn(...t){this._userLogHandler&&this._userLogHandler(this,E.WARN,...t),this._logHandler(this,E.WARN,...t)}error(...t){this._userLogHandler&&this._userLogHandler(this,E.ERROR,...t),this._logHandler(this,E.ERROR,...t)}}("@firebase/firestore");function Rs(){return ks.logLevel}function Ls(t){ks.setLogLevel(t)}function Ms(t,...e){if(ks.logLevel<=E.DEBUG){const n=e.map(Fs);ks.debug(`Firestore (${Ns}): ${t}`,...n)}}function Os(t,...e){if(ks.logLevel<=E.ERROR){const n=e.map(Fs);ks.error(`Firestore (${Ns}): ${t}`,...n)}}function Vs(t,...e){if(ks.logLevel<=E.WARN){const n=e.map(Fs);ks.warn(`Firestore (${Ns}): ${t}`,...n)}}function Fs(t){if("string"==typeof t)return t;try{return e=t,JSON.stringify(e)}catch(e){return t}var e}function Ps(t="Unexpected state"){const e=`FIRESTORE (${Ns}) INTERNAL ASSERTION FAILED: `+t;throw Os(e),new Error(e)}function Bs(t,e){t||Ps()}function Us(t,e){t||Ps()}function qs(t,e){return t}const Gs={OK:"ok",CANCELLED:"cancelled",UNKNOWN:"unknown",INVALID_ARGUMENT:"invalid-argument",DEADLINE_EXCEEDED:"deadline-exceeded",NOT_FOUND:"not-found",ALREADY_EXISTS:"already-exists",PERMISSION_DENIED:"permission-denied",UNAUTHENTICATED:"unauthenticated",RESOURCE_EXHAUSTED:"resource-exhausted",FAILED_PRECONDITION:"failed-precondition",ABORTED:"aborted",OUT_OF_RANGE:"out-of-range",UNIMPLEMENTED:"unimplemented",INTERNAL:"internal",UNAVAILABLE:"unavailable",DATA_LOSS:"data-loss"};class Ks extends g{constructor(t,e){super(t,e),this.code=t,this.message=e,this.toString=()=>`${this.name}: [code=${this.code}]: ${this.message}`}}class js{constructor(){this.promise=new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}}class $s{constructor(t,e){this.user=e,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization",`Bearer ${t}`)}}class Qs{getToken(){return Promise.resolve(null)}invalidateToken(){}start(t,e){t.enqueueRetryable((()=>e(Cs.UNAUTHENTICATED)))}shutdown(){}}class zs{constructor(t){this.token=t,this.changeListener=null}getToken(){return Promise.resolve(this.token)}invalidateToken(){}start(t,e){this.changeListener=e,t.enqueueRetryable((()=>e(this.token.user)))}shutdown(){this.changeListener=null}}class Hs{constructor(t){this.t=t,this.currentUser=Cs.UNAUTHENTICATED,this.i=0,this.forceRefresh=!1,this.auth=null}start(t,e){let n=this.i;const s=t=>this.i!==n?(n=this.i,e(t)):Promise.resolve();let r=new js;this.o=()=>{this.i++,this.currentUser=this.u(),r.resolve(),r=new js,t.enqueueRetryable((()=>s(this.currentUser)))};const i=()=>{const e=r;t.enqueueRetryable((async()=>{await e.promise,await s(this.currentUser)}))},o=t=>{Ms("FirebaseAuthCredentialsProvider","Auth detected"),this.auth=t,this.auth.addAuthTokenListener(this.o),i()};this.t.onInit((t=>o(t))),setTimeout((()=>{if(!this.auth){const t=this.t.getImmediate({optional:!0});t?o(t):(Ms("FirebaseAuthCredentialsProvider","Auth not yet detected"),r.resolve(),r=new js)}}),0),i()}getToken(){const t=this.i,e=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(e).then((e=>this.i!==t?(Ms("FirebaseAuthCredentialsProvider","getToken aborted due to token change."),this.getToken()):e?(Bs("string"==typeof e.accessToken),new $s(e.accessToken,this.currentUser)):null)):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.auth&&this.auth.removeAuthTokenListener(this.o)}u(){const t=this.auth&&this.auth.getUid();return Bs(null===t||"string"==typeof t),new Cs(t)}}class Ws{constructor(t,e,n,s){this.h=t,this.l=e,this.m=n,this.g=s,this.type="FirstParty",this.user=Cs.FIRST_PARTY,this.p=new Map}I(){return this.g?this.g():(Bs(!("object"!=typeof this.h||null===this.h||!this.h.auth||!this.h.auth.getAuthHeaderValueForFirstParty)),this.h.auth.getAuthHeaderValueForFirstParty([]))}get headers(){this.p.set("X-Goog-AuthUser",this.l);const t=this.I();return t&&this.p.set("Authorization",t),this.m&&this.p.set("X-Goog-Iam-Authorization-Token",this.m),this.p}}class Ys{constructor(t,e,n,s){this.h=t,this.l=e,this.m=n,this.g=s}getToken(){return Promise.resolve(new Ws(this.h,this.l,this.m,this.g))}start(t,e){t.enqueueRetryable((()=>e(Cs.FIRST_PARTY)))}shutdown(){}invalidateToken(){}}class Xs{constructor(t){this.value=t,this.type="AppCheck",this.headers=new Map,t&&t.length>0&&this.headers.set("x-firebase-appcheck",this.value)}}class Js{constructor(t){this.T=t,this.forceRefresh=!1,this.appCheck=null,this.A=null}start(t,e){const n=t=>{null!=t.error&&Ms("FirebaseAppCheckTokenProvider",`Error getting App Check token; using placeholder token instead. Error: ${t.error.message}`);const n=t.token!==this.A;return this.A=t.token,Ms("FirebaseAppCheckTokenProvider",`Received ${n?"new":"existing"} token.`),n?e(t.token):Promise.resolve()};this.o=e=>{t.enqueueRetryable((()=>n(e)))};const s=t=>{Ms("FirebaseAppCheckTokenProvider","AppCheck detected"),this.appCheck=t,this.appCheck.addTokenListener(this.o)};this.T.onInit((t=>s(t))),setTimeout((()=>{if(!this.appCheck){const t=this.T.getImmediate({optional:!0});t?s(t):Ms("FirebaseAppCheckTokenProvider","AppCheck not yet detected")}}),0)}getToken(){const t=this.forceRefresh;return this.forceRefresh=!1,this.appCheck?this.appCheck.getToken(t).then((t=>t?(Bs("string"==typeof t.token),this.A=t.token,new Xs(t.token)):null)):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.appCheck&&this.appCheck.removeTokenListener(this.o)}}class Zs{getToken(){return Promise.resolve(new Xs(""))}invalidateToken(){}start(t,e){}shutdown(){}}function tr(t){const e="undefined"!=typeof self&&(self.crypto||self.msCrypto),n=new Uint8Array(t);if(e&&"function"==typeof e.getRandomValues)e.getRandomValues(n);else for(let e=0;e<t;e++)n[e]=Math.floor(256*Math.random());return n}class er{static R(){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=Math.floor(256/t.length)*t.length;let n="";for(;n.length<20;){const s=tr(40);for(let r=0;r<s.length;++r)n.length<20&&s[r]<e&&(n+=t.charAt(s[r]%t.length))}return n}}function nr(t,e){return t<e?-1:t>e?1:0}function sr(t,e,n){return t.length===e.length&&t.every(((t,s)=>n(t,e[s])))}function rr(t){return t+"\0"}class ir{constructor(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new Ks(Gs.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new Ks(Gs.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new Ks(Gs.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new Ks(Gs.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t)}static now(){return ir.fromMillis(Date.now())}static fromDate(t){return ir.fromMillis(t.getTime())}static fromMillis(t){const e=Math.floor(t/1e3),n=Math.floor(1e6*(t-1e3*e));return new ir(e,n)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(t){return this.seconds===t.seconds?nr(this.nanoseconds,t.nanoseconds):nr(this.seconds,t.seconds)}isEqual(t){return t.seconds===this.seconds&&t.nanoseconds===this.nanoseconds}toString(){return"Timestamp(seconds="+this.seconds+", nanoseconds="+this.nanoseconds+")"}toJSON(){return{seconds:this.seconds,nanoseconds:this.nanoseconds}}valueOf(){const t=this.seconds- -62135596800;return String(t).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")}}class or{constructor(t){this.timestamp=t}static fromTimestamp(t){return new or(t)}static min(){return new or(new ir(0,0))}static max(){return new or(new ir(253402300799,999999999))}compareTo(t){return this.timestamp._compareTo(t.timestamp)}isEqual(t){return this.timestamp.isEqual(t.timestamp)}toMicroseconds(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3}toString(){return"SnapshotVersion("+this.timestamp.toString()+")"}toTimestamp(){return this.timestamp}}class ar{constructor(t,e,n){void 0===e?e=0:e>t.length&&Ps(),void 0===n?n=t.length-e:n>t.length-e&&Ps(),this.segments=t,this.offset=e,this.len=n}get length(){return this.len}isEqual(t){return 0===ar.comparator(this,t)}child(t){const e=this.segments.slice(this.offset,this.limit());return t instanceof ar?t.forEach((t=>{e.push(t)})):e.push(t),this.construct(e)}limit(){return this.offset+this.length}popFirst(t){return t=void 0===t?1:t,this.construct(this.segments,this.offset+t,this.length-t)}popLast(){return this.construct(this.segments,this.offset,this.length-1)}firstSegment(){return this.segments[this.offset]}lastSegment(){return this.get(this.length-1)}get(t){return this.segments[this.offset+t]}isEmpty(){return 0===this.length}isPrefixOf(t){if(t.length<this.length)return!1;for(let e=0;e<this.length;e++)if(this.get(e)!==t.get(e))return!1;return!0}isImmediateParentOf(t){if(this.length+1!==t.length)return!1;for(let e=0;e<this.length;e++)if(this.get(e)!==t.get(e))return!1;return!0}forEach(t){for(let e=this.offset,n=this.limit();e<n;e++)t(this.segments[e])}toArray(){return this.segments.slice(this.offset,this.limit())}static comparator(t,e){const n=Math.min(t.length,e.length);for(let s=0;s<n;s++){const n=t.get(s),r=e.get(s);if(n<r)return-1;if(n>r)return 1}return t.length<e.length?-1:t.length>e.length?1:0}}class ur extends ar{construct(t,e,n){return new ur(t,e,n)}canonicalString(){return this.toArray().join("/")}toString(){return this.canonicalString()}static fromString(...t){const e=[];for(const n of t){if(n.indexOf("//")>=0)throw new Ks(Gs.INVALID_ARGUMENT,`Invalid segment (${n}). Paths must not contain // in them.`);e.push(...n.split("/").filter((t=>t.length>0)))}return new ur(e)}static emptyPath(){return new ur([])}}const cr=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class hr extends ar{construct(t,e,n){return new hr(t,e,n)}static isValidIdentifier(t){return cr.test(t)}canonicalString(){return this.toArray().map((t=>(t=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),hr.isValidIdentifier(t)||(t="`"+t+"`"),t))).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&"__name__"===this.get(0)}static keyField(){return new hr(["__name__"])}static fromServerFormat(t){const e=[];let n="",s=0;const r=()=>{if(0===n.length)throw new Ks(Gs.INVALID_ARGUMENT,`Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`);e.push(n),n=""};let i=!1;for(;s<t.length;){const e=t[s];if("\\"===e){if(s+1===t.length)throw new Ks(Gs.INVALID_ARGUMENT,"Path has trailing escape character: "+t);const e=t[s+1];if("\\"!==e&&"."!==e&&"`"!==e)throw new Ks(Gs.INVALID_ARGUMENT,"Path has invalid escape sequence: "+t);n+=e,s+=2}else"`"===e?(i=!i,s++):"."!==e||i?(n+=e,s++):(r(),s++)}if(r(),i)throw new Ks(Gs.INVALID_ARGUMENT,"Unterminated ` in path: "+t);return new hr(e)}static emptyPath(){return new hr([])}}class lr{constructor(t){this.path=t}static fromPath(t){return new lr(ur.fromString(t))}static fromName(t){return new lr(ur.fromString(t).popFirst(5))}static empty(){return new lr(ur.emptyPath())}get collectionGroup(){return this.path.popLast().lastSegment()}hasCollectionId(t){return this.path.length>=2&&this.path.get(this.path.length-2)===t}getCollectionGroup(){return this.path.get(this.path.length-2)}getCollectionPath(){return this.path.popLast()}isEqual(t){return null!==t&&0===ur.comparator(this.path,t.path)}toString(){return this.path.toString()}static comparator(t,e){return ur.comparator(t.path,e.path)}static isDocumentKey(t){return t.length%2==0}static fromSegments(t){return new lr(new ur(t.slice()))}}class dr{constructor(t,e,n,s){this.indexId=t,this.collectionGroup=e,this.fields=n,this.indexState=s}}function fr(t){return t.fields.find((t=>2===t.kind))}function mr(t){return t.fields.filter((t=>2!==t.kind))}function gr(t,e){let n=nr(t.collectionGroup,e.collectionGroup);if(0!==n)return n;for(let s=0;s<Math.min(t.fields.length,e.fields.length);++s)if(n=yr(t.fields[s],e.fields[s]),0!==n)return n;return nr(t.fields.length,e.fields.length)}dr.UNKNOWN_ID=-1;class pr{constructor(t,e){this.fieldPath=t,this.kind=e}}function yr(t,e){const n=hr.comparator(t.fieldPath,e.fieldPath);return 0!==n?n:nr(t.kind,e.kind)}class wr{constructor(t,e){this.sequenceNumber=t,this.offset=e}static empty(){return new wr(0,br.min())}}function vr(t,e){const n=t.toTimestamp().seconds,s=t.toTimestamp().nanoseconds+1,r=or.fromTimestamp(1e9===s?new ir(n+1,0):new ir(n,s));return new br(r,lr.empty(),e)}function Ir(t){return new br(t.readTime,t.key,-1)}class br{constructor(t,e,n){this.readTime=t,this.documentKey=e,this.largestBatchId=n}static min(){return new br(or.min(),lr.empty(),-1)}static max(){return new br(or.max(),lr.empty(),-1)}}function Er(t,e){let n=t.readTime.compareTo(e.readTime);return 0!==n?n:(n=lr.comparator(t.documentKey,e.documentKey),0!==n?n:nr(t.largestBatchId,e.largestBatchId))}const Tr="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.";class Sr{constructor(){this.onCommittedListeners=[]}addOnCommittedListener(t){this.onCommittedListeners.push(t)}raiseOnCommittedEvent(){this.onCommittedListeners.forEach((t=>t()))}}async function _r(t){if(t.code!==Gs.FAILED_PRECONDITION||t.message!==Tr)throw t;Ms("LocalStore","Unexpectedly lost primary lease")}class xr{constructor(t){this.nextCallback=null,this.catchCallback=null,this.result=void 0,this.error=void 0,this.isDone=!1,this.callbackAttached=!1,t((t=>{this.isDone=!0,this.result=t,this.nextCallback&&this.nextCallback(t)}),(t=>{this.isDone=!0,this.error=t,this.catchCallback&&this.catchCallback(t)}))}catch(t){return this.next(void 0,t)}next(t,e){return this.callbackAttached&&Ps(),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(e,this.error):this.wrapSuccess(t,this.result):new xr(((n,s)=>{this.nextCallback=e=>{this.wrapSuccess(t,e).next(n,s)},this.catchCallback=t=>{this.wrapFailure(e,t).next(n,s)}}))}toPromise(){return new Promise(((t,e)=>{this.next(t,e)}))}wrapUserFunction(t){try{const e=t();return e instanceof xr?e:xr.resolve(e)}catch(t){return xr.reject(t)}}wrapSuccess(t,e){return t?this.wrapUserFunction((()=>t(e))):xr.resolve(e)}wrapFailure(t,e){return t?this.wrapUserFunction((()=>t(e))):xr.reject(e)}static resolve(t){return new xr(((e,n)=>{e(t)}))}static reject(t){return new xr(((e,n)=>{n(t)}))}static waitFor(t){return new xr(((e,n)=>{let s=0,r=0,i=!1;t.forEach((t=>{++s,t.next((()=>{++r,i&&r===s&&e()}),(t=>n(t)))})),i=!0,r===s&&e()}))}static or(t){let e=xr.resolve(!1);for(const n of t)e=e.next((t=>t?xr.resolve(t):n()));return e}static forEach(t,e){const n=[];return t.forEach(((t,s)=>{n.push(e.call(this,t,s))})),this.waitFor(n)}static mapArray(t,e){return new xr(((n,s)=>{const r=t.length,i=new Array(r);let o=0;for(let a=0;a<r;a++){const u=a;e(t[u]).next((t=>{i[u]=t,++o,o===r&&n(i)}),(t=>s(t)))}}))}static doWhile(t,e){return new xr(((n,s)=>{const r=()=>{!0===t()?e().next((()=>{r()}),s):n()};r()}))}}class Ar{constructor(t,e){this.action=t,this.transaction=e,this.aborted=!1,this.P=new js,this.transaction.oncomplete=()=>{this.P.resolve()},this.transaction.onabort=()=>{e.error?this.P.reject(new Nr(t,e.error)):this.P.resolve()},this.transaction.onerror=e=>{const n=Or(e.target.error);this.P.reject(new Nr(t,n))}}static open(t,e,n,s){try{return new Ar(e,t.transaction(s,n))}catch(t){throw new Nr(e,t)}}get v(){return this.P.promise}abort(t){t&&this.P.reject(t),this.aborted||(Ms("SimpleDb","Aborting transaction:",t?t.message:"Client-initiated abort"),this.aborted=!0,this.transaction.abort())}V(){const t=this.transaction;this.aborted||"function"!=typeof t.commit||t.commit()}store(t){const e=this.transaction.objectStore(t);return new Rr(e)}}class Dr{constructor(t,e,n){this.name=t,this.version=e,this.S=n,12.2===Dr.D(c())&&Os("Firestore persistence suffers from a bug in iOS 12.2 Safari that may cause your app to stop working. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.")}static delete(t){return Ms("SimpleDb","Removing database:",t),Lr(window.indexedDB.deleteDatabase(t)).toPromise()}static C(){if("object"!=typeof indexedDB)return!1;if(Dr.N())return!0;const t=c(),e=Dr.D(t),n=0<e&&e<10,s=Dr.k(t),r=0<s&&s<4.5;return!(t.indexOf("MSIE ")>0||t.indexOf("Trident/")>0||t.indexOf("Edge/")>0||n||r)}static N(){var t;return"undefined"!=typeof process&&"YES"===(null===(t=process.env)||void 0===t?void 0:t.O)}static M(t,e){return t.store(e)}static D(t){const e=t.match(/i(?:phone|pad|pod) os ([\d_]+)/i),n=e?e[1].split("_").slice(0,2).join("."):"-1";return Number(n)}static k(t){const e=t.match(/Android ([\d.]+)/i),n=e?e[1].split(".").slice(0,2).join("."):"-1";return Number(n)}async F(t){return this.db||(Ms("SimpleDb","Opening database:",this.name),this.db=await new Promise(((e,n)=>{const s=indexedDB.open(this.name,this.version);s.onsuccess=t=>{const n=t.target.result;e(n)},s.onblocked=()=>{n(new Nr(t,"Cannot upgrade IndexedDB schema while another tab is open. Close all tabs that access Firestore and reload this page to proceed."))},s.onerror=e=>{const s=e.target.error;"VersionError"===s.name?n(new Ks(Gs.FAILED_PRECONDITION,"A newer version of the Firestore SDK was previously used and so the persisted data is not compatible with the version of the SDK you are now using. The SDK will operate with persistence disabled. If you need persistence, please re-upgrade to a newer version of the SDK or else clear the persisted IndexedDB data for your app to start fresh.")):"InvalidStateError"===s.name?n(new Ks(Gs.FAILED_PRECONDITION,"Unable to open an IndexedDB connection. This could be due to running in a private browsing session on a browser whose private browsing sessions do not support IndexedDB: "+s)):n(new Nr(t,s))},s.onupgradeneeded=t=>{Ms("SimpleDb",'Database "'+this.name+'" requires upgrade from version:',t.oldVersion);const e=t.target.result;this.S.$(e,s.transaction,t.oldVersion,this.version).next((()=>{Ms("SimpleDb","Database upgrade to version "+this.version+" complete")}))}}))),this.B&&(this.db.onversionchange=t=>this.B(t)),this.db}L(t){this.B=t,this.db&&(this.db.onversionchange=e=>t(e))}async runTransaction(t,e,n,s){const r="readonly"===e;let i=0;for(;;){++i;try{this.db=await this.F(t);const e=Ar.open(this.db,t,r?"readonly":"readwrite",n),i=s(e).next((t=>(e.V(),t))).catch((t=>(e.abort(t),xr.reject(t)))).toPromise();return i.catch((()=>{})),await e.v,i}catch(t){const e=t,n="FirebaseError"!==e.name&&i<3;if(Ms("SimpleDb","Transaction failed with error:",e.message,"Retrying:",n),this.close(),!n)return Promise.reject(e)}}}close(){this.db&&this.db.close(),this.db=void 0}}class Cr{constructor(t){this.U=t,this.q=!1,this.K=null}get isDone(){return this.q}get G(){return this.K}set cursor(t){this.U=t}done(){this.q=!0}j(t){this.K=t}delete(){return Lr(this.U.delete())}}class Nr extends Ks{constructor(t,e){super(Gs.UNAVAILABLE,`IndexedDB transaction '${t}' failed: ${e}`),this.name="IndexedDbTransactionError"}}function kr(t){return"IndexedDbTransactionError"===t.name}class Rr{constructor(t){this.store=t}put(t,e){let n;return void 0!==e?(Ms("SimpleDb","PUT",this.store.name,t,e),n=this.store.put(e,t)):(Ms("SimpleDb","PUT",this.store.name,"<auto-key>",t),n=this.store.put(t)),Lr(n)}add(t){return Ms("SimpleDb","ADD",this.store.name,t,t),Lr(this.store.add(t))}get(t){return Lr(this.store.get(t)).next((e=>(void 0===e&&(e=null),Ms("SimpleDb","GET",this.store.name,t,e),e)))}delete(t){return Ms("SimpleDb","DELETE",this.store.name,t),Lr(this.store.delete(t))}count(){return Ms("SimpleDb","COUNT",this.store.name),Lr(this.store.count())}W(t,e){const n=this.options(t,e);if(n.index||"function"!=typeof this.store.getAll){const t=this.cursor(n),e=[];return this.H(t,((t,n)=>{e.push(n)})).next((()=>e))}{const t=this.store.getAll(n.range);return new xr(((e,n)=>{t.onerror=t=>{n(t.target.error)},t.onsuccess=t=>{e(t.target.result)}}))}}J(t,e){const n=this.store.getAll(t,null===e?void 0:e);return new xr(((t,e)=>{n.onerror=t=>{e(t.target.error)},n.onsuccess=e=>{t(e.target.result)}}))}Y(t,e){Ms("SimpleDb","DELETE ALL",this.store.name);const n=this.options(t,e);n.X=!1;const s=this.cursor(n);return this.H(s,((t,e,n)=>n.delete()))}Z(t,e){let n;e?n=t:(n={},e=t);const s=this.cursor(n);return this.H(s,e)}tt(t){const e=this.cursor({});return new xr(((n,s)=>{e.onerror=t=>{const e=Or(t.target.error);s(e)},e.onsuccess=e=>{const s=e.target.result;s?t(s.primaryKey,s.value).next((t=>{t?s.continue():n()})):n()}}))}H(t,e){const n=[];return new xr(((s,r)=>{t.onerror=t=>{r(t.target.error)},t.onsuccess=t=>{const r=t.target.result;if(!r)return void s();const i=new Cr(r),o=e(r.primaryKey,r.value,i);if(o instanceof xr){const t=o.catch((t=>(i.done(),xr.reject(t))));n.push(t)}i.isDone?s():null===i.G?r.continue():r.continue(i.G)}})).next((()=>xr.waitFor(n)))}options(t,e){let n;return void 0!==t&&("string"==typeof t?n=t:e=t),{index:n,range:e}}cursor(t){let e="next";if(t.reverse&&(e="prev"),t.index){const n=this.store.index(t.index);return t.X?n.openKeyCursor(t.range,e):n.openCursor(t.range,e)}return this.store.openCursor(t.range,e)}}function Lr(t){return new xr(((e,n)=>{t.onsuccess=t=>{const n=t.target.result;e(n)},t.onerror=t=>{const e=Or(t.target.error);n(e)}}))}let Mr=!1;function Or(t){const e=Dr.D(c());if(e>=12.2&&e<13){const e="An internal error was encountered in the Indexed Database server";if(t.message.indexOf(e)>=0){const t=new Ks("internal",`IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${e}'. This is likely due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.`);return Mr||(Mr=!0,setTimeout((()=>{throw t}),0)),t}}return t}class Vr{constructor(t,e){this.asyncQueue=t,this.et=e,this.task=null}start(){this.nt(15e3)}stop(){this.task&&(this.task.cancel(),this.task=null)}get started(){return null!==this.task}nt(t){Ms("IndexBackiller",`Scheduled in ${t}ms`),this.task=this.asyncQueue.enqueueAfterDelay("index_backfill",t,(async()=>{this.task=null;try{Ms("IndexBackiller",`Documents written: ${await this.et.st()}`)}catch(t){kr(t)?Ms("IndexBackiller","Ignoring IndexedDB error during index backfill: ",t):await _r(t)}await this.nt(6e4)}))}}class Fr{constructor(t,e){this.localStore=t,this.persistence=e}async st(t=50){return this.persistence.runTransaction("Backfill Indexes","readwrite-primary",(e=>this.it(e,t)))}it(t,e){const n=new Set;let s=e,r=!0;return xr.doWhile((()=>!0===r&&s>0),(()=>this.localStore.indexManager.getNextCollectionGroupToUpdate(t).next((e=>{if(null!==e&&!n.has(e))return Ms("IndexBackiller",`Processing collection: ${e}`),this.rt(t,e,s).next((t=>{s-=t,n.add(e)}));r=!1})))).next((()=>e-s))}rt(t,e,n){return this.localStore.indexManager.getMinOffsetFromCollectionGroup(t,e).next((s=>this.localStore.localDocuments.getNextDocuments(t,e,s,n).next((n=>{const r=n.changes;return this.localStore.indexManager.updateIndexEntries(t,r).next((()=>this.ot(s,n))).next((n=>(Ms("IndexBackiller",`Updating offset: ${n}`),this.localStore.indexManager.updateCollectionGroup(t,e,n)))).next((()=>r.size))}))))}ot(t,e){let n=t;return e.changes.forEach(((t,e)=>{const s=Ir(e);Er(s,n)>0&&(n=s)})),new br(n.readTime,n.documentKey,Math.max(e.batchId,t.largestBatchId))}}class Pr{constructor(t,e){this.previousValue=t,e&&(e.sequenceNumberHandler=t=>this.ut(t),this.ct=t=>e.writeSequenceNumber(t))}ut(t){return this.previousValue=Math.max(t,this.previousValue),this.previousValue}next(){const t=++this.previousValue;return this.ct&&this.ct(t),t}}function Br(t){let e=0;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e++;return e}function Ur(t,e){for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}function qr(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}Pr.at=-1;class Gr{constructor(t,e){this.comparator=t,this.root=e||jr.EMPTY}insert(t,e){return new Gr(this.comparator,this.root.insert(t,e,this.comparator).copy(null,null,jr.BLACK,null,null))}remove(t){return new Gr(this.comparator,this.root.remove(t,this.comparator).copy(null,null,jr.BLACK,null,null))}get(t){let e=this.root;for(;!e.isEmpty();){const n=this.comparator(t,e.key);if(0===n)return e.value;n<0?e=e.left:n>0&&(e=e.right)}return null}indexOf(t){let e=0,n=this.root;for(;!n.isEmpty();){const s=this.comparator(t,n.key);if(0===s)return e+n.left.size;s<0?n=n.left:(e+=n.left.size+1,n=n.right)}return-1}isEmpty(){return this.root.isEmpty()}get size(){return this.root.size}minKey(){return this.root.minKey()}maxKey(){return this.root.maxKey()}inorderTraversal(t){return this.root.inorderTraversal(t)}forEach(t){this.inorderTraversal(((e,n)=>(t(e,n),!1)))}toString(){const t=[];return this.inorderTraversal(((e,n)=>(t.push(`${e}:${n}`),!1))),`{${t.join(", ")}}`}reverseTraversal(t){return this.root.reverseTraversal(t)}getIterator(){return new Kr(this.root,null,this.comparator,!1)}getIteratorFrom(t){return new Kr(this.root,t,this.comparator,!1)}getReverseIterator(){return new Kr(this.root,null,this.comparator,!0)}getReverseIteratorFrom(t){return new Kr(this.root,t,this.comparator,!0)}}class Kr{constructor(t,e,n,s){this.isReverse=s,this.nodeStack=[];let r=1;for(;!t.isEmpty();)if(r=e?n(t.key,e):1,e&&s&&(r*=-1),r<0)t=this.isReverse?t.left:t.right;else{if(0===r){this.nodeStack.push(t);break}this.nodeStack.push(t),t=this.isReverse?t.right:t.left}}getNext(){let t=this.nodeStack.pop();const e={key:t.key,value:t.value};if(this.isReverse)for(t=t.left;!t.isEmpty();)this.nodeStack.push(t),t=t.right;else for(t=t.right;!t.isEmpty();)this.nodeStack.push(t),t=t.left;return e}hasNext(){return this.nodeStack.length>0}peek(){if(0===this.nodeStack.length)return null;const t=this.nodeStack[this.nodeStack.length-1];return{key:t.key,value:t.value}}}class jr{constructor(t,e,n,s,r){this.key=t,this.value=e,this.color=null!=n?n:jr.RED,this.left=null!=s?s:jr.EMPTY,this.right=null!=r?r:jr.EMPTY,this.size=this.left.size+1+this.right.size}copy(t,e,n,s,r){return new jr(null!=t?t:this.key,null!=e?e:this.value,null!=n?n:this.color,null!=s?s:this.left,null!=r?r:this.right)}isEmpty(){return!1}inorderTraversal(t){return this.left.inorderTraversal(t)||t(this.key,this.value)||this.right.inorderTraversal(t)}reverseTraversal(t){return this.right.reverseTraversal(t)||t(this.key,this.value)||this.left.reverseTraversal(t)}min(){return this.left.isEmpty()?this:this.left.min()}minKey(){return this.min().key}maxKey(){return this.right.isEmpty()?this.key:this.right.maxKey()}insert(t,e,n){let s=this;const r=n(t,s.key);return s=r<0?s.copy(null,null,null,s.left.insert(t,e,n),null):0===r?s.copy(null,e,null,null,null):s.copy(null,null,null,null,s.right.insert(t,e,n)),s.fixUp()}removeMin(){if(this.left.isEmpty())return jr.EMPTY;let t=this;return t.left.isRed()||t.left.left.isRed()||(t=t.moveRedLeft()),t=t.copy(null,null,null,t.left.removeMin(),null),t.fixUp()}remove(t,e){let n,s=this;if(e(t,s.key)<0)s.left.isEmpty()||s.left.isRed()||s.left.left.isRed()||(s=s.moveRedLeft()),s=s.copy(null,null,null,s.left.remove(t,e),null);else{if(s.left.isRed()&&(s=s.rotateRight()),s.right.isEmpty()||s.right.isRed()||s.right.left.isRed()||(s=s.moveRedRight()),0===e(t,s.key)){if(s.right.isEmpty())return jr.EMPTY;n=s.right.min(),s=s.copy(n.key,n.value,null,null,s.right.removeMin())}s=s.copy(null,null,null,null,s.right.remove(t,e))}return s.fixUp()}isRed(){return this.color}fixUp(){let t=this;return t.right.isRed()&&!t.left.isRed()&&(t=t.rotateLeft()),t.left.isRed()&&t.left.left.isRed()&&(t=t.rotateRight()),t.left.isRed()&&t.right.isRed()&&(t=t.colorFlip()),t}moveRedLeft(){let t=this.colorFlip();return t.right.left.isRed()&&(t=t.copy(null,null,null,null,t.right.rotateRight()),t=t.rotateLeft(),t=t.colorFlip()),t}moveRedRight(){let t=this.colorFlip();return t.left.left.isRed()&&(t=t.rotateRight(),t=t.colorFlip()),t}rotateLeft(){const t=this.copy(null,null,jr.RED,null,this.right.left);return this.right.copy(null,null,this.color,t,null)}rotateRight(){const t=this.copy(null,null,jr.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,t)}colorFlip(){const t=this.left.copy(null,null,!this.left.color,null,null),e=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,t,e)}checkMaxDepth(){const t=this.check();return Math.pow(2,t)<=this.size+1}check(){if(this.isRed()&&this.left.isRed())throw Ps();if(this.right.isRed())throw Ps();const t=this.left.check();if(t!==this.right.check())throw Ps();return t+(this.isRed()?0:1)}}jr.EMPTY=null,jr.RED=!0,jr.BLACK=!1,jr.EMPTY=new class{constructor(){this.size=0}get key(){throw Ps()}get value(){throw Ps()}get color(){throw Ps()}get left(){throw Ps()}get right(){throw Ps()}copy(t,e,n,s,r){return this}insert(t,e,n){return new jr(t,e)}remove(t,e){return this}isEmpty(){return!0}inorderTraversal(t){return!1}reverseTraversal(t){return!1}minKey(){return null}maxKey(){return null}isRed(){return!1}checkMaxDepth(){return!0}check(){return 0}};class $r{constructor(t){this.comparator=t,this.data=new Gr(this.comparator)}has(t){return null!==this.data.get(t)}first(){return this.data.minKey()}last(){return this.data.maxKey()}get size(){return this.data.size}indexOf(t){return this.data.indexOf(t)}forEach(t){this.data.inorderTraversal(((e,n)=>(t(e),!1)))}forEachInRange(t,e){const n=this.data.getIteratorFrom(t[0]);for(;n.hasNext();){const s=n.getNext();if(this.comparator(s.key,t[1])>=0)return;e(s.key)}}forEachWhile(t,e){let n;for(n=void 0!==e?this.data.getIteratorFrom(e):this.data.getIterator();n.hasNext();)if(!t(n.getNext().key))return}firstAfterOrEqual(t){const e=this.data.getIteratorFrom(t);return e.hasNext()?e.getNext().key:null}getIterator(){return new Qr(this.data.getIterator())}getIteratorFrom(t){return new Qr(this.data.getIteratorFrom(t))}add(t){return this.copy(this.data.remove(t).insert(t,!0))}delete(t){return this.has(t)?this.copy(this.data.remove(t)):this}isEmpty(){return this.data.isEmpty()}unionWith(t){let e=this;return e.size<t.size&&(e=t,t=this),t.forEach((t=>{e=e.add(t)})),e}isEqual(t){if(!(t instanceof $r))return!1;if(this.size!==t.size)return!1;const e=this.data.getIterator(),n=t.data.getIterator();for(;e.hasNext();){const t=e.getNext().key,s=n.getNext().key;if(0!==this.comparator(t,s))return!1}return!0}toArray(){const t=[];return this.forEach((e=>{t.push(e)})),t}toString(){const t=[];return this.forEach((e=>t.push(e))),"SortedSet("+t.toString()+")"}copy(t){const e=new $r(this.comparator);return e.data=t,e}}class Qr{constructor(t){this.iter=t}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}}function zr(t){return t.hasNext()?t.getNext():void 0}class Hr{constructor(t){this.fields=t,t.sort(hr.comparator)}static empty(){return new Hr([])}unionWith(t){let e=new $r(hr.comparator);for(const t of this.fields)e=e.add(t);for(const n of t)e=e.add(n);return new Hr(e.toArray())}covers(t){for(const e of this.fields)if(e.isPrefixOf(t))return!0;return!1}isEqual(t){return sr(this.fields,t.fields,((t,e)=>t.isEqual(e)))}}function Wr(){return"undefined"!=typeof atob}class Yr{constructor(t){this.binaryString=t}static fromBase64String(t){const e=atob(t);return new Yr(e)}static fromUint8Array(t){const e=function(t){let e="";for(let n=0;n<t.length;++n)e+=String.fromCharCode(t[n]);return e}(t);return new Yr(e)}[Symbol.iterator](){let t=0;return{next:()=>t<this.binaryString.length?{value:this.binaryString.charCodeAt(t++),done:!1}:{value:void 0,done:!0}}}toBase64(){return t=this.binaryString,btoa(t);var t}toUint8Array(){return function(t){const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}(this.binaryString)}approximateByteSize(){return 2*this.binaryString.length}compareTo(t){return nr(this.binaryString,t.binaryString)}isEqual(t){return this.binaryString===t.binaryString}}Yr.EMPTY_BYTE_STRING=new Yr("");const Xr=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function Jr(t){if(Bs(!!t),"string"==typeof t){let e=0;const n=Xr.exec(t);if(Bs(!!n),n[1]){let t=n[1];t=(t+"000000000").substr(0,9),e=Number(t)}const s=new Date(t);return{seconds:Math.floor(s.getTime()/1e3),nanos:e}}return{seconds:Zr(t.seconds),nanos:Zr(t.nanos)}}function Zr(t){return"number"==typeof t?t:"string"==typeof t?Number(t):0}function ti(t){return"string"==typeof t?Yr.fromBase64String(t):Yr.fromUint8Array(t)}function ei(t){var e,n;return"server_timestamp"===(null===(n=((null===(e=null==t?void 0:t.mapValue)||void 0===e?void 0:e.fields)||{}).__type__)||void 0===n?void 0:n.stringValue)}function ni(t){const e=t.mapValue.fields.__previous_value__;return ei(e)?ni(e):e}function si(t){const e=Jr(t.mapValue.fields.__local_write_time__.timestampValue);return new ir(e.seconds,e.nanos)}class ri{constructor(t,e,n,s,r,i,o,a){this.databaseId=t,this.appId=e,this.persistenceKey=n,this.host=s,this.ssl=r,this.forceLongPolling=i,this.autoDetectLongPolling=o,this.useFetchStreams=a}}class ii{constructor(t,e){this.projectId=t,this.database=e||"(default)"}static empty(){return new ii("","")}get isDefaultDatabase(){return"(default)"===this.database}isEqual(t){return t instanceof ii&&t.projectId===this.projectId&&t.database===this.database}}function oi(t){return null==t}function ai(t){return 0===t&&1/t==-1/0}function ui(t){return"number"==typeof t&&Number.isInteger(t)&&!ai(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}const ci={mapValue:{fields:{__type__:{stringValue:"__max__"}}}},hi={nullValue:"NULL_VALUE"};function li(t){return"nullValue"in t?0:"booleanValue"in t?1:"integerValue"in t||"doubleValue"in t?2:"timestampValue"in t?3:"stringValue"in t?5:"bytesValue"in t?6:"referenceValue"in t?7:"geoPointValue"in t?8:"arrayValue"in t?9:"mapValue"in t?ei(t)?4:_i(t)?9007199254740991:10:Ps()}function di(t,e){if(t===e)return!0;const n=li(t);if(n!==li(e))return!1;switch(n){case 0:case 9007199254740991:return!0;case 1:return t.booleanValue===e.booleanValue;case 4:return si(t).isEqual(si(e));case 3:return function(t,e){if("string"==typeof t.timestampValue&&"string"==typeof e.timestampValue&&t.timestampValue.length===e.timestampValue.length)return t.timestampValue===e.timestampValue;const n=Jr(t.timestampValue),s=Jr(e.timestampValue);return n.seconds===s.seconds&&n.nanos===s.nanos}(t,e);case 5:return t.stringValue===e.stringValue;case 6:return function(t,e){return ti(t.bytesValue).isEqual(ti(e.bytesValue))}(t,e);case 7:return t.referenceValue===e.referenceValue;case 8:return function(t,e){return Zr(t.geoPointValue.latitude)===Zr(e.geoPointValue.latitude)&&Zr(t.geoPointValue.longitude)===Zr(e.geoPointValue.longitude)}(t,e);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return Zr(t.integerValue)===Zr(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){const n=Zr(t.doubleValue),s=Zr(e.doubleValue);return n===s?ai(n)===ai(s):isNaN(n)&&isNaN(s)}return!1}(t,e);case 9:return sr(t.arrayValue.values||[],e.arrayValue.values||[],di);case 10:return function(t,e){const n=t.mapValue.fields||{},s=e.mapValue.fields||{};if(Br(n)!==Br(s))return!1;for(const t in n)if(n.hasOwnProperty(t)&&(void 0===s[t]||!di(n[t],s[t])))return!1;return!0}(t,e);default:return Ps()}}function fi(t,e){return void 0!==(t.values||[]).find((t=>di(t,e)))}function mi(t,e){if(t===e)return 0;const n=li(t),s=li(e);if(n!==s)return nr(n,s);switch(n){case 0:case 9007199254740991:return 0;case 1:return nr(t.booleanValue,e.booleanValue);case 2:return function(t,e){const n=Zr(t.integerValue||t.doubleValue),s=Zr(e.integerValue||e.doubleValue);return n<s?-1:n>s?1:n===s?0:isNaN(n)?isNaN(s)?0:-1:1}(t,e);case 3:return gi(t.timestampValue,e.timestampValue);case 4:return gi(si(t),si(e));case 5:return nr(t.stringValue,e.stringValue);case 6:return function(t,e){const n=ti(t),s=ti(e);return n.compareTo(s)}(t.bytesValue,e.bytesValue);case 7:return function(t,e){const n=t.split("/"),s=e.split("/");for(let t=0;t<n.length&&t<s.length;t++){const e=nr(n[t],s[t]);if(0!==e)return e}return nr(n.length,s.length)}(t.referenceValue,e.referenceValue);case 8:return function(t,e){const n=nr(Zr(t.latitude),Zr(e.latitude));return 0!==n?n:nr(Zr(t.longitude),Zr(e.longitude))}(t.geoPointValue,e.geoPointValue);case 9:return function(t,e){const n=t.values||[],s=e.values||[];for(let t=0;t<n.length&&t<s.length;++t){const e=mi(n[t],s[t]);if(e)return e}return nr(n.length,s.length)}(t.arrayValue,e.arrayValue);case 10:return function(t,e){if(t===ci.mapValue&&e===ci.mapValue)return 0;if(t===ci.mapValue)return 1;if(e===ci.mapValue)return-1;const n=t.fields||{},s=Object.keys(n),r=e.fields||{},i=Object.keys(r);s.sort(),i.sort();for(let t=0;t<s.length&&t<i.length;++t){const e=nr(s[t],i[t]);if(0!==e)return e;const o=mi(n[s[t]],r[i[t]]);if(0!==o)return o}return nr(s.length,i.length)}(t.mapValue,e.mapValue);default:throw Ps()}}function gi(t,e){if("string"==typeof t&&"string"==typeof e&&t.length===e.length)return nr(t,e);const n=Jr(t),s=Jr(e),r=nr(n.seconds,s.seconds);return 0!==r?r:nr(n.nanos,s.nanos)}function pi(t){return yi(t)}function yi(t){return"nullValue"in t?"null":"booleanValue"in t?""+t.booleanValue:"integerValue"in t?""+t.integerValue:"doubleValue"in t?""+t.doubleValue:"timestampValue"in t?function(t){const e=Jr(t);return`time(${e.seconds},${e.nanos})`}(t.timestampValue):"stringValue"in t?t.stringValue:"bytesValue"in t?ti(t.bytesValue).toBase64():"referenceValue"in t?(n=t.referenceValue,lr.fromName(n).toString()):"geoPointValue"in t?`geo(${(e=t.geoPointValue).latitude},${e.longitude})`:"arrayValue"in t?function(t){let e="[",n=!0;for(const s of t.values||[])n?n=!1:e+=",",e+=yi(s);return e+"]"}(t.arrayValue):"mapValue"in t?function(t){const e=Object.keys(t.fields||{}).sort();let n="{",s=!0;for(const r of e)s?s=!1:n+=",",n+=`${r}:${yi(t.fields[r])}`;return n+"}"}(t.mapValue):Ps();var e,n}function wi(t,e){return{referenceValue:`projects/${t.projectId}/databases/${t.database}/documents/${e.path.canonicalString()}`}}function vi(t){return!!t&&"integerValue"in t}function Ii(t){return!!t&&"arrayValue"in t}function bi(t){return!!t&&"nullValue"in t}function Ei(t){return!!t&&"doubleValue"in t&&isNaN(Number(t.doubleValue))}function Ti(t){return!!t&&"mapValue"in t}function Si(t){if(t.geoPointValue)return{geoPointValue:Object.assign({},t.geoPointValue)};if(t.timestampValue&&"object"==typeof t.timestampValue)return{timestampValue:Object.assign({},t.timestampValue)};if(t.mapValue){const e={mapValue:{fields:{}}};return Ur(t.mapValue.fields,((t,n)=>e.mapValue.fields[t]=Si(n))),e}if(t.arrayValue){const e={arrayValue:{values:[]}};for(let n=0;n<(t.arrayValue.values||[]).length;++n)e.arrayValue.values[n]=Si(t.arrayValue.values[n]);return e}return Object.assign({},t)}function _i(t){return"__max__"===(((t.mapValue||{}).fields||{}).__type__||{}).stringValue}function xi(t){return"nullValue"in t?hi:"booleanValue"in t?{booleanValue:!1}:"integerValue"in t||"doubleValue"in t?{doubleValue:NaN}:"timestampValue"in t?{timestampValue:{seconds:Number.MIN_SAFE_INTEGER}}:"stringValue"in t?{stringValue:""}:"bytesValue"in t?{bytesValue:""}:"referenceValue"in t?wi(ii.empty(),lr.empty()):"geoPointValue"in t?{geoPointValue:{latitude:-90,longitude:-180}}:"arrayValue"in t?{arrayValue:{}}:"mapValue"in t?{mapValue:{}}:Ps()}function Ai(t){return"nullValue"in t?{booleanValue:!1}:"booleanValue"in t?{doubleValue:NaN}:"integerValue"in t||"doubleValue"in t?{timestampValue:{seconds:Number.MIN_SAFE_INTEGER}}:"timestampValue"in t?{stringValue:""}:"stringValue"in t?{bytesValue:""}:"bytesValue"in t?wi(ii.empty(),lr.empty()):"referenceValue"in t?{geoPointValue:{latitude:-90,longitude:-180}}:"geoPointValue"in t?{arrayValue:{}}:"arrayValue"in t?{mapValue:{}}:"mapValue"in t?ci:Ps()}function Di(t,e){const n=mi(t.value,e.value);return 0!==n?n:t.inclusive&&!e.inclusive?-1:!t.inclusive&&e.inclusive?1:0}function Ci(t,e){const n=mi(t.value,e.value);return 0!==n?n:t.inclusive&&!e.inclusive?1:!t.inclusive&&e.inclusive?-1:0}class Ni{constructor(t){this.value=t}static empty(){return new Ni({mapValue:{}})}field(t){if(t.isEmpty())return this.value;{let e=this.value;for(let n=0;n<t.length-1;++n)if(e=(e.mapValue.fields||{})[t.get(n)],!Ti(e))return null;return e=(e.mapValue.fields||{})[t.lastSegment()],e||null}}set(t,e){this.getFieldsMap(t.popLast())[t.lastSegment()]=Si(e)}setAll(t){let e=hr.emptyPath(),n={},s=[];t.forEach(((t,r)=>{if(!e.isImmediateParentOf(r)){const t=this.getFieldsMap(e);this.applyChanges(t,n,s),n={},s=[],e=r.popLast()}t?n[r.lastSegment()]=Si(t):s.push(r.lastSegment())}));const r=this.getFieldsMap(e);this.applyChanges(r,n,s)}delete(t){const e=this.field(t.popLast());Ti(e)&&e.mapValue.fields&&delete e.mapValue.fields[t.lastSegment()]}isEqual(t){return di(this.value,t.value)}getFieldsMap(t){let e=this.value;e.mapValue.fields||(e.mapValue={fields:{}});for(let n=0;n<t.length;++n){let s=e.mapValue.fields[t.get(n)];Ti(s)&&s.mapValue.fields||(s={mapValue:{fields:{}}},e.mapValue.fields[t.get(n)]=s),e=s}return e.mapValue.fields}applyChanges(t,e,n){Ur(e,((e,n)=>t[e]=n));for(const e of n)delete t[e]}clone(){return new Ni(Si(this.value))}}function ki(t){const e=[];return Ur(t.fields,((t,n)=>{const s=new hr([t]);if(Ti(n)){const t=ki(n.mapValue).fields;if(0===t.length)e.push(s);else for(const n of t)e.push(s.child(n))}else e.push(s)})),new Hr(e)}class Ri{constructor(t,e,n,s,r,i){this.key=t,this.documentType=e,this.version=n,this.readTime=s,this.data=r,this.documentState=i}static newInvalidDocument(t){return new Ri(t,0,or.min(),or.min(),Ni.empty(),0)}static newFoundDocument(t,e,n){return new Ri(t,1,e,or.min(),n,0)}static newNoDocument(t,e){return new Ri(t,2,e,or.min(),Ni.empty(),0)}static newUnknownDocument(t,e){return new Ri(t,3,e,or.min(),Ni.empty(),2)}convertToFoundDocument(t,e){return this.version=t,this.documentType=1,this.data=e,this.documentState=0,this}convertToNoDocument(t){return this.version=t,this.documentType=2,this.data=Ni.empty(),this.documentState=0,this}convertToUnknownDocument(t){return this.version=t,this.documentType=3,this.data=Ni.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=or.min(),this}setReadTime(t){return this.readTime=t,this}get hasLocalMutations(){return 1===this.documentState}get hasCommittedMutations(){return 2===this.documentState}get hasPendingWrites(){return this.hasLocalMutations||this.hasCommittedMutations}isValidDocument(){return 0!==this.documentType}isFoundDocument(){return 1===this.documentType}isNoDocument(){return 2===this.documentType}isUnknownDocument(){return 3===this.documentType}isEqual(t){return t instanceof Ri&&this.key.isEqual(t.key)&&this.version.isEqual(t.version)&&this.documentType===t.documentType&&this.documentState===t.documentState&&this.data.isEqual(t.data)}mutableCopy(){return new Ri(this.key,this.documentType,this.version,this.readTime,this.data.clone(),this.documentState)}toString(){return`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, {documentType: ${this.documentType}}), {documentState: ${this.documentState}})`}}class Li{constructor(t,e=null,n=[],s=[],r=null,i=null,o=null){this.path=t,this.collectionGroup=e,this.orderBy=n,this.filters=s,this.limit=r,this.startAt=i,this.endAt=o,this.ht=null}}function Mi(t,e=null,n=[],s=[],r=null,i=null,o=null){return new Li(t,e,n,s,r,i,o)}function Oi(t){const e=qs(t);if(null===e.ht){let t=e.path.canonicalString();null!==e.collectionGroup&&(t+="|cg:"+e.collectionGroup),t+="|f:",t+=e.filters.map((t=>{return(e=t).field.canonicalString()+e.op.toString()+pi(e.value);var e})).join(","),t+="|ob:",t+=e.orderBy.map((t=>function(t){return t.field.canonicalString()+t.dir}(t))).join(","),oi(e.limit)||(t+="|l:",t+=e.limit),e.startAt&&(t+="|lb:",t+=e.startAt.inclusive?"b:":"a:",t+=e.startAt.position.map((t=>pi(t))).join(",")),e.endAt&&(t+="|ub:",t+=e.endAt.inclusive?"a:":"b:",t+=e.endAt.position.map((t=>pi(t))).join(",")),e.ht=t}return e.ht}function Vi(t,e){if(t.limit!==e.limit)return!1;if(t.orderBy.length!==e.orderBy.length)return!1;for(let n=0;n<t.orderBy.length;n++)if(!Ji(t.orderBy[n],e.orderBy[n]))return!1;if(t.filters.length!==e.filters.length)return!1;for(let r=0;r<t.filters.length;r++)if(n=t.filters[r],s=e.filters[r],n.op!==s.op||!n.field.isEqual(s.field)||!di(n.value,s.value))return!1;var n,s;return t.collectionGroup===e.collectionGroup&&!!t.path.isEqual(e.path)&&!!to(t.startAt,e.startAt)&&to(t.endAt,e.endAt)}function Fi(t){return lr.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}function Pi(t,e){return t.filters.filter((t=>t instanceof qi&&t.field.isEqual(e)))}function Bi(t,e,n){let s=hi,r=!0;for(const n of Pi(t,e)){let t=hi,e=!0;switch(n.op){case"<":case"<=":t=xi(n.value);break;case"==":case"in":case">=":t=n.value;break;case">":t=n.value,e=!1;break;case"!=":case"not-in":t=hi}Di({value:s,inclusive:r},{value:t,inclusive:e})<0&&(s=t,r=e)}if(null!==n)for(let i=0;i<t.orderBy.length;++i)if(t.orderBy[i].field.isEqual(e)){const t=n.position[i];Di({value:s,inclusive:r},{value:t,inclusive:n.inclusive})<0&&(s=t,r=n.inclusive);break}return{value:s,inclusive:r}}function Ui(t,e,n){let s=ci,r=!0;for(const n of Pi(t,e)){let t=ci,e=!0;switch(n.op){case">=":case">":t=Ai(n.value),e=!1;break;case"==":case"in":case"<=":t=n.value;break;case"<":t=n.value,e=!1;break;case"!=":case"not-in":t=ci}Ci({value:s,inclusive:r},{value:t,inclusive:e})>0&&(s=t,r=e)}if(null!==n)for(let i=0;i<t.orderBy.length;++i)if(t.orderBy[i].field.isEqual(e)){const t=n.position[i];Ci({value:s,inclusive:r},{value:t,inclusive:n.inclusive})>0&&(s=t,r=n.inclusive);break}return{value:s,inclusive:r}}class qi extends class{}{constructor(t,e,n){super(),this.field=t,this.op=e,this.value=n}static create(t,e,n){return t.isKeyField()?"in"===e||"not-in"===e?this.lt(t,e,n):new Gi(t,e,n):"array-contains"===e?new Qi(t,n):"in"===e?new zi(t,n):"not-in"===e?new Hi(t,n):"array-contains-any"===e?new Wi(t,n):new qi(t,e,n)}static lt(t,e,n){return"in"===e?new Ki(t,n):new ji(t,n)}matches(t){const e=t.data.field(this.field);return"!="===this.op?null!==e&&this.ft(mi(e,this.value)):null!==e&&li(this.value)===li(e)&&this.ft(mi(e,this.value))}ft(t){switch(this.op){case"<":return t<0;case"<=":return t<=0;case"==":return 0===t;case"!=":return 0!==t;case">":return t>0;case">=":return t>=0;default:return Ps()}}dt(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}}class Gi extends qi{constructor(t,e,n){super(t,e,n),this.key=lr.fromName(n.referenceValue)}matches(t){const e=lr.comparator(t.key,this.key);return this.ft(e)}}class Ki extends qi{constructor(t,e){super(t,"in",e),this.keys=$i("in",e)}matches(t){return this.keys.some((e=>e.isEqual(t.key)))}}class ji extends qi{constructor(t,e){super(t,"not-in",e),this.keys=$i("not-in",e)}matches(t){return!this.keys.some((e=>e.isEqual(t.key)))}}function $i(t,e){var n;return((null===(n=e.arrayValue)||void 0===n?void 0:n.values)||[]).map((t=>lr.fromName(t.referenceValue)))}class Qi extends qi{constructor(t,e){super(t,"array-contains",e)}matches(t){const e=t.data.field(this.field);return Ii(e)&&fi(e.arrayValue,this.value)}}class zi extends qi{constructor(t,e){super(t,"in",e)}matches(t){const e=t.data.field(this.field);return null!==e&&fi(this.value.arrayValue,e)}}class Hi extends qi{constructor(t,e){super(t,"not-in",e)}matches(t){if(fi(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;const e=t.data.field(this.field);return null!==e&&!fi(this.value.arrayValue,e)}}class Wi extends qi{constructor(t,e){super(t,"array-contains-any",e)}matches(t){const e=t.data.field(this.field);return!(!Ii(e)||!e.arrayValue.values)&&e.arrayValue.values.some((t=>fi(this.value.arrayValue,t)))}}class Yi{constructor(t,e){this.position=t,this.inclusive=e}}class Xi{constructor(t,e="asc"){this.field=t,this.dir=e}}function Ji(t,e){return t.dir===e.dir&&t.field.isEqual(e.field)}function Zi(t,e,n){let s=0;for(let r=0;r<t.position.length;r++){const i=e[r],o=t.position[r];if(s=i.field.isKeyField()?lr.comparator(lr.fromName(o.referenceValue),n.key):mi(o,n.data.field(i.field)),"desc"===i.dir&&(s*=-1),0!==s)break}return s}function to(t,e){if(null===t)return null===e;if(null===e)return!1;if(t.inclusive!==e.inclusive||t.position.length!==e.position.length)return!1;for(let n=0;n<t.position.length;n++)if(!di(t.position[n],e.position[n]))return!1;return!0}class eo{constructor(t,e=null,n=[],s=[],r=null,i="F",o=null,a=null){this.path=t,this.collectionGroup=e,this.explicitOrderBy=n,this.filters=s,this.limit=r,this.limitType=i,this.startAt=o,this.endAt=a,this._t=null,this.wt=null,this.startAt,this.endAt}}function no(t,e,n,s,r,i,o,a){return new eo(t,e,n,s,r,i,o,a)}function so(t){return new eo(t)}function ro(t){return 0===t.filters.length&&null===t.limit&&null==t.startAt&&null==t.endAt&&(0===t.explicitOrderBy.length||1===t.explicitOrderBy.length&&t.explicitOrderBy[0].field.isKeyField())}function io(t){return t.explicitOrderBy.length>0?t.explicitOrderBy[0].field:null}function oo(t){for(const e of t.filters)if(e.dt())return e.field;return null}function ao(t){return null!==t.collectionGroup}function uo(t){const e=qs(t);if(null===e._t){e._t=[];const t=oo(e),n=io(e);if(null!==t&&null===n)t.isKeyField()||e._t.push(new Xi(t)),e._t.push(new Xi(hr.keyField(),"asc"));else{let t=!1;for(const n of e.explicitOrderBy)e._t.push(n),n.field.isKeyField()&&(t=!0);if(!t){const t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e._t.push(new Xi(hr.keyField(),t))}}}return e._t}function co(t){const e=qs(t);if(!e.wt)if("F"===e.limitType)e.wt=Mi(e.path,e.collectionGroup,uo(e),e.filters,e.limit,e.startAt,e.endAt);else{const t=[];for(const n of uo(e)){const e="desc"===n.dir?"asc":"desc";t.push(new Xi(n.field,e))}const n=e.endAt?new Yi(e.endAt.position,e.endAt.inclusive):null,s=e.startAt?new Yi(e.startAt.position,e.startAt.inclusive):null;e.wt=Mi(e.path,e.collectionGroup,t,e.filters,e.limit,n,s)}return e.wt}function ho(t,e,n){return new eo(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),e,n,t.startAt,t.endAt)}function lo(t,e){return Vi(co(t),co(e))&&t.limitType===e.limitType}function fo(t){return`${Oi(co(t))}|lt:${t.limitType}`}function mo(t){return`Query(target=${function(t){let e=t.path.canonicalString();return null!==t.collectionGroup&&(e+=" collectionGroup="+t.collectionGroup),t.filters.length>0&&(e+=`, filters: [${t.filters.map((t=>{return`${(e=t).field.canonicalString()} ${e.op} ${pi(e.value)}`;var e})).join(", ")}]`),oi(t.limit)||(e+=", limit: "+t.limit),t.orderBy.length>0&&(e+=`, orderBy: [${t.orderBy.map((t=>function(t){return`${t.field.canonicalString()} (${t.dir})`}(t))).join(", ")}]`),t.startAt&&(e+=", startAt: ",e+=t.startAt.inclusive?"b:":"a:",e+=t.startAt.position.map((t=>pi(t))).join(",")),t.endAt&&(e+=", endAt: ",e+=t.endAt.inclusive?"a:":"b:",e+=t.endAt.position.map((t=>pi(t))).join(",")),`Target(${e})`}(co(t))}; limitType=${t.limitType})`}function go(t,e){return e.isFoundDocument()&&function(t,e){const n=e.key.path;return null!==t.collectionGroup?e.key.hasCollectionId(t.collectionGroup)&&t.path.isPrefixOf(n):lr.isDocumentKey(t.path)?t.path.isEqual(n):t.path.isImmediateParentOf(n)}(t,e)&&function(t,e){for(const n of t.explicitOrderBy)if(!n.field.isKeyField()&&null===e.data.field(n.field))return!1;return!0}(t,e)&&function(t,e){for(const n of t.filters)if(!n.matches(e))return!1;return!0}(t,e)&&function(t,e){return!(t.startAt&&!function(t,e,n){const s=Zi(t,e,n);return t.inclusive?s<=0:s<0}(t.startAt,uo(t),e))&&!(t.endAt&&!function(t,e,n){const s=Zi(t,e,n);return t.inclusive?s>=0:s>0}(t.endAt,uo(t),e))}(t,e)}function po(t){return t.collectionGroup||(t.path.length%2==1?t.path.lastSegment():t.path.get(t.path.length-2))}function yo(t){return(e,n)=>{let s=!1;for(const r of uo(t)){const t=wo(r,e,n);if(0!==t)return t;s=s||r.field.isKeyField()}return 0}}function wo(t,e,n){const s=t.field.isKeyField()?lr.comparator(e.key,n.key):function(t,e,n){const s=e.data.field(t),r=n.data.field(t);return null!==s&&null!==r?mi(s,r):Ps()}(t.field,e,n);switch(t.dir){case"asc":return s;case"desc":return-1*s;default:return Ps()}}function vo(t,e){if(t.gt){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:ai(e)?"-0":e}}function Io(t){return{integerValue:""+t}}function bo(t,e){return ui(e)?Io(e):vo(t,e)}class Eo{constructor(){this._=void 0}}function To(t,e,n){return t instanceof xo?function(t,e){const n={fields:{__type__:{stringValue:"server_timestamp"},__local_write_time__:{timestampValue:{seconds:t.seconds,nanos:t.nanoseconds}}}};return e&&(n.fields.__previous_value__=e),{mapValue:n}}(n,e):t instanceof Ao?Do(t,e):t instanceof Co?No(t,e):function(t,e){const n=_o(t,e),s=Ro(n)+Ro(t.yt);return vi(n)&&vi(t.yt)?Io(s):vo(t.It,s)}(t,e)}function So(t,e,n){return t instanceof Ao?Do(t,e):t instanceof Co?No(t,e):n}function _o(t,e){return t instanceof ko?vi(n=e)||function(t){return!!t&&"doubleValue"in t}(n)?e:{integerValue:0}:null;var n}class xo extends Eo{}class Ao extends Eo{constructor(t){super(),this.elements=t}}function Do(t,e){const n=Lo(e);for(const e of t.elements)n.some((t=>di(t,e)))||n.push(e);return{arrayValue:{values:n}}}class Co extends Eo{constructor(t){super(),this.elements=t}}function No(t,e){let n=Lo(e);for(const e of t.elements)n=n.filter((t=>!di(t,e)));return{arrayValue:{values:n}}}class ko extends Eo{constructor(t,e){super(),this.It=t,this.yt=e}}function Ro(t){return Zr(t.integerValue||t.doubleValue)}function Lo(t){return Ii(t)&&t.arrayValue.values?t.arrayValue.values.slice():[]}class Mo{constructor(t,e){this.field=t,this.transform=e}}class Oo{constructor(t,e){this.version=t,this.transformResults=e}}class Vo{constructor(t,e){this.updateTime=t,this.exists=e}static none(){return new Vo}static exists(t){return new Vo(void 0,t)}static updateTime(t){return new Vo(t)}get isNone(){return void 0===this.updateTime&&void 0===this.exists}isEqual(t){return this.exists===t.exists&&(this.updateTime?!!t.updateTime&&this.updateTime.isEqual(t.updateTime):!t.updateTime)}}function Fo(t,e){return void 0!==t.updateTime?e.isFoundDocument()&&e.version.isEqual(t.updateTime):void 0===t.exists||t.exists===e.isFoundDocument()}class Po{}function Bo(t,e){if(!t.hasLocalMutations||e&&0===e.fields.length)return null;if(null===e)return t.isNoDocument()?new Wo(t.key,Vo.none()):new jo(t.key,t.data,Vo.none());{const n=t.data,s=Ni.empty();let r=new $r(hr.comparator);for(let t of e.fields)if(!r.has(t)){let e=n.field(t);null===e&&t.length>1&&(t=t.popLast(),e=n.field(t)),null===e?s.delete(t):s.set(t,e),r=r.add(t)}return new $o(t.key,s,new Hr(r.toArray()),Vo.none())}}function Uo(t,e,n){t instanceof jo?function(t,e,n){const s=t.value.clone(),r=zo(t.fieldTransforms,e,n.transformResults);s.setAll(r),e.convertToFoundDocument(n.version,s).setHasCommittedMutations()}(t,e,n):t instanceof $o?function(t,e,n){if(!Fo(t.precondition,e))return void e.convertToUnknownDocument(n.version);const s=zo(t.fieldTransforms,e,n.transformResults),r=e.data;r.setAll(Qo(t)),r.setAll(s),e.convertToFoundDocument(n.version,r).setHasCommittedMutations()}(t,e,n):function(t,e,n){e.convertToNoDocument(n.version).setHasCommittedMutations()}(0,e,n)}function qo(t,e,n,s){return t instanceof jo?function(t,e,n,s){if(!Fo(t.precondition,e))return n;const r=t.value.clone(),i=Ho(t.fieldTransforms,s,e);return r.setAll(i),e.convertToFoundDocument(e.version,r).setHasLocalMutations(),null}(t,e,n,s):t instanceof $o?function(t,e,n,s){if(!Fo(t.precondition,e))return n;const r=Ho(t.fieldTransforms,s,e),i=e.data;return i.setAll(Qo(t)),i.setAll(r),e.convertToFoundDocument(e.version,i).setHasLocalMutations(),null===n?null:n.unionWith(t.fieldMask.fields).unionWith(t.fieldTransforms.map((t=>t.field)))}(t,e,n,s):function(t,e,n){return Fo(t.precondition,e)?(e.convertToNoDocument(e.version).setHasLocalMutations(),null):n}(t,e,n)}function Go(t,e){let n=null;for(const s of t.fieldTransforms){const t=e.data.field(s.field),r=_o(s.transform,t||null);null!=r&&(null===n&&(n=Ni.empty()),n.set(s.field,r))}return n||null}function Ko(t,e){return t.type===e.type&&!!t.key.isEqual(e.key)&&!!t.precondition.isEqual(e.precondition)&&!!function(t,e){return void 0===t&&void 0===e||!(!t||!e)&&sr(t,e,((t,e)=>function(t,e){return t.field.isEqual(e.field)&&function(t,e){return t instanceof Ao&&e instanceof Ao||t instanceof Co&&e instanceof Co?sr(t.elements,e.elements,di):t instanceof ko&&e instanceof ko?di(t.yt,e.yt):t instanceof xo&&e instanceof xo}(t.transform,e.transform)}(t,e)))}(t.fieldTransforms,e.fieldTransforms)&&(0===t.type?t.value.isEqual(e.value):1!==t.type||t.data.isEqual(e.data)&&t.fieldMask.isEqual(e.fieldMask))}class jo extends Po{constructor(t,e,n,s=[]){super(),this.key=t,this.value=e,this.precondition=n,this.fieldTransforms=s,this.type=0}getFieldMask(){return null}}class $o extends Po{constructor(t,e,n,s,r=[]){super(),this.key=t,this.data=e,this.fieldMask=n,this.precondition=s,this.fieldTransforms=r,this.type=1}getFieldMask(){return this.fieldMask}}function Qo(t){const e=new Map;return t.fieldMask.fields.forEach((n=>{if(!n.isEmpty()){const s=t.data.field(n);e.set(n,s)}})),e}function zo(t,e,n){const s=new Map;Bs(t.length===n.length);for(let r=0;r<n.length;r++){const i=t[r],o=i.transform,a=e.data.field(i.field);s.set(i.field,So(o,a,n[r]))}return s}function Ho(t,e,n){const s=new Map;for(const r of t){const t=r.transform,i=n.data.field(r.field);s.set(r.field,To(t,i,e))}return s}class Wo extends Po{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class Yo extends Po{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}class Xo{constructor(t){this.count=t}}var Jo,Zo;function ta(t){switch(t){default:return Ps();case Gs.CANCELLED:case Gs.UNKNOWN:case Gs.DEADLINE_EXCEEDED:case Gs.RESOURCE_EXHAUSTED:case Gs.INTERNAL:case Gs.UNAVAILABLE:case Gs.UNAUTHENTICATED:return!1;case Gs.INVALID_ARGUMENT:case Gs.NOT_FOUND:case Gs.ALREADY_EXISTS:case Gs.PERMISSION_DENIED:case Gs.FAILED_PRECONDITION:case Gs.ABORTED:case Gs.OUT_OF_RANGE:case Gs.UNIMPLEMENTED:case Gs.DATA_LOSS:return!0}}function ea(t){if(void 0===t)return Os("GRPC error has no .code"),Gs.UNKNOWN;switch(t){case Jo.OK:return Gs.OK;case Jo.CANCELLED:return Gs.CANCELLED;case Jo.UNKNOWN:return Gs.UNKNOWN;case Jo.DEADLINE_EXCEEDED:return Gs.DEADLINE_EXCEEDED;case Jo.RESOURCE_EXHAUSTED:return Gs.RESOURCE_EXHAUSTED;case Jo.INTERNAL:return Gs.INTERNAL;case Jo.UNAVAILABLE:return Gs.UNAVAILABLE;case Jo.UNAUTHENTICATED:return Gs.UNAUTHENTICATED;case Jo.INVALID_ARGUMENT:return Gs.INVALID_ARGUMENT;case Jo.NOT_FOUND:return Gs.NOT_FOUND;case Jo.ALREADY_EXISTS:return Gs.ALREADY_EXISTS;case Jo.PERMISSION_DENIED:return Gs.PERMISSION_DENIED;case Jo.FAILED_PRECONDITION:return Gs.FAILED_PRECONDITION;case Jo.ABORTED:return Gs.ABORTED;case Jo.OUT_OF_RANGE:return Gs.OUT_OF_RANGE;case Jo.UNIMPLEMENTED:return Gs.UNIMPLEMENTED;case Jo.DATA_LOSS:return Gs.DATA_LOSS;default:return Ps()}}(Zo=Jo||(Jo={}))[Zo.OK=0]="OK",Zo[Zo.CANCELLED=1]="CANCELLED",Zo[Zo.UNKNOWN=2]="UNKNOWN",Zo[Zo.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",Zo[Zo.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",Zo[Zo.NOT_FOUND=5]="NOT_FOUND",Zo[Zo.ALREADY_EXISTS=6]="ALREADY_EXISTS",Zo[Zo.PERMISSION_DENIED=7]="PERMISSION_DENIED",Zo[Zo.UNAUTHENTICATED=16]="UNAUTHENTICATED",Zo[Zo.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",Zo[Zo.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",Zo[Zo.ABORTED=10]="ABORTED",Zo[Zo.OUT_OF_RANGE=11]="OUT_OF_RANGE",Zo[Zo.UNIMPLEMENTED=12]="UNIMPLEMENTED",Zo[Zo.INTERNAL=13]="INTERNAL",Zo[Zo.UNAVAILABLE=14]="UNAVAILABLE",Zo[Zo.DATA_LOSS=15]="DATA_LOSS";class na{constructor(t,e){this.mapKeyFn=t,this.equalsFn=e,this.inner={},this.innerSize=0}get(t){const e=this.mapKeyFn(t),n=this.inner[e];if(void 0!==n)for(const[e,s]of n)if(this.equalsFn(e,t))return s}has(t){return void 0!==this.get(t)}set(t,e){const n=this.mapKeyFn(t),s=this.inner[n];if(void 0===s)return this.inner[n]=[[t,e]],void this.innerSize++;for(let n=0;n<s.length;n++)if(this.equalsFn(s[n][0],t))return void(s[n]=[t,e]);s.push([t,e]),this.innerSize++}delete(t){const e=this.mapKeyFn(t),n=this.inner[e];if(void 0===n)return!1;for(let s=0;s<n.length;s++)if(this.equalsFn(n[s][0],t))return 1===n.length?delete this.inner[e]:n.splice(s,1),this.innerSize--,!0;return!1}forEach(t){Ur(this.inner,((e,n)=>{for(const[e,s]of n)t(e,s)}))}isEmpty(){return qr(this.inner)}size(){return this.innerSize}}const sa=new Gr(lr.comparator);function ra(){return sa}const ia=new Gr(lr.comparator);function oa(...t){let e=ia;for(const n of t)e=e.insert(n.key,n);return e}function aa(t){let e=ia;return t.forEach(((t,n)=>e=e.insert(t,n.overlayedDocument))),e}function ua(){return ha()}function ca(){return ha()}function ha(){return new na((t=>t.toString()),((t,e)=>t.isEqual(e)))}const la=new Gr(lr.comparator),da=new $r(lr.comparator);function fa(...t){let e=da;for(const n of t)e=e.add(n);return e}const ma=new $r(nr);function ga(){return ma}class pa{constructor(t,e,n,s,r){this.snapshotVersion=t,this.targetChanges=e,this.targetMismatches=n,this.documentUpdates=s,this.resolvedLimboDocuments=r}static createSynthesizedRemoteEventForCurrentChange(t,e,n){const s=new Map;return s.set(t,ya.createSynthesizedTargetChangeForCurrentChange(t,e,n)),new pa(or.min(),s,ga(),ra(),fa())}}class ya{constructor(t,e,n,s,r){this.resumeToken=t,this.current=e,this.addedDocuments=n,this.modifiedDocuments=s,this.removedDocuments=r}static createSynthesizedTargetChangeForCurrentChange(t,e,n){return new ya(n,e,fa(),fa(),fa())}}class wa{constructor(t,e,n,s){this.Tt=t,this.removedTargetIds=e,this.key=n,this.Et=s}}class va{constructor(t,e){this.targetId=t,this.At=e}}class Ia{constructor(t,e,n=Yr.EMPTY_BYTE_STRING,s=null){this.state=t,this.targetIds=e,this.resumeToken=n,this.cause=s}}class ba{constructor(){this.Rt=0,this.bt=Sa(),this.Pt=Yr.EMPTY_BYTE_STRING,this.vt=!1,this.Vt=!0}get current(){return this.vt}get resumeToken(){return this.Pt}get St(){return 0!==this.Rt}get Dt(){return this.Vt}Ct(t){t.approximateByteSize()>0&&(this.Vt=!0,this.Pt=t)}xt(){let t=fa(),e=fa(),n=fa();return this.bt.forEach(((s,r)=>{switch(r){case 0:t=t.add(s);break;case 2:e=e.add(s);break;case 1:n=n.add(s);break;default:Ps()}})),new ya(this.Pt,this.vt,t,e,n)}Nt(){this.Vt=!1,this.bt=Sa()}kt(t,e){this.Vt=!0,this.bt=this.bt.insert(t,e)}Ot(t){this.Vt=!0,this.bt=this.bt.remove(t)}Mt(){this.Rt+=1}Ft(){this.Rt-=1}$t(){this.Vt=!0,this.vt=!0}}class Ea{constructor(t){this.Bt=t,this.Lt=new Map,this.Ut=ra(),this.qt=Ta(),this.Kt=new $r(nr)}Gt(t){for(const e of t.Tt)t.Et&&t.Et.isFoundDocument()?this.Qt(e,t.Et):this.jt(e,t.key,t.Et);for(const e of t.removedTargetIds)this.jt(e,t.key,t.Et)}Wt(t){this.forEachTarget(t,(e=>{const n=this.zt(e);switch(t.state){case 0:this.Ht(e)&&n.Ct(t.resumeToken);break;case 1:n.Ft(),n.St||n.Nt(),n.Ct(t.resumeToken);break;case 2:n.Ft(),n.St||this.removeTarget(e);break;case 3:this.Ht(e)&&(n.$t(),n.Ct(t.resumeToken));break;case 4:this.Ht(e)&&(this.Jt(e),n.Ct(t.resumeToken));break;default:Ps()}}))}forEachTarget(t,e){t.targetIds.length>0?t.targetIds.forEach(e):this.Lt.forEach(((t,n)=>{this.Ht(n)&&e(n)}))}Yt(t){const e=t.targetId,n=t.At.count,s=this.Xt(e);if(s){const t=s.target;if(Fi(t))if(0===n){const n=new lr(t.path);this.jt(e,n,Ri.newNoDocument(n,or.min()))}else Bs(1===n);else this.Zt(e)!==n&&(this.Jt(e),this.Kt=this.Kt.add(e))}}te(t){const e=new Map;this.Lt.forEach(((n,s)=>{const r=this.Xt(s);if(r){if(n.current&&Fi(r.target)){const e=new lr(r.target.path);null!==this.Ut.get(e)||this.ee(s,e)||this.jt(s,e,Ri.newNoDocument(e,t))}n.Dt&&(e.set(s,n.xt()),n.Nt())}}));let n=fa();this.qt.forEach(((t,e)=>{let s=!0;e.forEachWhile((t=>{const e=this.Xt(t);return!e||2===e.purpose||(s=!1,!1)})),s&&(n=n.add(t))})),this.Ut.forEach(((e,n)=>n.setReadTime(t)));const s=new pa(t,e,this.Kt,this.Ut,n);return this.Ut=ra(),this.qt=Ta(),this.Kt=new $r(nr),s}Qt(t,e){if(!this.Ht(t))return;const n=this.ee(t,e.key)?2:0;this.zt(t).kt(e.key,n),this.Ut=this.Ut.insert(e.key,e),this.qt=this.qt.insert(e.key,this.ne(e.key).add(t))}jt(t,e,n){if(!this.Ht(t))return;const s=this.zt(t);this.ee(t,e)?s.kt(e,1):s.Ot(e),this.qt=this.qt.insert(e,this.ne(e).delete(t)),n&&(this.Ut=this.Ut.insert(e,n))}removeTarget(t){this.Lt.delete(t)}Zt(t){const e=this.zt(t).xt();return this.Bt.getRemoteKeysForTarget(t).size+e.addedDocuments.size-e.removedDocuments.size}Mt(t){this.zt(t).Mt()}zt(t){let e=this.Lt.get(t);return e||(e=new ba,this.Lt.set(t,e)),e}ne(t){let e=this.qt.get(t);return e||(e=new $r(nr),this.qt=this.qt.insert(t,e)),e}Ht(t){const e=null!==this.Xt(t);return e||Ms("WatchChangeAggregator","Detected inactive target",t),e}Xt(t){const e=this.Lt.get(t);return e&&e.St?null:this.Bt.se(t)}Jt(t){this.Lt.set(t,new ba),this.Bt.getRemoteKeysForTarget(t).forEach((e=>{this.jt(t,e,null)}))}ee(t,e){return this.Bt.getRemoteKeysForTarget(t).has(e)}}function Ta(){return new Gr(lr.comparator)}function Sa(){return new Gr(lr.comparator)}const _a={asc:"ASCENDING",desc:"DESCENDING"},xa={"<":"LESS_THAN","<=":"LESS_THAN_OR_EQUAL",">":"GREATER_THAN",">=":"GREATER_THAN_OR_EQUAL","==":"EQUAL","!=":"NOT_EQUAL","array-contains":"ARRAY_CONTAINS",in:"IN","not-in":"NOT_IN","array-contains-any":"ARRAY_CONTAINS_ANY"};class Aa{constructor(t,e){this.databaseId=t,this.gt=e}}function Da(t,e){return t.gt?`${new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+e.nanoseconds).slice(-9)}Z`:{seconds:""+e.seconds,nanos:e.nanoseconds}}function Ca(t,e){return t.gt?e.toBase64():e.toUint8Array()}function Na(t,e){return Da(t,e.toTimestamp())}function ka(t){return Bs(!!t),or.fromTimestamp(function(t){const e=Jr(t);return new ir(e.seconds,e.nanos)}(t))}function Ra(t,e){return function(t){return new ur(["projects",t.projectId,"databases",t.database])}(t).child("documents").child(e).canonicalString()}function La(t){const e=ur.fromString(t);return Bs(eu(e)),e}function Ma(t,e){return Ra(t.databaseId,e.path)}function Oa(t,e){const n=La(e);if(n.get(1)!==t.databaseId.projectId)throw new Ks(Gs.INVALID_ARGUMENT,"Tried to deserialize key from different project: "+n.get(1)+" vs "+t.databaseId.projectId);if(n.get(3)!==t.databaseId.database)throw new Ks(Gs.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new lr(Ba(n))}function Va(t,e){return Ra(t.databaseId,e)}function Fa(t){const e=La(t);return 4===e.length?ur.emptyPath():Ba(e)}function Pa(t){return new ur(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function Ba(t){return Bs(t.length>4&&"documents"===t.get(4)),t.popFirst(5)}function Ua(t,e,n){return{name:Ma(t,e),fields:n.value.mapValue.fields}}function qa(t,e,n){const s=Oa(t,e.name),r=ka(e.updateTime),i=new Ni({mapValue:{fields:e.fields}}),o=Ri.newFoundDocument(s,r,i);return n&&o.setHasCommittedMutations(),n?o.setHasCommittedMutations():o}function Ga(t,e){let n;if(e instanceof jo)n={update:Ua(t,e.key,e.value)};else if(e instanceof Wo)n={delete:Ma(t,e.key)};else if(e instanceof $o)n={update:Ua(t,e.key,e.data),updateMask:tu(e.fieldMask)};else{if(!(e instanceof Yo))return Ps();n={verify:Ma(t,e.key)}}return e.fieldTransforms.length>0&&(n.updateTransforms=e.fieldTransforms.map((t=>function(t,e){const n=e.transform;if(n instanceof xo)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof Ao)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof Co)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof ko)return{fieldPath:e.field.canonicalString(),increment:n.yt};throw Ps()}(0,t)))),e.precondition.isNone||(n.currentDocument=function(t,e){return void 0!==e.updateTime?{updateTime:Na(t,e.updateTime)}:void 0!==e.exists?{exists:e.exists}:Ps()}(t,e.precondition)),n}function Ka(t,e){const n=e.currentDocument?function(t){return void 0!==t.updateTime?Vo.updateTime(ka(t.updateTime)):void 0!==t.exists?Vo.exists(t.exists):Vo.none()}(e.currentDocument):Vo.none(),s=e.updateTransforms?e.updateTransforms.map((e=>function(t,e){let n=null;if("setToServerValue"in e)Bs("REQUEST_TIME"===e.setToServerValue),n=new xo;else if("appendMissingElements"in e){const t=e.appendMissingElements.values||[];n=new Ao(t)}else if("removeAllFromArray"in e){const t=e.removeAllFromArray.values||[];n=new Co(t)}else"increment"in e?n=new ko(t,e.increment):Ps();const s=hr.fromServerFormat(e.fieldPath);return new Mo(s,n)}(t,e))):[];if(e.update){e.update.name;const r=Oa(t,e.update.name),i=new Ni({mapValue:{fields:e.update.fields}});if(e.updateMask){const t=function(t){const e=t.fieldPaths||[];return new Hr(e.map((t=>hr.fromServerFormat(t))))}(e.updateMask);return new $o(r,i,t,n,s)}return new jo(r,i,n,s)}if(e.delete){const s=Oa(t,e.delete);return new Wo(s,n)}if(e.verify){const s=Oa(t,e.verify);return new Yo(s,n)}return Ps()}function ja(t,e){return{documents:[Va(t,e.path)]}}function $a(t,e){const n={structuredQuery:{}},s=e.path;null!==e.collectionGroup?(n.parent=Va(t,s),n.structuredQuery.from=[{collectionId:e.collectionGroup,allDescendants:!0}]):(n.parent=Va(t,s.popLast()),n.structuredQuery.from=[{collectionId:s.lastSegment()}]);const r=function(t){if(0===t.length)return;const e=t.map((t=>function(t){if("=="===t.op){if(Ei(t.value))return{unaryFilter:{field:Ya(t.field),op:"IS_NAN"}};if(bi(t.value))return{unaryFilter:{field:Ya(t.field),op:"IS_NULL"}}}else if("!="===t.op){if(Ei(t.value))return{unaryFilter:{field:Ya(t.field),op:"IS_NOT_NAN"}};if(bi(t.value))return{unaryFilter:{field:Ya(t.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:Ya(t.field),op:Wa(t.op),value:t.value}}}(t)));return 1===e.length?e[0]:{compositeFilter:{op:"AND",filters:e}}}(e.filters);r&&(n.structuredQuery.where=r);const i=function(t){if(0!==t.length)return t.map((t=>function(t){return{field:Ya(t.field),direction:Ha(t.dir)}}(t)))}(e.orderBy);i&&(n.structuredQuery.orderBy=i);const o=function(t,e){return t.gt||oi(e)?e:{value:e}}(t,e.limit);var a;return null!==o&&(n.structuredQuery.limit=o),e.startAt&&(n.structuredQuery.startAt={before:(a=e.startAt).inclusive,values:a.position}),e.endAt&&(n.structuredQuery.endAt=function(t){return{before:!t.inclusive,values:t.position}}(e.endAt)),n}function Qa(t){let e=Fa(t.parent);const n=t.structuredQuery,s=n.from?n.from.length:0;let r=null;if(s>0){Bs(1===s);const t=n.from[0];t.allDescendants?r=t.collectionId:e=e.child(t.collectionId)}let i=[];n.where&&(i=za(n.where));let o=[];n.orderBy&&(o=n.orderBy.map((t=>function(t){return new Xi(Xa(t.field),function(t){switch(t){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}}(t.direction))}(t))));let a=null;n.limit&&(a=function(t){let e;return e="object"==typeof t?t.value:t,oi(e)?null:e}(n.limit));let u=null;n.startAt&&(u=function(t){const e=!!t.before,n=t.values||[];return new Yi(n,e)}(n.startAt));let c=null;return n.endAt&&(c=function(t){const e=!t.before,n=t.values||[];return new Yi(n,e)}(n.endAt)),no(e,r,o,i,a,"F",u,c)}function za(t){return t?void 0!==t.unaryFilter?[Za(t)]:void 0!==t.fieldFilter?[Ja(t)]:void 0!==t.compositeFilter?t.compositeFilter.filters.map((t=>za(t))).reduce(((t,e)=>t.concat(e))):Ps():[]}function Ha(t){return _a[t]}function Wa(t){return xa[t]}function Ya(t){return{fieldPath:t.canonicalString()}}function Xa(t){return hr.fromServerFormat(t.fieldPath)}function Ja(t){return qi.create(Xa(t.fieldFilter.field),function(t){switch(t){case"EQUAL":return"==";case"NOT_EQUAL":return"!=";case"GREATER_THAN":return">";case"GREATER_THAN_OR_EQUAL":return">=";case"LESS_THAN":return"<";case"LESS_THAN_OR_EQUAL":return"<=";case"ARRAY_CONTAINS":return"array-contains";case"IN":return"in";case"NOT_IN":return"not-in";case"ARRAY_CONTAINS_ANY":return"array-contains-any";default:return Ps()}}(t.fieldFilter.op),t.fieldFilter.value)}function Za(t){switch(t.unaryFilter.op){case"IS_NAN":const e=Xa(t.unaryFilter.field);return qi.create(e,"==",{doubleValue:NaN});case"IS_NULL":const n=Xa(t.unaryFilter.field);return qi.create(n,"==",{nullValue:"NULL_VALUE"});case"IS_NOT_NAN":const s=Xa(t.unaryFilter.field);return qi.create(s,"!=",{doubleValue:NaN});case"IS_NOT_NULL":const r=Xa(t.unaryFilter.field);return qi.create(r,"!=",{nullValue:"NULL_VALUE"});default:return Ps()}}function tu(t){const e=[];return t.fields.forEach((t=>e.push(t.canonicalString()))),{fieldPaths:e}}function eu(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)}function nu(t){let e="";for(let n=0;n<t.length;n++)e.length>0&&(e=ru(e)),e=su(t.get(n),e);return ru(e)}function su(t,e){let n=e;const s=t.length;for(let e=0;e<s;e++){const s=t.charAt(e);switch(s){case"\0":n+="";break;case"":n+="";break;default:n+=s}}return n}function ru(t){return t+""}function iu(t){const e=t.length;if(Bs(e>=2),2===e)return Bs(""===t.charAt(0)&&""===t.charAt(1)),ur.emptyPath();const n=e-2,s=[];let r="";for(let i=0;i<e;){const e=t.indexOf("",i);switch((e<0||e>n)&&Ps(),t.charAt(e+1)){case"":const n=t.substring(i,e);let o;0===r.length?o=n:(r+=n,o=r,r=""),s.push(o);break;case"":r+=t.substring(i,e),r+="\0";break;case"":r+=t.substring(i,e+1);break;default:Ps()}i=e+2}return new ur(s)}const ou=["userId","batchId"];function au(t,e){return[t,nu(e)]}function uu(t,e,n){return[t,nu(e),n]}const cu={},hu=["prefixPath","collectionGroup","readTime","documentId"],lu=["prefixPath","collectionGroup","documentId"],du=["collectionGroup","readTime","prefixPath","documentId"],fu=["canonicalId","targetId"],mu=["targetId","path"],gu=["path","targetId"],pu=["collectionId","parent"],yu=["indexId","uid"],wu=["uid","sequenceNumber"],vu=["indexId","uid","arrayValue","directionalValue","orderedDocumentKey","documentKey"],Iu=["indexId","uid","orderedDocumentKey"],bu=["userId","collectionPath","documentId"],Eu=["userId","collectionPath","largestBatchId"],Tu=["userId","collectionGroup","largestBatchId"],Su=["mutationQueues","mutations","documentMutations","remoteDocuments","targets","owner","targetGlobal","targetDocuments","clientMetadata","remoteDocumentGlobal","collectionParents","bundles","namedQueries"],_u=[...Su,"documentOverlays"],xu=["mutationQueues","mutations","documentMutations","remoteDocumentsV14","targets","owner","targetGlobal","targetDocuments","clientMetadata","remoteDocumentGlobal","collectionParents","bundles","namedQueries","documentOverlays"],Au=xu,Du=[...Au,"indexConfiguration","indexState","indexEntries"];class Cu extends Sr{constructor(t,e){super(),this.ie=t,this.currentSequenceNumber=e}}function Nu(t,e){const n=qs(t);return Dr.M(n.ie,e)}class ku{constructor(t,e,n,s){this.batchId=t,this.localWriteTime=e,this.baseMutations=n,this.mutations=s}applyToRemoteDocument(t,e){const n=e.mutationResults;for(let e=0;e<this.mutations.length;e++){const s=this.mutations[e];s.key.isEqual(t.key)&&Uo(s,t,n[e])}}applyToLocalView(t,e){for(const n of this.baseMutations)n.key.isEqual(t.key)&&(e=qo(n,t,e,this.localWriteTime));for(const n of this.mutations)n.key.isEqual(t.key)&&(e=qo(n,t,e,this.localWriteTime));return e}applyToLocalDocumentSet(t,e){const n=ca();return this.mutations.forEach((s=>{const r=t.get(s.key),i=r.overlayedDocument;let o=this.applyToLocalView(i,r.mutatedFields);o=e.has(s.key)?null:o;const a=Bo(i,o);null!==a&&n.set(s.key,a),i.isValidDocument()||i.convertToNoDocument(or.min())})),n}keys(){return this.mutations.reduce(((t,e)=>t.add(e.key)),fa())}isEqual(t){return this.batchId===t.batchId&&sr(this.mutations,t.mutations,((t,e)=>Ko(t,e)))&&sr(this.baseMutations,t.baseMutations,((t,e)=>Ko(t,e)))}}class Ru{constructor(t,e,n,s){this.batch=t,this.commitVersion=e,this.mutationResults=n,this.docVersions=s}static from(t,e,n){Bs(t.mutations.length===n.length);let s=la;const r=t.mutations;for(let t=0;t<r.length;t++)s=s.insert(r[t].key,n[t].version);return new Ru(t,e,n,s)}}class Lu{constructor(t,e){this.largestBatchId=t,this.mutation=e}getKey(){return this.mutation.key}isEqual(t){return null!==t&&this.mutation===t.mutation}toString(){return`Overlay{\n largestBatchId: ${this.largestBatchId},\n mutation: ${this.mutation.toString()}\n }`}}class Mu{constructor(t,e,n,s,r=or.min(),i=or.min(),o=Yr.EMPTY_BYTE_STRING){this.target=t,this.targetId=e,this.purpose=n,this.sequenceNumber=s,this.snapshotVersion=r,this.lastLimboFreeSnapshotVersion=i,this.resumeToken=o}withSequenceNumber(t){return new Mu(this.target,this.targetId,this.purpose,t,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken)}withResumeToken(t,e){return new Mu(this.target,this.targetId,this.purpose,this.sequenceNumber,e,this.lastLimboFreeSnapshotVersion,t)}withLastLimboFreeSnapshotVersion(t){return new Mu(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,t,this.resumeToken)}}class Ou{constructor(t){this.re=t}}function Vu(t,e){const n=e.key,s={prefixPath:n.getCollectionPath().popLast().toArray(),collectionGroup:n.collectionGroup,documentId:n.path.lastSegment(),readTime:Fu(e.readTime),hasCommittedMutations:e.hasCommittedMutations};if(e.isFoundDocument())s.document=function(t,e){return{name:Ma(t,e.key),fields:e.data.value.mapValue.fields,updateTime:Da(t,e.version.toTimestamp())}}(t.re,e);else if(e.isNoDocument())s.noDocument={path:n.path.toArray(),readTime:Pu(e.version)};else{if(!e.isUnknownDocument())return Ps();s.unknownDocument={path:n.path.toArray(),version:Pu(e.version)}}return s}function Fu(t){const e=t.toTimestamp();return[e.seconds,e.nanoseconds]}function Pu(t){const e=t.toTimestamp();return{seconds:e.seconds,nanoseconds:e.nanoseconds}}function Bu(t){const e=new ir(t.seconds,t.nanoseconds);return or.fromTimestamp(e)}function Uu(t,e){const n=(e.baseMutations||[]).map((e=>Ka(t.re,e)));for(let t=0;t<e.mutations.length-1;++t){const n=e.mutations[t];if(t+1<e.mutations.length&&void 0!==e.mutations[t+1].transform){const s=e.mutations[t+1];n.updateTransforms=s.transform.fieldTransforms,e.mutations.splice(t+1,1),++t}}const s=e.mutations.map((e=>Ka(t.re,e))),r=ir.fromMillis(e.localWriteTimeMs);return new ku(e.batchId,r,n,s)}function qu(t){const e=Bu(t.readTime),n=void 0!==t.lastLimboFreeSnapshotVersion?Bu(t.lastLimboFreeSnapshotVersion):or.min();let s;var r;return void 0!==t.query.documents?(Bs(1===(r=t.query).documents.length),s=co(so(Fa(r.documents[0])))):s=function(t){return co(Qa(t))}(t.query),new Mu(s,t.targetId,0,t.lastListenSequenceNumber,e,n,Yr.fromBase64String(t.resumeToken))}function Gu(t,e){const n=Pu(e.snapshotVersion),s=Pu(e.lastLimboFreeSnapshotVersion);let r;r=Fi(e.target)?ja(t.re,e.target):$a(t.re,e.target);const i=e.resumeToken.toBase64();return{targetId:e.targetId,canonicalId:Oi(e.target),readTime:n,resumeToken:i,lastListenSequenceNumber:e.sequenceNumber,lastLimboFreeSnapshotVersion:s,query:r}}function Ku(t){const e=Qa({parent:t.parent,structuredQuery:t.structuredQuery});return"LAST"===t.limitType?ho(e,e.limit,"L"):e}function ju(t,e){return new Lu(e.largestBatchId,Ka(t.re,e.overlayMutation))}function $u(t,e){const n=e.path.lastSegment();return[t,nu(e.path.popLast()),n]}function Qu(t,e,n,s){return{indexId:t,uid:e.uid||"",sequenceNumber:n,readTime:Pu(s.readTime),documentKey:nu(s.documentKey.path),largestBatchId:s.largestBatchId}}class zu{getBundleMetadata(t,e){return Hu(t).get(e).next((t=>{if(t)return{id:(e=t).bundleId,createTime:Bu(e.createTime),version:e.version};var e}))}saveBundleMetadata(t,e){return Hu(t).put({bundleId:(n=e).id,createTime:Pu(ka(n.createTime)),version:n.version});var n}getNamedQuery(t,e){return Wu(t).get(e).next((t=>{if(t)return{name:(e=t).name,query:Ku(e.bundledQuery),readTime:Bu(e.readTime)};var e}))}saveNamedQuery(t,e){return Wu(t).put(function(t){return{name:t.name,readTime:Pu(ka(t.readTime)),bundledQuery:t.bundledQuery}}(e))}}function Hu(t){return Nu(t,"bundles")}function Wu(t){return Nu(t,"namedQueries")}class Yu{constructor(t,e){this.It=t,this.userId=e}static oe(t,e){const n=e.uid||"";return new Yu(t,n)}getOverlay(t,e){return Xu(t).get($u(this.userId,e)).next((t=>t?ju(this.It,t):null))}getOverlays(t,e){const n=ua();return xr.forEach(e,(e=>this.getOverlay(t,e).next((t=>{null!==t&&n.set(e,t)})))).next((()=>n))}saveOverlays(t,e,n){const s=[];return n.forEach(((n,r)=>{const i=new Lu(e,r);s.push(this.ue(t,i))})),xr.waitFor(s)}removeOverlaysForBatchId(t,e,n){const s=new Set;e.forEach((t=>s.add(nu(t.getCollectionPath()))));const r=[];return s.forEach((e=>{const s=IDBKeyRange.bound([this.userId,e,n],[this.userId,e,n+1],!1,!0);r.push(Xu(t).Y("collectionPathOverlayIndex",s))})),xr.waitFor(r)}getOverlaysForCollection(t,e,n){const s=ua(),r=nu(e),i=IDBKeyRange.bound([this.userId,r,n],[this.userId,r,Number.POSITIVE_INFINITY],!0);return Xu(t).W("collectionPathOverlayIndex",i).next((t=>{for(const e of t){const t=ju(this.It,e);s.set(t.getKey(),t)}return s}))}getOverlaysForCollectionGroup(t,e,n,s){const r=ua();let i;const o=IDBKeyRange.bound([this.userId,e,n],[this.userId,e,Number.POSITIVE_INFINITY],!0);return Xu(t).Z({index:"collectionGroupOverlayIndex",range:o},((t,e,n)=>{const o=ju(this.It,e);r.size()<s||o.largestBatchId===i?(r.set(o.getKey(),o),i=o.largestBatchId):n.done()})).next((()=>r))}ue(t,e){return Xu(t).put(function(t,e,n){const[s,r,i]=$u(e,n.mutation.key);return{userId:e,collectionPath:r,documentId:i,collectionGroup:n.mutation.key.getCollectionGroup(),largestBatchId:n.largestBatchId,overlayMutation:Ga(t.re,n.mutation)}}(this.It,this.userId,e))}}function Xu(t){return Nu(t,"documentOverlays")}class Ju{constructor(){}ce(t,e){this.ae(t,e),e.he()}ae(t,e){if("nullValue"in t)this.le(e,5);else if("booleanValue"in t)this.le(e,10),e.fe(t.booleanValue?1:0);else if("integerValue"in t)this.le(e,15),e.fe(Zr(t.integerValue));else if("doubleValue"in t){const n=Zr(t.doubleValue);isNaN(n)?this.le(e,13):(this.le(e,15),ai(n)?e.fe(0):e.fe(n))}else if("timestampValue"in t){const n=t.timestampValue;this.le(e,20),"string"==typeof n?e.de(n):(e.de(`${n.seconds||""}`),e.fe(n.nanos||0))}else if("stringValue"in t)this._e(t.stringValue,e),this.we(e);else if("bytesValue"in t)this.le(e,30),e.me(ti(t.bytesValue)),this.we(e);else if("referenceValue"in t)this.ge(t.referenceValue,e);else if("geoPointValue"in t){const n=t.geoPointValue;this.le(e,45),e.fe(n.latitude||0),e.fe(n.longitude||0)}else"mapValue"in t?_i(t)?this.le(e,Number.MAX_SAFE_INTEGER):(this.ye(t.mapValue,e),this.we(e)):"arrayValue"in t?(this.pe(t.arrayValue,e),this.we(e)):Ps()}_e(t,e){this.le(e,25),this.Ie(t,e)}Ie(t,e){e.de(t)}ye(t,e){const n=t.fields||{};this.le(e,55);for(const t of Object.keys(n))this._e(t,e),this.ae(n[t],e)}pe(t,e){const n=t.values||[];this.le(e,50);for(const t of n)this.ae(t,e)}ge(t,e){this.le(e,37),lr.fromName(t).path.forEach((t=>{this.le(e,60),this.Ie(t,e)}))}le(t,e){t.fe(e)}we(t){t.fe(2)}}function Zu(t){if(0===t)return 8;let e=0;return t>>4==0&&(e+=4,t<<=4),t>>6==0&&(e+=2,t<<=2),t>>7==0&&(e+=1),e}function tc(t){const e=64-function(t){let e=0;for(let n=0;n<8;++n){const s=Zu(255&t[n]);if(e+=s,8!==s)break}return e}(t);return Math.ceil(e/8)}Ju.Te=new Ju;class ec{constructor(){this.buffer=new Uint8Array(1024),this.position=0}Ee(t){const e=t[Symbol.iterator]();let n=e.next();for(;!n.done;)this.Ae(n.value),n=e.next();this.Re()}be(t){const e=t[Symbol.iterator]();let n=e.next();for(;!n.done;)this.Pe(n.value),n=e.next();this.ve()}Ve(t){for(const e of t){const t=e.charCodeAt(0);if(t<128)this.Ae(t);else if(t<2048)this.Ae(960|t>>>6),this.Ae(128|63&t);else if(e<"\ud800"||"\udbff"<e)this.Ae(480|t>>>12),this.Ae(128|63&t>>>6),this.Ae(128|63&t);else{const t=e.codePointAt(0);this.Ae(240|t>>>18),this.Ae(128|63&t>>>12),this.Ae(128|63&t>>>6),this.Ae(128|63&t)}}this.Re()}Se(t){for(const e of t){const t=e.charCodeAt(0);if(t<128)this.Pe(t);else if(t<2048)this.Pe(960|t>>>6),this.Pe(128|63&t);else if(e<"\ud800"||"\udbff"<e)this.Pe(480|t>>>12),this.Pe(128|63&t>>>6),this.Pe(128|63&t);else{const t=e.codePointAt(0);this.Pe(240|t>>>18),this.Pe(128|63&t>>>12),this.Pe(128|63&t>>>6),this.Pe(128|63&t)}}this.ve()}De(t){const e=this.Ce(t),n=tc(e);this.xe(1+n),this.buffer[this.position++]=255&n;for(let t=e.length-n;t<e.length;++t)this.buffer[this.position++]=255&e[t]}Ne(t){const e=this.Ce(t),n=tc(e);this.xe(1+n),this.buffer[this.position++]=~(255&n);for(let t=e.length-n;t<e.length;++t)this.buffer[this.position++]=~(255&e[t])}ke(){this.Oe(255),this.Oe(255)}Me(){this.Fe(255),this.Fe(255)}reset(){this.position=0}seed(t){this.xe(t.length),this.buffer.set(t,this.position),this.position+=t.length}$e(){return this.buffer.slice(0,this.position)}Ce(t){const e=function(t){const e=new DataView(new ArrayBuffer(8));return e.setFloat64(0,t,!1),new Uint8Array(e.buffer)}(t),n=0!=(128&e[0]);e[0]^=n?255:128;for(let t=1;t<e.length;++t)e[t]^=n?255:0;return e}Ae(t){const e=255&t;0===e?(this.Oe(0),this.Oe(255)):255===e?(this.Oe(255),this.Oe(0)):this.Oe(e)}Pe(t){const e=255&t;0===e?(this.Fe(0),this.Fe(255)):255===e?(this.Fe(255),this.Fe(0)):this.Fe(t)}Re(){this.Oe(0),this.Oe(1)}ve(){this.Fe(0),this.Fe(1)}Oe(t){this.xe(1),this.buffer[this.position++]=t}Fe(t){this.xe(1),this.buffer[this.position++]=~t}xe(t){const e=t+this.position;if(e<=this.buffer.length)return;let n=2*this.buffer.length;n<e&&(n=e);const s=new Uint8Array(n);s.set(this.buffer),this.buffer=s}}class nc{constructor(t){this.Be=t}me(t){this.Be.Ee(t)}de(t){this.Be.Ve(t)}fe(t){this.Be.De(t)}he(){this.Be.ke()}}class sc{constructor(t){this.Be=t}me(t){this.Be.be(t)}de(t){this.Be.Se(t)}fe(t){this.Be.Ne(t)}he(){this.Be.Me()}}class rc{constructor(){this.Be=new ec,this.Le=new nc(this.Be),this.Ue=new sc(this.Be)}seed(t){this.Be.seed(t)}qe(t){return 0===t?this.Le:this.Ue}$e(){return this.Be.$e()}reset(){this.Be.reset()}}class ic{constructor(t,e,n,s){this.indexId=t,this.documentKey=e,this.arrayValue=n,this.directionalValue=s}Ke(){const t=this.directionalValue.length,e=0===t||255===this.directionalValue[t-1]?t+1:t,n=new Uint8Array(e);return n.set(this.directionalValue,0),e!==t?n.set([0],this.directionalValue.length):++n[n.length-1],new ic(this.indexId,this.documentKey,this.arrayValue,n)}}function oc(t,e){let n=t.indexId-e.indexId;return 0!==n?n:(n=ac(t.arrayValue,e.arrayValue),0!==n?n:(n=ac(t.directionalValue,e.directionalValue),0!==n?n:lr.comparator(t.documentKey,e.documentKey)))}function ac(t,e){for(let n=0;n<t.length&&n<e.length;++n){const s=t[n]-e[n];if(0!==s)return s}return t.length-e.length}class uc{constructor(t){this.collectionId=null!=t.collectionGroup?t.collectionGroup:t.path.lastSegment(),this.Ge=t.orderBy,this.Qe=[];for(const e of t.filters){const t=e;t.dt()?this.je=t:this.Qe.push(t)}}We(t){const e=fr(t);if(void 0!==e&&!this.ze(e))return!1;const n=mr(t);let s=0,r=0;for(;s<n.length&&this.ze(n[s]);++s);if(s===n.length)return!0;if(void 0!==this.je){const t=n[s];if(!this.He(this.je,t)||!this.Je(this.Ge[r++],t))return!1;++s}for(;s<n.length;++s){const t=n[s];if(r>=this.Ge.length||!this.Je(this.Ge[r++],t))return!1}return!0}ze(t){for(const e of this.Qe)if(this.He(e,t))return!0;return!1}He(t,e){if(void 0===t||!t.field.isEqual(e.fieldPath))return!1;const n="array-contains"===t.op||"array-contains-any"===t.op;return 2===e.kind===n}Je(t,e){return!!t.field.isEqual(e.fieldPath)&&(0===e.kind&&"asc"===t.dir||1===e.kind&&"desc"===t.dir)}}class cc{constructor(){this.Ye=new hc}addToCollectionParentIndex(t,e){return this.Ye.add(e),xr.resolve()}getCollectionParents(t,e){return xr.resolve(this.Ye.getEntries(e))}addFieldIndex(t,e){return xr.resolve()}deleteFieldIndex(t,e){return xr.resolve()}getDocumentsMatchingTarget(t,e){return xr.resolve(null)}getIndexType(t,e){return xr.resolve(0)}getFieldIndexes(t,e){return xr.resolve([])}getNextCollectionGroupToUpdate(t){return xr.resolve(null)}getMinOffset(t,e){return xr.resolve(br.min())}getMinOffsetFromCollectionGroup(t,e){return xr.resolve(br.min())}updateCollectionGroup(t,e,n){return xr.resolve()}updateIndexEntries(t,e){return xr.resolve()}}class hc{constructor(){this.index={}}add(t){const e=t.lastSegment(),n=t.popLast(),s=this.index[e]||new $r(ur.comparator),r=!s.has(n);return this.index[e]=s.add(n),r}has(t){const e=t.lastSegment(),n=t.popLast(),s=this.index[e];return s&&s.has(n)}getEntries(t){return(this.index[t]||new $r(ur.comparator)).toArray()}}const lc=new Uint8Array(0);class dc{constructor(t,e){this.user=t,this.databaseId=e,this.Xe=new hc,this.Ze=new na((t=>Oi(t)),((t,e)=>Vi(t,e))),this.uid=t.uid||""}addToCollectionParentIndex(t,e){if(!this.Xe.has(e)){const n=e.lastSegment(),s=e.popLast();t.addOnCommittedListener((()=>{this.Xe.add(e)}));const r={collectionId:n,parent:nu(s)};return fc(t).put(r)}return xr.resolve()}getCollectionParents(t,e){const n=[],s=IDBKeyRange.bound([e,""],[rr(e),""],!1,!0);return fc(t).W(s).next((t=>{for(const s of t){if(s.collectionId!==e)break;n.push(iu(s.parent))}return n}))}addFieldIndex(t,e){const n=gc(t),s=function(t){return{indexId:t.indexId,collectionGroup:t.collectionGroup,fields:t.fields.map((t=>[t.fieldPath.canonicalString(),t.kind]))}}(e);delete s.indexId;const r=n.add(s);if(e.indexState){const n=pc(t);return r.next((t=>{n.put(Qu(t,this.user,e.indexState.sequenceNumber,e.indexState.offset))}))}return r.next()}deleteFieldIndex(t,e){const n=gc(t),s=pc(t),r=mc(t);return n.delete(e.indexId).next((()=>s.delete(IDBKeyRange.bound([e.indexId],[e.indexId+1],!1,!0)))).next((()=>r.delete(IDBKeyRange.bound([e.indexId],[e.indexId+1],!1,!0))))}getDocumentsMatchingTarget(t,e){const n=mc(t);let s=!0;const r=new Map;return xr.forEach(this.tn(e),(e=>this.en(t,e).next((t=>{s&&(s=!!t),r.set(e,t)})))).next((()=>{if(s){let t=fa();const s=[];return xr.forEach(r,((r,i)=>{var o;Ms("IndexedDbIndexManager",`Using index ${o=r,`id=${o.indexId}|cg=${o.collectionGroup}|f=${o.fields.map((t=>`${t.fieldPath}:${t.kind}`)).join(",")}`} to execute ${Oi(e)}`);const a=function(t,e){const n=fr(e);if(void 0===n)return null;for(const e of Pi(t,n.fieldPath))switch(e.op){case"array-contains-any":return e.value.arrayValue.values||[];case"array-contains":return[e.value]}return null}(i,r),u=function(t,e){const n=new Map;for(const s of mr(e))for(const e of Pi(t,s.fieldPath))switch(e.op){case"==":case"in":n.set(s.fieldPath.canonicalString(),e.value);break;case"not-in":case"!=":return n.set(s.fieldPath.canonicalString(),e.value),Array.from(n.values())}return null}(i,r),c=function(t,e){const n=[];let s=!0;for(const r of mr(e)){const e=0===r.kind?Bi(t,r.fieldPath,t.startAt):Ui(t,r.fieldPath,t.startAt);n.push(e.value),s&&(s=e.inclusive)}return new Yi(n,s)}(i,r),h=function(t,e){const n=[];let s=!0;for(const r of mr(e)){const e=0===r.kind?Ui(t,r.fieldPath,t.endAt):Bi(t,r.fieldPath,t.endAt);n.push(e.value),s&&(s=e.inclusive)}return new Yi(n,s)}(i,r),l=this.nn(r,i,c),d=this.nn(r,i,h),f=this.sn(r,i,u),m=this.rn(r.indexId,a,l,c.inclusive,d,h.inclusive,f);return xr.forEach(m,(r=>n.J(r,e.limit).next((e=>{e.forEach((e=>{const n=lr.fromSegments(e.documentKey);t.has(n)||(t=t.add(n),s.push(n))}))}))))})).next((()=>s))}return xr.resolve(null)}))}tn(t){let e=this.Ze.get(t);return e||(e=[t],this.Ze.set(t,e),e)}rn(t,e,n,s,r,i,o){const a=(null!=e?e.length:1)*Math.max(n.length,r.length),u=a/(null!=e?e.length:1),c=[];for(let h=0;h<a;++h){const a=e?this.on(e[h/u]):lc,l=this.un(t,a,n[h%u],s),d=this.cn(t,a,r[h%u],i),f=o.map((e=>this.un(t,a,e,!0)));c.push(...this.createRange(l,d,f))}return c}un(t,e,n,s){const r=new ic(t,lr.empty(),e,n);return s?r:r.Ke()}cn(t,e,n,s){const r=new ic(t,lr.empty(),e,n);return s?r.Ke():r}en(t,e){const n=new uc(e),s=null!=e.collectionGroup?e.collectionGroup:e.path.lastSegment();return this.getFieldIndexes(t,s).next((t=>{let e=null;for(const s of t)n.We(s)&&(!e||s.fields.length>e.fields.length)&&(e=s);return e}))}getIndexType(t,e){let n=2;return xr.forEach(this.tn(e),(e=>this.en(t,e).next((t=>{t?0!==n&&t.fields.length<function(t){let e=new $r(hr.comparator),n=!1;for(const s of t.filters){const t=s;t.field.isKeyField()||("array-contains"===t.op||"array-contains-any"===t.op?n=!0:e=e.add(t.field))}for(const n of t.orderBy)n.field.isKeyField()||(e=e.add(n.field));return e.size+(n?1:0)}(e)&&(n=1):n=0})))).next((()=>n))}an(t,e){const n=new rc;for(const s of mr(t)){const t=e.data.field(s.fieldPath);if(null==t)return null;const r=n.qe(s.kind);Ju.Te.ce(t,r)}return n.$e()}on(t){const e=new rc;return Ju.Te.ce(t,e.qe(0)),e.$e()}hn(t,e){const n=new rc;return Ju.Te.ce(wi(this.databaseId,e),n.qe(function(t){const e=mr(t);return 0===e.length?0:e[e.length-1].kind}(t))),n.$e()}sn(t,e,n){if(null===n)return[];let s=[];s.push(new rc);let r=0;for(const i of mr(t)){const t=n[r++];for(const n of s)if(this.ln(e,i.fieldPath)&&Ii(t))s=this.fn(s,i,t);else{const e=n.qe(i.kind);Ju.Te.ce(t,e)}}return this.dn(s)}nn(t,e,n){return this.sn(t,e,n.position)}dn(t){const e=[];for(let n=0;n<t.length;++n)e[n]=t[n].$e();return e}fn(t,e,n){const s=[...t],r=[];for(const t of n.arrayValue.values||[])for(const n of s){const s=new rc;s.seed(n.$e()),Ju.Te.ce(t,s.qe(e.kind)),r.push(s)}return r}ln(t,e){return!!t.filters.find((t=>t instanceof qi&&t.field.isEqual(e)&&("in"===t.op||"not-in"===t.op)))}getFieldIndexes(t,e){const n=gc(t),s=pc(t);return(e?n.W("collectionGroupIndex",IDBKeyRange.bound(e,e)):n.W()).next((t=>{const e=[];return xr.forEach(t,(t=>s.get([t.indexId,this.uid]).next((n=>{e.push(function(t,e){const n=e?new wr(e.sequenceNumber,new br(Bu(e.readTime),new lr(iu(e.documentKey)),e.largestBatchId)):wr.empty(),s=t.fields.map((([t,e])=>new pr(hr.fromServerFormat(t),e)));return new dr(t.indexId,t.collectionGroup,s,n)}(t,n))})))).next((()=>e))}))}getNextCollectionGroupToUpdate(t){return this.getFieldIndexes(t).next((t=>0===t.length?null:(t.sort(((t,e)=>{const n=t.indexState.sequenceNumber-e.indexState.sequenceNumber;return 0!==n?n:nr(t.collectionGroup,e.collectionGroup)})),t[0].collectionGroup)))}updateCollectionGroup(t,e,n){const s=gc(t),r=pc(t);return this._n(t).next((t=>s.W("collectionGroupIndex",IDBKeyRange.bound(e,e)).next((e=>xr.forEach(e,(e=>r.put(Qu(e.indexId,this.user,t,n))))))))}updateIndexEntries(t,e){const n=new Map;return xr.forEach(e,((e,s)=>{const r=n.get(e.collectionGroup);return(r?xr.resolve(r):this.getFieldIndexes(t,e.collectionGroup)).next((r=>(n.set(e.collectionGroup,r),xr.forEach(r,(n=>this.wn(t,e,n).next((e=>{const r=this.mn(s,n);return e.isEqual(r)?xr.resolve():this.gn(t,s,n,e,r)})))))))}))}yn(t,e,n,s){return mc(t).put({indexId:s.indexId,uid:this.uid,arrayValue:s.arrayValue,directionalValue:s.directionalValue,orderedDocumentKey:this.hn(n,e.key),documentKey:e.key.path.toArray()})}pn(t,e,n,s){return mc(t).delete([s.indexId,this.uid,s.arrayValue,s.directionalValue,this.hn(n,e.key),e.key.path.toArray()])}wn(t,e,n){const s=mc(t);let r=new $r(oc);return s.Z({index:"documentKeyIndex",range:IDBKeyRange.only([n.indexId,this.uid,this.hn(n,e)])},((t,s)=>{r=r.add(new ic(n.indexId,e,s.arrayValue,s.directionalValue))})).next((()=>r))}mn(t,e){let n=new $r(oc);const s=this.an(e,t);if(null==s)return n;const r=fr(e);if(null!=r){const i=t.data.field(r.fieldPath);if(Ii(i))for(const r of i.arrayValue.values||[])n=n.add(new ic(e.indexId,t.key,this.on(r),s))}else n=n.add(new ic(e.indexId,t.key,lc,s));return n}gn(t,e,n,s,r){Ms("IndexedDbIndexManager","Updating index entries for document '%s'",e.key);const i=[];return function(t,e,n,s,r){const i=t.getIterator(),o=e.getIterator();let a=zr(i),u=zr(o);for(;a||u;){let t=!1,e=!1;if(a&&u){const s=n(a,u);s<0?e=!0:s>0&&(t=!0)}else null!=a?e=!0:t=!0;t?(s(u),u=zr(o)):e?(r(a),a=zr(i)):(a=zr(i),u=zr(o))}}(s,r,oc,(s=>{i.push(this.yn(t,e,n,s))}),(s=>{i.push(this.pn(t,e,n,s))})),xr.waitFor(i)}_n(t){let e=1;return pc(t).Z({index:"sequenceNumberIndex",reverse:!0,range:IDBKeyRange.upperBound([this.uid,Number.MAX_SAFE_INTEGER])},((t,n,s)=>{s.done(),e=n.sequenceNumber+1})).next((()=>e))}createRange(t,e,n){n=n.sort(((t,e)=>oc(t,e))).filter(((t,e,n)=>!e||0!==oc(t,n[e-1])));const s=[];s.push(t);for(const r of n){const n=oc(r,t),i=oc(r,e);if(0===n)s[0]=t.Ke();else if(n>0&&i<0)s.push(r),s.push(r.Ke());else if(i>0)break}s.push(e);const r=[];for(let t=0;t<s.length;t+=2)r.push(IDBKeyRange.bound([s[t].indexId,this.uid,s[t].arrayValue,s[t].directionalValue,lc,[]],[s[t+1].indexId,this.uid,s[t+1].arrayValue,s[t+1].directionalValue,lc,[]]));return r}getMinOffsetFromCollectionGroup(t,e){return this.getFieldIndexes(t,e).next(yc)}getMinOffset(t,e){return xr.mapArray(this.tn(e),(e=>this.en(t,e).next((t=>t||Ps())))).next(yc)}}function fc(t){return Nu(t,"collectionParents")}function mc(t){return Nu(t,"indexEntries")}function gc(t){return Nu(t,"indexConfiguration")}function pc(t){return Nu(t,"indexState")}function yc(t){Bs(0!==t.length);let e=t[0].indexState.offset,n=e.largestBatchId;for(let s=1;s<t.length;s++){const r=t[s].indexState.offset;Er(r,e)<0&&(e=r),n<r.largestBatchId&&(n=r.largestBatchId)}return new br(e.readTime,e.documentKey,n)}const wc={didRun:!1,sequenceNumbersCollected:0,targetsRemoved:0,documentsRemoved:0};class vc{constructor(t,e,n){this.cacheSizeCollectionThreshold=t,this.percentileToCollect=e,this.maximumSequenceNumbersToCollect=n}static withCacheSize(t){return new vc(t,vc.DEFAULT_COLLECTION_PERCENTILE,vc.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)}}function Ic(t,e,n){const s=t.store("mutations"),r=t.store("documentMutations"),i=[],o=IDBKeyRange.only(n.batchId);let a=0;const u=s.Z({range:o},((t,e,n)=>(a++,n.delete())));i.push(u.next((()=>{Bs(1===a)})));const c=[];for(const t of n.mutations){const s=uu(e,t.key.path,n.batchId);i.push(r.delete(s)),c.push(t.key)}return xr.waitFor(i).next((()=>c))}function bc(t){if(!t)return 0;let e;if(t.document)e=t.document;else if(t.unknownDocument)e=t.unknownDocument;else{if(!t.noDocument)throw Ps();e=t.noDocument}return JSON.stringify(e).length}vc.DEFAULT_COLLECTION_PERCENTILE=10,vc.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,vc.DEFAULT=new vc(41943040,vc.DEFAULT_COLLECTION_PERCENTILE,vc.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),vc.DISABLED=new vc(-1,0,0);class Ec{constructor(t,e,n,s){this.userId=t,this.It=e,this.indexManager=n,this.referenceDelegate=s,this.In={}}static oe(t,e,n,s){Bs(""!==t.uid);const r=t.isAuthenticated()?t.uid:"";return new Ec(r,e,n,s)}checkEmpty(t){let e=!0;const n=IDBKeyRange.bound([this.userId,Number.NEGATIVE_INFINITY],[this.userId,Number.POSITIVE_INFINITY]);return Sc(t).Z({index:"userMutationsIndex",range:n},((t,n,s)=>{e=!1,s.done()})).next((()=>e))}addMutationBatch(t,e,n,s){const r=_c(t),i=Sc(t);return i.add({}).next((o=>{Bs("number"==typeof o);const a=new ku(o,e,n,s),u=function(t,e,n){const s=n.baseMutations.map((e=>Ga(t.re,e))),r=n.mutations.map((e=>Ga(t.re,e)));return{userId:e,batchId:n.batchId,localWriteTimeMs:n.localWriteTime.toMillis(),baseMutations:s,mutations:r}}(this.It,this.userId,a),c=[];let h=new $r(((t,e)=>nr(t.canonicalString(),e.canonicalString())));for(const t of s){const e=uu(this.userId,t.key.path,o);h=h.add(t.key.path.popLast()),c.push(i.put(u)),c.push(r.put(e,cu))}return h.forEach((e=>{c.push(this.indexManager.addToCollectionParentIndex(t,e))})),t.addOnCommittedListener((()=>{this.In[o]=a.keys()})),xr.waitFor(c).next((()=>a))}))}lookupMutationBatch(t,e){return Sc(t).get(e).next((t=>t?(Bs(t.userId===this.userId),Uu(this.It,t)):null))}Tn(t,e){return this.In[e]?xr.resolve(this.In[e]):this.lookupMutationBatch(t,e).next((t=>{if(t){const n=t.keys();return this.In[e]=n,n}return null}))}getNextMutationBatchAfterBatchId(t,e){const n=e+1,s=IDBKeyRange.lowerBound([this.userId,n]);let r=null;return Sc(t).Z({index:"userMutationsIndex",range:s},((t,e,s)=>{e.userId===this.userId&&(Bs(e.batchId>=n),r=Uu(this.It,e)),s.done()})).next((()=>r))}getHighestUnacknowledgedBatchId(t){const e=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]);let n=-1;return Sc(t).Z({index:"userMutationsIndex",range:e,reverse:!0},((t,e,s)=>{n=e.batchId,s.done()})).next((()=>n))}getAllMutationBatches(t){const e=IDBKeyRange.bound([this.userId,-1],[this.userId,Number.POSITIVE_INFINITY]);return Sc(t).W("userMutationsIndex",e).next((t=>t.map((t=>Uu(this.It,t)))))}getAllMutationBatchesAffectingDocumentKey(t,e){const n=au(this.userId,e.path),s=IDBKeyRange.lowerBound(n),r=[];return _c(t).Z({range:s},((n,s,i)=>{const[o,a,u]=n,c=iu(a);if(o===this.userId&&e.path.isEqual(c))return Sc(t).get(u).next((t=>{if(!t)throw Ps();Bs(t.userId===this.userId),r.push(Uu(this.It,t))}));i.done()})).next((()=>r))}getAllMutationBatchesAffectingDocumentKeys(t,e){let n=new $r(nr);const s=[];return e.forEach((e=>{const r=au(this.userId,e.path),i=IDBKeyRange.lowerBound(r),o=_c(t).Z({range:i},((t,s,r)=>{const[i,o,a]=t,u=iu(o);i===this.userId&&e.path.isEqual(u)?n=n.add(a):r.done()}));s.push(o)})),xr.waitFor(s).next((()=>this.En(t,n)))}getAllMutationBatchesAffectingQuery(t,e){const n=e.path,s=n.length+1,r=au(this.userId,n),i=IDBKeyRange.lowerBound(r);let o=new $r(nr);return _c(t).Z({range:i},((t,e,r)=>{const[i,a,u]=t,c=iu(a);i===this.userId&&n.isPrefixOf(c)?c.length===s&&(o=o.add(u)):r.done()})).next((()=>this.En(t,o)))}En(t,e){const n=[],s=[];return e.forEach((e=>{s.push(Sc(t).get(e).next((t=>{if(null===t)throw Ps();Bs(t.userId===this.userId),n.push(Uu(this.It,t))})))})),xr.waitFor(s).next((()=>n))}removeMutationBatch(t,e){return Ic(t.ie,this.userId,e).next((n=>(t.addOnCommittedListener((()=>{this.An(e.batchId)})),xr.forEach(n,(e=>this.referenceDelegate.markPotentiallyOrphaned(t,e))))))}An(t){delete this.In[t]}performConsistencyCheck(t){return this.checkEmpty(t).next((e=>{if(!e)return xr.resolve();const n=IDBKeyRange.lowerBound([this.userId]),s=[];return _c(t).Z({range:n},((t,e,n)=>{if(t[0]===this.userId){const e=iu(t[1]);s.push(e)}else n.done()})).next((()=>{Bs(0===s.length)}))}))}containsKey(t,e){return Tc(t,this.userId,e)}Rn(t){return xc(t).get(this.userId).next((t=>t||{userId:this.userId,lastAcknowledgedBatchId:-1,lastStreamToken:""}))}}function Tc(t,e,n){const s=au(e,n.path),r=s[1],i=IDBKeyRange.lowerBound(s);let o=!1;return _c(t).Z({range:i,X:!0},((t,n,s)=>{const[i,a,u]=t;i===e&&a===r&&(o=!0),s.done()})).next((()=>o))}function Sc(t){return Nu(t,"mutations")}function _c(t){return Nu(t,"documentMutations")}function xc(t){return Nu(t,"mutationQueues")}class Ac{constructor(t){this.bn=t}next(){return this.bn+=2,this.bn}static Pn(){return new Ac(0)}static vn(){return new Ac(-1)}}class Dc{constructor(t,e){this.referenceDelegate=t,this.It=e}allocateTargetId(t){return this.Vn(t).next((e=>{const n=new Ac(e.highestTargetId);return e.highestTargetId=n.next(),this.Sn(t,e).next((()=>e.highestTargetId))}))}getLastRemoteSnapshotVersion(t){return this.Vn(t).next((t=>or.fromTimestamp(new ir(t.lastRemoteSnapshotVersion.seconds,t.lastRemoteSnapshotVersion.nanoseconds))))}getHighestSequenceNumber(t){return this.Vn(t).next((t=>t.highestListenSequenceNumber))}setTargetsMetadata(t,e,n){return this.Vn(t).next((s=>(s.highestListenSequenceNumber=e,n&&(s.lastRemoteSnapshotVersion=n.toTimestamp()),e>s.highestListenSequenceNumber&&(s.highestListenSequenceNumber=e),this.Sn(t,s))))}addTargetData(t,e){return this.Dn(t,e).next((()=>this.Vn(t).next((n=>(n.targetCount+=1,this.Cn(e,n),this.Sn(t,n))))))}updateTargetData(t,e){return this.Dn(t,e)}removeTargetData(t,e){return this.removeMatchingKeysForTargetId(t,e.targetId).next((()=>Cc(t).delete(e.targetId))).next((()=>this.Vn(t))).next((e=>(Bs(e.targetCount>0),e.targetCount-=1,this.Sn(t,e))))}removeTargets(t,e,n){let s=0;const r=[];return Cc(t).Z(((i,o)=>{const a=qu(o);a.sequenceNumber<=e&&null===n.get(a.targetId)&&(s++,r.push(this.removeTargetData(t,a)))})).next((()=>xr.waitFor(r))).next((()=>s))}forEachTarget(t,e){return Cc(t).Z(((t,n)=>{const s=qu(n);e(s)}))}Vn(t){return Nc(t).get("targetGlobalKey").next((t=>(Bs(null!==t),t)))}Sn(t,e){return Nc(t).put("targetGlobalKey",e)}Dn(t,e){return Cc(t).put(Gu(this.It,e))}Cn(t,e){let n=!1;return t.targetId>e.highestTargetId&&(e.highestTargetId=t.targetId,n=!0),t.sequenceNumber>e.highestListenSequenceNumber&&(e.highestListenSequenceNumber=t.sequenceNumber,n=!0),n}getTargetCount(t){return this.Vn(t).next((t=>t.targetCount))}getTargetData(t,e){const n=Oi(e),s=IDBKeyRange.bound([n,Number.NEGATIVE_INFINITY],[n,Number.POSITIVE_INFINITY]);let r=null;return Cc(t).Z({range:s,index:"queryTargetsIndex"},((t,n,s)=>{const i=qu(n);Vi(e,i.target)&&(r=i,s.done())})).next((()=>r))}addMatchingKeys(t,e,n){const s=[],r=kc(t);return e.forEach((e=>{const i=nu(e.path);s.push(r.put({targetId:n,path:i})),s.push(this.referenceDelegate.addReference(t,n,e))})),xr.waitFor(s)}removeMatchingKeys(t,e,n){const s=kc(t);return xr.forEach(e,(e=>{const r=nu(e.path);return xr.waitFor([s.delete([n,r]),this.referenceDelegate.removeReference(t,n,e)])}))}removeMatchingKeysForTargetId(t,e){const n=kc(t),s=IDBKeyRange.bound([e],[e+1],!1,!0);return n.delete(s)}getMatchingKeysForTargetId(t,e){const n=IDBKeyRange.bound([e],[e+1],!1,!0),s=kc(t);let r=fa();return s.Z({range:n,X:!0},((t,e,n)=>{const s=iu(t[1]),i=new lr(s);r=r.add(i)})).next((()=>r))}containsKey(t,e){const n=nu(e.path),s=IDBKeyRange.bound([n],[rr(n)],!1,!0);let r=0;return kc(t).Z({index:"documentTargetsIndex",X:!0,range:s},(([t,e],n,s)=>{0!==t&&(r++,s.done())})).next((()=>r>0))}se(t,e){return Cc(t).get(e).next((t=>t?qu(t):null))}}function Cc(t){return Nu(t,"targets")}function Nc(t){return Nu(t,"targetGlobal")}function kc(t){return Nu(t,"targetDocuments")}function Rc([t,e],[n,s]){const r=nr(t,n);return 0===r?nr(e,s):r}class Lc{constructor(t){this.xn=t,this.buffer=new $r(Rc),this.Nn=0}kn(){return++this.Nn}On(t){const e=[t,this.kn()];if(this.buffer.size<this.xn)this.buffer=this.buffer.add(e);else{const t=this.buffer.last();Rc(e,t)<0&&(this.buffer=this.buffer.delete(t).add(e))}}get maxValue(){return this.buffer.last()[0]}}class Mc{constructor(t,e,n){this.garbageCollector=t,this.asyncQueue=e,this.localStore=n,this.Mn=null}start(){-1!==this.garbageCollector.params.cacheSizeCollectionThreshold&&this.Fn(6e4)}stop(){this.Mn&&(this.Mn.cancel(),this.Mn=null)}get started(){return null!==this.Mn}Fn(t){Ms("LruGarbageCollector",`Garbage collection scheduled in ${t}ms`),this.Mn=this.asyncQueue.enqueueAfterDelay("lru_garbage_collection",t,(async()=>{this.Mn=null;try{await this.localStore.collectGarbage(this.garbageCollector)}catch(t){kr(t)?Ms("LruGarbageCollector","Ignoring IndexedDB error during garbage collection: ",t):await _r(t)}await this.Fn(3e5)}))}}class Oc{constructor(t,e){this.$n=t,this.params=e}calculateTargetCount(t,e){return this.$n.Bn(t).next((t=>Math.floor(e/100*t)))}nthSequenceNumber(t,e){if(0===e)return xr.resolve(Pr.at);const n=new Lc(e);return this.$n.forEachTarget(t,(t=>n.On(t.sequenceNumber))).next((()=>this.$n.Ln(t,(t=>n.On(t))))).next((()=>n.maxValue))}removeTargets(t,e,n){return this.$n.removeTargets(t,e,n)}removeOrphanedDocuments(t,e){return this.$n.removeOrphanedDocuments(t,e)}collect(t,e){return-1===this.params.cacheSizeCollectionThreshold?(Ms("LruGarbageCollector","Garbage collection skipped; disabled"),xr.resolve(wc)):this.getCacheSize(t).next((n=>n<this.params.cacheSizeCollectionThreshold?(Ms("LruGarbageCollector",`Garbage collection skipped; Cache size ${n} is lower than threshold ${this.params.cacheSizeCollectionThreshold}`),wc):this.Un(t,e)))}getCacheSize(t){return this.$n.getCacheSize(t)}Un(t,e){let n,s,r,i,o,a,u;const c=Date.now();return this.calculateTargetCount(t,this.params.percentileToCollect).next((e=>(e>this.params.maximumSequenceNumbersToCollect?(Ms("LruGarbageCollector",`Capping sequence numbers to collect down to the maximum of ${this.params.maximumSequenceNumbersToCollect} from ${e}`),s=this.params.maximumSequenceNumbersToCollect):s=e,i=Date.now(),this.nthSequenceNumber(t,s)))).next((s=>(n=s,o=Date.now(),this.removeTargets(t,n,e)))).next((e=>(r=e,a=Date.now(),this.removeOrphanedDocuments(t,n)))).next((t=>(u=Date.now(),Rs()<=E.DEBUG&&Ms("LruGarbageCollector",`LRU Garbage Collection\n\tCounted targets in ${i-c}ms\n\tDetermined least recently used ${s} in `+(o-i)+"ms\n"+`\tRemoved ${r} targets in `+(a-o)+"ms\n"+`\tRemoved ${t} documents in `+(u-a)+"ms\n"+`Total Duration: ${u-c}ms`),xr.resolve({didRun:!0,sequenceNumbersCollected:s,targetsRemoved:r,documentsRemoved:t}))))}}class Vc{constructor(t,e){this.db=t,this.garbageCollector=function(t,e){return new Oc(t,e)}(this,e)}Bn(t){const e=this.qn(t);return this.db.getTargetCache().getTargetCount(t).next((t=>e.next((e=>t+e))))}qn(t){let e=0;return this.Ln(t,(t=>{e++})).next((()=>e))}forEachTarget(t,e){return this.db.getTargetCache().forEachTarget(t,e)}Ln(t,e){return this.Kn(t,((t,n)=>e(n)))}addReference(t,e,n){return Fc(t,n)}removeReference(t,e,n){return Fc(t,n)}removeTargets(t,e,n){return this.db.getTargetCache().removeTargets(t,e,n)}markPotentiallyOrphaned(t,e){return Fc(t,e)}Gn(t,e){return function(t,e){let n=!1;return xc(t).tt((s=>Tc(t,s,e).next((t=>(t&&(n=!0),xr.resolve(!t)))))).next((()=>n))}(t,e)}removeOrphanedDocuments(t,e){const n=this.db.getRemoteDocumentCache().newChangeBuffer(),s=[];let r=0;return this.Kn(t,((i,o)=>{if(o<=e){const e=this.Gn(t,i).next((e=>{if(!e)return r++,n.getEntry(t,i).next((()=>(n.removeEntry(i,or.min()),kc(t).delete([0,nu(i.path)]))))}));s.push(e)}})).next((()=>xr.waitFor(s))).next((()=>n.apply(t))).next((()=>r))}removeTarget(t,e){const n=e.withSequenceNumber(t.currentSequenceNumber);return this.db.getTargetCache().updateTargetData(t,n)}updateLimboDocument(t,e){return Fc(t,e)}Kn(t,e){const n=kc(t);let s,r=Pr.at;return n.Z({index:"documentTargetsIndex"},(([t,n],{path:i,sequenceNumber:o})=>{0===t?(r!==Pr.at&&e(new lr(iu(s)),r),r=o,s=i):r=Pr.at})).next((()=>{r!==Pr.at&&e(new lr(iu(s)),r)}))}getCacheSize(t){return this.db.getRemoteDocumentCache().getSize(t)}}function Fc(t,e){return kc(t).put(function(t,e){return{targetId:0,path:nu(t.path),sequenceNumber:e}}(e,t.currentSequenceNumber))}class Pc{constructor(){this.changes=new na((t=>t.toString()),((t,e)=>t.isEqual(e))),this.changesApplied=!1}addEntry(t){this.assertNotApplied(),this.changes.set(t.key,t)}removeEntry(t,e){this.assertNotApplied(),this.changes.set(t,Ri.newInvalidDocument(t).setReadTime(e))}getEntry(t,e){this.assertNotApplied();const n=this.changes.get(e);return void 0!==n?xr.resolve(n):this.getFromCache(t,e)}getEntries(t,e){return this.getAllFromCache(t,e)}apply(t){return this.assertNotApplied(),this.changesApplied=!0,this.applyChanges(t)}assertNotApplied(){}}class Bc{constructor(t){this.It=t}setIndexManager(t){this.indexManager=t}addEntry(t,e,n){return Kc(t).put(n)}removeEntry(t,e,n){return Kc(t).delete(function(t,e){const n=t.path.toArray();return[n.slice(0,n.length-2),n[n.length-2],Fu(e),n[n.length-1]]}(e,n))}updateMetadata(t,e){return this.getMetadata(t).next((n=>(n.byteSize+=e,this.Qn(t,n))))}getEntry(t,e){let n=Ri.newInvalidDocument(e);return Kc(t).Z({index:"documentKeyIndex",range:IDBKeyRange.only(jc(e))},((t,s)=>{n=this.jn(e,s)})).next((()=>n))}Wn(t,e){let n={size:0,document:Ri.newInvalidDocument(e)};return Kc(t).Z({index:"documentKeyIndex",range:IDBKeyRange.only(jc(e))},((t,s)=>{n={document:this.jn(e,s),size:bc(s)}})).next((()=>n))}getEntries(t,e){let n=ra();return this.zn(t,e,((t,e)=>{const s=this.jn(t,e);n=n.insert(t,s)})).next((()=>n))}Hn(t,e){let n=ra(),s=new Gr(lr.comparator);return this.zn(t,e,((t,e)=>{const r=this.jn(t,e);n=n.insert(t,r),s=s.insert(t,bc(e))})).next((()=>({documents:n,Jn:s})))}zn(t,e,n){if(e.isEmpty())return xr.resolve();let s=new $r(Qc);e.forEach((t=>s=s.add(t)));const r=IDBKeyRange.bound(jc(s.first()),jc(s.last())),i=s.getIterator();let o=i.getNext();return Kc(t).Z({index:"documentKeyIndex",range:r},((t,e,s)=>{const r=lr.fromSegments([...e.prefixPath,e.collectionGroup,e.documentId]);for(;o&&Qc(o,r)<0;)n(o,null),o=i.getNext();o&&o.isEqual(r)&&(n(o,e),o=i.hasNext()?i.getNext():null),o?s.j(jc(o)):s.done()})).next((()=>{for(;o;)n(o,null),o=i.hasNext()?i.getNext():null}))}getAllFromCollection(t,e,n){const s=[e.popLast().toArray(),e.lastSegment(),Fu(n.readTime),n.documentKey.path.isEmpty()?"":n.documentKey.path.lastSegment()],r=[e.popLast().toArray(),e.lastSegment(),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],""];return Kc(t).W(IDBKeyRange.bound(s,r,!0)).next((t=>{let e=ra();for(const n of t){const t=this.jn(lr.fromSegments(n.prefixPath.concat(n.collectionGroup,n.documentId)),n);e=e.insert(t.key,t)}return e}))}getAllFromCollectionGroup(t,e,n,s){let r=ra();const i=$c(e,n),o=$c(e,br.max());return Kc(t).Z({index:"collectionGroupIndex",range:IDBKeyRange.bound(i,o,!0)},((t,e,n)=>{const i=this.jn(lr.fromSegments(e.prefixPath.concat(e.collectionGroup,e.documentId)),e);r=r.insert(i.key,i),r.size===s&&n.done()})).next((()=>r))}newChangeBuffer(t){return new qc(this,!!t&&t.trackRemovals)}getSize(t){return this.getMetadata(t).next((t=>t.byteSize))}getMetadata(t){return Gc(t).get("remoteDocumentGlobalKey").next((t=>(Bs(!!t),t)))}Qn(t,e){return Gc(t).put("remoteDocumentGlobalKey",e)}jn(t,e){if(e){const t=function(t,e){let n;if(e.document)n=qa(t.re,e.document,!!e.hasCommittedMutations);else if(e.noDocument){const t=lr.fromSegments(e.noDocument.path),s=Bu(e.noDocument.readTime);n=Ri.newNoDocument(t,s),e.hasCommittedMutations&&n.setHasCommittedMutations()}else{if(!e.unknownDocument)return Ps();{const t=lr.fromSegments(e.unknownDocument.path),s=Bu(e.unknownDocument.version);n=Ri.newUnknownDocument(t,s)}}return e.readTime&&n.setReadTime(function(t){const e=new ir(t[0],t[1]);return or.fromTimestamp(e)}(e.readTime)),n}(this.It,e);if(!t.isNoDocument()||!t.version.isEqual(or.min()))return t}return Ri.newInvalidDocument(t)}}function Uc(t){return new Bc(t)}class qc extends Pc{constructor(t,e){super(),this.Yn=t,this.trackRemovals=e,this.Xn=new na((t=>t.toString()),((t,e)=>t.isEqual(e)))}applyChanges(t){const e=[];let n=0,s=new $r(((t,e)=>nr(t.canonicalString(),e.canonicalString())));return this.changes.forEach(((r,i)=>{const o=this.Xn.get(r);if(e.push(this.Yn.removeEntry(t,r,o.readTime)),i.isValidDocument()){const a=Vu(this.Yn.It,i);s=s.add(r.path.popLast());const u=bc(a);n+=u-o.size,e.push(this.Yn.addEntry(t,r,a))}else if(n-=o.size,this.trackRemovals){const n=Vu(this.Yn.It,i.convertToNoDocument(or.min()));e.push(this.Yn.addEntry(t,r,n))}})),s.forEach((n=>{e.push(this.Yn.indexManager.addToCollectionParentIndex(t,n))})),e.push(this.Yn.updateMetadata(t,n)),xr.waitFor(e)}getFromCache(t,e){return this.Yn.Wn(t,e).next((t=>(this.Xn.set(e,{size:t.size,readTime:t.document.readTime}),t.document)))}getAllFromCache(t,e){return this.Yn.Hn(t,e).next((({documents:t,Jn:e})=>(e.forEach(((e,n)=>{this.Xn.set(e,{size:n,readTime:t.get(e).readTime})})),t)))}}function Gc(t){return Nu(t,"remoteDocumentGlobal")}function Kc(t){return Nu(t,"remoteDocumentsV14")}function jc(t){const e=t.path.toArray();return[e.slice(0,e.length-2),e[e.length-2],e[e.length-1]]}function $c(t,e){const n=e.documentKey.path.toArray();return[t,Fu(e.readTime),n.slice(0,n.length-2),n.length>0?n[n.length-1]:""]}function Qc(t,e){const n=t.path.toArray(),s=e.path.toArray();let r=0;for(let t=0;t<n.length-2&&t<s.length-2;++t)if(r=nr(n[t],s[t]),r)return r;return r=nr(n.length,s.length),r||(r=nr(n[n.length-2],s[s.length-2]),r||nr(n[n.length-1],s[s.length-1]))}class zc{constructor(t,e){this.overlayedDocument=t,this.mutatedFields=e}}class Hc{constructor(t,e,n,s){this.remoteDocumentCache=t,this.mutationQueue=e,this.documentOverlayCache=n,this.indexManager=s}getDocument(t,e){let n=null;return this.documentOverlayCache.getOverlay(t,e).next((s=>(n=s,this.getBaseDocument(t,e,n)))).next((t=>(null!==n&&qo(n.mutation,t,Hr.empty(),ir.now()),t)))}getDocuments(t,e){return this.remoteDocumentCache.getEntries(t,e).next((e=>this.getLocalViewOfDocuments(t,e,fa()).next((()=>e))))}getLocalViewOfDocuments(t,e,n=fa()){const s=ua();return this.populateOverlays(t,s,e).next((()=>this.computeViews(t,e,s,n).next((t=>{let e=oa();return t.forEach(((t,n)=>{e=e.insert(t,n.overlayedDocument)})),e}))))}getOverlayedDocuments(t,e){const n=ua();return this.populateOverlays(t,n,e).next((()=>this.computeViews(t,e,n,fa())))}populateOverlays(t,e,n){const s=[];return n.forEach((t=>{e.has(t)||s.push(t)})),this.documentOverlayCache.getOverlays(t,s).next((t=>{t.forEach(((t,n)=>{e.set(t,n)}))}))}computeViews(t,e,n,s){let r=ra();const i=ha(),o=ha();return e.forEach(((t,e)=>{const o=n.get(e.key);s.has(e.key)&&(void 0===o||o.mutation instanceof $o)?r=r.insert(e.key,e):void 0!==o&&(i.set(e.key,o.mutation.getFieldMask()),qo(o.mutation,e,o.mutation.getFieldMask(),ir.now()))})),this.recalculateAndSaveOverlays(t,r).next((t=>(t.forEach(((t,e)=>i.set(t,e))),e.forEach(((t,e)=>{var n;return o.set(t,new zc(e,null!==(n=i.get(t))&&void 0!==n?n:null))})),o)))}recalculateAndSaveOverlays(t,e){const n=ha();let s=new Gr(((t,e)=>t-e)),r=fa();return this.mutationQueue.getAllMutationBatchesAffectingDocumentKeys(t,e).next((t=>{for(const r of t)r.keys().forEach((t=>{const i=e.get(t);if(null===i)return;let o=n.get(t)||Hr.empty();o=r.applyToLocalView(i,o),n.set(t,o);const a=(s.get(r.batchId)||fa()).add(t);s=s.insert(r.batchId,a)}))})).next((()=>{const i=[],o=s.getReverseIterator();for(;o.hasNext();){const s=o.getNext(),a=s.key,u=s.value,c=ca();u.forEach((t=>{if(!r.has(t)){const s=Bo(e.get(t),n.get(t));null!==s&&c.set(t,s),r=r.add(t)}})),i.push(this.documentOverlayCache.saveOverlays(t,a,c))}return xr.waitFor(i)})).next((()=>n))}recalculateAndSaveOverlaysForDocumentKeys(t,e){return this.remoteDocumentCache.getEntries(t,e).next((e=>this.recalculateAndSaveOverlays(t,e)))}getDocumentsMatchingQuery(t,e,n){return function(t){return lr.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}(e)?this.getDocumentsMatchingDocumentQuery(t,e.path):ao(e)?this.getDocumentsMatchingCollectionGroupQuery(t,e,n):this.getDocumentsMatchingCollectionQuery(t,e,n)}getNextDocuments(t,e,n,s){return this.remoteDocumentCache.getAllFromCollectionGroup(t,e,n,s).next((r=>{const i=s-r.size>0?this.documentOverlayCache.getOverlaysForCollectionGroup(t,e,n.largestBatchId,s-r.size):xr.resolve(ua());let o=-1,a=r;return i.next((e=>xr.forEach(e,((e,n)=>(o<n.largestBatchId&&(o=n.largestBatchId),r.get(e)?xr.resolve():this.getBaseDocument(t,e,n).next((t=>{a=a.insert(e,t)}))))).next((()=>this.populateOverlays(t,e,r))).next((()=>this.computeViews(t,a,e,fa()))).next((t=>({batchId:o,changes:aa(t)})))))}))}getDocumentsMatchingDocumentQuery(t,e){return this.getDocument(t,new lr(e)).next((t=>{let e=oa();return t.isFoundDocument()&&(e=e.insert(t.key,t)),e}))}getDocumentsMatchingCollectionGroupQuery(t,e,n){const s=e.collectionGroup;let r=oa();return this.indexManager.getCollectionParents(t,s).next((i=>xr.forEach(i,(i=>{const o=function(t,e){return new eo(e,null,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(e,i.child(s));return this.getDocumentsMatchingCollectionQuery(t,o,n).next((t=>{t.forEach(((t,e)=>{r=r.insert(t,e)}))}))})).next((()=>r))))}getDocumentsMatchingCollectionQuery(t,e,n){let s;return this.remoteDocumentCache.getAllFromCollection(t,e.path,n).next((r=>(s=r,this.documentOverlayCache.getOverlaysForCollection(t,e.path,n.largestBatchId)))).next((t=>{t.forEach(((t,e)=>{const n=e.getKey();null===s.get(n)&&(s=s.insert(n,Ri.newInvalidDocument(n)))}));let n=oa();return s.forEach(((s,r)=>{const i=t.get(s);void 0!==i&&qo(i.mutation,r,Hr.empty(),ir.now()),go(e,r)&&(n=n.insert(s,r))})),n}))}getBaseDocument(t,e,n){return null===n||1===n.mutation.type?this.remoteDocumentCache.getEntry(t,e):xr.resolve(Ri.newInvalidDocument(e))}}class Wc{constructor(t){this.It=t,this.Zn=new Map,this.ts=new Map}getBundleMetadata(t,e){return xr.resolve(this.Zn.get(e))}saveBundleMetadata(t,e){var n;return this.Zn.set(e.id,{id:(n=e).id,version:n.version,createTime:ka(n.createTime)}),xr.resolve()}getNamedQuery(t,e){return xr.resolve(this.ts.get(e))}saveNamedQuery(t,e){return this.ts.set(e.name,function(t){return{name:t.name,query:Ku(t.bundledQuery),readTime:ka(t.readTime)}}(e)),xr.resolve()}}class Yc{constructor(){this.overlays=new Gr(lr.comparator),this.es=new Map}getOverlay(t,e){return xr.resolve(this.overlays.get(e))}getOverlays(t,e){const n=ua();return xr.forEach(e,(e=>this.getOverlay(t,e).next((t=>{null!==t&&n.set(e,t)})))).next((()=>n))}saveOverlays(t,e,n){return n.forEach(((n,s)=>{this.ue(t,e,s)})),xr.resolve()}removeOverlaysForBatchId(t,e,n){const s=this.es.get(n);return void 0!==s&&(s.forEach((t=>this.overlays=this.overlays.remove(t))),this.es.delete(n)),xr.resolve()}getOverlaysForCollection(t,e,n){const s=ua(),r=e.length+1,i=new lr(e.child("")),o=this.overlays.getIteratorFrom(i);for(;o.hasNext();){const t=o.getNext().value,i=t.getKey();if(!e.isPrefixOf(i.path))break;i.path.length===r&&t.largestBatchId>n&&s.set(t.getKey(),t)}return xr.resolve(s)}getOverlaysForCollectionGroup(t,e,n,s){let r=new Gr(((t,e)=>t-e));const i=this.overlays.getIterator();for(;i.hasNext();){const t=i.getNext().value;if(t.getKey().getCollectionGroup()===e&&t.largestBatchId>n){let e=r.get(t.largestBatchId);null===e&&(e=ua(),r=r.insert(t.largestBatchId,e)),e.set(t.getKey(),t)}}const o=ua(),a=r.getIterator();for(;a.hasNext()&&(a.getNext().value.forEach(((t,e)=>o.set(t,e))),!(o.size()>=s)););return xr.resolve(o)}ue(t,e,n){const s=this.overlays.get(n.key);if(null!==s){const t=this.es.get(s.largestBatchId).delete(n.key);this.es.set(s.largestBatchId,t)}this.overlays=this.overlays.insert(n.key,new Lu(e,n));let r=this.es.get(e);void 0===r&&(r=fa(),this.es.set(e,r)),this.es.set(e,r.add(n.key))}}class Xc{constructor(){this.ns=new $r(Jc.ss),this.rs=new $r(Jc.os)}isEmpty(){return this.ns.isEmpty()}addReference(t,e){const n=new Jc(t,e);this.ns=this.ns.add(n),this.rs=this.rs.add(n)}us(t,e){t.forEach((t=>this.addReference(t,e)))}removeReference(t,e){this.cs(new Jc(t,e))}hs(t,e){t.forEach((t=>this.removeReference(t,e)))}ls(t){const e=new lr(new ur([])),n=new Jc(e,t),s=new Jc(e,t+1),r=[];return this.rs.forEachInRange([n,s],(t=>{this.cs(t),r.push(t.key)})),r}fs(){this.ns.forEach((t=>this.cs(t)))}cs(t){this.ns=this.ns.delete(t),this.rs=this.rs.delete(t)}ds(t){const e=new lr(new ur([])),n=new Jc(e,t),s=new Jc(e,t+1);let r=fa();return this.rs.forEachInRange([n,s],(t=>{r=r.add(t.key)})),r}containsKey(t){const e=new Jc(t,0),n=this.ns.firstAfterOrEqual(e);return null!==n&&t.isEqual(n.key)}}class Jc{constructor(t,e){this.key=t,this._s=e}static ss(t,e){return lr.comparator(t.key,e.key)||nr(t._s,e._s)}static os(t,e){return nr(t._s,e._s)||lr.comparator(t.key,e.key)}}class Zc{constructor(t,e){this.indexManager=t,this.referenceDelegate=e,this.mutationQueue=[],this.ws=1,this.gs=new $r(Jc.ss)}checkEmpty(t){return xr.resolve(0===this.mutationQueue.length)}addMutationBatch(t,e,n,s){const r=this.ws;this.ws++,this.mutationQueue.length>0&&this.mutationQueue[this.mutationQueue.length-1];const i=new ku(r,e,n,s);this.mutationQueue.push(i);for(const e of s)this.gs=this.gs.add(new Jc(e.key,r)),this.indexManager.addToCollectionParentIndex(t,e.key.path.popLast());return xr.resolve(i)}lookupMutationBatch(t,e){return xr.resolve(this.ys(e))}getNextMutationBatchAfterBatchId(t,e){const n=e+1,s=this.ps(n),r=s<0?0:s;return xr.resolve(this.mutationQueue.length>r?this.mutationQueue[r]:null)}getHighestUnacknowledgedBatchId(){return xr.resolve(0===this.mutationQueue.length?-1:this.ws-1)}getAllMutationBatches(t){return xr.resolve(this.mutationQueue.slice())}getAllMutationBatchesAffectingDocumentKey(t,e){const n=new Jc(e,0),s=new Jc(e,Number.POSITIVE_INFINITY),r=[];return this.gs.forEachInRange([n,s],(t=>{const e=this.ys(t._s);r.push(e)})),xr.resolve(r)}getAllMutationBatchesAffectingDocumentKeys(t,e){let n=new $r(nr);return e.forEach((t=>{const e=new Jc(t,0),s=new Jc(t,Number.POSITIVE_INFINITY);this.gs.forEachInRange([e,s],(t=>{n=n.add(t._s)}))})),xr.resolve(this.Is(n))}getAllMutationBatchesAffectingQuery(t,e){const n=e.path,s=n.length+1;let r=n;lr.isDocumentKey(r)||(r=r.child(""));const i=new Jc(new lr(r),0);let o=new $r(nr);return this.gs.forEachWhile((t=>{const e=t.key.path;return!!n.isPrefixOf(e)&&(e.length===s&&(o=o.add(t._s)),!0)}),i),xr.resolve(this.Is(o))}Is(t){const e=[];return t.forEach((t=>{const n=this.ys(t);null!==n&&e.push(n)})),e}removeMutationBatch(t,e){Bs(0===this.Ts(e.batchId,"removed")),this.mutationQueue.shift();let n=this.gs;return xr.forEach(e.mutations,(s=>{const r=new Jc(s.key,e.batchId);return n=n.delete(r),this.referenceDelegate.markPotentiallyOrphaned(t,s.key)})).next((()=>{this.gs=n}))}An(t){}containsKey(t,e){const n=new Jc(e,0),s=this.gs.firstAfterOrEqual(n);return xr.resolve(e.isEqual(s&&s.key))}performConsistencyCheck(t){return this.mutationQueue.length,xr.resolve()}Ts(t,e){return this.ps(t)}ps(t){return 0===this.mutationQueue.length?0:t-this.mutationQueue[0].batchId}ys(t){const e=this.ps(t);return e<0||e>=this.mutationQueue.length?null:this.mutationQueue[e]}}class th{constructor(t){this.Es=t,this.docs=new Gr(lr.comparator),this.size=0}setIndexManager(t){this.indexManager=t}addEntry(t,e){const n=e.key,s=this.docs.get(n),r=s?s.size:0,i=this.Es(e);return this.docs=this.docs.insert(n,{document:e.mutableCopy(),size:i}),this.size+=i-r,this.indexManager.addToCollectionParentIndex(t,n.path.popLast())}removeEntry(t){const e=this.docs.get(t);e&&(this.docs=this.docs.remove(t),this.size-=e.size)}getEntry(t,e){const n=this.docs.get(e);return xr.resolve(n?n.document.mutableCopy():Ri.newInvalidDocument(e))}getEntries(t,e){let n=ra();return e.forEach((t=>{const e=this.docs.get(t);n=n.insert(t,e?e.document.mutableCopy():Ri.newInvalidDocument(t))})),xr.resolve(n)}getAllFromCollection(t,e,n){let s=ra();const r=new lr(e.child("")),i=this.docs.getIteratorFrom(r);for(;i.hasNext();){const{key:t,value:{document:r}}=i.getNext();if(!e.isPrefixOf(t.path))break;t.path.length>e.length+1||Er(Ir(r),n)<=0||(s=s.insert(r.key,r.mutableCopy()))}return xr.resolve(s)}getAllFromCollectionGroup(t,e,n,s){Ps()}As(t,e){return xr.forEach(this.docs,(t=>e(t)))}newChangeBuffer(t){return new eh(this)}getSize(t){return xr.resolve(this.size)}}class eh extends Pc{constructor(t){super(),this.Yn=t}applyChanges(t){const e=[];return this.changes.forEach(((n,s)=>{s.isValidDocument()?e.push(this.Yn.addEntry(t,s)):this.Yn.removeEntry(n)})),xr.waitFor(e)}getFromCache(t,e){return this.Yn.getEntry(t,e)}getAllFromCache(t,e){return this.Yn.getEntries(t,e)}}class nh{constructor(t){this.persistence=t,this.Rs=new na((t=>Oi(t)),Vi),this.lastRemoteSnapshotVersion=or.min(),this.highestTargetId=0,this.bs=0,this.Ps=new Xc,this.targetCount=0,this.vs=Ac.Pn()}forEachTarget(t,e){return this.Rs.forEach(((t,n)=>e(n))),xr.resolve()}getLastRemoteSnapshotVersion(t){return xr.resolve(this.lastRemoteSnapshotVersion)}getHighestSequenceNumber(t){return xr.resolve(this.bs)}allocateTargetId(t){return this.highestTargetId=this.vs.next(),xr.resolve(this.highestTargetId)}setTargetsMetadata(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.bs&&(this.bs=e),xr.resolve()}Dn(t){this.Rs.set(t.target,t);const e=t.targetId;e>this.highestTargetId&&(this.vs=new Ac(e),this.highestTargetId=e),t.sequenceNumber>this.bs&&(this.bs=t.sequenceNumber)}addTargetData(t,e){return this.Dn(e),this.targetCount+=1,xr.resolve()}updateTargetData(t,e){return this.Dn(e),xr.resolve()}removeTargetData(t,e){return this.Rs.delete(e.target),this.Ps.ls(e.targetId),this.targetCount-=1,xr.resolve()}removeTargets(t,e,n){let s=0;const r=[];return this.Rs.forEach(((i,o)=>{o.sequenceNumber<=e&&null===n.get(o.targetId)&&(this.Rs.delete(i),r.push(this.removeMatchingKeysForTargetId(t,o.targetId)),s++)})),xr.waitFor(r).next((()=>s))}getTargetCount(t){return xr.resolve(this.targetCount)}getTargetData(t,e){const n=this.Rs.get(e)||null;return xr.resolve(n)}addMatchingKeys(t,e,n){return this.Ps.us(e,n),xr.resolve()}removeMatchingKeys(t,e,n){this.Ps.hs(e,n);const s=this.persistence.referenceDelegate,r=[];return s&&e.forEach((e=>{r.push(s.markPotentiallyOrphaned(t,e))})),xr.waitFor(r)}removeMatchingKeysForTargetId(t,e){return this.Ps.ls(e),xr.resolve()}getMatchingKeysForTargetId(t,e){const n=this.Ps.ds(e);return xr.resolve(n)}containsKey(t,e){return xr.resolve(this.Ps.containsKey(e))}}class sh{constructor(t,e){this.Vs={},this.overlays={},this.Ss=new Pr(0),this.Ds=!1,this.Ds=!0,this.referenceDelegate=t(this),this.Cs=new nh(this),this.indexManager=new cc,this.remoteDocumentCache=function(t){return new th(t)}((t=>this.referenceDelegate.xs(t))),this.It=new Ou(e),this.Ns=new Wc(this.It)}start(){return Promise.resolve()}shutdown(){return this.Ds=!1,Promise.resolve()}get started(){return this.Ds}setDatabaseDeletedListener(){}setNetworkEnabled(){}getIndexManager(t){return this.indexManager}getDocumentOverlayCache(t){let e=this.overlays[t.toKey()];return e||(e=new Yc,this.overlays[t.toKey()]=e),e}getMutationQueue(t,e){let n=this.Vs[t.toKey()];return n||(n=new Zc(e,this.referenceDelegate),this.Vs[t.toKey()]=n),n}getTargetCache(){return this.Cs}getRemoteDocumentCache(){return this.remoteDocumentCache}getBundleCache(){return this.Ns}runTransaction(t,e,n){Ms("MemoryPersistence","Starting transaction:",t);const s=new rh(this.Ss.next());return this.referenceDelegate.ks(),n(s).next((t=>this.referenceDelegate.Os(s).next((()=>t)))).toPromise().then((t=>(s.raiseOnCommittedEvent(),t)))}Ms(t,e){return xr.or(Object.values(this.Vs).map((n=>()=>n.containsKey(t,e))))}}class rh extends Sr{constructor(t){super(),this.currentSequenceNumber=t}}class ih{constructor(t){this.persistence=t,this.Fs=new Xc,this.$s=null}static Bs(t){return new ih(t)}get Ls(){if(this.$s)return this.$s;throw Ps()}addReference(t,e,n){return this.Fs.addReference(n,e),this.Ls.delete(n.toString()),xr.resolve()}removeReference(t,e,n){return this.Fs.removeReference(n,e),this.Ls.add(n.toString()),xr.resolve()}markPotentiallyOrphaned(t,e){return this.Ls.add(e.toString()),xr.resolve()}removeTarget(t,e){this.Fs.ls(e.targetId).forEach((t=>this.Ls.add(t.toString())));const n=this.persistence.getTargetCache();return n.getMatchingKeysForTargetId(t,e.targetId).next((t=>{t.forEach((t=>this.Ls.add(t.toString())))})).next((()=>n.removeTargetData(t,e)))}ks(){this.$s=new Set}Os(t){const e=this.persistence.getRemoteDocumentCache().newChangeBuffer();return xr.forEach(this.Ls,(n=>{const s=lr.fromPath(n);return this.Us(t,s).next((t=>{t||e.removeEntry(s,or.min())}))})).next((()=>(this.$s=null,e.apply(t))))}updateLimboDocument(t,e){return this.Us(t,e).next((t=>{t?this.Ls.delete(e.toString()):this.Ls.add(e.toString())}))}xs(t){return 0}Us(t,e){return xr.or([()=>xr.resolve(this.Fs.containsKey(e)),()=>this.persistence.getTargetCache().containsKey(t,e),()=>this.persistence.Ms(t,e)])}}class oh{constructor(t){this.It=t}$(t,e,n,s){const r=new Ar("createOrUpgrade",e);n<1&&s>=1&&(function(t){t.createObjectStore("owner")}(t),function(t){t.createObjectStore("mutationQueues",{keyPath:"userId"}),t.createObjectStore("mutations",{keyPath:"batchId",autoIncrement:!0}).createIndex("userMutationsIndex",ou,{unique:!0}),t.createObjectStore("documentMutations")}(t),ah(t),function(t){t.createObjectStore("remoteDocuments")}(t));let i=xr.resolve();return n<3&&s>=3&&(0!==n&&(function(t){t.deleteObjectStore("targetDocuments"),t.deleteObjectStore("targets"),t.deleteObjectStore("targetGlobal")}(t),ah(t)),i=i.next((()=>function(t){const e=t.store("targetGlobal"),n={highestTargetId:0,highestListenSequenceNumber:0,lastRemoteSnapshotVersion:or.min().toTimestamp(),targetCount:0};return e.put("targetGlobalKey",n)}(r)))),n<4&&s>=4&&(0!==n&&(i=i.next((()=>function(t,e){return e.store("mutations").W().next((n=>{t.deleteObjectStore("mutations"),t.createObjectStore("mutations",{keyPath:"batchId",autoIncrement:!0}).createIndex("userMutationsIndex",ou,{unique:!0});const s=e.store("mutations"),r=n.map((t=>s.put(t)));return xr.waitFor(r)}))}(t,r)))),i=i.next((()=>{!function(t){t.createObjectStore("clientMetadata",{keyPath:"clientId"})}(t)}))),n<5&&s>=5&&(i=i.next((()=>this.qs(r)))),n<6&&s>=6&&(i=i.next((()=>(function(t){t.createObjectStore("remoteDocumentGlobal")}(t),this.Ks(r))))),n<7&&s>=7&&(i=i.next((()=>this.Gs(r)))),n<8&&s>=8&&(i=i.next((()=>this.Qs(t,r)))),n<9&&s>=9&&(i=i.next((()=>{!function(t){t.objectStoreNames.contains("remoteDocumentChanges")&&t.deleteObjectStore("remoteDocumentChanges")}(t)}))),n<10&&s>=10&&(i=i.next((()=>this.js(r)))),n<11&&s>=11&&(i=i.next((()=>{!function(t){t.createObjectStore("bundles",{keyPath:"bundleId"})}(t),function(t){t.createObjectStore("namedQueries",{keyPath:"name"})}(t)}))),n<12&&s>=12&&(i=i.next((()=>{!function(t){const e=t.createObjectStore("documentOverlays",{keyPath:bu});e.createIndex("collectionPathOverlayIndex",Eu,{unique:!1}),e.createIndex("collectionGroupOverlayIndex",Tu,{unique:!1})}(t)}))),n<13&&s>=13&&(i=i.next((()=>function(t){const e=t.createObjectStore("remoteDocumentsV14",{keyPath:hu});e.createIndex("documentKeyIndex",lu),e.createIndex("collectionGroupIndex",du)}(t))).next((()=>this.Ws(t,r))).next((()=>t.deleteObjectStore("remoteDocuments")))),n<14&&s>=14&&(i=i.next((()=>this.zs(t,r)))),n<15&&s>=15&&(i=i.next((()=>function(t){t.createObjectStore("indexConfiguration",{keyPath:"indexId",autoIncrement:!0}).createIndex("collectionGroupIndex","collectionGroup",{unique:!1}),t.createObjectStore("indexState",{keyPath:yu}).createIndex("sequenceNumberIndex",wu,{unique:!1}),t.createObjectStore("indexEntries",{keyPath:vu}).createIndex("documentKeyIndex",Iu,{unique:!1})}(t)))),i}Ks(t){let e=0;return t.store("remoteDocuments").Z(((t,n)=>{e+=bc(n)})).next((()=>{const n={byteSize:e};return t.store("remoteDocumentGlobal").put("remoteDocumentGlobalKey",n)}))}qs(t){const e=t.store("mutationQueues"),n=t.store("mutations");return e.W().next((e=>xr.forEach(e,(e=>{const s=IDBKeyRange.bound([e.userId,-1],[e.userId,e.lastAcknowledgedBatchId]);return n.W("userMutationsIndex",s).next((n=>xr.forEach(n,(n=>{Bs(n.userId===e.userId);const s=Uu(this.It,n);return Ic(t,e.userId,s).next((()=>{}))}))))}))))}Gs(t){const e=t.store("targetDocuments"),n=t.store("remoteDocuments");return t.store("targetGlobal").get("targetGlobalKey").next((t=>{const s=[];return n.Z(((n,r)=>{const i=new ur(n),o=function(t){return[0,nu(t)]}(i);s.push(e.get(o).next((n=>n?xr.resolve():(n=>e.put({targetId:0,path:nu(n),sequenceNumber:t.highestListenSequenceNumber}))(i))))})).next((()=>xr.waitFor(s)))}))}Qs(t,e){t.createObjectStore("collectionParents",{keyPath:pu});const n=e.store("collectionParents"),s=new hc,r=t=>{if(s.add(t)){const e=t.lastSegment(),s=t.popLast();return n.put({collectionId:e,parent:nu(s)})}};return e.store("remoteDocuments").Z({X:!0},((t,e)=>{const n=new ur(t);return r(n.popLast())})).next((()=>e.store("documentMutations").Z({X:!0},(([t,e,n],s)=>{const i=iu(e);return r(i.popLast())}))))}js(t){const e=t.store("targets");return e.Z(((t,n)=>{const s=qu(n),r=Gu(this.It,s);return e.put(r)}))}Ws(t,e){const n=e.store("remoteDocuments"),s=[];return n.Z(((t,n)=>{const r=e.store("remoteDocumentsV14"),i=(o=n,o.document?new lr(ur.fromString(o.document.name).popFirst(5)):o.noDocument?lr.fromSegments(o.noDocument.path):o.unknownDocument?lr.fromSegments(o.unknownDocument.path):Ps()).path.toArray();var o;const a={prefixPath:i.slice(0,i.length-2),collectionGroup:i[i.length-2],documentId:i[i.length-1],readTime:n.readTime||[0,0],unknownDocument:n.unknownDocument,noDocument:n.noDocument,document:n.document,hasCommittedMutations:!!n.hasCommittedMutations};s.push(r.put(a))})).next((()=>xr.waitFor(s)))}zs(t,e){const n=e.store("mutations"),s=Uc(this.It),r=new sh(ih.Bs,this.It.re);return n.W().next((t=>{const n=new Map;return t.forEach((t=>{var e;let s=null!==(e=n.get(t.userId))&&void 0!==e?e:fa();Uu(this.It,t).keys().forEach((t=>s=s.add(t))),n.set(t.userId,s)})),xr.forEach(n,((t,n)=>{const i=new Cs(n),o=Yu.oe(this.It,i),a=r.getIndexManager(i),u=Ec.oe(i,this.It,a,r.referenceDelegate);return new Hc(s,u,o,a).recalculateAndSaveOverlaysForDocumentKeys(new Cu(e,Pr.at),t).next()}))}))}}function ah(t){t.createObjectStore("targetDocuments",{keyPath:mu}).createIndex("documentTargetsIndex",gu,{unique:!0}),t.createObjectStore("targets",{keyPath:"targetId"}).createIndex("queryTargetsIndex",fu,{unique:!0}),t.createObjectStore("targetGlobal")}const uh="Failed to obtain exclusive access to the persistence layer. To allow shared access, multi-tab synchronization has to be enabled in all tabs. If you are using `experimentalForceOwningTab:true`, make sure that only one tab has persistence enabled at any given time.";class ch{constructor(t,e,n,s,r,i,o,a,u,c,h=15){if(this.allowTabSynchronization=t,this.persistenceKey=e,this.clientId=n,this.Hs=r,this.window=i,this.document=o,this.Js=u,this.Ys=c,this.Xs=h,this.Ss=null,this.Ds=!1,this.isPrimary=!1,this.networkEnabled=!0,this.Zs=null,this.inForeground=!1,this.ti=null,this.ei=null,this.ni=Number.NEGATIVE_INFINITY,this.si=t=>Promise.resolve(),!ch.C())throw new Ks(Gs.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");this.referenceDelegate=new Vc(this,s),this.ii=e+"main",this.It=new Ou(a),this.ri=new Dr(this.ii,this.Xs,new oh(this.It)),this.Cs=new Dc(this.referenceDelegate,this.It),this.remoteDocumentCache=Uc(this.It),this.Ns=new zu,this.window&&this.window.localStorage?this.oi=this.window.localStorage:(this.oi=null,!1===c&&Os("IndexedDbPersistence","LocalStorage is unavailable. As a result, persistence may not work reliably. In particular enablePersistence() could fail immediately after refreshing the page."))}start(){return this.ui().then((()=>{if(!this.isPrimary&&!this.allowTabSynchronization)throw new Ks(Gs.FAILED_PRECONDITION,uh);return this.ci(),this.ai(),this.hi(),this.runTransaction("getHighestListenSequenceNumber","readonly",(t=>this.Cs.getHighestSequenceNumber(t)))})).then((t=>{this.Ss=new Pr(t,this.Js)})).then((()=>{this.Ds=!0})).catch((t=>(this.ri&&this.ri.close(),Promise.reject(t))))}li(t){return this.si=async e=>{if(this.started)return t(e)},t(this.isPrimary)}setDatabaseDeletedListener(t){this.ri.L((async e=>{null===e.newVersion&&await t()}))}setNetworkEnabled(t){this.networkEnabled!==t&&(this.networkEnabled=t,this.Hs.enqueueAndForget((async()=>{this.started&&await this.ui()})))}ui(){return this.runTransaction("updateClientMetadataAndTryBecomePrimary","readwrite",(t=>lh(t).put({clientId:this.clientId,updateTimeMs:Date.now(),networkEnabled:this.networkEnabled,inForeground:this.inForeground}).next((()=>{if(this.isPrimary)return this.fi(t).next((t=>{t||(this.isPrimary=!1,this.Hs.enqueueRetryable((()=>this.si(!1))))}))})).next((()=>this.di(t))).next((e=>this.isPrimary&&!e?this._i(t).next((()=>!1)):!!e&&this.wi(t).next((()=>!0)))))).catch((t=>{if(kr(t))return Ms("IndexedDbPersistence","Failed to extend owner lease: ",t),this.isPrimary;if(!this.allowTabSynchronization)throw t;return Ms("IndexedDbPersistence","Releasing owner lease after error during lease refresh",t),!1})).then((t=>{this.isPrimary!==t&&this.Hs.enqueueRetryable((()=>this.si(t))),this.isPrimary=t}))}fi(t){return hh(t).get("owner").next((t=>xr.resolve(this.mi(t))))}gi(t){return lh(t).delete(this.clientId)}async yi(){if(this.isPrimary&&!this.pi(this.ni,18e5)){this.ni=Date.now();const t=await this.runTransaction("maybeGarbageCollectMultiClientState","readwrite-primary",(t=>{const e=Nu(t,"clientMetadata");return e.W().next((t=>{const n=this.Ii(t,18e5),s=t.filter((t=>-1===n.indexOf(t)));return xr.forEach(s,(t=>e.delete(t.clientId))).next((()=>s))}))})).catch((()=>[]));if(this.oi)for(const e of t)this.oi.removeItem(this.Ti(e.clientId))}}hi(){this.ei=this.Hs.enqueueAfterDelay("client_metadata_refresh",4e3,(()=>this.ui().then((()=>this.yi())).then((()=>this.hi()))))}mi(t){return!!t&&t.ownerId===this.clientId}di(t){return this.Ys?xr.resolve(!0):hh(t).get("owner").next((e=>{if(null!==e&&this.pi(e.leaseTimestampMs,5e3)&&!this.Ei(e.ownerId)){if(this.mi(e)&&this.networkEnabled)return!0;if(!this.mi(e)){if(!e.allowTabSynchronization)throw new Ks(Gs.FAILED_PRECONDITION,uh);return!1}}return!(!this.networkEnabled||!this.inForeground)||lh(t).W().next((t=>void 0===this.Ii(t,5e3).find((t=>{if(this.clientId!==t.clientId){const e=!this.networkEnabled&&t.networkEnabled,n=!this.inForeground&&t.inForeground,s=this.networkEnabled===t.networkEnabled;if(e||n&&s)return!0}return!1}))))})).next((t=>(this.isPrimary!==t&&Ms("IndexedDbPersistence",`Client ${t?"is":"is not"} eligible for a primary lease.`),t)))}async shutdown(){this.Ds=!1,this.Ai(),this.ei&&(this.ei.cancel(),this.ei=null),this.Ri(),this.bi(),await this.ri.runTransaction("shutdown","readwrite",["owner","clientMetadata"],(t=>{const e=new Cu(t,Pr.at);return this._i(e).next((()=>this.gi(e)))})),this.ri.close(),this.Pi()}Ii(t,e){return t.filter((t=>this.pi(t.updateTimeMs,e)&&!this.Ei(t.clientId)))}vi(){return this.runTransaction("getActiveClients","readonly",(t=>lh(t).W().next((t=>this.Ii(t,18e5).map((t=>t.clientId))))))}get started(){return this.Ds}getMutationQueue(t,e){return Ec.oe(t,this.It,e,this.referenceDelegate)}getTargetCache(){return this.Cs}getRemoteDocumentCache(){return this.remoteDocumentCache}getIndexManager(t){return new dc(t,this.It.re.databaseId)}getDocumentOverlayCache(t){return Yu.oe(this.It,t)}getBundleCache(){return this.Ns}runTransaction(t,e,n){Ms("IndexedDbPersistence","Starting transaction:",t);const s="readonly"===e?"readonly":"readwrite",r=15===(i=this.Xs)?Du:14===i?Au:13===i?xu:12===i?_u:11===i?Su:void Ps();var i;let o;return this.ri.runTransaction(t,s,r,(s=>(o=new Cu(s,this.Ss?this.Ss.next():Pr.at),"readwrite-primary"===e?this.fi(o).next((t=>!!t||this.di(o))).next((e=>{if(!e)throw Os(`Failed to obtain primary lease for action '${t}'.`),this.isPrimary=!1,this.Hs.enqueueRetryable((()=>this.si(!1))),new Ks(Gs.FAILED_PRECONDITION,Tr);return n(o)})).next((t=>this.wi(o).next((()=>t)))):this.Vi(o).next((()=>n(o)))))).then((t=>(o.raiseOnCommittedEvent(),t)))}Vi(t){return hh(t).get("owner").next((t=>{if(null!==t&&this.pi(t.leaseTimestampMs,5e3)&&!this.Ei(t.ownerId)&&!this.mi(t)&&!(this.Ys||this.allowTabSynchronization&&t.allowTabSynchronization))throw new Ks(Gs.FAILED_PRECONDITION,uh)}))}wi(t){const e={ownerId:this.clientId,allowTabSynchronization:this.allowTabSynchronization,leaseTimestampMs:Date.now()};return hh(t).put("owner",e)}static C(){return Dr.C()}_i(t){const e=hh(t);return e.get("owner").next((t=>this.mi(t)?(Ms("IndexedDbPersistence","Releasing primary lease."),e.delete("owner")):xr.resolve()))}pi(t,e){const n=Date.now();return!(t<n-e||t>n&&(Os(`Detected an update time that is in the future: ${t} > ${n}`),1))}ci(){null!==this.document&&"function"==typeof this.document.addEventListener&&(this.ti=()=>{this.Hs.enqueueAndForget((()=>(this.inForeground="visible"===this.document.visibilityState,this.ui())))},this.document.addEventListener("visibilitychange",this.ti),this.inForeground="visible"===this.document.visibilityState)}Ri(){this.ti&&(this.document.removeEventListener("visibilitychange",this.ti),this.ti=null)}ai(){var t;"function"==typeof(null===(t=this.window)||void 0===t?void 0:t.addEventListener)&&(this.Zs=()=>{this.Ai(),h()&&navigator.appVersion.match(/Version\/1[45]/)&&this.Hs.enterRestrictedMode(!0),this.Hs.enqueueAndForget((()=>this.shutdown()))},this.window.addEventListener("pagehide",this.Zs))}bi(){this.Zs&&(this.window.removeEventListener("pagehide",this.Zs),this.Zs=null)}Ei(t){var e;try{const n=null!==(null===(e=this.oi)||void 0===e?void 0:e.getItem(this.Ti(t)));return Ms("IndexedDbPersistence",`Client '${t}' ${n?"is":"is not"} zombied in LocalStorage`),n}catch(t){return Os("IndexedDbPersistence","Failed to get zombied client id.",t),!1}}Ai(){if(this.oi)try{this.oi.setItem(this.Ti(this.clientId),String(Date.now()))}catch(t){Os("Failed to set zombie client id.",t)}}Pi(){if(this.oi)try{this.oi.removeItem(this.Ti(this.clientId))}catch(t){}}Ti(t){return`firestore_zombie_${this.persistenceKey}_${t}`}}function hh(t){return Nu(t,"owner")}function lh(t){return Nu(t,"clientMetadata")}function dh(t,e){let n=t.projectId;return t.isDefaultDatabase||(n+="."+t.database),"firestore/"+e+"/"+n+"/"}class fh{constructor(t,e,n,s){this.targetId=t,this.fromCache=e,this.Si=n,this.Di=s}static Ci(t,e){let n=fa(),s=fa();for(const t of e.docChanges)switch(t.type){case 0:n=n.add(t.doc.key);break;case 1:s=s.add(t.doc.key)}return new fh(t,e.fromCache,n,s)}}class mh{constructor(){this.xi=!1}initialize(t,e){this.Ni=t,this.indexManager=e,this.xi=!0}getDocumentsMatchingQuery(t,e,n,s){return this.ki(t,e).next((r=>r||this.Oi(t,e,s,n))).next((n=>n||this.Mi(t,e)))}ki(t,e){if(ro(e))return xr.resolve(null);let n=co(e);return this.indexManager.getIndexType(t,n).next((s=>0===s?null:(null!==e.limit&&1===s&&(e=ho(e,null,"F"),n=co(e)),this.indexManager.getDocumentsMatchingTarget(t,n).next((s=>{const r=fa(...s);return this.Ni.getDocuments(t,r).next((s=>this.indexManager.getMinOffset(t,n).next((n=>{const i=this.Fi(e,s);return this.$i(e,i,r,n.readTime)?this.ki(t,ho(e,null,"F")):this.Bi(t,i,e,n)}))))})))))}Oi(t,e,n,s){return ro(e)||s.isEqual(or.min())?this.Mi(t,e):this.Ni.getDocuments(t,n).next((r=>{const i=this.Fi(e,r);return this.$i(e,i,n,s)?this.Mi(t,e):(Rs()<=E.DEBUG&&Ms("QueryEngine","Re-using previous result from %s to execute query: %s",s.toString(),mo(e)),this.Bi(t,i,e,vr(s,-1)))}))}Fi(t,e){let n=new $r(yo(t));return e.forEach(((e,s)=>{go(t,s)&&(n=n.add(s))})),n}$i(t,e,n,s){if(null===t.limit)return!1;if(n.size!==e.size)return!0;const r="F"===t.limitType?e.last():e.first();return!!r&&(r.hasPendingWrites||r.version.compareTo(s)>0)}Mi(t,e){return Rs()<=E.DEBUG&&Ms("QueryEngine","Using full collection scan to execute query:",mo(e)),this.Ni.getDocumentsMatchingQuery(t,e,br.min())}Bi(t,e,n,s){return this.Ni.getDocumentsMatchingQuery(t,n,s).next((t=>(e.forEach((e=>{t=t.insert(e.key,e)})),t)))}}class gh{constructor(t,e,n,s){this.persistence=t,this.Li=e,this.It=s,this.Ui=new Gr(nr),this.qi=new na((t=>Oi(t)),Vi),this.Ki=new Map,this.Gi=t.getRemoteDocumentCache(),this.Cs=t.getTargetCache(),this.Ns=t.getBundleCache(),this.Qi(n)}Qi(t){this.documentOverlayCache=this.persistence.getDocumentOverlayCache(t),this.indexManager=this.persistence.getIndexManager(t),this.mutationQueue=this.persistence.getMutationQueue(t,this.indexManager),this.localDocuments=new Hc(this.Gi,this.mutationQueue,this.documentOverlayCache,this.indexManager),this.Gi.setIndexManager(this.indexManager),this.Li.initialize(this.localDocuments,this.indexManager)}collectGarbage(t){return this.persistence.runTransaction("Collect garbage","readwrite-primary",(e=>t.collect(e,this.Ui)))}}function ph(t,e,n,s){return new gh(t,e,n,s)}async function yh(t,e){const n=qs(t);return await n.persistence.runTransaction("Handle user change","readonly",(t=>{let s;return n.mutationQueue.getAllMutationBatches(t).next((r=>(s=r,n.Qi(e),n.mutationQueue.getAllMutationBatches(t)))).next((e=>{const r=[],i=[];let o=fa();for(const t of s){r.push(t.batchId);for(const e of t.mutations)o=o.add(e.key)}for(const t of e){i.push(t.batchId);for(const e of t.mutations)o=o.add(e.key)}return n.localDocuments.getDocuments(t,o).next((t=>({ji:t,removedBatchIds:r,addedBatchIds:i})))}))}))}function wh(t){const e=qs(t);return e.persistence.runTransaction("Get last remote snapshot version","readonly",(t=>e.Cs.getLastRemoteSnapshotVersion(t)))}function vh(t,e,n){let s=fa(),r=fa();return n.forEach((t=>s=s.add(t))),e.getEntries(t,s).next((t=>{let s=ra();return n.forEach(((n,i)=>{const o=t.get(n);i.isFoundDocument()!==o.isFoundDocument()&&(r=r.add(n)),i.isNoDocument()&&i.version.isEqual(or.min())?(e.removeEntry(n,i.readTime),s=s.insert(n,i)):!o.isValidDocument()||i.version.compareTo(o.version)>0||0===i.version.compareTo(o.version)&&o.hasPendingWrites?(e.addEntry(i),s=s.insert(n,i)):Ms("LocalStore","Ignoring outdated watch update for ",n,". Current version:",o.version," Watch version:",i.version)})),{Wi:s,zi:r}}))}function Ih(t,e){const n=qs(t);return n.persistence.runTransaction("Get next mutation batch","readonly",(t=>(void 0===e&&(e=-1),n.mutationQueue.getNextMutationBatchAfterBatchId(t,e))))}function bh(t,e){const n=qs(t);return n.persistence.runTransaction("Allocate target","readwrite",(t=>{let s;return n.Cs.getTargetData(t,e).next((r=>r?(s=r,xr.resolve(s)):n.Cs.allocateTargetId(t).next((r=>(s=new Mu(e,r,0,t.currentSequenceNumber),n.Cs.addTargetData(t,s).next((()=>s)))))))})).then((t=>{const s=n.Ui.get(t.targetId);return(null===s||t.snapshotVersion.compareTo(s.snapshotVersion)>0)&&(n.Ui=n.Ui.insert(t.targetId,t),n.qi.set(e,t.targetId)),t}))}async function Eh(t,e,n){const s=qs(t),r=s.Ui.get(e),i=n?"readwrite":"readwrite-primary";try{n||await s.persistence.runTransaction("Release target",i,(t=>s.persistence.referenceDelegate.removeTarget(t,r)))}catch(t){if(!kr(t))throw t;Ms("LocalStore",`Failed to update sequence numbers for target ${e}: ${t}`)}s.Ui=s.Ui.remove(e),s.qi.delete(r.target)}function Th(t,e,n){const s=qs(t);let r=or.min(),i=fa();return s.persistence.runTransaction("Execute query","readonly",(t=>function(t,e,n){const s=qs(t),r=s.qi.get(n);return void 0!==r?xr.resolve(s.Ui.get(r)):s.Cs.getTargetData(e,n)}(s,t,co(e)).next((e=>{if(e)return r=e.lastLimboFreeSnapshotVersion,s.Cs.getMatchingKeysForTargetId(t,e.targetId).next((t=>{i=t}))})).next((()=>s.Li.getDocumentsMatchingQuery(t,e,n?r:or.min(),n?i:fa()))).next((t=>(xh(s,po(e),t),{documents:t,Hi:i})))))}function Sh(t,e){const n=qs(t),s=qs(n.Cs),r=n.Ui.get(e);return r?Promise.resolve(r.target):n.persistence.runTransaction("Get target data","readonly",(t=>s.se(t,e).next((t=>t?t.target:null))))}function _h(t,e){const n=qs(t),s=n.Ki.get(e)||or.min();return n.persistence.runTransaction("Get new document changes","readonly",(t=>n.Gi.getAllFromCollectionGroup(t,e,vr(s,-1),Number.MAX_SAFE_INTEGER))).then((t=>(xh(n,e,t),t)))}function xh(t,e,n){let s=t.Ki.get(e)||or.min();n.forEach(((t,e)=>{e.readTime.compareTo(s)>0&&(s=e.readTime)})),t.Ki.set(e,s)}async function Ah(t,e,n=fa()){const s=await bh(t,co(Ku(e.bundledQuery))),r=qs(t);return r.persistence.runTransaction("Save named query","readwrite",(t=>{const i=ka(e.readTime);if(s.snapshotVersion.compareTo(i)>=0)return r.Ns.saveNamedQuery(t,e);const o=s.withResumeToken(Yr.EMPTY_BYTE_STRING,i);return r.Ui=r.Ui.insert(o.targetId,o),r.Cs.updateTargetData(t,o).next((()=>r.Cs.removeMatchingKeysForTargetId(t,s.targetId))).next((()=>r.Cs.addMatchingKeys(t,n,s.targetId))).next((()=>r.Ns.saveNamedQuery(t,e)))}))}function Dh(t,e){return`firestore_clients_${t}_${e}`}function Ch(t,e,n){let s=`firestore_mutations_${t}_${n}`;return e.isAuthenticated()&&(s+=`_${e.uid}`),s}function Nh(t,e){return`firestore_targets_${t}_${e}`}class kh{constructor(t,e,n,s){this.user=t,this.batchId=e,this.state=n,this.error=s}static Zi(t,e,n){const s=JSON.parse(n);let r,i="object"==typeof s&&-1!==["pending","acknowledged","rejected"].indexOf(s.state)&&(void 0===s.error||"object"==typeof s.error);return i&&s.error&&(i="string"==typeof s.error.message&&"string"==typeof s.error.code,i&&(r=new Ks(s.error.code,s.error.message))),i?new kh(t,e,s.state,r):(Os("SharedClientState",`Failed to parse mutation state for ID '${e}': ${n}`),null)}tr(){const t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)}}class Rh{constructor(t,e,n){this.targetId=t,this.state=e,this.error=n}static Zi(t,e){const n=JSON.parse(e);let s,r="object"==typeof n&&-1!==["not-current","current","rejected"].indexOf(n.state)&&(void 0===n.error||"object"==typeof n.error);return r&&n.error&&(r="string"==typeof n.error.message&&"string"==typeof n.error.code,r&&(s=new Ks(n.error.code,n.error.message))),r?new Rh(t,n.state,s):(Os("SharedClientState",`Failed to parse target state for ID '${t}': ${e}`),null)}tr(){const t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)}}class Lh{constructor(t,e){this.clientId=t,this.activeTargetIds=e}static Zi(t,e){const n=JSON.parse(e);let s="object"==typeof n&&n.activeTargetIds instanceof Array,r=ga();for(let t=0;s&&t<n.activeTargetIds.length;++t)s=ui(n.activeTargetIds[t]),r=r.add(n.activeTargetIds[t]);return s?new Lh(t,r):(Os("SharedClientState",`Failed to parse client data for instance '${t}': ${e}`),null)}}class Mh{constructor(t,e){this.clientId=t,this.onlineState=e}static Zi(t){const e=JSON.parse(t);return"object"==typeof e&&-1!==["Unknown","Online","Offline"].indexOf(e.onlineState)&&"string"==typeof e.clientId?new Mh(e.clientId,e.onlineState):(Os("SharedClientState",`Failed to parse online state: ${t}`),null)}}class Oh{constructor(){this.activeTargetIds=ga()}er(t){this.activeTargetIds=this.activeTargetIds.add(t)}nr(t){this.activeTargetIds=this.activeTargetIds.delete(t)}tr(){const t={activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()};return JSON.stringify(t)}}class Vh{constructor(t,e,n,s,r){this.window=t,this.Hs=e,this.persistenceKey=n,this.sr=s,this.syncEngine=null,this.onlineStateHandler=null,this.sequenceNumberHandler=null,this.ir=this.rr.bind(this),this.ur=new Gr(nr),this.started=!1,this.cr=[];const i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");this.storage=this.window.localStorage,this.currentUser=r,this.ar=Dh(this.persistenceKey,this.sr),this.hr=function(t){return`firestore_sequence_number_${t}`}(this.persistenceKey),this.ur=this.ur.insert(this.sr,new Oh),this.lr=new RegExp(`^firestore_clients_${i}_([^_]*)$`),this.dr=new RegExp(`^firestore_mutations_${i}_(\\d+)(?:_(.*))?$`),this._r=new RegExp(`^firestore_targets_${i}_(\\d+)$`),this.wr=function(t){return`firestore_online_state_${t}`}(this.persistenceKey),this.mr=function(t){return`firestore_bundle_loaded_v2_${t}`}(this.persistenceKey),this.window.addEventListener("storage",this.ir)}static C(t){return!(!t||!t.localStorage)}async start(){const t=await this.syncEngine.vi();for(const e of t){if(e===this.sr)continue;const t=this.getItem(Dh(this.persistenceKey,e));if(t){const n=Lh.Zi(e,t);n&&(this.ur=this.ur.insert(n.clientId,n))}}this.gr();const e=this.storage.getItem(this.wr);if(e){const t=this.yr(e);t&&this.pr(t)}for(const t of this.cr)this.rr(t);this.cr=[],this.window.addEventListener("pagehide",(()=>this.shutdown())),this.started=!0}writeSequenceNumber(t){this.setItem(this.hr,JSON.stringify(t))}getAllActiveQueryTargets(){return this.Ir(this.ur)}isActiveQueryTarget(t){let e=!1;return this.ur.forEach(((n,s)=>{s.activeTargetIds.has(t)&&(e=!0)})),e}addPendingMutation(t){this.Tr(t,"pending")}updateMutationState(t,e,n){this.Tr(t,e,n),this.Er(t)}addLocalQueryTarget(t){let e="not-current";if(this.isActiveQueryTarget(t)){const n=this.storage.getItem(Nh(this.persistenceKey,t));if(n){const s=Rh.Zi(t,n);s&&(e=s.state)}}return this.Ar.er(t),this.gr(),e}removeLocalQueryTarget(t){this.Ar.nr(t),this.gr()}isLocalQueryTarget(t){return this.Ar.activeTargetIds.has(t)}clearQueryState(t){this.removeItem(Nh(this.persistenceKey,t))}updateQueryState(t,e,n){this.Rr(t,e,n)}handleUserChange(t,e,n){e.forEach((t=>{this.Er(t)})),this.currentUser=t,n.forEach((t=>{this.addPendingMutation(t)}))}setOnlineState(t){this.br(t)}notifyBundleLoaded(t){this.Pr(t)}shutdown(){this.started&&(this.window.removeEventListener("storage",this.ir),this.removeItem(this.ar),this.started=!1)}getItem(t){const e=this.storage.getItem(t);return Ms("SharedClientState","READ",t,e),e}setItem(t,e){Ms("SharedClientState","SET",t,e),this.storage.setItem(t,e)}removeItem(t){Ms("SharedClientState","REMOVE",t),this.storage.removeItem(t)}rr(t){const e=t;if(e.storageArea===this.storage){if(Ms("SharedClientState","EVENT",e.key,e.newValue),e.key===this.ar)return void Os("Received WebStorage notification for local change. Another client might have garbage-collected our state");this.Hs.enqueueRetryable((async()=>{if(this.started){if(null!==e.key)if(this.lr.test(e.key)){if(null==e.newValue){const t=this.vr(e.key);return this.Vr(t,null)}{const t=this.Sr(e.key,e.newValue);if(t)return this.Vr(t.clientId,t)}}else if(this.dr.test(e.key)){if(null!==e.newValue){const t=this.Dr(e.key,e.newValue);if(t)return this.Cr(t)}}else if(this._r.test(e.key)){if(null!==e.newValue){const t=this.Nr(e.key,e.newValue);if(t)return this.kr(t)}}else if(e.key===this.wr){if(null!==e.newValue){const t=this.yr(e.newValue);if(t)return this.pr(t)}}else if(e.key===this.hr){const t=function(t){let e=Pr.at;if(null!=t)try{const n=JSON.parse(t);Bs("number"==typeof n),e=n}catch(t){Os("SharedClientState","Failed to read sequence number from WebStorage",t)}return e}(e.newValue);t!==Pr.at&&this.sequenceNumberHandler(t)}else if(e.key===this.mr){const t=this.Or(e.newValue);await Promise.all(t.map((t=>this.syncEngine.Mr(t))))}}else this.cr.push(e)}))}}get Ar(){return this.ur.get(this.sr)}gr(){this.setItem(this.ar,this.Ar.tr())}Tr(t,e,n){const s=new kh(this.currentUser,t,e,n),r=Ch(this.persistenceKey,this.currentUser,t);this.setItem(r,s.tr())}Er(t){const e=Ch(this.persistenceKey,this.currentUser,t);this.removeItem(e)}br(t){const e={clientId:this.sr,onlineState:t};this.storage.setItem(this.wr,JSON.stringify(e))}Rr(t,e,n){const s=Nh(this.persistenceKey,t),r=new Rh(t,e,n);this.setItem(s,r.tr())}Pr(t){const e=JSON.stringify(Array.from(t));this.setItem(this.mr,e)}vr(t){const e=this.lr.exec(t);return e?e[1]:null}Sr(t,e){const n=this.vr(t);return Lh.Zi(n,e)}Dr(t,e){const n=this.dr.exec(t),s=Number(n[1]),r=void 0!==n[2]?n[2]:null;return kh.Zi(new Cs(r),s,e)}Nr(t,e){const n=this._r.exec(t),s=Number(n[1]);return Rh.Zi(s,e)}yr(t){return Mh.Zi(t)}Or(t){return JSON.parse(t)}async Cr(t){if(t.user.uid===this.currentUser.uid)return this.syncEngine.Fr(t.batchId,t.state,t.error);Ms("SharedClientState",`Ignoring mutation for non-active user ${t.user.uid}`)}kr(t){return this.syncEngine.$r(t.targetId,t.state,t.error)}Vr(t,e){const n=e?this.ur.insert(t,e):this.ur.remove(t),s=this.Ir(this.ur),r=this.Ir(n),i=[],o=[];return r.forEach((t=>{s.has(t)||i.push(t)})),s.forEach((t=>{r.has(t)||o.push(t)})),this.syncEngine.Br(i,o).then((()=>{this.ur=n}))}pr(t){this.ur.get(t.clientId)&&this.onlineStateHandler(t.onlineState)}Ir(t){let e=ga();return t.forEach(((t,n)=>{e=e.unionWith(n.activeTargetIds)})),e}}class Fh{constructor(){this.Lr=new Oh,this.Ur={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}addPendingMutation(t){}updateMutationState(t,e,n){}addLocalQueryTarget(t){return this.Lr.er(t),this.Ur[t]||"not-current"}updateQueryState(t,e,n){this.Ur[t]=e}removeLocalQueryTarget(t){this.Lr.nr(t)}isLocalQueryTarget(t){return this.Lr.activeTargetIds.has(t)}clearQueryState(t){delete this.Ur[t]}getAllActiveQueryTargets(){return this.Lr.activeTargetIds}isActiveQueryTarget(t){return this.Lr.activeTargetIds.has(t)}start(){return this.Lr=new Oh,Promise.resolve()}handleUserChange(t,e,n){}setOnlineState(t){}shutdown(){}writeSequenceNumber(t){}notifyBundleLoaded(t){}}class Ph{qr(t){}shutdown(){}}class Bh{constructor(){this.Kr=()=>this.Gr(),this.Qr=()=>this.jr(),this.Wr=[],this.zr()}qr(t){this.Wr.push(t)}shutdown(){window.removeEventListener("online",this.Kr),window.removeEventListener("offline",this.Qr)}zr(){window.addEventListener("online",this.Kr),window.addEventListener("offline",this.Qr)}Gr(){Ms("ConnectivityMonitor","Network connectivity changed: AVAILABLE");for(const t of this.Wr)t(0)}jr(){Ms("ConnectivityMonitor","Network connectivity changed: UNAVAILABLE");for(const t of this.Wr)t(1)}static C(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener}}const Uh={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery"};class qh{constructor(t){this.Hr=t.Hr,this.Jr=t.Jr}Yr(t){this.Xr=t}Zr(t){this.eo=t}onMessage(t){this.no=t}close(){this.Jr()}send(t){this.Hr(t)}so(){this.Xr()}io(t){this.eo(t)}ro(t){this.no(t)}}class Gh extends class{constructor(t){this.databaseInfo=t,this.databaseId=t.databaseId;const e=t.ssl?"https":"http";this.oo=e+"://"+t.host,this.uo="projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database+"/documents"}get co(){return!1}ao(t,e,n,s,r){const i=this.ho(t,e);Ms("RestConnection","Sending: ",i,n);const o={};return this.lo(o,s,r),this.fo(t,i,o,n).then((t=>(Ms("RestConnection","Received: ",t),t)),(e=>{throw Vs("RestConnection",`${t} failed with error: `,e,"url: ",i,"request:",n),e}))}_o(t,e,n,s,r,i){return this.ao(t,e,n,s,r)}lo(t,e,n){t["X-Goog-Api-Client"]="gl-js/ fire/"+Ns,t["Content-Type"]="text/plain",this.databaseInfo.appId&&(t["X-Firebase-GMPID"]=this.databaseInfo.appId),e&&e.headers.forEach(((e,n)=>t[n]=e)),n&&n.headers.forEach(((e,n)=>t[n]=e))}ho(t,e){const n=Uh[t];return`${this.oo}/v1/${e}:${n}`}}{constructor(t){super(t),this.forceLongPolling=t.forceLongPolling,this.autoDetectLongPolling=t.autoDetectLongPolling,this.useFetchStreams=t.useFetchStreams}fo(t,e,n,s){return new Promise(((r,i)=>{const o=new As;o.setWithCredentials(!0),o.listenOnce(bs.COMPLETE,(()=>{try{switch(o.getLastErrorCode()){case Is.NO_ERROR:const e=o.getResponseJson();Ms("Connection","XHR received:",JSON.stringify(e)),r(e);break;case Is.TIMEOUT:Ms("Connection",'RPC "'+t+'" timed out'),i(new Ks(Gs.DEADLINE_EXCEEDED,"Request time out"));break;case Is.HTTP_ERROR:const n=o.getStatus();if(Ms("Connection",'RPC "'+t+'" failed with status:',n,"response text:",o.getResponseText()),n>0){const t=o.getResponseJson().error;if(t&&t.status&&t.message){const e=function(t){const e=t.toLowerCase().replace(/_/g,"-");return Object.values(Gs).indexOf(e)>=0?e:Gs.UNKNOWN}(t.status);i(new Ks(e,t.message))}else i(new Ks(Gs.UNKNOWN,"Server responded with status "+o.getStatus()))}else i(new Ks(Gs.UNAVAILABLE,"Connection failed."));break;default:Ps()}}finally{Ms("Connection",'RPC "'+t+'" completed.')}}));const a=JSON.stringify(s);o.send(e,"POST",a,n,15)}))}wo(t,e,n){const s=[this.oo,"/","google.firestore.v1.Firestore","/",t,"/channel"],r=new gs,i=fe(),o={httpSessionIdParam:"gsessionid",initMessageHeaders:{},messageUrlParams:{database:`projects/${this.databaseId.projectId}/databases/${this.databaseId.database}`},sendRawJson:!0,supportsCrossDomainXhr:!0,internalChannelParams:{forwardChannelRequestTimeoutMs:6e5},forceLongPolling:this.forceLongPolling,detectBufferingProxy:this.autoDetectLongPolling};this.useFetchStreams&&(o.xmlHttpFactory=new _s({})),this.lo(o.initMessageHeaders,e,n),o.encodeInitMessageHeaders=!0;const a=s.join("");Ms("Connection","Creating WebChannel: "+a,o);const u=r.createWebChannel(a,o);let c=!1,h=!1;const l=new qh({Hr:t=>{h?Ms("Connection","Not sending because WebChannel is closed:",t):(c||(Ms("Connection","Opening WebChannel transport."),u.open(),c=!0),Ms("Connection","WebChannel sending:",t),u.send(t))},Jr:()=>u.close()}),d=(t,e,n)=>{t.listen(e,(t=>{try{n(t)}catch(t){setTimeout((()=>{throw t}),0)}}))};return d(u,xs.EventType.OPEN,(()=>{h||Ms("Connection","WebChannel transport opened.")})),d(u,xs.EventType.CLOSE,(()=>{h||(h=!0,Ms("Connection","WebChannel transport closed"),l.io())})),d(u,xs.EventType.ERROR,(t=>{h||(h=!0,Vs("Connection","WebChannel transport errored:",t),l.io(new Ks(Gs.UNAVAILABLE,"The operation could not be completed")))})),d(u,xs.EventType.MESSAGE,(t=>{var e;if(!h){const n=t.data[0];Bs(!!n);const s=n,r=s.error||(null===(e=s[0])||void 0===e?void 0:e.error);if(r){Ms("Connection","WebChannel received error:",r);const t=r.status;let e=function(t){const e=Jo[t];if(void 0!==e)return ea(e)}(t),n=r.message;void 0===e&&(e=Gs.INTERNAL,n="Unknown error status: "+t+" with message "+r.message),h=!0,l.io(new Ks(e,n)),u.close()}else Ms("Connection","WebChannel received:",n),l.ro(n)}})),d(i,Es.STAT_EVENT,(t=>{t.stat===Ts?Ms("Connection","Detected buffering proxy"):t.stat===Ss&&Ms("Connection","Detected no buffering proxy")})),setTimeout((()=>{l.so()}),0),l}}function Kh(){return"undefined"!=typeof window?window:null}function jh(){return"undefined"!=typeof document?document:null}function $h(t){return new Aa(t,!0)}class Qh{constructor(t,e,n=1e3,s=1.5,r=6e4){this.Hs=t,this.timerId=e,this.mo=n,this.yo=s,this.po=r,this.Io=0,this.To=null,this.Eo=Date.now(),this.reset()}reset(){this.Io=0}Ao(){this.Io=this.po}Ro(t){this.cancel();const e=Math.floor(this.Io+this.bo()),n=Math.max(0,Date.now()-this.Eo),s=Math.max(0,e-n);s>0&&Ms("ExponentialBackoff",`Backing off for ${s} ms (base delay: ${this.Io} ms, delay with jitter: ${e} ms, last attempt: ${n} ms ago)`),this.To=this.Hs.enqueueAfterDelay(this.timerId,s,(()=>(this.Eo=Date.now(),t()))),this.Io*=this.yo,this.Io<this.mo&&(this.Io=this.mo),this.Io>this.po&&(this.Io=this.po)}Po(){null!==this.To&&(this.To.skipDelay(),this.To=null)}cancel(){null!==this.To&&(this.To.cancel(),this.To=null)}bo(){return(Math.random()-.5)*this.Io}}class zh{constructor(t,e,n,s,r,i,o,a){this.Hs=t,this.vo=n,this.Vo=s,this.connection=r,this.authCredentialsProvider=i,this.appCheckCredentialsProvider=o,this.listener=a,this.state=0,this.So=0,this.Do=null,this.Co=null,this.stream=null,this.xo=new Qh(t,e)}No(){return 1===this.state||5===this.state||this.ko()}ko(){return 2===this.state||3===this.state}start(){4!==this.state?this.auth():this.Oo()}async stop(){this.No()&&await this.close(0)}Mo(){this.state=0,this.xo.reset()}Fo(){this.ko()&&null===this.Do&&(this.Do=this.Hs.enqueueAfterDelay(this.vo,6e4,(()=>this.$o())))}Bo(t){this.Lo(),this.stream.send(t)}async $o(){if(this.ko())return this.close(0)}Lo(){this.Do&&(this.Do.cancel(),this.Do=null)}Uo(){this.Co&&(this.Co.cancel(),this.Co=null)}async close(t,e){this.Lo(),this.Uo(),this.xo.cancel(),this.So++,4!==t?this.xo.reset():e&&e.code===Gs.RESOURCE_EXHAUSTED?(Os(e.toString()),Os("Using maximum backoff delay to prevent overloading the backend."),this.xo.Ao()):e&&e.code===Gs.UNAUTHENTICATED&&3!==this.state&&(this.authCredentialsProvider.invalidateToken(),this.appCheckCredentialsProvider.invalidateToken()),null!==this.stream&&(this.qo(),this.stream.close(),this.stream=null),this.state=t,await this.listener.Zr(e)}qo(){}auth(){this.state=1;const t=this.Ko(this.So),e=this.So;Promise.all([this.authCredentialsProvider.getToken(),this.appCheckCredentialsProvider.getToken()]).then((([t,n])=>{this.So===e&&this.Go(t,n)}),(e=>{t((()=>{const t=new Ks(Gs.UNKNOWN,"Fetching auth token failed: "+e.message);return this.Qo(t)}))}))}Go(t,e){const n=this.Ko(this.So);this.stream=this.jo(t,e),this.stream.Yr((()=>{n((()=>(this.state=2,this.Co=this.Hs.enqueueAfterDelay(this.Vo,1e4,(()=>(this.ko()&&(this.state=3),Promise.resolve()))),this.listener.Yr())))})),this.stream.Zr((t=>{n((()=>this.Qo(t)))})),this.stream.onMessage((t=>{n((()=>this.onMessage(t)))}))}Oo(){this.state=5,this.xo.Ro((async()=>{this.state=0,this.start()}))}Qo(t){return Ms("PersistentStream",`close with error: ${t}`),this.stream=null,this.close(4,t)}Ko(t){return e=>{this.Hs.enqueueAndForget((()=>this.So===t?e():(Ms("PersistentStream","stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())))}}}class Hh extends zh{constructor(t,e,n,s,r,i){super(t,"listen_stream_connection_backoff","listen_stream_idle","health_check_timeout",e,n,s,i),this.It=r}jo(t,e){return this.connection.wo("Listen",t,e)}onMessage(t){this.xo.reset();const e=function(t,e){let n;if("targetChange"in e){e.targetChange;const s=function(t){return"NO_CHANGE"===t?0:"ADD"===t?1:"REMOVE"===t?2:"CURRENT"===t?3:"RESET"===t?4:Ps()}(e.targetChange.targetChangeType||"NO_CHANGE"),r=e.targetChange.targetIds||[],i=function(t,e){return t.gt?(Bs(void 0===e||"string"==typeof e),Yr.fromBase64String(e||"")):(Bs(void 0===e||e instanceof Uint8Array),Yr.fromUint8Array(e||new Uint8Array))}(t,e.targetChange.resumeToken),o=e.targetChange.cause,a=o&&function(t){const e=void 0===t.code?Gs.UNKNOWN:ea(t.code);return new Ks(e,t.message||"")}(o);n=new Ia(s,r,i,a||null)}else if("documentChange"in e){e.documentChange;const s=e.documentChange;s.document,s.document.name,s.document.updateTime;const r=Oa(t,s.document.name),i=ka(s.document.updateTime),o=new Ni({mapValue:{fields:s.document.fields}}),a=Ri.newFoundDocument(r,i,o),u=s.targetIds||[],c=s.removedTargetIds||[];n=new wa(u,c,a.key,a)}else if("documentDelete"in e){e.documentDelete;const s=e.documentDelete;s.document;const r=Oa(t,s.document),i=s.readTime?ka(s.readTime):or.min(),o=Ri.newNoDocument(r,i),a=s.removedTargetIds||[];n=new wa([],a,o.key,o)}else if("documentRemove"in e){e.documentRemove;const s=e.documentRemove;s.document;const r=Oa(t,s.document),i=s.removedTargetIds||[];n=new wa([],i,r,null)}else{if(!("filter"in e))return Ps();{e.filter;const t=e.filter;t.targetId;const s=t.count||0,r=new Xo(s),i=t.targetId;n=new va(i,r)}}return n}(this.It,t),n=function(t){if(!("targetChange"in t))return or.min();const e=t.targetChange;return e.targetIds&&e.targetIds.length?or.min():e.readTime?ka(e.readTime):or.min()}(t);return this.listener.Wo(e,n)}zo(t){const e={};e.database=Pa(this.It),e.addTarget=function(t,e){let n;const s=e.target;return n=Fi(s)?{documents:ja(t,s)}:{query:$a(t,s)},n.targetId=e.targetId,e.resumeToken.approximateByteSize()>0?n.resumeToken=Ca(t,e.resumeToken):e.snapshotVersion.compareTo(or.min())>0&&(n.readTime=Da(t,e.snapshotVersion.toTimestamp())),n}(this.It,t);const n=function(t,e){const n=function(t,e){switch(e){case 0:return null;case 1:return"existence-filter-mismatch";case 2:return"limbo-document";default:return Ps()}}(0,e.purpose);return null==n?null:{"goog-listen-tags":n}}(this.It,t);n&&(e.labels=n),this.Bo(e)}Ho(t){const e={};e.database=Pa(this.It),e.removeTarget=t,this.Bo(e)}}class Wh extends zh{constructor(t,e,n,s,r,i){super(t,"write_stream_connection_backoff","write_stream_idle","health_check_timeout",e,n,s,i),this.It=r,this.Jo=!1}get Yo(){return this.Jo}start(){this.Jo=!1,this.lastStreamToken=void 0,super.start()}qo(){this.Jo&&this.Xo([])}jo(t,e){return this.connection.wo("Write",t,e)}onMessage(t){if(Bs(!!t.streamToken),this.lastStreamToken=t.streamToken,this.Jo){this.xo.reset();const e=function(t,e){return t&&t.length>0?(Bs(void 0!==e),t.map((t=>function(t,e){let n=t.updateTime?ka(t.updateTime):ka(e);return n.isEqual(or.min())&&(n=ka(e)),new Oo(n,t.transformResults||[])}(t,e)))):[]}(t.writeResults,t.commitTime),n=ka(t.commitTime);return this.listener.Zo(n,e)}return Bs(!t.writeResults||0===t.writeResults.length),this.Jo=!0,this.listener.tu()}eu(){const t={};t.database=Pa(this.It),this.Bo(t)}Xo(t){const e={streamToken:this.lastStreamToken,writes:t.map((t=>Ga(this.It,t)))};this.Bo(e)}}class Yh extends class{}{constructor(t,e,n,s){super(),this.authCredentials=t,this.appCheckCredentials=e,this.connection=n,this.It=s,this.nu=!1}su(){if(this.nu)throw new Ks(Gs.FAILED_PRECONDITION,"The client has already been terminated.")}ao(t,e,n){return this.su(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([s,r])=>this.connection.ao(t,e,n,s,r))).catch((t=>{throw"FirebaseError"===t.name?(t.code===Gs.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Ks(Gs.UNKNOWN,t.toString())}))}_o(t,e,n,s){return this.su(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([r,i])=>this.connection._o(t,e,n,r,i,s))).catch((t=>{throw"FirebaseError"===t.name?(t.code===Gs.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Ks(Gs.UNKNOWN,t.toString())}))}terminate(){this.nu=!0}}class Xh{constructor(t,e){this.asyncQueue=t,this.onlineStateHandler=e,this.state="Unknown",this.iu=0,this.ru=null,this.ou=!0}uu(){0===this.iu&&(this.cu("Unknown"),this.ru=this.asyncQueue.enqueueAfterDelay("online_state_timeout",1e4,(()=>(this.ru=null,this.au("Backend didn't respond within 10 seconds."),this.cu("Offline"),Promise.resolve()))))}hu(t){"Online"===this.state?this.cu("Unknown"):(this.iu++,this.iu>=1&&(this.lu(),this.au(`Connection failed 1 times. Most recent error: ${t.toString()}`),this.cu("Offline")))}set(t){this.lu(),this.iu=0,"Online"===t&&(this.ou=!1),this.cu(t)}cu(t){t!==this.state&&(this.state=t,this.onlineStateHandler(t))}au(t){const e=`Could not reach Cloud Firestore backend. ${t}\nThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.`;this.ou?(Os(e),this.ou=!1):Ms("OnlineStateTracker",e)}lu(){null!==this.ru&&(this.ru.cancel(),this.ru=null)}}class Jh{constructor(t,e,n,s,r){this.localStore=t,this.datastore=e,this.asyncQueue=n,this.remoteSyncer={},this.fu=[],this.du=new Map,this._u=new Set,this.wu=[],this.mu=r,this.mu.qr((t=>{n.enqueueAndForget((async()=>{al(this)&&(Ms("RemoteStore","Restarting streams for network reachability change."),await async function(t){const e=qs(t);e._u.add(4),await tl(e),e.gu.set("Unknown"),e._u.delete(4),await Zh(e)}(this))}))})),this.gu=new Xh(n,s)}}async function Zh(t){if(al(t))for(const e of t.wu)await e(!0)}async function tl(t){for(const e of t.wu)await e(!1)}function el(t,e){const n=qs(t);n.du.has(e.targetId)||(n.du.set(e.targetId,e),ol(n)?il(n):_l(n).ko()&&sl(n,e))}function nl(t,e){const n=qs(t),s=_l(n);n.du.delete(e),s.ko()&&rl(n,e),0===n.du.size&&(s.ko()?s.Fo():al(n)&&n.gu.set("Unknown"))}function sl(t,e){t.yu.Mt(e.targetId),_l(t).zo(e)}function rl(t,e){t.yu.Mt(e),_l(t).Ho(e)}function il(t){t.yu=new Ea({getRemoteKeysForTarget:e=>t.remoteSyncer.getRemoteKeysForTarget(e),se:e=>t.du.get(e)||null}),_l(t).start(),t.gu.uu()}function ol(t){return al(t)&&!_l(t).No()&&t.du.size>0}function al(t){return 0===qs(t)._u.size}function ul(t){t.yu=void 0}async function cl(t){t.du.forEach(((e,n)=>{sl(t,e)}))}async function hl(t,e){ul(t),ol(t)?(t.gu.hu(e),il(t)):t.gu.set("Unknown")}async function ll(t,e,n){if(t.gu.set("Online"),e instanceof Ia&&2===e.state&&e.cause)try{await async function(t,e){const n=e.cause;for(const s of e.targetIds)t.du.has(s)&&(await t.remoteSyncer.rejectListen(s,n),t.du.delete(s),t.yu.removeTarget(s))}(t,e)}catch(n){Ms("RemoteStore","Failed to remove targets %s: %s ",e.targetIds.join(","),n),await dl(t,n)}else if(e instanceof wa?t.yu.Gt(e):e instanceof va?t.yu.Yt(e):t.yu.Wt(e),!n.isEqual(or.min()))try{const e=await wh(t.localStore);n.compareTo(e)>=0&&await function(t,e){const n=t.yu.te(e);return n.targetChanges.forEach(((n,s)=>{if(n.resumeToken.approximateByteSize()>0){const r=t.du.get(s);r&&t.du.set(s,r.withResumeToken(n.resumeToken,e))}})),n.targetMismatches.forEach((e=>{const n=t.du.get(e);if(!n)return;t.du.set(e,n.withResumeToken(Yr.EMPTY_BYTE_STRING,n.snapshotVersion)),rl(t,e);const s=new Mu(n.target,e,1,n.sequenceNumber);sl(t,s)})),t.remoteSyncer.applyRemoteEvent(n)}(t,n)}catch(e){Ms("RemoteStore","Failed to raise snapshot:",e),await dl(t,e)}}async function dl(t,e,n){if(!kr(e))throw e;t._u.add(1),await tl(t),t.gu.set("Offline"),n||(n=()=>wh(t.localStore)),t.asyncQueue.enqueueRetryable((async()=>{Ms("RemoteStore","Retrying IndexedDB access"),await n(),t._u.delete(1),await Zh(t)}))}function fl(t,e){return e().catch((n=>dl(t,n,e)))}async function ml(t){const e=qs(t),n=xl(e);let s=e.fu.length>0?e.fu[e.fu.length-1].batchId:-1;for(;gl(e);)try{const t=await Ih(e.localStore,s);if(null===t){0===e.fu.length&&n.Fo();break}s=t.batchId,pl(e,t)}catch(t){await dl(e,t)}yl(e)&&wl(e)}function gl(t){return al(t)&&t.fu.length<10}function pl(t,e){t.fu.push(e);const n=xl(t);n.ko()&&n.Yo&&n.Xo(e.mutations)}function yl(t){return al(t)&&!xl(t).No()&&t.fu.length>0}function wl(t){xl(t).start()}async function vl(t){xl(t).eu()}async function Il(t){const e=xl(t);for(const n of t.fu)e.Xo(n.mutations)}async function bl(t,e,n){const s=t.fu.shift(),r=Ru.from(s,e,n);await fl(t,(()=>t.remoteSyncer.applySuccessfulWrite(r))),await ml(t)}async function El(t,e){e&&xl(t).Yo&&await async function(t,e){if(ta(n=e.code)&&n!==Gs.ABORTED){const n=t.fu.shift();xl(t).Mo(),await fl(t,(()=>t.remoteSyncer.rejectFailedWrite(n.batchId,e))),await ml(t)}var n}(t,e),yl(t)&&wl(t)}async function Tl(t,e){const n=qs(t);n.asyncQueue.verifyOperationInProgress(),Ms("RemoteStore","RemoteStore received new credentials");const s=al(n);n._u.add(3),await tl(n),s&&n.gu.set("Unknown"),await n.remoteSyncer.handleCredentialChange(e),n._u.delete(3),await Zh(n)}async function Sl(t,e){const n=qs(t);e?(n._u.delete(2),await Zh(n)):e||(n._u.add(2),await tl(n),n.gu.set("Unknown"))}function _l(t){return t.pu||(t.pu=function(t,e,n){const s=qs(t);return s.su(),new Hh(e,s.connection,s.authCredentials,s.appCheckCredentials,s.It,n)}(t.datastore,t.asyncQueue,{Yr:cl.bind(null,t),Zr:hl.bind(null,t),Wo:ll.bind(null,t)}),t.wu.push((async e=>{e?(t.pu.Mo(),ol(t)?il(t):t.gu.set("Unknown")):(await t.pu.stop(),ul(t))}))),t.pu}function xl(t){return t.Iu||(t.Iu=function(t,e,n){const s=qs(t);return s.su(),new Wh(e,s.connection,s.authCredentials,s.appCheckCredentials,s.It,n)}(t.datastore,t.asyncQueue,{Yr:vl.bind(null,t),Zr:El.bind(null,t),tu:Il.bind(null,t),Zo:bl.bind(null,t)}),t.wu.push((async e=>{e?(t.Iu.Mo(),await ml(t)):(await t.Iu.stop(),t.fu.length>0&&(Ms("RemoteStore",`Stopping write stream with ${t.fu.length} pending writes`),t.fu=[]))}))),t.Iu}class Al{constructor(t,e,n,s,r){this.asyncQueue=t,this.timerId=e,this.targetTimeMs=n,this.op=s,this.removalCallback=r,this.deferred=new js,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch((t=>{}))}static createAndSchedule(t,e,n,s,r){const i=Date.now()+n,o=new Al(t,e,i,s,r);return o.start(n),o}start(t){this.timerHandle=setTimeout((()=>this.handleDelayElapsed()),t)}skipDelay(){return this.handleDelayElapsed()}cancel(t){null!==this.timerHandle&&(this.clearTimeout(),this.deferred.reject(new Ks(Gs.CANCELLED,"Operation cancelled"+(t?": "+t:""))))}handleDelayElapsed(){this.asyncQueue.enqueueAndForget((()=>null!==this.timerHandle?(this.clearTimeout(),this.op().then((t=>this.deferred.resolve(t)))):Promise.resolve()))}clearTimeout(){null!==this.timerHandle&&(this.removalCallback(this),clearTimeout(this.timerHandle),this.timerHandle=null)}}function Dl(t,e){if(Os("AsyncQueue",`${e}: ${t}`),kr(t))return new Ks(Gs.UNAVAILABLE,`${e}: ${t}`);throw t}class Cl{constructor(t){this.comparator=t?(e,n)=>t(e,n)||lr.comparator(e.key,n.key):(t,e)=>lr.comparator(t.key,e.key),this.keyedMap=oa(),this.sortedSet=new Gr(this.comparator)}static emptySet(t){return new Cl(t.comparator)}has(t){return null!=this.keyedMap.get(t)}get(t){return this.keyedMap.get(t)}first(){return this.sortedSet.minKey()}last(){return this.sortedSet.maxKey()}isEmpty(){return this.sortedSet.isEmpty()}indexOf(t){const e=this.keyedMap.get(t);return e?this.sortedSet.indexOf(e):-1}get size(){return this.sortedSet.size}forEach(t){this.sortedSet.inorderTraversal(((e,n)=>(t(e),!1)))}add(t){const e=this.delete(t.key);return e.copy(e.keyedMap.insert(t.key,t),e.sortedSet.insert(t,null))}delete(t){const e=this.get(t);return e?this.copy(this.keyedMap.remove(t),this.sortedSet.remove(e)):this}isEqual(t){if(!(t instanceof Cl))return!1;if(this.size!==t.size)return!1;const e=this.sortedSet.getIterator(),n=t.sortedSet.getIterator();for(;e.hasNext();){const t=e.getNext().key,s=n.getNext().key;if(!t.isEqual(s))return!1}return!0}toString(){const t=[];return this.forEach((e=>{t.push(e.toString())})),0===t.length?"DocumentSet ()":"DocumentSet (\n "+t.join(" \n")+"\n)"}copy(t,e){const n=new Cl;return n.comparator=this.comparator,n.keyedMap=t,n.sortedSet=e,n}}class Nl{constructor(){this.Tu=new Gr(lr.comparator)}track(t){const e=t.doc.key,n=this.Tu.get(e);n?0!==t.type&&3===n.type?this.Tu=this.Tu.insert(e,t):3===t.type&&1!==n.type?this.Tu=this.Tu.insert(e,{type:n.type,doc:t.doc}):2===t.type&&2===n.type?this.Tu=this.Tu.insert(e,{type:2,doc:t.doc}):2===t.type&&0===n.type?this.Tu=this.Tu.insert(e,{type:0,doc:t.doc}):1===t.type&&0===n.type?this.Tu=this.Tu.remove(e):1===t.type&&2===n.type?this.Tu=this.Tu.insert(e,{type:1,doc:n.doc}):0===t.type&&1===n.type?this.Tu=this.Tu.insert(e,{type:2,doc:t.doc}):Ps():this.Tu=this.Tu.insert(e,t)}Eu(){const t=[];return this.Tu.inorderTraversal(((e,n)=>{t.push(n)})),t}}class kl{constructor(t,e,n,s,r,i,o,a,u){this.query=t,this.docs=e,this.oldDocs=n,this.docChanges=s,this.mutatedKeys=r,this.fromCache=i,this.syncStateChanged=o,this.excludesMetadataChanges=a,this.hasCachedResults=u}static fromInitialDocuments(t,e,n,s,r){const i=[];return e.forEach((t=>{i.push({type:0,doc:t})})),new kl(t,e,Cl.emptySet(e),i,n,s,!0,!1,r)}get hasPendingWrites(){return!this.mutatedKeys.isEmpty()}isEqual(t){if(!(this.fromCache===t.fromCache&&this.hasCachedResults===t.hasCachedResults&&this.syncStateChanged===t.syncStateChanged&&this.mutatedKeys.isEqual(t.mutatedKeys)&&lo(this.query,t.query)&&this.docs.isEqual(t.docs)&&this.oldDocs.isEqual(t.oldDocs)))return!1;const e=this.docChanges,n=t.docChanges;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t].type!==n[t].type||!e[t].doc.isEqual(n[t].doc))return!1;return!0}}class Rl{constructor(){this.Au=void 0,this.listeners=[]}}class Ll{constructor(){this.queries=new na((t=>fo(t)),lo),this.onlineState="Unknown",this.Ru=new Set}}async function Ml(t,e){const n=qs(t),s=e.query;let r=!1,i=n.queries.get(s);if(i||(r=!0,i=new Rl),r)try{i.Au=await n.onListen(s)}catch(t){const n=Dl(t,`Initialization of query '${mo(e.query)}' failed`);return void e.onError(n)}n.queries.set(s,i),i.listeners.push(e),e.bu(n.onlineState),i.Au&&e.Pu(i.Au)&&Pl(n)}async function Ol(t,e){const n=qs(t),s=e.query;let r=!1;const i=n.queries.get(s);if(i){const t=i.listeners.indexOf(e);t>=0&&(i.listeners.splice(t,1),r=0===i.listeners.length)}if(r)return n.queries.delete(s),n.onUnlisten(s)}function Vl(t,e){const n=qs(t);let s=!1;for(const t of e){const e=t.query,r=n.queries.get(e);if(r){for(const e of r.listeners)e.Pu(t)&&(s=!0);r.Au=t}}s&&Pl(n)}function Fl(t,e,n){const s=qs(t),r=s.queries.get(e);if(r)for(const t of r.listeners)t.onError(n);s.queries.delete(e)}function Pl(t){t.Ru.forEach((t=>{t.next()}))}class Bl{constructor(t,e,n){this.query=t,this.vu=e,this.Vu=!1,this.Su=null,this.onlineState="Unknown",this.options=n||{}}Pu(t){if(!this.options.includeMetadataChanges){const e=[];for(const n of t.docChanges)3!==n.type&&e.push(n);t=new kl(t.query,t.docs,t.oldDocs,e,t.mutatedKeys,t.fromCache,t.syncStateChanged,!0,t.hasCachedResults)}let e=!1;return this.Vu?this.Du(t)&&(this.vu.next(t),e=!0):this.Cu(t,this.onlineState)&&(this.xu(t),e=!0),this.Su=t,e}onError(t){this.vu.error(t)}bu(t){this.onlineState=t;let e=!1;return this.Su&&!this.Vu&&this.Cu(this.Su,t)&&(this.xu(this.Su),e=!0),e}Cu(t,e){if(!t.fromCache)return!0;const n="Offline"!==e;return(!this.options.Nu||!n)&&(!t.docs.isEmpty()||t.hasCachedResults||"Offline"===e)}Du(t){if(t.docChanges.length>0)return!0;const e=this.Su&&this.Su.hasPendingWrites!==t.hasPendingWrites;return!(!t.syncStateChanged&&!e)&&!0===this.options.includeMetadataChanges}xu(t){t=kl.fromInitialDocuments(t.query,t.docs,t.mutatedKeys,t.fromCache,t.hasCachedResults),this.Vu=!0,this.vu.next(t)}}class Ul{constructor(t,e){this.ku=t,this.byteLength=e}Ou(){return"metadata"in this.ku}}class ql{constructor(t){this.It=t}Ji(t){return Oa(this.It,t)}Yi(t){return t.metadata.exists?qa(this.It,t.document,!1):Ri.newNoDocument(this.Ji(t.metadata.name),this.Xi(t.metadata.readTime))}Xi(t){return ka(t)}}class Gl{constructor(t,e,n){this.Mu=t,this.localStore=e,this.It=n,this.queries=[],this.documents=[],this.collectionGroups=new Set,this.progress=Kl(t)}Fu(t){this.progress.bytesLoaded+=t.byteLength;let e=this.progress.documentsLoaded;if(t.ku.namedQuery)this.queries.push(t.ku.namedQuery);else if(t.ku.documentMetadata){this.documents.push({metadata:t.ku.documentMetadata}),t.ku.documentMetadata.exists||++e;const n=ur.fromString(t.ku.documentMetadata.name);this.collectionGroups.add(n.get(n.length-2))}else t.ku.document&&(this.documents[this.documents.length-1].document=t.ku.document,++e);return e!==this.progress.documentsLoaded?(this.progress.documentsLoaded=e,Object.assign({},this.progress)):null}$u(t){const e=new Map,n=new ql(this.It);for(const s of t)if(s.metadata.queries){const t=n.Ji(s.metadata.name);for(const n of s.metadata.queries){const s=(e.get(n)||fa()).add(t);e.set(n,s)}}return e}async complete(){const t=await async function(t,e,n,s){const r=qs(t);let i=fa(),o=ra();for(const t of n){const n=e.Ji(t.metadata.name);t.document&&(i=i.add(n));const s=e.Yi(t);s.setReadTime(e.Xi(t.metadata.readTime)),o=o.insert(n,s)}const a=r.Gi.newChangeBuffer({trackRemovals:!0}),u=await bh(r,function(t){return co(so(ur.fromString(`__bundle__/docs/${t}`)))}(s));return r.persistence.runTransaction("Apply bundle documents","readwrite",(t=>vh(t,a,o).next((e=>(a.apply(t),e))).next((e=>r.Cs.removeMatchingKeysForTargetId(t,u.targetId).next((()=>r.Cs.addMatchingKeys(t,i,u.targetId))).next((()=>r.localDocuments.getLocalViewOfDocuments(t,e.Wi,e.zi))).next((()=>e.Wi))))))}(this.localStore,new ql(this.It),this.documents,this.Mu.id),e=this.$u(this.documents);for(const t of this.queries)await Ah(this.localStore,t,e.get(t.name));return this.progress.taskState="Success",{progress:this.progress,Bu:this.collectionGroups,Lu:t}}}function Kl(t){return{taskState:"Running",documentsLoaded:0,bytesLoaded:0,totalDocuments:t.totalDocuments,totalBytes:t.totalBytes}}class jl{constructor(t){this.key=t}}class $l{constructor(t){this.key=t}}class Ql{constructor(t,e){this.query=t,this.Uu=e,this.qu=null,this.hasCachedResults=!1,this.current=!1,this.Ku=fa(),this.mutatedKeys=fa(),this.Gu=yo(t),this.Qu=new Cl(this.Gu)}get ju(){return this.Uu}Wu(t,e){const n=e?e.zu:new Nl,s=e?e.Qu:this.Qu;let r=e?e.mutatedKeys:this.mutatedKeys,i=s,o=!1;const a="F"===this.query.limitType&&s.size===this.query.limit?s.last():null,u="L"===this.query.limitType&&s.size===this.query.limit?s.first():null;if(t.inorderTraversal(((t,e)=>{const c=s.get(t),h=go(this.query,e)?e:null,l=!!c&&this.mutatedKeys.has(c.key),d=!!h&&(h.hasLocalMutations||this.mutatedKeys.has(h.key)&&h.hasCommittedMutations);let f=!1;c&&h?c.data.isEqual(h.data)?l!==d&&(n.track({type:3,doc:h}),f=!0):this.Hu(c,h)||(n.track({type:2,doc:h}),f=!0,(a&&this.Gu(h,a)>0||u&&this.Gu(h,u)<0)&&(o=!0)):!c&&h?(n.track({type:0,doc:h}),f=!0):c&&!h&&(n.track({type:1,doc:c}),f=!0,(a||u)&&(o=!0)),f&&(h?(i=i.add(h),r=d?r.add(t):r.delete(t)):(i=i.delete(t),r=r.delete(t)))})),null!==this.query.limit)for(;i.size>this.query.limit;){const t="F"===this.query.limitType?i.last():i.first();i=i.delete(t.key),r=r.delete(t.key),n.track({type:1,doc:t})}return{Qu:i,zu:n,$i:o,mutatedKeys:r}}Hu(t,e){return t.hasLocalMutations&&e.hasCommittedMutations&&!e.hasLocalMutations}applyChanges(t,e,n){const s=this.Qu;this.Qu=t.Qu,this.mutatedKeys=t.mutatedKeys;const r=t.zu.Eu();r.sort(((t,e)=>function(t,e){const n=t=>{switch(t){case 0:return 1;case 2:case 3:return 2;case 1:return 0;default:return Ps()}};return n(t)-n(e)}(t.type,e.type)||this.Gu(t.doc,e.doc))),this.Ju(n);const i=e?this.Yu():[],o=0===this.Ku.size&&this.current?1:0,a=o!==this.qu;return this.qu=o,0!==r.length||a?{snapshot:new kl(this.query,t.Qu,s,r,t.mutatedKeys,0===o,a,!1,!!n&&n.resumeToken.approximateByteSize()>0),Xu:i}:{Xu:i}}bu(t){return this.current&&"Offline"===t?(this.current=!1,this.applyChanges({Qu:this.Qu,zu:new Nl,mutatedKeys:this.mutatedKeys,$i:!1},!1)):{Xu:[]}}Zu(t){return!this.Uu.has(t)&&!!this.Qu.has(t)&&!this.Qu.get(t).hasLocalMutations}Ju(t){t&&(t.addedDocuments.forEach((t=>this.Uu=this.Uu.add(t))),t.modifiedDocuments.forEach((t=>{})),t.removedDocuments.forEach((t=>this.Uu=this.Uu.delete(t))),this.current=t.current)}Yu(){if(!this.current)return[];const t=this.Ku;this.Ku=fa(),this.Qu.forEach((t=>{this.Zu(t.key)&&(this.Ku=this.Ku.add(t.key))}));const e=[];return t.forEach((t=>{this.Ku.has(t)||e.push(new $l(t))})),this.Ku.forEach((n=>{t.has(n)||e.push(new jl(n))})),e}tc(t){this.Uu=t.Hi,this.Ku=fa();const e=this.Wu(t.documents);return this.applyChanges(e,!0)}ec(){return kl.fromInitialDocuments(this.query,this.Qu,this.mutatedKeys,0===this.qu,this.hasCachedResults)}}class zl{constructor(t,e,n){this.query=t,this.targetId=e,this.view=n}}class Hl{constructor(t){this.key=t,this.nc=!1}}class Wl{constructor(t,e,n,s,r,i){this.localStore=t,this.remoteStore=e,this.eventManager=n,this.sharedClientState=s,this.currentUser=r,this.maxConcurrentLimboResolutions=i,this.sc={},this.ic=new na((t=>fo(t)),lo),this.rc=new Map,this.oc=new Set,this.uc=new Gr(lr.comparator),this.cc=new Map,this.ac=new Xc,this.hc={},this.lc=new Map,this.fc=Ac.vn(),this.onlineState="Unknown",this.dc=void 0}get isPrimaryClient(){return!0===this.dc}}async function Yl(t,e){const n=Ed(t);let s,r;const i=n.ic.get(e);if(i)s=i.targetId,n.sharedClientState.addLocalQueryTarget(s),r=i.view.ec();else{const t=await bh(n.localStore,co(e));n.isPrimaryClient&&el(n.remoteStore,t);const i=n.sharedClientState.addLocalQueryTarget(t.targetId);s=t.targetId,r=await Xl(n,e,s,"current"===i,t.resumeToken)}return r}async function Xl(t,e,n,s,r){t._c=(e,n,s)=>async function(t,e,n,s){let r=e.view.Wu(n);r.$i&&(r=await Th(t.localStore,e.query,!1).then((({documents:t})=>e.view.Wu(t,r))));const i=s&&s.targetChanges.get(e.targetId),o=e.view.applyChanges(r,t.isPrimaryClient,i);return ud(t,e.targetId,o.Xu),o.snapshot}(t,e,n,s);const i=await Th(t.localStore,e,!0),o=new Ql(e,i.Hi),a=o.Wu(i.documents),u=ya.createSynthesizedTargetChangeForCurrentChange(n,s&&"Offline"!==t.onlineState,r),c=o.applyChanges(a,t.isPrimaryClient,u);ud(t,n,c.Xu);const h=new zl(e,n,o);return t.ic.set(e,h),t.rc.has(n)?t.rc.get(n).push(e):t.rc.set(n,[e]),c.snapshot}async function Jl(t,e){const n=qs(t),s=n.ic.get(e),r=n.rc.get(s.targetId);if(r.length>1)return n.rc.set(s.targetId,r.filter((t=>!lo(t,e)))),void n.ic.delete(e);n.isPrimaryClient?(n.sharedClientState.removeLocalQueryTarget(s.targetId),n.sharedClientState.isActiveQueryTarget(s.targetId)||await Eh(n.localStore,s.targetId,!1).then((()=>{n.sharedClientState.clearQueryState(s.targetId),nl(n.remoteStore,s.targetId),od(n,s.targetId)})).catch(_r)):(od(n,s.targetId),await Eh(n.localStore,s.targetId,!0))}async function Zl(t,e){const n=qs(t);try{const t=await function(t,e){const n=qs(t),s=e.snapshotVersion;let r=n.Ui;return n.persistence.runTransaction("Apply remote event","readwrite-primary",(t=>{const i=n.Gi.newChangeBuffer({trackRemovals:!0});r=n.Ui;const o=[];e.targetChanges.forEach(((i,a)=>{const u=r.get(a);if(!u)return;o.push(n.Cs.removeMatchingKeys(t,i.removedDocuments,a).next((()=>n.Cs.addMatchingKeys(t,i.addedDocuments,a))));let c=u.withSequenceNumber(t.currentSequenceNumber);e.targetMismatches.has(a)?c=c.withResumeToken(Yr.EMPTY_BYTE_STRING,or.min()).withLastLimboFreeSnapshotVersion(or.min()):i.resumeToken.approximateByteSize()>0&&(c=c.withResumeToken(i.resumeToken,s)),r=r.insert(a,c),function(t,e,n){return 0===t.resumeToken.approximateByteSize()||e.snapshotVersion.toMicroseconds()-t.snapshotVersion.toMicroseconds()>=3e8||n.addedDocuments.size+n.modifiedDocuments.size+n.removedDocuments.size>0}(u,c,i)&&o.push(n.Cs.updateTargetData(t,c))}));let a=ra(),u=fa();if(e.documentUpdates.forEach((s=>{e.resolvedLimboDocuments.has(s)&&o.push(n.persistence.referenceDelegate.updateLimboDocument(t,s))})),o.push(vh(t,i,e.documentUpdates).next((t=>{a=t.Wi,u=t.zi}))),!s.isEqual(or.min())){const e=n.Cs.getLastRemoteSnapshotVersion(t).next((e=>n.Cs.setTargetsMetadata(t,t.currentSequenceNumber,s)));o.push(e)}return xr.waitFor(o).next((()=>i.apply(t))).next((()=>n.localDocuments.getLocalViewOfDocuments(t,a,u))).next((()=>a))})).then((t=>(n.Ui=r,t)))}(n.localStore,e);e.targetChanges.forEach(((t,e)=>{const s=n.cc.get(e);s&&(Bs(t.addedDocuments.size+t.modifiedDocuments.size+t.removedDocuments.size<=1),t.addedDocuments.size>0?s.nc=!0:t.modifiedDocuments.size>0?Bs(s.nc):t.removedDocuments.size>0&&(Bs(s.nc),s.nc=!1))})),await ld(n,t,e)}catch(t){await _r(t)}}function td(t,e,n){const s=qs(t);if(s.isPrimaryClient&&0===n||!s.isPrimaryClient&&1===n){const t=[];s.ic.forEach(((n,s)=>{const r=s.view.bu(e);r.snapshot&&t.push(r.snapshot)})),function(t,e){const n=qs(t);n.onlineState=e;let s=!1;n.queries.forEach(((t,n)=>{for(const t of n.listeners)t.bu(e)&&(s=!0)})),s&&Pl(n)}(s.eventManager,e),t.length&&s.sc.Wo(t),s.onlineState=e,s.isPrimaryClient&&s.sharedClientState.setOnlineState(e)}}async function ed(t,e,n){const s=qs(t);s.sharedClientState.updateQueryState(e,"rejected",n);const r=s.cc.get(e),i=r&&r.key;if(i){let t=new Gr(lr.comparator);t=t.insert(i,Ri.newNoDocument(i,or.min()));const n=fa().add(i),r=new pa(or.min(),new Map,new $r(nr),t,n);await Zl(s,r),s.uc=s.uc.remove(i),s.cc.delete(e),hd(s)}else await Eh(s.localStore,e,!1).then((()=>od(s,e,n))).catch(_r)}async function nd(t,e){const n=qs(t),s=e.batch.batchId;try{const t=await function(t,e){const n=qs(t);return n.persistence.runTransaction("Acknowledge batch","readwrite-primary",(t=>{const s=e.batch.keys(),r=n.Gi.newChangeBuffer({trackRemovals:!0});return function(t,e,n,s){const r=n.batch,i=r.keys();let o=xr.resolve();return i.forEach((t=>{o=o.next((()=>s.getEntry(e,t))).next((e=>{const i=n.docVersions.get(t);Bs(null!==i),e.version.compareTo(i)<0&&(r.applyToRemoteDocument(e,n),e.isValidDocument()&&(e.setReadTime(n.commitVersion),s.addEntry(e)))}))})),o.next((()=>t.mutationQueue.removeMutationBatch(e,r)))}(n,t,e,r).next((()=>r.apply(t))).next((()=>n.mutationQueue.performConsistencyCheck(t))).next((()=>n.documentOverlayCache.removeOverlaysForBatchId(t,s,e.batch.batchId))).next((()=>n.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(t,function(t){let e=fa();for(let n=0;n<t.mutationResults.length;++n)t.mutationResults[n].transformResults.length>0&&(e=e.add(t.batch.mutations[n].key));return e}(e)))).next((()=>n.localDocuments.getDocuments(t,s)))}))}(n.localStore,e);id(n,s,null),rd(n,s),n.sharedClientState.updateMutationState(s,"acknowledged"),await ld(n,t)}catch(t){await _r(t)}}async function sd(t,e,n){const s=qs(t);try{const t=await function(t,e){const n=qs(t);return n.persistence.runTransaction("Reject batch","readwrite-primary",(t=>{let s;return n.mutationQueue.lookupMutationBatch(t,e).next((e=>(Bs(null!==e),s=e.keys(),n.mutationQueue.removeMutationBatch(t,e)))).next((()=>n.mutationQueue.performConsistencyCheck(t))).next((()=>n.documentOverlayCache.removeOverlaysForBatchId(t,s,e))).next((()=>n.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(t,s))).next((()=>n.localDocuments.getDocuments(t,s)))}))}(s.localStore,e);id(s,e,n),rd(s,e),s.sharedClientState.updateMutationState(e,"rejected",n),await ld(s,t)}catch(n){await _r(n)}}function rd(t,e){(t.lc.get(e)||[]).forEach((t=>{t.resolve()})),t.lc.delete(e)}function id(t,e,n){const s=qs(t);let r=s.hc[s.currentUser.toKey()];if(r){const t=r.get(e);t&&(n?t.reject(n):t.resolve(),r=r.remove(e)),s.hc[s.currentUser.toKey()]=r}}function od(t,e,n=null){t.sharedClientState.removeLocalQueryTarget(e);for(const s of t.rc.get(e))t.ic.delete(s),n&&t.sc.wc(s,n);t.rc.delete(e),t.isPrimaryClient&&t.ac.ls(e).forEach((e=>{t.ac.containsKey(e)||ad(t,e)}))}function ad(t,e){t.oc.delete(e.path.canonicalString());const n=t.uc.get(e);null!==n&&(nl(t.remoteStore,n),t.uc=t.uc.remove(e),t.cc.delete(n),hd(t))}function ud(t,e,n){for(const s of n)s instanceof jl?(t.ac.addReference(s.key,e),cd(t,s)):s instanceof $l?(Ms("SyncEngine","Document no longer in limbo: "+s.key),t.ac.removeReference(s.key,e),t.ac.containsKey(s.key)||ad(t,s.key)):Ps()}function cd(t,e){const n=e.key,s=n.path.canonicalString();t.uc.get(n)||t.oc.has(s)||(Ms("SyncEngine","New document in limbo: "+n),t.oc.add(s),hd(t))}function hd(t){for(;t.oc.size>0&&t.uc.size<t.maxConcurrentLimboResolutions;){const e=t.oc.values().next().value;t.oc.delete(e);const n=new lr(ur.fromString(e)),s=t.fc.next();t.cc.set(s,new Hl(n)),t.uc=t.uc.insert(n,s),el(t.remoteStore,new Mu(co(so(n.path)),s,2,Pr.at))}}async function ld(t,e,n){const s=qs(t),r=[],i=[],o=[];s.ic.isEmpty()||(s.ic.forEach(((t,a)=>{o.push(s._c(a,e,n).then((t=>{if((t||n)&&s.isPrimaryClient&&s.sharedClientState.updateQueryState(a.targetId,(null==t?void 0:t.fromCache)?"not-current":"current"),t){r.push(t);const e=fh.Ci(a.targetId,t);i.push(e)}})))})),await Promise.all(o),s.sc.Wo(r),await async function(t,e){const n=qs(t);try{await n.persistence.runTransaction("notifyLocalViewChanges","readwrite",(t=>xr.forEach(e,(e=>xr.forEach(e.Si,(s=>n.persistence.referenceDelegate.addReference(t,e.targetId,s))).next((()=>xr.forEach(e.Di,(s=>n.persistence.referenceDelegate.removeReference(t,e.targetId,s)))))))))}catch(t){if(!kr(t))throw t;Ms("LocalStore","Failed to update sequence numbers: "+t)}for(const t of e){const e=t.targetId;if(!t.fromCache){const t=n.Ui.get(e),s=t.snapshotVersion,r=t.withLastLimboFreeSnapshotVersion(s);n.Ui=n.Ui.insert(e,r)}}}(s.localStore,i))}async function dd(t,e){const n=qs(t);if(!n.currentUser.isEqual(e)){Ms("SyncEngine","User change. New user:",e.toKey());const t=await yh(n.localStore,e);n.currentUser=e,function(t,e){t.lc.forEach((t=>{t.forEach((t=>{t.reject(new Ks(Gs.CANCELLED,"'waitForPendingWrites' promise is rejected due to a user change."))}))})),t.lc.clear()}(n),n.sharedClientState.handleUserChange(e,t.removedBatchIds,t.addedBatchIds),await ld(n,t.ji)}}function fd(t,e){const n=qs(t),s=n.cc.get(e);if(s&&s.nc)return fa().add(s.key);{let t=fa();const s=n.rc.get(e);if(!s)return t;for(const e of s){const s=n.ic.get(e);t=t.unionWith(s.view.ju)}return t}}async function md(t,e){const n=qs(t),s=await Th(n.localStore,e.query,!0),r=e.view.tc(s);return n.isPrimaryClient&&ud(n,e.targetId,r.Xu),r}async function gd(t,e){const n=qs(t);return _h(n.localStore,e).then((t=>ld(n,t)))}async function pd(t,e,n,s){const r=qs(t),i=await function(t,e){const n=qs(t),s=qs(n.mutationQueue);return n.persistence.runTransaction("Lookup mutation documents","readonly",(t=>s.Tn(t,e).next((e=>e?n.localDocuments.getDocuments(t,e):xr.resolve(null)))))}(r.localStore,e);null!==i?("pending"===n?await ml(r.remoteStore):"acknowledged"===n||"rejected"===n?(id(r,e,s||null),rd(r,e),function(t,e){qs(qs(t).mutationQueue).An(e)}(r.localStore,e)):Ps(),await ld(r,i)):Ms("SyncEngine","Cannot apply mutation batch with id: "+e)}async function yd(t,e,n){const s=qs(t),r=[],i=[];for(const t of e){let e;const n=s.rc.get(t);if(n&&0!==n.length){e=await bh(s.localStore,co(n[0]));for(const t of n){const e=s.ic.get(t),n=await md(s,e);n.snapshot&&i.push(n.snapshot)}}else{const n=await Sh(s.localStore,t);e=await bh(s.localStore,n),await Xl(s,wd(n),t,!1,e.resumeToken)}r.push(e)}return s.sc.Wo(i),r}function wd(t){return no(t.path,t.collectionGroup,t.orderBy,t.filters,t.limit,"F",t.startAt,t.endAt)}function vd(t){const e=qs(t);return qs(qs(e.localStore).persistence).vi()}async function Id(t,e,n,s){const r=qs(t);if(r.dc)return void Ms("SyncEngine","Ignoring unexpected query state notification.");const i=r.rc.get(e);if(i&&i.length>0)switch(n){case"current":case"not-current":{const t=await _h(r.localStore,po(i[0])),s=pa.createSynthesizedRemoteEventForCurrentChange(e,"current"===n,Yr.EMPTY_BYTE_STRING);await ld(r,t,s);break}case"rejected":await Eh(r.localStore,e,!0),od(r,e,s);break;default:Ps()}}async function bd(t,e,n){const s=Ed(t);if(s.dc){for(const t of e){if(s.rc.has(t)){Ms("SyncEngine","Adding an already active target "+t);continue}const e=await Sh(s.localStore,t),n=await bh(s.localStore,e);await Xl(s,wd(e),n.targetId,!1,n.resumeToken),el(s.remoteStore,n)}for(const t of n)s.rc.has(t)&&await Eh(s.localStore,t,!1).then((()=>{nl(s.remoteStore,t),od(s,t)})).catch(_r)}}function Ed(t){const e=qs(t);return e.remoteStore.remoteSyncer.applyRemoteEvent=Zl.bind(null,e),e.remoteStore.remoteSyncer.getRemoteKeysForTarget=fd.bind(null,e),e.remoteStore.remoteSyncer.rejectListen=ed.bind(null,e),e.sc.Wo=Vl.bind(null,e.eventManager),e.sc.wc=Fl.bind(null,e.eventManager),e}function Td(t){const e=qs(t);return e.remoteStore.remoteSyncer.applySuccessfulWrite=nd.bind(null,e),e.remoteStore.remoteSyncer.rejectFailedWrite=sd.bind(null,e),e}class Sd{constructor(){this.synchronizeTabs=!1}async initialize(t){this.It=$h(t.databaseInfo.databaseId),this.sharedClientState=this.gc(t),this.persistence=this.yc(t),await this.persistence.start(),this.localStore=this.Ic(t),this.gcScheduler=this.Tc(t,this.localStore),this.indexBackfillerScheduler=this.Ec(t,this.localStore)}Tc(t,e){return null}Ec(t,e){return null}Ic(t){return ph(this.persistence,new mh,t.initialUser,this.It)}yc(t){return new sh(ih.Bs,this.It)}gc(t){return new Fh}async terminate(){this.gcScheduler&&this.gcScheduler.stop(),await this.sharedClientState.shutdown(),await this.persistence.shutdown()}}class _d extends Sd{constructor(t,e,n){super(),this.Ac=t,this.cacheSizeBytes=e,this.forceOwnership=n,this.synchronizeTabs=!1}async initialize(t){await super.initialize(t),await this.Ac.initialize(this,t),await Td(this.Ac.syncEngine),await ml(this.Ac.remoteStore),await this.persistence.li((()=>(this.gcScheduler&&!this.gcScheduler.started&&this.gcScheduler.start(),this.indexBackfillerScheduler&&!this.indexBackfillerScheduler.started&&this.indexBackfillerScheduler.start(),Promise.resolve())))}Ic(t){return ph(this.persistence,new mh,t.initialUser,this.It)}Tc(t,e){const n=this.persistence.referenceDelegate.garbageCollector;return new Mc(n,t.asyncQueue,e)}Ec(t,e){const n=new Fr(e,this.persistence);return new Vr(t.asyncQueue,n)}yc(t){const e=dh(t.databaseInfo.databaseId,t.databaseInfo.persistenceKey),n=void 0!==this.cacheSizeBytes?vc.withCacheSize(this.cacheSizeBytes):vc.DEFAULT;return new ch(this.synchronizeTabs,e,t.clientId,n,t.asyncQueue,Kh(),jh(),this.It,this.sharedClientState,!!this.forceOwnership)}gc(t){return new Fh}}class xd extends _d{constructor(t,e){super(t,e,!1),this.Ac=t,this.cacheSizeBytes=e,this.synchronizeTabs=!0}async initialize(t){await super.initialize(t);const e=this.Ac.syncEngine;this.sharedClientState instanceof Vh&&(this.sharedClientState.syncEngine={Fr:pd.bind(null,e),$r:Id.bind(null,e),Br:bd.bind(null,e),vi:vd.bind(null,e),Mr:gd.bind(null,e)},await this.sharedClientState.start()),await this.persistence.li((async t=>{await async function(t,e){const n=qs(t);if(Ed(n),Td(n),!0===e&&!0!==n.dc){const t=n.sharedClientState.getAllActiveQueryTargets(),e=await yd(n,t.toArray());n.dc=!0,await Sl(n.remoteStore,!0);for(const t of e)el(n.remoteStore,t)}else if(!1===e&&!1!==n.dc){const t=[];let e=Promise.resolve();n.rc.forEach(((s,r)=>{n.sharedClientState.isLocalQueryTarget(r)?t.push(r):e=e.then((()=>(od(n,r),Eh(n.localStore,r,!0)))),nl(n.remoteStore,r)})),await e,await yd(n,t),function(t){const e=qs(t);e.cc.forEach(((t,n)=>{nl(e.remoteStore,n)})),e.ac.fs(),e.cc=new Map,e.uc=new Gr(lr.comparator)}(n),n.dc=!1,await Sl(n.remoteStore,!1)}}(this.Ac.syncEngine,t),this.gcScheduler&&(t&&!this.gcScheduler.started?this.gcScheduler.start():t||this.gcScheduler.stop()),this.indexBackfillerScheduler&&(t&&!this.indexBackfillerScheduler.started?this.indexBackfillerScheduler.start():t||this.indexBackfillerScheduler.stop())}))}gc(t){const e=Kh();if(!Vh.C(e))throw new Ks(Gs.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");const n=dh(t.databaseInfo.databaseId,t.databaseInfo.persistenceKey);return new Vh(e,t.asyncQueue,n,t.clientId,t.initialUser)}}class Ad{async initialize(t,e){this.localStore||(this.localStore=t.localStore,this.sharedClientState=t.sharedClientState,this.datastore=this.createDatastore(e),this.remoteStore=this.createRemoteStore(e),this.eventManager=this.createEventManager(e),this.syncEngine=this.createSyncEngine(e,!t.synchronizeTabs),this.sharedClientState.onlineStateHandler=t=>td(this.syncEngine,t,1),this.remoteStore.remoteSyncer.handleCredentialChange=dd.bind(null,this.syncEngine),await Sl(this.remoteStore,this.syncEngine.isPrimaryClient))}createEventManager(t){return new Ll}createDatastore(t){const e=$h(t.databaseInfo.databaseId),n=(s=t.databaseInfo,new Gh(s));var s;return function(t,e,n,s){return new Yh(t,e,n,s)}(t.authCredentials,t.appCheckCredentials,n,e)}createRemoteStore(t){return e=this.localStore,n=this.datastore,s=t.asyncQueue,r=t=>td(this.syncEngine,t,0),i=Bh.C()?new Bh:new Ph,new Jh(e,n,s,r,i);var e,n,s,r,i}createSyncEngine(t,e){return function(t,e,n,s,r,i,o){const a=new Wl(t,e,n,s,r,i);return o&&(a.dc=!0),a}(this.localStore,this.remoteStore,this.eventManager,this.sharedClientState,t.initialUser,t.maxConcurrentLimboResolutions,e)}terminate(){return async function(t){const e=qs(t);Ms("RemoteStore","RemoteStore shutting down."),e._u.add(5),await tl(e),e.mu.shutdown(),e.gu.set("Unknown")}(this.remoteStore)}}function Dd(t,e,n){if(!n)throw new Ks(Gs.INVALID_ARGUMENT,`Function ${t}() cannot be called with an empty ${e}.`)}function Cd(t,e,n,s){if(!0===e&&!0===s)throw new Ks(Gs.INVALID_ARGUMENT,`${t} and ${n} cannot be used together.`)}function Nd(t){if(!lr.isDocumentKey(t))throw new Ks(Gs.INVALID_ARGUMENT,`Invalid document reference. Document references must have an even number of segments, but ${t} has ${t.length}.`)}function kd(t){if(lr.isDocumentKey(t))throw new Ks(Gs.INVALID_ARGUMENT,`Invalid collection reference. Collection references must have an odd number of segments, but ${t} has ${t.length}.`)}function Rd(t){if(void 0===t)return"undefined";if(null===t)return"null";if("string"==typeof t)return t.length>20&&(t=`${t.substring(0,20)}...`),JSON.stringify(t);if("number"==typeof t||"boolean"==typeof t)return""+t;if("object"==typeof t){if(t instanceof Array)return"an array";{const e=function(t){return t.constructor?t.constructor.name:null}(t);return e?`a custom ${e} object`:"an object"}}return"function"==typeof t?"a function":Ps()}function Ld(t,e){if("_delegate"in t&&(t=t._delegate),!(t instanceof e)){if(e.name===t.constructor.name)throw new Ks(Gs.INVALID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{const n=Rd(t);throw new Ks(Gs.INVALID_ARGUMENT,`Expected type '${e.name}', but it was: ${n}`)}}return t}function Md(t,e){if(e<=0)throw new Ks(Gs.INVALID_ARGUMENT,`Function ${t}() requires a positive number, but it was: ${e}.`)}const Od=new Map;class Vd{constructor(t){var e;if(void 0===t.host){if(void 0!==t.ssl)throw new Ks(Gs.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host="firestore.googleapis.com",this.ssl=!0}else this.host=t.host,this.ssl=null===(e=t.ssl)||void 0===e||e;if(this.credentials=t.credentials,this.ignoreUndefinedProperties=!!t.ignoreUndefinedProperties,void 0===t.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==t.cacheSizeBytes&&t.cacheSizeBytes<1048576)throw new Ks(Gs.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=t.cacheSizeBytes}this.experimentalForceLongPolling=!!t.experimentalForceLongPolling,this.experimentalAutoDetectLongPolling=!!t.experimentalAutoDetectLongPolling,this.useFetchStreams=!!t.useFetchStreams,Cd("experimentalForceLongPolling",t.experimentalForceLongPolling,"experimentalAutoDetectLongPolling",t.experimentalAutoDetectLongPolling)}isEqual(t){return this.host===t.host&&this.ssl===t.ssl&&this.credentials===t.credentials&&this.cacheSizeBytes===t.cacheSizeBytes&&this.experimentalForceLongPolling===t.experimentalForceLongPolling&&this.experimentalAutoDetectLongPolling===t.experimentalAutoDetectLongPolling&&this.ignoreUndefinedProperties===t.ignoreUndefinedProperties&&this.useFetchStreams===t.useFetchStreams}}class Fd{constructor(t,e,n,s){this._authCredentials=t,this._appCheckCredentials=e,this._databaseId=n,this._app=s,this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new Vd({}),this._settingsFrozen=!1}get app(){if(!this._app)throw new Ks(Gs.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this._app}get _initialized(){return this._settingsFrozen}get _terminated(){return void 0!==this._terminateTask}_setSettings(t){if(this._settingsFrozen)throw new Ks(Gs.FAILED_PRECONDITION,"Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.");this._settings=new Vd(t),void 0!==t.credentials&&(this._authCredentials=function(t){if(!t)return new Qs;switch(t.type){case"gapi":const e=t.client;return new Ys(e,t.sessionIndex||"0",t.iamToken||null,t.authTokenFactory||null);case"provider":return t.client;default:throw new Ks(Gs.INVALID_ARGUMENT,"makeAuthCredentialsProvider failed due to invalid credential type")}}(t.credentials))}_getSettings(){return this._settings}_freezeSettings(){return this._settingsFrozen=!0,this._settings}_delete(){return this._terminateTask||(this._terminateTask=this._terminate()),this._terminateTask}toJSON(){return{app:this._app,databaseId:this._databaseId,settings:this._settings}}_terminate(){return function(t){const e=Od.get(t);e&&(Ms("ComponentProvider","Removing Datastore"),Od.delete(t),e.terminate())}(this),Promise.resolve()}}function Pd(t,e,n,s={}){var r;const i=(t=Ld(t,Fd))._getSettings();if("firestore.googleapis.com"!==i.host&&i.host!==e&&Vs("Host has been set in both settings() and useEmulator(), emulator host will be used"),t._setSettings(Object.assign(Object.assign({},i),{host:`${e}:${n}`,ssl:!1})),s.mockUserToken){let e,n;if("string"==typeof s.mockUserToken)e=s.mockUserToken,n=Cs.MOCK_USER;else{e=function(t,e){if(t.uid)throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');const n=e||"demo-project",s=t.iat||0,r=t.sub||t.user_id;if(!r)throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");const i=Object.assign({iss:`https://securetoken.google.com/${n}`,aud:n,iat:s,exp:s+3600,auth_time:s,sub:r,user_id:r,firebase:{sign_in_provider:"custom",identities:{}}},t);return[u(JSON.stringify({alg:"none",type:"JWT"})),u(JSON.stringify(i)),""].join(".")}(s.mockUserToken,null===(r=t._app)||void 0===r?void 0:r.options.projectId);const i=s.mockUserToken.sub||s.mockUserToken.user_id;if(!i)throw new Ks(Gs.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");n=new Cs(i)}t._authCredentials=new zs(new $s(e,n))}}class Bd{constructor(t,e,n){this.converter=e,this._key=n,this.type="document",this.firestore=t}get _path(){return this._key.path}get id(){return this._key.path.lastSegment()}get path(){return this._key.path.canonicalString()}get parent(){return new qd(this.firestore,this.converter,this._key.path.popLast())}withConverter(t){return new Bd(this.firestore,t,this._key)}}class Ud{constructor(t,e,n){this.converter=e,this._query=n,this.type="query",this.firestore=t}withConverter(t){return new Ud(this.firestore,t,this._query)}}class qd extends Ud{constructor(t,e,n){super(t,e,so(n)),this._path=n,this.type="collection"}get id(){return this._query.path.lastSegment()}get path(){return this._query.path.canonicalString()}get parent(){const t=this._path.popLast();return t.isEmpty()?null:new Bd(this.firestore,null,new lr(t))}withConverter(t){return new qd(this.firestore,t,this._path)}}function Gd(t,e,...n){if(t=I(t),Dd("collection","path",e),t instanceof Fd){const s=ur.fromString(e,...n);return kd(s),new qd(t,null,s)}{if(!(t instanceof Bd||t instanceof qd))throw new Ks(Gs.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const s=t._path.child(ur.fromString(e,...n));return kd(s),new qd(t.firestore,null,s)}}function Kd(t,e){if(t=Ld(t,Fd),Dd("collectionGroup","collection id",e),e.indexOf("/")>=0)throw new Ks(Gs.INVALID_ARGUMENT,`Invalid collection ID '${e}' passed to function collectionGroup(). Collection IDs must not contain '/'.`);return new Ud(t,null,function(t){return new eo(ur.emptyPath(),t)}(e))}function jd(t,e,...n){if(t=I(t),1===arguments.length&&(e=er.R()),Dd("doc","path",e),t instanceof Fd){const s=ur.fromString(e,...n);return Nd(s),new Bd(t,null,new lr(s))}{if(!(t instanceof Bd||t instanceof qd))throw new Ks(Gs.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const s=t._path.child(ur.fromString(e,...n));return Nd(s),new Bd(t.firestore,t instanceof qd?t.converter:null,new lr(s))}}function $d(t,e){return t=I(t),e=I(e),(t instanceof Bd||t instanceof qd)&&(e instanceof Bd||e instanceof qd)&&t.firestore===e.firestore&&t.path===e.path&&t.converter===e.converter}function Qd(t,e){return t=I(t),e=I(e),t instanceof Ud&&e instanceof Ud&&t.firestore===e.firestore&&lo(t._query,e._query)&&t.converter===e.converter}function zd(t,e=10240){let n=0;return{async read(){if(n<t.byteLength){const s={value:t.slice(n,n+e),done:!1};return n+=e,s}return{done:!0}},async cancel(){},releaseLock(){},closed:Promise.reject("unimplemented")}}class Hd{constructor(t){this.observer=t,this.muted=!1}next(t){this.observer.next&&this.Rc(this.observer.next,t)}error(t){this.observer.error?this.Rc(this.observer.error,t):Os("Uncaught Error in snapshot listener:",t)}bc(){this.muted=!0}Rc(t,e){this.muted||setTimeout((()=>{this.muted||t(e)}),0)}}class Wd{constructor(t,e){this.Pc=t,this.It=e,this.metadata=new js,this.buffer=new Uint8Array,this.vc=new TextDecoder("utf-8"),this.Vc().then((t=>{t&&t.Ou()?this.metadata.resolve(t.ku.metadata):this.metadata.reject(new Error(`The first element of the bundle is not a metadata, it is\n ${JSON.stringify(null==t?void 0:t.ku)}`))}),(t=>this.metadata.reject(t)))}close(){return this.Pc.cancel()}async getMetadata(){return this.metadata.promise}async mc(){return await this.getMetadata(),this.Vc()}async Vc(){const t=await this.Sc();if(null===t)return null;const e=this.vc.decode(t),n=Number(e);isNaN(n)&&this.Dc(`length string (${e}) is not valid number`);const s=await this.Cc(n);return new Ul(JSON.parse(s),t.length+n)}xc(){return this.buffer.findIndex((t=>t==="{".charCodeAt(0)))}async Sc(){for(;this.xc()<0&&!await this.Nc(););if(0===this.buffer.length)return null;const t=this.xc();t<0&&this.Dc("Reached the end of bundle when a length string is expected.");const e=this.buffer.slice(0,t);return this.buffer=this.buffer.slice(t),e}async Cc(t){for(;this.buffer.length<t;)await this.Nc()&&this.Dc("Reached the end of bundle when more is expected.");const e=this.vc.decode(this.buffer.slice(0,t));return this.buffer=this.buffer.slice(t),e}Dc(t){throw this.Pc.cancel(),new Error(`Invalid bundle format: ${t}`)}async Nc(){const t=await this.Pc.read();if(!t.done){const e=new Uint8Array(this.buffer.length+t.value.length);e.set(this.buffer),e.set(t.value,this.buffer.length),this.buffer=e}return t.done}}class Yd{constructor(){this.type="AggregateField"}}class Xd{constructor(t,e){this._data=e,this.type="AggregateQuerySnapshot",this.query=t}data(){return this._data}}class Jd{constructor(t,e,n){this.query=t,this.datastore=e,this.userDataWriter=n}run(){return async function(t,e){const n=qs(t),s=function(t,e){const n=$a(t,e);return{structuredAggregationQuery:{aggregations:[{count:{},alias:"count_alias"}],structuredQuery:n.structuredQuery},parent:n.parent}}(n.It,co(e)),r=s.parent;return n.connection.co||delete s.parent,(await n._o("RunAggregationQuery",r,s,1)).filter((t=>!!t.result)).map((t=>t.result.aggregateFields))}(this.datastore,this.query._query).then((t=>{Bs(void 0!==t[0]);const e=Object.entries(t[0]).filter((([t,e])=>"count_alias"===t)).map((([t,e])=>this.userDataWriter.convertValue(e)))[0];return Bs("number"==typeof e),Promise.resolve(new Xd(this.query,{count:e}))}))}}class Zd{constructor(t){this.datastore=t,this.readVersions=new Map,this.mutations=[],this.committed=!1,this.lastWriteError=null,this.writtenDocs=new Set}async lookup(t){if(this.ensureCommitNotCalled(),this.mutations.length>0)throw new Ks(Gs.INVALID_ARGUMENT,"Firestore transactions require all reads to be executed before all writes.");const e=await async function(t,e){const n=qs(t),s=Pa(n.It)+"/documents",r={documents:e.map((t=>Ma(n.It,t)))},i=await n._o("BatchGetDocuments",s,r,e.length),o=new Map;i.forEach((t=>{const e=function(t,e){return"found"in e?function(t,e){Bs(!!e.found),e.found.name,e.found.updateTime;const n=Oa(t,e.found.name),s=ka(e.found.updateTime),r=new Ni({mapValue:{fields:e.found.fields}});return Ri.newFoundDocument(n,s,r)}(t,e):"missing"in e?function(t,e){Bs(!!e.missing),Bs(!!e.readTime);const n=Oa(t,e.missing),s=ka(e.readTime);return Ri.newNoDocument(n,s)}(t,e):Ps()}(n.It,t);o.set(e.key.toString(),e)}));const a=[];return e.forEach((t=>{const e=o.get(t.toString());Bs(!!e),a.push(e)})),a}(this.datastore,t);return e.forEach((t=>this.recordVersion(t))),e}set(t,e){this.write(e.toMutation(t,this.precondition(t))),this.writtenDocs.add(t.toString())}update(t,e){try{this.write(e.toMutation(t,this.preconditionForUpdate(t)))}catch(t){this.lastWriteError=t}this.writtenDocs.add(t.toString())}delete(t){this.write(new Wo(t,this.precondition(t))),this.writtenDocs.add(t.toString())}async commit(){if(this.ensureCommitNotCalled(),this.lastWriteError)throw this.lastWriteError;const t=this.readVersions;this.mutations.forEach((e=>{t.delete(e.key.toString())})),t.forEach(((t,e)=>{const n=lr.fromPath(e);this.mutations.push(new Yo(n,this.precondition(n)))})),await async function(t,e){const n=qs(t),s=Pa(n.It)+"/documents",r={writes:e.map((t=>Ga(n.It,t)))};await n.ao("Commit",s,r)}(this.datastore,this.mutations),this.committed=!0}recordVersion(t){let e;if(t.isFoundDocument())e=t.version;else{if(!t.isNoDocument())throw Ps();e=or.min()}const n=this.readVersions.get(t.key.toString());if(n){if(!e.isEqual(n))throw new Ks(Gs.ABORTED,"Document version changed between two reads.")}else this.readVersions.set(t.key.toString(),e)}precondition(t){const e=this.readVersions.get(t.toString());return!this.writtenDocs.has(t.toString())&&e?e.isEqual(or.min())?Vo.exists(!1):Vo.updateTime(e):Vo.none()}preconditionForUpdate(t){const e=this.readVersions.get(t.toString());if(!this.writtenDocs.has(t.toString())&&e){if(e.isEqual(or.min()))throw new Ks(Gs.INVALID_ARGUMENT,"Can't update a document that doesn't exist.");return Vo.updateTime(e)}return Vo.exists(!0)}write(t){this.ensureCommitNotCalled(),this.mutations.push(t)}ensureCommitNotCalled(){}}class tf{constructor(t,e,n,s,r){this.asyncQueue=t,this.datastore=e,this.options=n,this.updateFunction=s,this.deferred=r,this.kc=n.maxAttempts,this.xo=new Qh(this.asyncQueue,"transaction_retry")}run(){this.kc-=1,this.Oc()}Oc(){this.xo.Ro((async()=>{const t=new Zd(this.datastore),e=this.Mc(t);e&&e.then((e=>{this.asyncQueue.enqueueAndForget((()=>t.commit().then((()=>{this.deferred.resolve(e)})).catch((t=>{this.Fc(t)}))))})).catch((t=>{this.Fc(t)}))}))}Mc(t){try{const e=this.updateFunction(t);return!oi(e)&&e.catch&&e.then?e:(this.deferred.reject(Error("Transaction callback must return a Promise")),null)}catch(t){return this.deferred.reject(t),null}}Fc(t){this.kc>0&&this.$c(t)?(this.kc-=1,this.asyncQueue.enqueueAndForget((()=>(this.Oc(),Promise.resolve())))):this.deferred.reject(t)}$c(t){if("FirebaseError"===t.name){const e=t.code;return"aborted"===e||"failed-precondition"===e||!ta(e)}return!1}}class ef{constructor(t,e,n,s){this.authCredentials=t,this.appCheckCredentials=e,this.asyncQueue=n,this.databaseInfo=s,this.user=Cs.UNAUTHENTICATED,this.clientId=er.R(),this.authCredentialListener=()=>Promise.resolve(),this.appCheckCredentialListener=()=>Promise.resolve(),this.authCredentials.start(n,(async t=>{Ms("FirestoreClient","Received user=",t.uid),await this.authCredentialListener(t),this.user=t})),this.appCheckCredentials.start(n,(t=>(Ms("FirestoreClient","Received new app check token=",t),this.appCheckCredentialListener(t,this.user))))}async getConfiguration(){return{asyncQueue:this.asyncQueue,databaseInfo:this.databaseInfo,clientId:this.clientId,authCredentials:this.authCredentials,appCheckCredentials:this.appCheckCredentials,initialUser:this.user,maxConcurrentLimboResolutions:100}}setCredentialChangeListener(t){this.authCredentialListener=t}setAppCheckTokenChangeListener(t){this.appCheckCredentialListener=t}verifyNotTerminated(){if(this.asyncQueue.isShuttingDown)throw new Ks(Gs.FAILED_PRECONDITION,"The client has already been terminated.")}terminate(){this.asyncQueue.enterRestrictedMode();const t=new js;return this.asyncQueue.enqueueAndForgetEvenWhileRestricted((async()=>{try{this.onlineComponents&&await this.onlineComponents.terminate(),this.offlineComponents&&await this.offlineComponents.terminate(),this.authCredentials.shutdown(),this.appCheckCredentials.shutdown(),t.resolve()}catch(e){const n=Dl(e,"Failed to shutdown persistence");t.reject(n)}})),t.promise}}async function nf(t,e){t.asyncQueue.verifyOperationInProgress(),Ms("FirestoreClient","Initializing OfflineComponentProvider");const n=await t.getConfiguration();await e.initialize(n);let s=n.initialUser;t.setCredentialChangeListener((async t=>{s.isEqual(t)||(await yh(e.localStore,t),s=t)})),e.persistence.setDatabaseDeletedListener((()=>t.terminate())),t.offlineComponents=e}async function sf(t,e){t.asyncQueue.verifyOperationInProgress();const n=await rf(t);Ms("FirestoreClient","Initializing OnlineComponentProvider");const s=await t.getConfiguration();await e.initialize(n,s),t.setCredentialChangeListener((t=>Tl(e.remoteStore,t))),t.setAppCheckTokenChangeListener(((t,n)=>Tl(e.remoteStore,n))),t.onlineComponents=e}async function rf(t){return t.offlineComponents||(Ms("FirestoreClient","Using default OfflineComponentProvider"),await nf(t,new Sd)),t.offlineComponents}async function of(t){return t.onlineComponents||(Ms("FirestoreClient","Using default OnlineComponentProvider"),await sf(t,new Ad)),t.onlineComponents}function af(t){return rf(t).then((t=>t.persistence))}function uf(t){return rf(t).then((t=>t.localStore))}function cf(t){return of(t).then((t=>t.remoteStore))}function hf(t){return of(t).then((t=>t.syncEngine))}function lf(t){return of(t).then((t=>t.datastore))}async function df(t){const e=await of(t),n=e.eventManager;return n.onListen=Yl.bind(null,e.syncEngine),n.onUnlisten=Jl.bind(null,e.syncEngine),n}function ff(t,e,n={}){const s=new js;return t.asyncQueue.enqueueAndForget((async()=>function(t,e,n,s,r){const i=new Hd({next:i=>{e.enqueueAndForget((()=>Ol(t,o)));const a=i.docs.has(n);!a&&i.fromCache?r.reject(new Ks(Gs.UNAVAILABLE,"Failed to get document because the client is offline.")):a&&i.fromCache&&s&&"server"===s.source?r.reject(new Ks(Gs.UNAVAILABLE,'Failed to get document from server. (However, this document does exist in the local cache. Run again without setting source to "server" to retrieve the cached document.)')):r.resolve(i)},error:t=>r.reject(t)}),o=new Bl(so(n.path),i,{includeMetadataChanges:!0,Nu:!0});return Ml(t,o)}(await df(t),t.asyncQueue,e,n,s))),s.promise}function mf(t,e,n={}){const s=new js;return t.asyncQueue.enqueueAndForget((async()=>function(t,e,n,s,r){const i=new Hd({next:n=>{e.enqueueAndForget((()=>Ol(t,o))),n.fromCache&&"server"===s.source?r.reject(new Ks(Gs.UNAVAILABLE,'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')):r.resolve(n)},error:t=>r.reject(t)}),o=new Bl(n,i,{includeMetadataChanges:!0,Nu:!0});return Ml(t,o)}(await df(t),t.asyncQueue,e,n,s))),s.promise}function gf(t,e,n,s){const r=function(t,e){let n;return n="string"==typeof t?(new TextEncoder).encode(t):t,function(t,e){return new Wd(t,e)}(function(t,e){if(t instanceof Uint8Array)return zd(t,e);if(t instanceof ArrayBuffer)return zd(new Uint8Array(t),e);if(t instanceof ReadableStream)return t.getReader();throw new Error("Source of `toByteStreamReader` has to be a ArrayBuffer or ReadableStream")}(n),e)}(n,$h(e));t.asyncQueue.enqueueAndForget((async()=>{!function(t,e,n){const s=qs(t);(async function(t,e,n){try{const s=await e.getMetadata();if(await function(t,e){const n=qs(t),s=ka(e.createTime);return n.persistence.runTransaction("hasNewerBundle","readonly",(t=>n.Ns.getBundleMetadata(t,e.id))).then((t=>!!t&&t.createTime.compareTo(s)>=0))}(t.localStore,s))return await e.close(),n._completeWith(function(t){return{taskState:"Success",documentsLoaded:t.totalDocuments,bytesLoaded:t.totalBytes,totalDocuments:t.totalDocuments,totalBytes:t.totalBytes}}(s)),Promise.resolve(new Set);n._updateProgress(Kl(s));const r=new Gl(s,t.localStore,e.It);let i=await e.mc();for(;i;){const t=await r.Fu(i);t&&n._updateProgress(t),i=await e.mc()}const o=await r.complete();return await ld(t,o.Lu,void 0),await function(t,e){const n=qs(t);return n.persistence.runTransaction("Save bundle","readwrite",(t=>n.Ns.saveBundleMetadata(t,e)))}(t.localStore,s),n._completeWith(o.progress),Promise.resolve(o.Bu)}catch(t){return Vs("SyncEngine",`Loading bundle failed with ${t}`),n._failWith(t),Promise.resolve(new Set)}})(s,e,n).then((t=>{s.sharedClientState.notifyBundleLoaded(t)}))}(await hf(t),r,s)}))}class pf{constructor(){this.Bc=Promise.resolve(),this.Lc=[],this.Uc=!1,this.qc=[],this.Kc=null,this.Gc=!1,this.Qc=!1,this.jc=[],this.xo=new Qh(this,"async_queue_retry"),this.Wc=()=>{const t=jh();t&&Ms("AsyncQueue","Visibility state changed to "+t.visibilityState),this.xo.Po()};const t=jh();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.Wc)}get isShuttingDown(){return this.Uc}enqueueAndForget(t){this.enqueue(t)}enqueueAndForgetEvenWhileRestricted(t){this.zc(),this.Hc(t)}enterRestrictedMode(t){if(!this.Uc){this.Uc=!0,this.Qc=t||!1;const e=jh();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("visibilitychange",this.Wc)}}enqueue(t){if(this.zc(),this.Uc)return new Promise((()=>{}));const e=new js;return this.Hc((()=>this.Uc&&this.Qc?Promise.resolve():(t().then(e.resolve,e.reject),e.promise))).then((()=>e.promise))}enqueueRetryable(t){this.enqueueAndForget((()=>(this.Lc.push(t),this.Jc())))}async Jc(){if(0!==this.Lc.length){try{await this.Lc[0](),this.Lc.shift(),this.xo.reset()}catch(t){if(!kr(t))throw t;Ms("AsyncQueue","Operation failed with retryable error: "+t)}this.Lc.length>0&&this.xo.Ro((()=>this.Jc()))}}Hc(t){const e=this.Bc.then((()=>(this.Gc=!0,t().catch((t=>{this.Kc=t,this.Gc=!1;const e=function(t){let e=t.message||"";return t.stack&&(e=t.stack.includes(t.message)?t.stack:t.message+"\n"+t.stack),e}(t);throw Os("INTERNAL UNHANDLED ERROR: ",e),t})).then((t=>(this.Gc=!1,t))))));return this.Bc=e,e}enqueueAfterDelay(t,e,n){this.zc(),this.jc.indexOf(t)>-1&&(e=0);const s=Al.createAndSchedule(this,t,e,n,(t=>this.Yc(t)));return this.qc.push(s),s}zc(){this.Kc&&Ps()}verifyOperationInProgress(){}async Xc(){let t;do{t=this.Bc,await t}while(t!==this.Bc)}Zc(t){for(const e of this.qc)if(e.timerId===t)return!0;return!1}ta(t){return this.Xc().then((()=>{this.qc.sort(((t,e)=>t.targetTimeMs-e.targetTimeMs));for(const e of this.qc)if(e.skipDelay(),"all"!==t&&e.timerId===t)break;return this.Xc()}))}ea(t){this.jc.push(t)}Yc(t){const e=this.qc.indexOf(t);this.qc.splice(e,1)}}function yf(t){return function(t,e){if("object"!=typeof t||null===t)return!1;const n=t;for(const t of["next","error","complete"])if(t in n&&"function"==typeof n[t])return!0;return!1}(t)}class wf{constructor(){this._progressObserver={},this._taskCompletionResolver=new js,this._lastProgress={taskState:"Running",totalBytes:0,totalDocuments:0,bytesLoaded:0,documentsLoaded:0}}onProgress(t,e,n){this._progressObserver={next:t,error:e,complete:n}}catch(t){return this._taskCompletionResolver.promise.catch(t)}then(t,e){return this._taskCompletionResolver.promise.then(t,e)}_completeWith(t){this._updateProgress(t),this._progressObserver.complete&&this._progressObserver.complete(),this._taskCompletionResolver.resolve(t)}_failWith(t){this._lastProgress.taskState="Error",this._progressObserver.next&&this._progressObserver.next(this._lastProgress),this._progressObserver.error&&this._progressObserver.error(t),this._taskCompletionResolver.reject(t)}_updateProgress(t){this._lastProgress=t,this._progressObserver.next&&this._progressObserver.next(t)}}const vf=-1;class If extends Fd{constructor(t,e,n,s){super(t,e,n,s),this.type="firestore",this._queue=new pf,this._persistenceKey=(null==s?void 0:s.name)||"[DEFAULT]"}_terminate(){return this._firestoreClient||Sf(this),this._firestoreClient.terminate()}}function bf(t,e,s){s||(s="(default)");const r=n(t,"firestore");if(r.isInitialized(s)){const t=r.getImmediate({identifier:s});if(w(r.getOptions(s),e))return t;throw new Ks(Gs.FAILED_PRECONDITION,"initializeFirestore() has already been called with different options. To avoid this error, call initializeFirestore() with the same options as when it was originally called, or call getFirestore() to return the already initialized instance.")}if(void 0!==e.cacheSizeBytes&&-1!==e.cacheSizeBytes&&e.cacheSizeBytes<1048576)throw new Ks(Gs.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");return r.initialize({options:e,instanceIdentifier:s})}function Ef(t,e){const r="object"==typeof t?t:s(),i="string"==typeof t?t:e||"(default)",o=n(r,"firestore").getImmediate({identifier:i});if(!o._initialized){const t=m("firestore");t&&Pd(o,...t)}return o}function Tf(t){return t._firestoreClient||Sf(t),t._firestoreClient.verifyNotTerminated(),t._firestoreClient}function Sf(t){var e;const n=t._freezeSettings(),s=function(t,e,n,s){return new ri(t,e,n,s.host,s.ssl,s.experimentalForceLongPolling,s.experimentalAutoDetectLongPolling,s.useFetchStreams)}(t._databaseId,(null===(e=t._app)||void 0===e?void 0:e.options.appId)||"",t._persistenceKey,n);t._firestoreClient=new ef(t._authCredentials,t._appCheckCredentials,t._queue,s)}function _f(t,e){Of(t=Ld(t,If));const n=Tf(t),s=t._freezeSettings(),r=new Ad;return Af(n,r,new _d(r,s.cacheSizeBytes,null==e?void 0:e.forceOwnership))}function xf(t){Of(t=Ld(t,If));const e=Tf(t),n=t._freezeSettings(),s=new Ad;return Af(e,s,new xd(s,n.cacheSizeBytes))}function Af(t,e,n){const s=new js;return t.asyncQueue.enqueue((async()=>{try{await nf(t,n),await sf(t,e),s.resolve()}catch(t){const e=t;if(!function(t){return"FirebaseError"===t.name?t.code===Gs.FAILED_PRECONDITION||t.code===Gs.UNIMPLEMENTED:!("undefined"!=typeof DOMException&&t instanceof DOMException)||(22===t.code||20===t.code||11===t.code)}(e))throw e;Vs("Error enabling offline persistence. Falling back to persistence disabled: "+e),s.reject(e)}})).then((()=>s.promise))}function Df(t){if(t._initialized&&!t._terminated)throw new Ks(Gs.FAILED_PRECONDITION,"Persistence can only be cleared before a Firestore instance is initialized or after it is terminated.");const e=new js;return t._queue.enqueueAndForgetEvenWhileRestricted((async()=>{try{await async function(t){if(!Dr.C())return Promise.resolve();const e=t+"main";await Dr.delete(e)}(dh(t._databaseId,t._persistenceKey)),e.resolve()}catch(t){e.reject(t)}})),e.promise}function Cf(t){return function(t){const e=new js;return t.asyncQueue.enqueueAndForget((async()=>async function(t,e){const n=qs(t);al(n.remoteStore)||Ms("SyncEngine","The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled.");try{const t=await function(t){const e=qs(t);return e.persistence.runTransaction("Get highest unacknowledged batch id","readonly",(t=>e.mutationQueue.getHighestUnacknowledgedBatchId(t)))}(n.localStore);if(-1===t)return void e.resolve();const s=n.lc.get(t)||[];s.push(e),n.lc.set(t,s)}catch(t){const n=Dl(t,"Initialization of waitForPendingWrites() operation failed");e.reject(n)}}(await hf(t),e))),e.promise}(Tf(t=Ld(t,If)))}function Nf(t){return function(t){return t.asyncQueue.enqueue((async()=>{const e=await af(t),n=await cf(t);return e.setNetworkEnabled(!0),function(t){const e=qs(t);return e._u.delete(0),Zh(e)}(n)}))}(Tf(t=Ld(t,If)))}function kf(t){return function(t){return t.asyncQueue.enqueue((async()=>{const e=await af(t),n=await cf(t);return e.setNetworkEnabled(!1),async function(t){const e=qs(t);e._u.add(0),await tl(e),e.gu.set("Offline")}(n)}))}(Tf(t=Ld(t,If)))}function Rf(t){return r(t.app,"firestore",t._databaseId.database),t._delete()}function Lf(t,e){const n=Tf(t=Ld(t,If)),s=new wf;return gf(n,t._databaseId,e,s),s}function Mf(t,e){return function(t,e){return t.asyncQueue.enqueue((async()=>function(t,e){const n=qs(t);return n.persistence.runTransaction("Get named query","readonly",(t=>n.Ns.getNamedQuery(t,e)))}(await uf(t),e)))}(Tf(t=Ld(t,If)),e).then((e=>e?new Ud(t,null,e.query):null))}function Of(t){if(t._initialized||t._terminated)throw new Ks(Gs.FAILED_PRECONDITION,"Firestore has already been started and persistence can no longer be enabled. You can only enable persistence before calling any other methods on a Firestore object.")}class Vf{constructor(t){this._byteString=t}static fromBase64String(t){try{return new Vf(Yr.fromBase64String(t))}catch(t){throw new Ks(Gs.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+t)}}static fromUint8Array(t){return new Vf(Yr.fromUint8Array(t))}toBase64(){return this._byteString.toBase64()}toUint8Array(){return this._byteString.toUint8Array()}toString(){return"Bytes(base64: "+this.toBase64()+")"}isEqual(t){return this._byteString.isEqual(t._byteString)}}class Ff{constructor(...t){for(let e=0;e<t.length;++e)if(0===t[e].length)throw new Ks(Gs.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new hr(t)}isEqual(t){return this._internalPath.isEqual(t._internalPath)}}function Pf(){return new Ff("__name__")}class Bf{constructor(t){this._methodName=t}}class Uf{constructor(t,e){if(!isFinite(t)||t<-90||t>90)throw new Ks(Gs.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new Ks(Gs.INVALID_ARGUMENT,"Longitude must be a number between -180 and 180, but was: "+e);this._lat=t,this._long=e}get latitude(){return this._lat}get longitude(){return this._long}isEqual(t){return this._lat===t._lat&&this._long===t._long}toJSON(){return{latitude:this._lat,longitude:this._long}}_compareTo(t){return nr(this._lat,t._lat)||nr(this._long,t._long)}}const qf=/^__.*__$/;class Gf{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return null!==this.fieldMask?new $o(t,this.data,this.fieldMask,e,this.fieldTransforms):new jo(t,this.data,e,this.fieldTransforms)}}class Kf{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return new $o(t,this.data,this.fieldMask,e,this.fieldTransforms)}}function jf(t){switch(t){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw Ps()}}class $f{constructor(t,e,n,s,r,i){this.settings=t,this.databaseId=e,this.It=n,this.ignoreUndefinedProperties=s,void 0===r&&this.na(),this.fieldTransforms=r||[],this.fieldMask=i||[]}get path(){return this.settings.path}get sa(){return this.settings.sa}ia(t){return new $f(Object.assign(Object.assign({},this.settings),t),this.databaseId,this.It,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}ra(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),s=this.ia({path:n,oa:!1});return s.ua(t),s}ca(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),s=this.ia({path:n,oa:!1});return s.na(),s}aa(t){return this.ia({path:void 0,oa:!0})}ha(t){return lm(t,this.settings.methodName,this.settings.la||!1,this.path,this.settings.fa)}contains(t){return void 0!==this.fieldMask.find((e=>t.isPrefixOf(e)))||void 0!==this.fieldTransforms.find((e=>t.isPrefixOf(e.field)))}na(){if(this.path)for(let t=0;t<this.path.length;t++)this.ua(this.path.get(t))}ua(t){if(0===t.length)throw this.ha("Document fields must not be empty");if(jf(this.sa)&&qf.test(t))throw this.ha('Document fields cannot begin and end with "__"')}}class Qf{constructor(t,e,n){this.databaseId=t,this.ignoreUndefinedProperties=e,this.It=n||$h(t)}da(t,e,n,s=!1){return new $f({sa:t,methodName:e,fa:n,path:hr.emptyPath(),oa:!1,la:s},this.databaseId,this.It,this.ignoreUndefinedProperties)}}function zf(t){const e=t._freezeSettings(),n=$h(t._databaseId);return new Qf(t._databaseId,!!e.ignoreUndefinedProperties,n)}function Hf(t,e,n,s,r,i={}){const o=t.da(i.merge||i.mergeFields?2:0,e,n,r);am("Data must be an object, but it was:",o,s);const a=im(s,o);let u,c;if(i.merge)u=new Hr(o.fieldMask),c=o.fieldTransforms;else if(i.mergeFields){const t=[];for(const s of i.mergeFields){const r=um(e,s,n);if(!o.contains(r))throw new Ks(Gs.INVALID_ARGUMENT,`Field '${r}' is specified in your field mask but missing from your input data.`);dm(t,r)||t.push(r)}u=new Hr(t),c=o.fieldTransforms.filter((t=>u.covers(t.field)))}else u=null,c=o.fieldTransforms;return new Gf(new Ni(a),u,c)}class Wf extends Bf{_toFieldTransform(t){if(2!==t.sa)throw 1===t.sa?t.ha(`${this._methodName}() can only appear at the top level of your update data`):t.ha(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);return t.fieldMask.push(t.path),null}isEqual(t){return t instanceof Wf}}function Yf(t,e,n){return new $f({sa:3,fa:e.settings.fa,methodName:t._methodName,oa:n},e.databaseId,e.It,e.ignoreUndefinedProperties)}class Xf extends Bf{_toFieldTransform(t){return new Mo(t.path,new xo)}isEqual(t){return t instanceof Xf}}class Jf extends Bf{constructor(t,e){super(t),this._a=e}_toFieldTransform(t){const e=Yf(this,t,!0),n=this._a.map((t=>rm(t,e))),s=new Ao(n);return new Mo(t.path,s)}isEqual(t){return this===t}}class Zf extends Bf{constructor(t,e){super(t),this._a=e}_toFieldTransform(t){const e=Yf(this,t,!0),n=this._a.map((t=>rm(t,e))),s=new Co(n);return new Mo(t.path,s)}isEqual(t){return this===t}}class tm extends Bf{constructor(t,e){super(t),this.wa=e}_toFieldTransform(t){const e=new ko(t.It,bo(t.It,this.wa));return new Mo(t.path,e)}isEqual(t){return this===t}}function em(t,e,n,s){const r=t.da(1,e,n);am("Data must be an object, but it was:",r,s);const i=[],o=Ni.empty();Ur(s,((t,s)=>{const a=hm(e,t,n);s=I(s);const u=r.ca(a);if(s instanceof Wf)i.push(a);else{const t=rm(s,u);null!=t&&(i.push(a),o.set(a,t))}}));const a=new Hr(i);return new Kf(o,a,r.fieldTransforms)}function nm(t,e,n,s,r,i){const o=t.da(1,e,n),a=[um(e,s,n)],u=[r];if(i.length%2!=0)throw new Ks(Gs.INVALID_ARGUMENT,`Function ${e}() needs to be called with an even number of arguments that alternate between field names and values.`);for(let t=0;t<i.length;t+=2)a.push(um(e,i[t])),u.push(i[t+1]);const c=[],h=Ni.empty();for(let t=a.length-1;t>=0;--t)if(!dm(c,a[t])){const e=a[t];let n=u[t];n=I(n);const s=o.ca(e);if(n instanceof Wf)c.push(e);else{const t=rm(n,s);null!=t&&(c.push(e),h.set(e,t))}}const l=new Hr(c);return new Kf(h,l,o.fieldTransforms)}function sm(t,e,n,s=!1){return rm(n,t.da(s?4:3,e))}function rm(t,e){if(om(t=I(t)))return am("Unsupported field value:",e,t),im(t,e);if(t instanceof Bf)return function(t,e){if(!jf(e.sa))throw e.ha(`${t._methodName}() can only be used with update() and set()`);if(!e.path)throw e.ha(`${t._methodName}() is not currently supported inside arrays`);const n=t._toFieldTransform(e);n&&e.fieldTransforms.push(n)}(t,e),null;if(void 0===t&&e.ignoreUndefinedProperties)return null;if(e.path&&e.fieldMask.push(e.path),t instanceof Array){if(e.settings.oa&&4!==e.sa)throw e.ha("Nested arrays are not supported");return function(t,e){const n=[];let s=0;for(const r of t){let t=rm(r,e.aa(s));null==t&&(t={nullValue:"NULL_VALUE"}),n.push(t),s++}return{arrayValue:{values:n}}}(t,e)}return function(t,e){if(null===(t=I(t)))return{nullValue:"NULL_VALUE"};if("number"==typeof t)return bo(e.It,t);if("boolean"==typeof t)return{booleanValue:t};if("string"==typeof t)return{stringValue:t};if(t instanceof Date){const n=ir.fromDate(t);return{timestampValue:Da(e.It,n)}}if(t instanceof ir){const n=new ir(t.seconds,1e3*Math.floor(t.nanoseconds/1e3));return{timestampValue:Da(e.It,n)}}if(t instanceof Uf)return{geoPointValue:{latitude:t.latitude,longitude:t.longitude}};if(t instanceof Vf)return{bytesValue:Ca(e.It,t._byteString)};if(t instanceof Bd){const n=e.databaseId,s=t.firestore._databaseId;if(!s.isEqual(n))throw e.ha(`Document reference is for database ${s.projectId}/${s.database} but should be for database ${n.projectId}/${n.database}`);return{referenceValue:Ra(t.firestore._databaseId||e.databaseId,t._key.path)}}throw e.ha(`Unsupported field value: ${Rd(t)}`)}(t,e)}function im(t,e){const n={};return qr(t)?e.path&&e.path.length>0&&e.fieldMask.push(e.path):Ur(t,((t,s)=>{const r=rm(s,e.ra(t));null!=r&&(n[t]=r)})),{mapValue:{fields:n}}}function om(t){return!("object"!=typeof t||null===t||t instanceof Array||t instanceof Date||t instanceof ir||t instanceof Uf||t instanceof Vf||t instanceof Bd||t instanceof Bf)}function am(t,e,n){if(!om(n)||!function(t){return"object"==typeof t&&null!==t&&(Object.getPrototypeOf(t)===Object.prototype||null===Object.getPrototypeOf(t))}(n)){const s=Rd(n);throw"an object"===s?e.ha(t+" a custom object"):e.ha(t+" "+s)}}function um(t,e,n){if((e=I(e))instanceof Ff)return e._internalPath;if("string"==typeof e)return hm(t,e);throw lm("Field path arguments must be of type string or ",t,!1,void 0,n)}const cm=new RegExp("[~\\*/\\[\\]]");function hm(t,e,n){if(e.search(cm)>=0)throw lm(`Invalid field path (${e}). Paths must not contain '~', '*', '/', '[', or ']'`,t,!1,void 0,n);try{return new Ff(...e.split("."))._internalPath}catch(s){throw lm(`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,t,!1,void 0,n)}}function lm(t,e,n,s,r){const i=s&&!s.isEmpty(),o=void 0!==r;let a=`Function ${e}() called with invalid data`;n&&(a+=" (via `toFirestore()`)"),a+=". ";let u="";return(i||o)&&(u+=" (found",i&&(u+=` in field ${s}`),o&&(u+=` in document ${r}`),u+=")"),new Ks(Gs.INVALID_ARGUMENT,a+t+u)}function dm(t,e){return t.some((t=>t.isEqual(e)))}class fm{constructor(t,e,n,s,r){this._firestore=t,this._userDataWriter=e,this._key=n,this._document=s,this._converter=r}get id(){return this._key.path.lastSegment()}get ref(){return new Bd(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){if(this._document){if(this._converter){const t=new mm(this._firestore,this._userDataWriter,this._key,this._document,null);return this._converter.fromFirestore(t)}return this._userDataWriter.convertValue(this._document.data.value)}}get(t){if(this._document){const e=this._document.data.field(gm("DocumentSnapshot.get",t));if(null!==e)return this._userDataWriter.convertValue(e)}}}class mm extends fm{data(){return super.data()}}function gm(t,e){return"string"==typeof e?hm(t,e):e instanceof Ff?e._internalPath:e._delegate._internalPath}function pm(t){if("L"===t.limitType&&0===t.explicitOrderBy.length)throw new Ks(Gs.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")}class ym{}function wm(t,...e){for(const n of e)t=n._apply(t);return t}class vm extends ym{constructor(t,e,n){super(),this.ma=t,this.ga=e,this.ya=n,this.type="where"}_apply(t){const e=zf(t.firestore),n=function(t,e,n,s,r,i,o){let a;if(r.isKeyField()){if("array-contains"===i||"array-contains-any"===i)throw new Ks(Gs.INVALID_ARGUMENT,`Invalid Query. You can't perform '${i}' queries on documentId().`);if("in"===i||"not-in"===i){Mm(o,i);const e=[];for(const n of o)e.push(Lm(s,t,n));a={arrayValue:{values:e}}}else a=Lm(s,t,o)}else"in"!==i&&"not-in"!==i&&"array-contains-any"!==i||Mm(o,i),a=sm(n,"where",o,"in"===i||"not-in"===i);const u=qi.create(r,i,a);return function(t,e){if(e.dt()){const n=oo(t);if(null!==n&&!n.isEqual(e.field))throw new Ks(Gs.INVALID_ARGUMENT,`Invalid query. All where filters with an inequality (<, <=, !=, not-in, >, or >=) must be on the same field. But you have inequality filters on '${n.toString()}' and '${e.field.toString()}'`);const s=io(t);null!==s&&Om(t,e.field,s)}const n=function(t,e){for(const n of t.filters)if(e.indexOf(n.op)>=0)return n.op;return null}(t,function(t){switch(t){case"!=":return["!=","not-in"];case"array-contains":return["array-contains","array-contains-any","not-in"];case"in":return["array-contains-any","in","not-in"];case"array-contains-any":return["array-contains","array-contains-any","in","not-in"];case"not-in":return["array-contains","array-contains-any","in","not-in","!="];default:return[]}}(e.op));if(null!==n)throw n===e.op?new Ks(Gs.INVALID_ARGUMENT,`Invalid query. You cannot use more than one '${e.op.toString()}' filter.`):new Ks(Gs.INVALID_ARGUMENT,`Invalid query. You cannot use '${e.op.toString()}' filters with '${n.toString()}' filters.`)}(t,u),u}(t._query,0,e,t.firestore._databaseId,this.ma,this.ga,this.ya);return new Ud(t.firestore,t.converter,function(t,e){const n=t.filters.concat([e]);return new eo(t.path,t.collectionGroup,t.explicitOrderBy.slice(),n,t.limit,t.limitType,t.startAt,t.endAt)}(t._query,n))}}function Im(t,e,n){const s=e,r=gm("where",t);return new vm(r,s,n)}class bm extends ym{constructor(t,e){super(),this.ma=t,this.pa=e,this.type="orderBy"}_apply(t){const e=function(t,e,n){if(null!==t.startAt)throw new Ks(Gs.INVALID_ARGUMENT,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==t.endAt)throw new Ks(Gs.INVALID_ARGUMENT,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");const s=new Xi(e,n);return function(t,e){if(null===io(t)){const n=oo(t);null!==n&&Om(t,n,e.field)}}(t,s),s}(t._query,this.ma,this.pa);return new Ud(t.firestore,t.converter,function(t,e){const n=t.explicitOrderBy.concat([e]);return new eo(t.path,t.collectionGroup,n,t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(t._query,e))}}function Em(t,e="asc"){const n=e,s=gm("orderBy",t);return new bm(s,n)}class Tm extends ym{constructor(t,e,n){super(),this.type=t,this.Ia=e,this.Ta=n}_apply(t){return new Ud(t.firestore,t.converter,ho(t._query,this.Ia,this.Ta))}}function Sm(t){return Md("limit",t),new Tm("limit",t,"F")}function _m(t){return Md("limitToLast",t),new Tm("limitToLast",t,"L")}class xm extends ym{constructor(t,e,n){super(),this.type=t,this.Ea=e,this.Aa=n}_apply(t){const e=Rm(t,this.type,this.Ea,this.Aa);return new Ud(t.firestore,t.converter,function(t,e){return new eo(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,e,t.endAt)}(t._query,e))}}function Am(...t){return new xm("startAt",t,!0)}function Dm(...t){return new xm("startAfter",t,!1)}class Cm extends ym{constructor(t,e,n){super(),this.type=t,this.Ea=e,this.Aa=n}_apply(t){const e=Rm(t,this.type,this.Ea,this.Aa);return new Ud(t.firestore,t.converter,function(t,e){return new eo(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,e)}(t._query,e))}}function Nm(...t){return new Cm("endBefore",t,!1)}function km(...t){return new Cm("endAt",t,!0)}function Rm(t,e,n,s){if(n[0]=I(n[0]),n[0]instanceof fm)return function(t,e,n,s,r){if(!s)throw new Ks(Gs.NOT_FOUND,`Can't use a DocumentSnapshot that doesn't exist for ${n}().`);const i=[];for(const n of uo(t))if(n.field.isKeyField())i.push(wi(e,s.key));else{const t=s.data.field(n.field);if(ei(t))throw new Ks(Gs.INVALID_ARGUMENT,'Invalid query. You are trying to start or end a query using a document for which the field "'+n.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===t){const t=n.field.canonicalString();throw new Ks(Gs.INVALID_ARGUMENT,`Invalid query. You are trying to start or end a query using a document for which the field '${t}' (used as the orderBy) does not exist.`)}i.push(t)}return new Yi(i,r)}(t._query,t.firestore._databaseId,e,n[0]._document,s);{const r=zf(t.firestore);return function(t,e,n,s,r,i){const o=t.explicitOrderBy;if(r.length>o.length)throw new Ks(Gs.INVALID_ARGUMENT,`Too many arguments provided to ${s}(). The number of arguments must be less than or equal to the number of orderBy() clauses`);const a=[];for(let i=0;i<r.length;i++){const u=r[i];if(o[i].field.isKeyField()){if("string"!=typeof u)throw new Ks(Gs.INVALID_ARGUMENT,`Invalid query. Expected a string for document ID in ${s}(), but got a ${typeof u}`);if(!ao(t)&&-1!==u.indexOf("/"))throw new Ks(Gs.INVALID_ARGUMENT,`Invalid query. When querying a collection and ordering by documentId(), the value passed to ${s}() must be a plain document ID, but '${u}' contains a slash.`);const n=t.path.child(ur.fromString(u));if(!lr.isDocumentKey(n))throw new Ks(Gs.INVALID_ARGUMENT,`Invalid query. When querying a collection group and ordering by documentId(), the value passed to ${s}() must result in a valid document path, but '${n}' is not because it contains an odd number of segments.`);const r=new lr(n);a.push(wi(e,r))}else{const t=sm(n,s,u);a.push(t)}}return new Yi(a,i)}(t._query,t.firestore._databaseId,r,e,n,s)}}function Lm(t,e,n){if("string"==typeof(n=I(n))){if(""===n)throw new Ks(Gs.INVALID_ARGUMENT,"Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");if(!ao(e)&&-1!==n.indexOf("/"))throw new Ks(Gs.INVALID_ARGUMENT,`Invalid query. When querying a collection by documentId(), you must provide a plain document ID, but '${n}' contains a '/' character.`);const s=e.path.child(ur.fromString(n));if(!lr.isDocumentKey(s))throw new Ks(Gs.INVALID_ARGUMENT,`Invalid query. When querying a collection group by documentId(), the value provided must result in a valid document path, but '${s}' is not because it has an odd number of segments (${s.length}).`);return wi(t,new lr(s))}if(n instanceof Bd)return wi(t,n._key);throw new Ks(Gs.INVALID_ARGUMENT,`Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${Rd(n)}.`)}function Mm(t,e){if(!Array.isArray(t)||0===t.length)throw new Ks(Gs.INVALID_ARGUMENT,`Invalid Query. A non-empty array is required for '${e.toString()}' filters.`);if(t.length>10)throw new Ks(Gs.INVALID_ARGUMENT,`Invalid Query. '${e.toString()}' filters support a maximum of 10 elements in the value array.`)}function Om(t,e,n){if(!n.isEqual(e))throw new Ks(Gs.INVALID_ARGUMENT,`Invalid query. You have a where filter with an inequality (<, <=, !=, not-in, >, or >=) on field '${e.toString()}' and so you must also use '${e.toString()}' as your first argument to orderBy(), but your first orderBy() is on field '${n.toString()}' instead.`)}class Vm{convertValue(t,e="none"){switch(li(t)){case 0:return null;case 1:return t.booleanValue;case 2:return Zr(t.integerValue||t.doubleValue);case 3:return this.convertTimestamp(t.timestampValue);case 4:return this.convertServerTimestamp(t,e);case 5:return t.stringValue;case 6:return this.convertBytes(ti(t.bytesValue));case 7:return this.convertReference(t.referenceValue);case 8:return this.convertGeoPoint(t.geoPointValue);case 9:return this.convertArray(t.arrayValue,e);case 10:return this.convertObject(t.mapValue,e);default:throw Ps()}}convertObject(t,e){const n={};return Ur(t.fields,((t,s)=>{n[t]=this.convertValue(s,e)})),n}convertGeoPoint(t){return new Uf(Zr(t.latitude),Zr(t.longitude))}convertArray(t,e){return(t.values||[]).map((t=>this.convertValue(t,e)))}convertServerTimestamp(t,e){switch(e){case"previous":const n=ni(t);return null==n?null:this.convertValue(n,e);case"estimate":return this.convertTimestamp(si(t));default:return null}}convertTimestamp(t){const e=Jr(t);return new ir(e.seconds,e.nanos)}convertDocumentKey(t,e){const n=ur.fromString(t);Bs(eu(n));const s=new ii(n.get(1),n.get(3)),r=new lr(n.popFirst(5));return s.isEqual(e)||Os(`Document ${r} contains a document reference within a different database (${s.projectId}/${s.database}) which is not supported. It will be treated as a reference in the current database (${e.projectId}/${e.database}) instead.`),r}}function Fm(t,e,n){let s;return s=t?n&&(n.merge||n.mergeFields)?t.toFirestore(e,n):t.toFirestore(e):e,s}class Pm extends Vm{constructor(t){super(),this.firestore=t}convertBytes(t){return new Vf(t)}convertReference(t){const e=this.convertDocumentKey(t,this.firestore._databaseId);return new Bd(this.firestore,null,e)}}class Bm{constructor(t,e){this.hasPendingWrites=t,this.fromCache=e}isEqual(t){return this.hasPendingWrites===t.hasPendingWrites&&this.fromCache===t.fromCache}}class Um extends fm{constructor(t,e,n,s,r,i){super(t,e,n,s,i),this._firestore=t,this._firestoreImpl=t,this.metadata=r}exists(){return super.exists()}data(t={}){if(this._document){if(this._converter){const e=new qm(this._firestore,this._userDataWriter,this._key,this._document,this.metadata,null);return this._converter.fromFirestore(e,t)}return this._userDataWriter.convertValue(this._document.data.value,t.serverTimestamps)}}get(t,e={}){if(this._document){const n=this._document.data.field(gm("DocumentSnapshot.get",t));if(null!==n)return this._userDataWriter.convertValue(n,e.serverTimestamps)}}}class qm extends Um{data(t={}){return super.data(t)}}class Gm{constructor(t,e,n,s){this._firestore=t,this._userDataWriter=e,this._snapshot=s,this.metadata=new Bm(s.hasPendingWrites,s.fromCache),this.query=n}get docs(){const t=[];return this.forEach((e=>t.push(e))),t}get size(){return this._snapshot.docs.size}get empty(){return 0===this.size}forEach(t,e){this._snapshot.docs.forEach((n=>{t.call(e,new qm(this._firestore,this._userDataWriter,n.key,n,new Bm(this._snapshot.mutatedKeys.has(n.key),this._snapshot.fromCache),this.query.converter))}))}docChanges(t={}){const e=!!t.includeMetadataChanges;if(e&&this._snapshot.excludesMetadataChanges)throw new Ks(Gs.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this._cachedChanges&&this._cachedChangesIncludeMetadataChanges===e||(this._cachedChanges=function(t,e){if(t._snapshot.oldDocs.isEmpty()){let e=0;return t._snapshot.docChanges.map((n=>{const s=new qm(t._firestore,t._userDataWriter,n.doc.key,n.doc,new Bm(t._snapshot.mutatedKeys.has(n.doc.key),t._snapshot.fromCache),t.query.converter);return n.doc,{type:"added",doc:s,oldIndex:-1,newIndex:e++}}))}{let n=t._snapshot.oldDocs;return t._snapshot.docChanges.filter((t=>e||3!==t.type)).map((e=>{const s=new qm(t._firestore,t._userDataWriter,e.doc.key,e.doc,new Bm(t._snapshot.mutatedKeys.has(e.doc.key),t._snapshot.fromCache),t.query.converter);let r=-1,i=-1;return 0!==e.type&&(r=n.indexOf(e.doc.key),n=n.delete(e.doc.key)),1!==e.type&&(n=n.add(e.doc),i=n.indexOf(e.doc.key)),{type:Km(e.type),doc:s,oldIndex:r,newIndex:i}}))}}(this,e),this._cachedChangesIncludeMetadataChanges=e),this._cachedChanges}}function Km(t){switch(t){case 0:return"added";case 2:case 3:return"modified";case 1:return"removed";default:return Ps()}}function jm(t,e){return t instanceof Um&&e instanceof Um?t._firestore===e._firestore&&t._key.isEqual(e._key)&&(null===t._document?null===e._document:t._document.isEqual(e._document))&&t._converter===e._converter:t instanceof Gm&&e instanceof Gm&&t._firestore===e._firestore&&Qd(t.query,e.query)&&t.metadata.isEqual(e.metadata)&&t._snapshot.isEqual(e._snapshot)}function $m(t){t=Ld(t,Bd);const e=Ld(t.firestore,If);return ff(Tf(e),t._key).then((n=>ig(e,t,n)))}class Qm extends Vm{constructor(t){super(),this.firestore=t}convertBytes(t){return new Vf(t)}convertReference(t){const e=this.convertDocumentKey(t,this.firestore._databaseId);return new Bd(this.firestore,null,e)}}function zm(t){t=Ld(t,Bd);const e=Ld(t.firestore,If),n=Tf(e),s=new Qm(e);return function(t,e){const n=new js;return t.asyncQueue.enqueueAndForget((async()=>async function(t,e,n){try{const s=await function(t,e){const n=qs(t);return n.persistence.runTransaction("read document","readonly",(t=>n.localDocuments.getDocument(t,e)))}(t,e);s.isFoundDocument()?n.resolve(s):s.isNoDocument()?n.resolve(null):n.reject(new Ks(Gs.UNAVAILABLE,"Failed to get document from cache. (However, this document may exist on the server. Run again without setting 'source' in the GetOptions to attempt to retrieve the document from the server.)"))}catch(t){const s=Dl(t,`Failed to get document '${e} from cache`);n.reject(s)}}(await uf(t),e,n))),n.promise}(n,t._key).then((n=>new Um(e,s,t._key,n,new Bm(null!==n&&n.hasLocalMutations,!0),t.converter)))}function Hm(t){t=Ld(t,Bd);const e=Ld(t.firestore,If);return ff(Tf(e),t._key,{source:"server"}).then((n=>ig(e,t,n)))}function Wm(t){t=Ld(t,Ud);const e=Ld(t.firestore,If),n=Tf(e),s=new Qm(e);return pm(t._query),mf(n,t._query).then((n=>new Gm(e,s,t,n)))}function Ym(t){t=Ld(t,Ud);const e=Ld(t.firestore,If),n=Tf(e),s=new Qm(e);return function(t,e){const n=new js;return t.asyncQueue.enqueueAndForget((async()=>async function(t,e,n){try{const s=await Th(t,e,!0),r=new Ql(e,s.Hi),i=r.Wu(s.documents),o=r.applyChanges(i,!1);n.resolve(o.snapshot)}catch(t){const s=Dl(t,`Failed to execute query '${e} against cache`);n.reject(s)}}(await uf(t),e,n))),n.promise}(n,t._query).then((n=>new Gm(e,s,t,n)))}function Xm(t){t=Ld(t,Ud);const e=Ld(t.firestore,If),n=Tf(e),s=new Qm(e);return mf(n,t._query,{source:"server"}).then((n=>new Gm(e,s,t,n)))}function Jm(t,e,n){t=Ld(t,Bd);const s=Ld(t.firestore,If),r=Fm(t.converter,e,n);return rg(s,[Hf(zf(s),"setDoc",t._key,r,null!==t.converter,n).toMutation(t._key,Vo.none())])}function Zm(t,e,n,...s){t=Ld(t,Bd);const r=Ld(t.firestore,If),i=zf(r);let o;return o="string"==typeof(e=I(e))||e instanceof Ff?nm(i,"updateDoc",t._key,e,n,s):em(i,"updateDoc",t._key,e),rg(r,[o.toMutation(t._key,Vo.exists(!0))])}function tg(t){return rg(Ld(t.firestore,If),[new Wo(t._key,Vo.none())])}function eg(t,e){const n=Ld(t.firestore,If),s=jd(t),r=Fm(t.converter,e);return rg(n,[Hf(zf(t.firestore),"addDoc",s._key,r,null!==t.converter,{}).toMutation(s._key,Vo.exists(!1))]).then((()=>s))}function ng(t,...e){var n,s,r;t=I(t);let i={includeMetadataChanges:!1},o=0;"object"!=typeof e[o]||yf(e[o])||(i=e[o],o++);const a={includeMetadataChanges:i.includeMetadataChanges};if(yf(e[o])){const t=e[o];e[o]=null===(n=t.next)||void 0===n?void 0:n.bind(t),e[o+1]=null===(s=t.error)||void 0===s?void 0:s.bind(t),e[o+2]=null===(r=t.complete)||void 0===r?void 0:r.bind(t)}let u,c,h;if(t instanceof Bd)c=Ld(t.firestore,If),h=so(t._key.path),u={next:n=>{e[o]&&e[o](ig(c,t,n))},error:e[o+1],complete:e[o+2]};else{const n=Ld(t,Ud);c=Ld(n.firestore,If),h=n._query;const s=new Qm(c);u={next:t=>{e[o]&&e[o](new Gm(c,s,n,t))},error:e[o+1],complete:e[o+2]},pm(t._query)}return function(t,e,n,s){const r=new Hd(s),i=new Bl(e,r,n);return t.asyncQueue.enqueueAndForget((async()=>Ml(await df(t),i))),()=>{r.bc(),t.asyncQueue.enqueueAndForget((async()=>Ol(await df(t),i)))}}(Tf(c),h,a,u)}function sg(t,e){return function(t,e){const n=new Hd(e);return t.asyncQueue.enqueueAndForget((async()=>function(t,e){qs(t).Ru.add(e),e.next()}(await df(t),n))),()=>{n.bc(),t.asyncQueue.enqueueAndForget((async()=>function(t,e){qs(t).Ru.delete(e)}(await df(t),n)))}}(Tf(t=Ld(t,If)),yf(e)?e:{next:e})}function rg(t,e){return function(t,e){const n=new js;return t.asyncQueue.enqueueAndForget((async()=>async function(t,e,n){const s=Td(t);try{const t=await function(t,e){const n=qs(t),s=ir.now(),r=e.reduce(((t,e)=>t.add(e.key)),fa());let i,o;return n.persistence.runTransaction("Locally write mutations","readwrite",(t=>{let a=ra(),u=fa();return n.Gi.getEntries(t,r).next((t=>{a=t,a.forEach(((t,e)=>{e.isValidDocument()||(u=u.add(t))}))})).next((()=>n.localDocuments.getOverlayedDocuments(t,a))).next((r=>{i=r;const o=[];for(const t of e){const e=Go(t,i.get(t.key).overlayedDocument);null!=e&&o.push(new $o(t.key,e,ki(e.value.mapValue),Vo.exists(!0)))}return n.mutationQueue.addMutationBatch(t,s,o,e)})).next((e=>{o=e;const s=e.applyToLocalDocumentSet(i,u);return n.documentOverlayCache.saveOverlays(t,e.batchId,s)}))})).then((()=>({batchId:o.batchId,changes:aa(i)})))}(s.localStore,e);s.sharedClientState.addPendingMutation(t.batchId),function(t,e,n){let s=t.hc[t.currentUser.toKey()];s||(s=new Gr(nr)),s=s.insert(e,n),t.hc[t.currentUser.toKey()]=s}(s,t.batchId,n),await ld(s,t.changes),await ml(s.remoteStore)}catch(t){const e=Dl(t,"Failed to persist write");n.reject(e)}}(await hf(t),e,n))),n.promise}(Tf(t),e)}function ig(t,e,n){const s=n.docs.get(e._key),r=new Qm(t);return new Um(t,r,e._key,s,new Bm(n.hasPendingWrites,n.fromCache),e.converter)}function og(t,e){return Qd(t.query,e.query)&&w(t.data(),e.data())}function ag(t){const e=Ld(t.firestore,If);return function(t,e,n){const s=new js;return t.asyncQueue.enqueueAndForget((async()=>{try{if(al(await cf(t))){const r=await lf(t),i=new Jd(e,r,n).run();s.resolve(i)}else s.reject(new Ks(Gs.UNAVAILABLE,"Failed to get count result because the client is offline."))}catch(t){s.reject(t)}})),s.promise}(Tf(e),t,new Qm(e))}const ug={maxAttempts:5};class cg{constructor(t,e){this._firestore=t,this._commitHandler=e,this._mutations=[],this._committed=!1,this._dataReader=zf(t)}set(t,e,n){this._verifyNotCommitted();const s=hg(t,this._firestore),r=Fm(s.converter,e,n),i=Hf(this._dataReader,"WriteBatch.set",s._key,r,null!==s.converter,n);return this._mutations.push(i.toMutation(s._key,Vo.none())),this}update(t,e,n,...s){this._verifyNotCommitted();const r=hg(t,this._firestore);let i;return i="string"==typeof(e=I(e))||e instanceof Ff?nm(this._dataReader,"WriteBatch.update",r._key,e,n,s):em(this._dataReader,"WriteBatch.update",r._key,e),this._mutations.push(i.toMutation(r._key,Vo.exists(!0))),this}delete(t){this._verifyNotCommitted();const e=hg(t,this._firestore);return this._mutations=this._mutations.concat(new Wo(e._key,Vo.none())),this}commit(){return this._verifyNotCommitted(),this._committed=!0,this._mutations.length>0?this._commitHandler(this._mutations):Promise.resolve()}_verifyNotCommitted(){if(this._committed)throw new Ks(Gs.FAILED_PRECONDITION,"A write batch can no longer be used after commit() has been called.")}}function hg(t,e){if((t=I(t)).firestore!==e)throw new Ks(Gs.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return t}class lg extends class{constructor(t,e){this._firestore=t,this._transaction=e,this._dataReader=zf(t)}get(t){const e=hg(t,this._firestore),n=new Pm(this._firestore);return this._transaction.lookup([e._key]).then((t=>{if(!t||1!==t.length)return Ps();const s=t[0];if(s.isFoundDocument())return new fm(this._firestore,n,s.key,s,e.converter);if(s.isNoDocument())return new fm(this._firestore,n,e._key,null,e.converter);throw Ps()}))}set(t,e,n){const s=hg(t,this._firestore),r=Fm(s.converter,e,n),i=Hf(this._dataReader,"Transaction.set",s._key,r,null!==s.converter,n);return this._transaction.set(s._key,i),this}update(t,e,n,...s){const r=hg(t,this._firestore);let i;return i="string"==typeof(e=I(e))||e instanceof Ff?nm(this._dataReader,"Transaction.update",r._key,e,n,s):em(this._dataReader,"Transaction.update",r._key,e),this._transaction.update(r._key,i),this}delete(t){const e=hg(t,this._firestore);return this._transaction.delete(e._key),this}}{constructor(t,e){super(t,e),this._firestore=t}get(t){const e=hg(t,this._firestore),n=new Qm(this._firestore);return super.get(t).then((t=>new Um(this._firestore,n,e._key,t._document,new Bm(!1,!1),e.converter)))}}function dg(t,e,n){t=Ld(t,If);const s=Object.assign(Object.assign({},ug),n);return function(t){if(t.maxAttempts<1)throw new Ks(Gs.INVALID_ARGUMENT,"Max attempts must be at least 1")}(s),function(t,e,n){const s=new js;return t.asyncQueue.enqueueAndForget((async()=>{const r=await lf(t);new tf(t.asyncQueue,r,n,e,s).run()})),s.promise}(Tf(t),(n=>e(new lg(t,n))),s)}function fg(){return new Wf("deleteField")}function mg(){return new Xf("serverTimestamp")}function gg(...t){return new Jf("arrayUnion",t)}function pg(...t){return new Zf("arrayRemove",t)}function yg(t){return new tm("increment",t)}function wg(t){return Tf(t=Ld(t,If)),new cg(t,(e=>rg(t,e)))}function vg(t,e){var n;const s=Tf(t=Ld(t,If));if(!(null===(n=s.offlineComponents)||void 0===n?void 0:n.indexBackfillerScheduler))return Vs("Cannot enable indexes when persistence is disabled"),Promise.resolve();const r=function(t){const e="string"==typeof t?function(t){var e;try{return JSON.parse(t)}catch(t){throw new Ks(Gs.INVALID_ARGUMENT,"Failed to parse JSON: "+(null===(e=t)||void 0===e?void 0:e.message))}}(t):t,n=[];if(Array.isArray(e.indexes))for(const t of e.indexes){const e=Ig(t,"collectionGroup"),s=[];if(Array.isArray(t.fields))for(const e of t.fields){const t=hm("setIndexConfiguration",Ig(e,"fieldPath"));"CONTAINS"===e.arrayConfig?s.push(new pr(t,2)):"ASCENDING"===e.order?s.push(new pr(t,0)):"DESCENDING"===e.order&&s.push(new pr(t,1))}n.push(new dr(dr.UNKNOWN_ID,e,s,wr.empty()))}return n}(e);return uf(s).then((t=>async function(t,e){const n=qs(t),s=n.indexManager,r=[];return n.persistence.runTransaction("Configure indexes","readwrite",(t=>s.getFieldIndexes(t).next((n=>function(t,e,n,s,r){t=[...t],e=[...e],t.sort(n),e.sort(n);const i=t.length,o=e.length;let a=0,u=0;for(;a<o&&u<i;){const i=n(t[u],e[a]);i<0?r(t[u++]):i>0?s(e[a++]):(a++,u++)}for(;a<o;)s(e[a++]);for(;u<i;)r(t[u++])}(n,e,gr,(e=>{r.push(s.addFieldIndex(t,e))}),(e=>{r.push(s.deleteFieldIndex(t,e))})))).next((()=>xr.waitFor(r)))))}(t,r)))}function Ig(t,e){if("string"!=typeof t[e])throw new Ks(Gs.INVALID_ARGUMENT,"Missing string value for: "+e);return t[e]}!function(n,s=!0){Ns=i,t(new b("firestore",((t,{instanceIdentifier:e,options:n})=>{const r=t.getProvider("app").getImmediate(),i=new If(new Hs(t.getProvider("auth-internal")),new Js(t.getProvider("app-check-internal")),function(t,e){if(!Object.prototype.hasOwnProperty.apply(t.options,["projectId"]))throw new Ks(Gs.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');return new ii(t.options.projectId,e)}(r,e),r);return n=Object.assign({useFetchStreams:s},n),i._setSettings(n),i}),"PUBLIC").setMultipleInstances(!0)),e(Ds,"3.7.2",n),e(Ds,"3.7.2","esm2017")}();export{Vm as AbstractUserDataWriter,Yd as AggregateField,Xd as AggregateQuerySnapshot,Vf as Bytes,vf as CACHE_SIZE_UNLIMITED,qd as CollectionReference,Bd as DocumentReference,Um as DocumentSnapshot,Ff as FieldPath,Bf as FieldValue,If as Firestore,Ks as FirestoreError,Uf as GeoPoint,wf as LoadBundleTask,Ud as Query,ym as QueryConstraint,qm as QueryDocumentSnapshot,Gm as QuerySnapshot,Bm as SnapshotMetadata,ir as Timestamp,lg as Transaction,cg as WriteBatch,ii as _DatabaseId,lr as _DocumentKey,Zs as _EmptyAppCheckTokenProvider,Qs as _EmptyAuthCredentialsProvider,hr as _FieldPath,Ld as _cast,Us as _debugAssert,Wr as _isBase64Available,Vs as _logWarn,Cd as _validateIsNotUsedTogether,eg as addDoc,og as aggregateQuerySnapshotEqual,pg as arrayRemove,gg as arrayUnion,Df as clearIndexedDbPersistence,Gd as collection,Kd as collectionGroup,Pd as connectFirestoreEmulator,tg as deleteDoc,fg as deleteField,kf as disableNetwork,jd as doc,Pf as documentId,_f as enableIndexedDbPersistence,xf as enableMultiTabIndexedDbPersistence,Nf as enableNetwork,km as endAt,Nm as endBefore,Tf as ensureFirestoreConfigured,rg as executeWrite,ag as getCountFromServer,$m as getDoc,zm as getDocFromCache,Hm as getDocFromServer,Wm as getDocs,Ym as getDocsFromCache,Xm as getDocsFromServer,Ef as getFirestore,yg as increment,bf as initializeFirestore,Sm as limit,_m as limitToLast,Lf as loadBundle,Mf as namedQuery,ng as onSnapshot,sg as onSnapshotsInSync,Em as orderBy,wm as query,Qd as queryEqual,$d as refEqual,dg as runTransaction,mg as serverTimestamp,Jm as setDoc,vg as setIndexConfiguration,Ls as setLogLevel,jm as snapshotEqual,Dm as startAfter,Am as startAt,Rf as terminate,Zm as updateDoc,Cf as waitForPendingWrites,Im as where,wg as writeBatch};
2
2
 
3
3
  //# sourceMappingURL=firebase-firestore.js.map