-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbundle.js
2 lines (2 loc) · 247 KB
/
bundle.js
1
2
/*! For license information please see bundle.js.LICENSE.txt */
(()=>{"use strict";var t={};t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}();const e=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},n={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,c=a?t[e+2]:0,u=r>>2,h=(3&r)<<4|o>>4;let l=(15&o)<<2|c>>6,d=63&c;a||(d=64,i||(l=64)),s.push(n[u],n[h],n[l],n[d])}return s.join("")},encodeString(t,n){return this.HAS_NATIVE_SUPPORT&&!n?btoa(t):this.encodeByteArray(e(t),n)},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_,r=[];for(let e=0;e<t.length;){const i=n[t.charAt(e++)],o=e<t.length?n[t.charAt(e)]:0;++e;const a=e<t.length?n[t.charAt(e)]:64;++e;const c=e<t.length?n[t.charAt(e)]:64;if(++e,null==i||null==o||null==a||null==c)throw new s;const u=i<<2|o>>4;if(r.push(u),64!==a){const t=o<<4&240|a>>2;if(r.push(t),64!==c){const t=a<<6&192|c;r.push(t)}}}return r},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)}}};class s extends Error{constructor(){super(...arguments),this.name="DecodeBase64StringError"}}const r=function(t){return function(t){const s=e(t);return n.encodeByteArray(s,!0)}(t).replace(/\./g,"")},i=function(t){try{return n.decodeString(t,!0)}catch(t){console.error("base64Decode failed: ",t)}return null};const o=()=>function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==t.g)return t.g;throw new Error("Unable to locate global object.")}().__FIREBASE_DEFAULTS__,a=()=>{try{return o()||(()=>{if("undefined"==typeof process||void 0===process.env)return;const t=process.env.__FIREBASE_DEFAULTS__;return t?JSON.parse(t):void 0})()||(()=>{if("undefined"==typeof document)return;let t;try{t=document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/)}catch(t){return}const e=t&&i(t[1]);return e&&JSON.parse(e)})()}catch(t){return void console.info(`Unable to get __FIREBASE_DEFAULTS__ due to: ${t}`)}},c=t=>{const e=(t=>{var e,n;return null===(n=null===(e=a())||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]},u=()=>{var t;return null===(t=a())||void 0===t?void 0:t.config};class h{constructor(){this.reject=()=>{},this.resolve=()=>{},this.promise=new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}wrapCallback(t){return(e,n)=>{e?this.reject(e):this.resolve(n),"function"==typeof t&&(this.promise.catch((()=>{})),1===t.length?t(e):t(e,n))}}}function l(){try{return"object"==typeof indexedDB}catch(t){return!1}}class d extends Error{constructor(t,e,n){super(e),this.code=t,this.customData=n,this.name="FirebaseError",Object.setPrototypeOf(this,d.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,f.prototype.create)}}class f{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(g,((t,n)=>{const s=e[n];return null!=s?String(s):`<${n}?>`}))}(r,n):"Error",o=`${this.serviceName}: ${i} (${s}).`;return new d(s,o,n)}}const g=/\{\$([^}]+)}/g;function m(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(p(n)&&p(i)){if(!m(n,i))return!1}else if(n!==i)return!1}for(const t of s)if(!n.includes(t))return!1;return!0}function p(t){return null!==t&&"object"==typeof t}function y(t){return t&&t._delegate?t._delegate:t}class v{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}}const w="[DEFAULT]";class E{constructor(t,e){this.name=t,this.container=e,this.component=null,this.instances=new Map,this.instancesDeferred=new Map,this.instancesOptions=new Map,this.onInitCallbacks=new Map}get(t){const e=this.normalizeInstanceIdentifier(t);if(!this.instancesDeferred.has(e)){const t=new h;if(this.instancesDeferred.set(e,t),this.isInitialized(e)||this.shouldAutoInitialize())try{const n=this.getOrInitializeService({instanceIdentifier:e});n&&t.resolve(n)}catch(t){}}return this.instancesDeferred.get(e).promise}getImmediate(t){var e;const n=this.normalizeInstanceIdentifier(null==t?void 0:t.identifier),s=null!==(e=null==t?void 0:t.optional)&&void 0!==e&&e;if(!this.isInitialized(n)&&!this.shouldAutoInitialize()){if(s)return null;throw Error(`Service ${this.name} is not available`)}try{return this.getOrInitializeService({instanceIdentifier:n})}catch(t){if(s)return null;throw t}}getComponent(){return this.component}setComponent(t){if(t.name!==this.name)throw Error(`Mismatching Component ${t.name} for Provider ${this.name}.`);if(this.component)throw Error(`Component for ${this.name} has already been provided`);if(this.component=t,this.shouldAutoInitialize()){if(function(t){return"EAGER"===t.instantiationMode}(t))try{this.getOrInitializeService({instanceIdentifier:w})}catch(t){}for(const[t,e]of this.instancesDeferred.entries()){const n=this.normalizeInstanceIdentifier(t);try{const t=this.getOrInitializeService({instanceIdentifier:n});e.resolve(t)}catch(t){}}}}clearInstance(t=w){this.instancesDeferred.delete(t),this.instancesOptions.delete(t),this.instances.delete(t)}async delete(){const t=Array.from(this.instances.values());await Promise.all([...t.filter((t=>"INTERNAL"in t)).map((t=>t.INTERNAL.delete())),...t.filter((t=>"_delete"in t)).map((t=>t._delete()))])}isComponentSet(){return null!=this.component}isInitialized(t=w){return this.instances.has(t)}getOptions(t=w){return this.instancesOptions.get(t)||{}}initialize(t={}){const{options:e={}}=t,n=this.normalizeInstanceIdentifier(t.instanceIdentifier);if(this.isInitialized(n))throw Error(`${this.name}(${n}) has already been initialized`);if(!this.isComponentSet())throw Error(`Component ${this.name} has not been registered yet`);const s=this.getOrInitializeService({instanceIdentifier:n,options:e});for(const[t,e]of this.instancesDeferred.entries()){n===this.normalizeInstanceIdentifier(t)&&e.resolve(s)}return s}onInit(t,e){var n;const s=this.normalizeInstanceIdentifier(e),r=null!==(n=this.onInitCallbacks.get(s))&&void 0!==n?n:new Set;r.add(t),this.onInitCallbacks.set(s,r);const i=this.instances.get(s);return i&&t(i,s),()=>{r.delete(t)}}invokeOnInitCallbacks(t,e){const n=this.onInitCallbacks.get(e);if(n)for(const s of n)try{s(t,e)}catch(t){}}getOrInitializeService({instanceIdentifier:t,options:e={}}){let n=this.instances.get(t);if(!n&&this.component&&(n=this.component.instanceFactory(this.container,{instanceIdentifier:(s=t,s===w?void 0:s),options:e}),this.instances.set(t,n),this.instancesOptions.set(t,e),this.invokeOnInitCallbacks(n,t),this.component.onInstanceCreated))try{this.component.onInstanceCreated(this.container,t,n)}catch(t){}var s;return n||null}normalizeInstanceIdentifier(t=w){return this.component?this.component.multipleInstances?t:w:t}shouldAutoInitialize(){return!!this.component&&"EXPLICIT"!==this.component.instantiationMode}}class _{constructor(t){this.name=t,this.providers=new Map}addComponent(t){const e=this.getProvider(t.name);if(e.isComponentSet())throw new Error(`Component ${t.name} has already been registered with ${this.name}`);e.setComponent(t)}addOrOverwriteComponent(t){this.getProvider(t.name).isComponentSet()&&this.providers.delete(t.name),this.addComponent(t)}getProvider(t){if(this.providers.has(t))return this.providers.get(t);const e=new E(t,this);return this.providers.set(t,e),e}getProviders(){return Array.from(this.providers.values())}}const b=[];var I;!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"}(I||(I={}));const T={debug:I.DEBUG,verbose:I.VERBOSE,info:I.INFO,warn:I.WARN,error:I.ERROR,silent:I.SILENT},S=I.INFO,C={[I.DEBUG]:"log",[I.VERBOSE]:"log",[I.INFO]:"info",[I.WARN]:"warn",[I.ERROR]:"error"},A=(t,e,...n)=>{if(e<t.logLevel)return;const s=(new Date).toISOString(),r=C[e];if(!r)throw new Error(`Attempted to log a message with an invalid logType (value: ${e})`);console[r](`[${s}] ${t.name}:`,...n)};class D{constructor(t){this.name=t,this._logLevel=S,this._logHandler=A,this._userLogHandler=null,b.push(this)}get logLevel(){return this._logLevel}set logLevel(t){if(!(t in I))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,I.DEBUG,...t),this._logHandler(this,I.DEBUG,...t)}log(...t){this._userLogHandler&&this._userLogHandler(this,I.VERBOSE,...t),this._logHandler(this,I.VERBOSE,...t)}info(...t){this._userLogHandler&&this._userLogHandler(this,I.INFO,...t),this._logHandler(this,I.INFO,...t)}warn(...t){this._userLogHandler&&this._userLogHandler(this,I.WARN,...t),this._logHandler(this,I.WARN,...t)}error(...t){this._userLogHandler&&this._userLogHandler(this,I.ERROR,...t),this._logHandler(this,I.ERROR,...t)}}const k=(t,e)=>e.some((e=>t instanceof e));let N,R;const L=new WeakMap,x=new WeakMap,O=new WeakMap,M=new WeakMap,P=new WeakMap;let F={get(t,e,n){if(t instanceof IDBTransaction){if("done"===e)return x.get(t);if("objectStoreNames"===e)return t.objectStoreNames||O.get(t);if("store"===e)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return U(t[e])},set:(t,e,n)=>(t[e]=n,!0),has:(t,e)=>t instanceof IDBTransaction&&("done"===e||"store"===e)||e in t};function B(t){return t!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(R||(R=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(q(this),e),U(L.get(this))}:function(...e){return U(t.apply(q(this),e))}:function(e,...n){const s=t.call(q(this),e,...n);return O.set(s,e.sort?e.sort():[e]),U(s)}}function V(t){return"function"==typeof t?B(t):(t instanceof IDBTransaction&&function(t){if(x.has(t))return;const e=new Promise(((e,n)=>{const s=()=>{t.removeEventListener("complete",r),t.removeEventListener("error",i),t.removeEventListener("abort",i)},r=()=>{e(),s()},i=()=>{n(t.error||new DOMException("AbortError","AbortError")),s()};t.addEventListener("complete",r),t.addEventListener("error",i),t.addEventListener("abort",i)}));x.set(t,e)}(t),k(t,N||(N=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(t,F):t)}function U(t){if(t instanceof IDBRequest)return function(t){const e=new Promise(((e,n)=>{const s=()=>{t.removeEventListener("success",r),t.removeEventListener("error",i)},r=()=>{e(U(t.result)),s()},i=()=>{n(t.error),s()};t.addEventListener("success",r),t.addEventListener("error",i)}));return e.then((e=>{e instanceof IDBCursor&&L.set(e,t)})).catch((()=>{})),P.set(e,t),e}(t);if(M.has(t))return M.get(t);const e=V(t);return e!==t&&(M.set(t,e),P.set(e,t)),e}const q=t=>P.get(t);const j=["get","getKey","getAll","getAllKeys","count"],$=["put","add","delete","clear"],z=new Map;function K(t,e){if(!(t instanceof IDBDatabase)||e in t||"string"!=typeof e)return;if(z.get(e))return z.get(e);const n=e.replace(/FromIndex$/,""),s=e!==n,r=$.includes(n);if(!(n in(s?IDBIndex:IDBObjectStore).prototype)||!r&&!j.includes(n))return;const i=async function(t,...e){const i=this.transaction(t,r?"readwrite":"readonly");let o=i.store;return s&&(o=o.index(e.shift())),(await Promise.all([o[n](...e),r&&i.done]))[0]};return z.set(e,i),i}F=(t=>({...t,get:(e,n,s)=>K(e,n)||t.get(e,n,s),has:(e,n)=>!!K(e,n)||t.has(e,n)}))(F);class H{constructor(t){this.container=t}getPlatformInfoString(){return this.container.getProviders().map((t=>{if(function(t){const e=t.getComponent();return"VERSION"===(null==e?void 0:e.type)}(t)){const e=t.getImmediate();return`${e.library}/${e.version}`}return null})).filter((t=>t)).join(" ")}}const G="@firebase/app",Q="0.9.19",W=new D("@firebase/app"),Y="[DEFAULT]",X={[G]:"fire-core","@firebase/app-compat":"fire-core-compat","@firebase/analytics":"fire-analytics","@firebase/analytics-compat":"fire-analytics-compat","@firebase/app-check":"fire-app-check","@firebase/app-check-compat":"fire-app-check-compat","@firebase/auth":"fire-auth","@firebase/auth-compat":"fire-auth-compat","@firebase/database":"fire-rtdb","@firebase/database-compat":"fire-rtdb-compat","@firebase/functions":"fire-fn","@firebase/functions-compat":"fire-fn-compat","@firebase/installations":"fire-iid","@firebase/installations-compat":"fire-iid-compat","@firebase/messaging":"fire-fcm","@firebase/messaging-compat":"fire-fcm-compat","@firebase/performance":"fire-perf","@firebase/performance-compat":"fire-perf-compat","@firebase/remote-config":"fire-rc","@firebase/remote-config-compat":"fire-rc-compat","@firebase/storage":"fire-gcs","@firebase/storage-compat":"fire-gcs-compat","@firebase/firestore":"fire-fst","@firebase/firestore-compat":"fire-fst-compat","fire-js":"fire-js",firebase:"fire-js-all"},J=new Map,Z=new Map;function tt(t,e){try{t.container.addComponent(e)}catch(n){W.debug(`Component ${e.name} failed to register with FirebaseApp ${t.name}`,n)}}function et(t){const e=t.name;if(Z.has(e))return W.debug(`There were multiple attempts to register component ${e}.`),!1;Z.set(e,t);for(const e of J.values())tt(e,t);return!0}function nt(t,e){const n=t.container.getProvider("heartbeat").getImmediate({optional:!0});return n&&n.triggerHeartbeat(),t.container.getProvider(e)}const st=new f("app","Firebase",{"no-app":"No Firebase App '{$appName}' has been created - call initializeApp() first","bad-app-name":"Illegal App name: '{$appName}","duplicate-app":"Firebase App named '{$appName}' already exists with different options or config","app-deleted":"Firebase App named '{$appName}' already deleted","no-options":"Need to provide options, when not being deployed to hosting via source.","invalid-app-argument":"firebase.{$appName}() takes either no argument or a Firebase App instance.","invalid-log-argument":"First argument to `onLog` must be null or a function.","idb-open":"Error thrown when opening IndexedDB. Original error: {$originalErrorMessage}.","idb-get":"Error thrown when reading from IndexedDB. Original error: {$originalErrorMessage}.","idb-set":"Error thrown when writing to IndexedDB. Original error: {$originalErrorMessage}.","idb-delete":"Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}."});class rt{constructor(t,e,n){this._isDeleted=!1,this._options=Object.assign({},t),this._config=Object.assign({},e),this._name=e.name,this._automaticDataCollectionEnabled=e.automaticDataCollectionEnabled,this._container=n,this.container.addComponent(new v("app",(()=>this),"PUBLIC"))}get automaticDataCollectionEnabled(){return this.checkDestroyed(),this._automaticDataCollectionEnabled}set automaticDataCollectionEnabled(t){this.checkDestroyed(),this._automaticDataCollectionEnabled=t}get name(){return this.checkDestroyed(),this._name}get options(){return this.checkDestroyed(),this._options}get config(){return this.checkDestroyed(),this._config}get container(){return this._container}get isDeleted(){return this._isDeleted}set isDeleted(t){this._isDeleted=t}checkDestroyed(){if(this.isDeleted)throw st.create("app-deleted",{appName:this._name})}}function it(t,e={}){let n=t;if("object"!=typeof e){e={name:e}}const s=Object.assign({name:Y,automaticDataCollectionEnabled:!1},e),r=s.name;if("string"!=typeof r||!r)throw st.create("bad-app-name",{appName:String(r)});if(n||(n=u()),!n)throw st.create("no-options");const i=J.get(r);if(i){if(m(n,i.options)&&m(s,i.config))return i;throw st.create("duplicate-app",{appName:r})}const o=new _(r);for(const t of Z.values())o.addComponent(t);const a=new rt(n,s,o);return J.set(r,a),a}function ot(t,e,n){var s;let r=null!==(s=X[t])&&void 0!==s?s:t;n&&(r+=`-${n}`);const i=r.match(/\s|\//),o=e.match(/\s|\//);if(i||o){const t=[`Unable to register library "${r}" with version "${e}":`];return i&&t.push(`library name "${r}" contains illegal characters (whitespace or "/")`),i&&o&&t.push("and"),o&&t.push(`version name "${e}" contains illegal characters (whitespace or "/")`),void W.warn(t.join(" "))}et(new v(`${r}-version`,(()=>({library:r,version:e})),"VERSION"))}const at="firebase-heartbeat-database",ct=1,ut="firebase-heartbeat-store";let ht=null;function lt(){return ht||(ht=function(t,e,{blocked:n,upgrade:s,blocking:r,terminated:i}={}){const o=indexedDB.open(t,e),a=U(o);return s&&o.addEventListener("upgradeneeded",(t=>{s(U(o.result),t.oldVersion,t.newVersion,U(o.transaction),t)})),n&&o.addEventListener("blocked",(t=>n(t.oldVersion,t.newVersion,t))),a.then((t=>{i&&t.addEventListener("close",(()=>i())),r&&t.addEventListener("versionchange",(t=>r(t.oldVersion,t.newVersion,t)))})).catch((()=>{})),a}(at,ct,{upgrade:(t,e)=>{if(0===e)t.createObjectStore(ut)}}).catch((t=>{throw st.create("idb-open",{originalErrorMessage:t.message})}))),ht}async function dt(t,e){try{const n=(await lt()).transaction(ut,"readwrite"),s=n.objectStore(ut);await s.put(e,ft(t)),await n.done}catch(t){if(t instanceof d)W.warn(t.message);else{const e=st.create("idb-set",{originalErrorMessage:null==t?void 0:t.message});W.warn(e.message)}}}function ft(t){return`${t.name}!${t.options.appId}`}class gt{constructor(t){this.container=t,this._heartbeatsCache=null;const e=this.container.getProvider("app").getImmediate();this._storage=new pt(e),this._heartbeatsCachePromise=this._storage.read().then((t=>(this._heartbeatsCache=t,t)))}async triggerHeartbeat(){const t=this.container.getProvider("platform-logger").getImmediate().getPlatformInfoString(),e=mt();if(null===this._heartbeatsCache&&(this._heartbeatsCache=await this._heartbeatsCachePromise),this._heartbeatsCache.lastSentHeartbeatDate!==e&&!this._heartbeatsCache.heartbeats.some((t=>t.date===e)))return this._heartbeatsCache.heartbeats.push({date:e,agent:t}),this._heartbeatsCache.heartbeats=this._heartbeatsCache.heartbeats.filter((t=>{const e=new Date(t.date).valueOf();return Date.now()-e<=2592e6})),this._storage.overwrite(this._heartbeatsCache)}async getHeartbeatsHeader(){if(null===this._heartbeatsCache&&await this._heartbeatsCachePromise,null===this._heartbeatsCache||0===this._heartbeatsCache.heartbeats.length)return"";const t=mt(),{heartbeatsToSend:e,unsentEntries:n}=function(t,e=1024){const n=[];let s=t.slice();for(const r of t){const t=n.find((t=>t.agent===r.agent));if(t){if(t.dates.push(r.date),yt(n)>e){t.dates.pop();break}}else if(n.push({agent:r.agent,dates:[r.date]}),yt(n)>e){n.pop();break}s=s.slice(1)}return{heartbeatsToSend:n,unsentEntries:s}}(this._heartbeatsCache.heartbeats),s=r(JSON.stringify({version:2,heartbeats:e}));return this._heartbeatsCache.lastSentHeartbeatDate=t,n.length>0?(this._heartbeatsCache.heartbeats=n,await this._storage.overwrite(this._heartbeatsCache)):(this._heartbeatsCache.heartbeats=[],this._storage.overwrite(this._heartbeatsCache)),s}}function mt(){return(new Date).toISOString().substring(0,10)}class pt{constructor(t){this.app=t,this._canUseIndexedDBPromise=this.runIndexedDBEnvironmentCheck()}async runIndexedDBEnvironmentCheck(){return!!l()&&new Promise(((t,e)=>{try{let n=!0;const s="validate-browser-context-for-indexeddb-analytics-module",r=self.indexedDB.open(s);r.onsuccess=()=>{r.result.close(),n||self.indexedDB.deleteDatabase(s),t(!0)},r.onupgradeneeded=()=>{n=!1},r.onerror=()=>{var t;e((null===(t=r.error)||void 0===t?void 0:t.message)||"")}}catch(t){e(t)}})).then((()=>!0)).catch((()=>!1))}async read(){if(await this._canUseIndexedDBPromise){const t=await async function(t){try{const e=await lt();return await e.transaction(ut).objectStore(ut).get(ft(t))}catch(t){if(t instanceof d)W.warn(t.message);else{const e=st.create("idb-get",{originalErrorMessage:null==t?void 0:t.message});W.warn(e.message)}}}(this.app);return t||{heartbeats:[]}}return{heartbeats:[]}}async overwrite(t){var e;if(await this._canUseIndexedDBPromise){const n=await this.read();return dt(this.app,{lastSentHeartbeatDate:null!==(e=t.lastSentHeartbeatDate)&&void 0!==e?e:n.lastSentHeartbeatDate,heartbeats:t.heartbeats})}}async add(t){var e;if(await this._canUseIndexedDBPromise){const n=await this.read();return dt(this.app,{lastSentHeartbeatDate:null!==(e=t.lastSentHeartbeatDate)&&void 0!==e?e:n.lastSentHeartbeatDate,heartbeats:[...n.heartbeats,...t.heartbeats]})}}}function yt(t){return r(JSON.stringify({version:2,heartbeats:t})).length}var vt;vt="",et(new v("platform-logger",(t=>new H(t)),"PRIVATE")),et(new v("heartbeat",(t=>new gt(t)),"PRIVATE")),ot(G,Q,vt),ot(G,Q,"esm2017"),ot("fire-js","");ot("firebase","10.4.0","app");var wt,Et="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},_t={},bt=bt||{},It=Et||self;function Tt(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 St(t){var e=typeof t;return"object"==e&&null!=t||"function"==e}var Ct="closure_uid_"+(1e9*Math.random()>>>0),At=0;function Dt(t,e,n){return t.call.apply(t.bind,arguments)}function kt(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 Nt(t,e,n){return(Nt=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?Dt:kt).apply(null,arguments)}function Rt(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 Lt(t,e){function n(){}n.prototype=e.prototype,t.$=e.prototype,t.prototype=new n,t.prototype.constructor=t,t.ac=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 xt(){this.s=this.s,this.o=this.o}xt.prototype.s=!1,xt.prototype.sa=function(){var t;!this.s&&(this.s=!0,this.N(),0)&&(t=this,Object.prototype.hasOwnProperty.call(t,Ct)&&t[Ct]||(t[Ct]=++At))},xt.prototype.N=function(){if(this.o)for(;this.o.length;)this.o.shift()()};const Ot=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 Mt(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 Pt(t,e){for(let e=1;e<arguments.length;e++){const n=arguments[e];if(Tt(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 Ft(t,e){this.type=t,this.g=this.target=e,this.defaultPrevented=!1}Ft.prototype.h=function(){this.defaultPrevented=!0};var Bt=function(){if(!It.addEventListener||!Object.defineProperty)return!1;var t=!1,e=Object.defineProperty({},"passive",{get:function(){t=!0}});try{It.addEventListener("test",(()=>{}),e),It.removeEventListener("test",(()=>{}),e)}catch(t){}return t}();function Vt(t){return/^[\s\xa0]*$/.test(t)}function Ut(){var t=It.navigator;return t&&(t=t.userAgent)?t:""}function qt(t){return-1!=Ut().indexOf(t)}function jt(t){return jt[" "](t),t}jt[" "]=function(){};var $t,zt,Kt,Ht=qt("Opera"),Gt=qt("Trident")||qt("MSIE"),Qt=qt("Edge"),Wt=Qt||Gt,Yt=qt("Gecko")&&!(-1!=Ut().toLowerCase().indexOf("webkit")&&!qt("Edge"))&&!(qt("Trident")||qt("MSIE"))&&!qt("Edge"),Xt=-1!=Ut().toLowerCase().indexOf("webkit")&&!qt("Edge");function Jt(){var t=It.document;return t?t.documentMode:void 0}t:{var Zt="",te=(zt=Ut(),Yt?/rv:([^\);]+)(\)|;)/.exec(zt):Qt?/Edge\/([\d\.]+)/.exec(zt):Gt?/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(zt):Xt?/WebKit\/(\S+)/.exec(zt):Ht?/(?:Version)[ \/]?(\S+)/.exec(zt):void 0);if(te&&(Zt=te?te[1]:""),Gt){var ee=Jt();if(null!=ee&&ee>parseFloat(Zt)){$t=String(ee);break t}}$t=Zt}if(It.document&&Gt){var ne=Jt();Kt=ne||(parseInt($t,10)||void 0)}else Kt=void 0;var se=Kt;function re(t,e){if(Ft.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(Yt){t:{try{jt(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:ie[t.pointerType]||"",this.state=t.state,this.i=t,t.defaultPrevented&&re.$.h.call(this)}}Lt(re,Ft);var ie={2:"touch",3:"pen",4:"mouse"};re.prototype.h=function(){re.$.h.call(this);var t=this.i;t.preventDefault?t.preventDefault():t.returnValue=!1};var oe="closure_listenable_"+(1e6*Math.random()|0),ae=0;function ce(t,e,n,s,r){this.listener=t,this.proxy=null,this.src=e,this.type=n,this.capture=!!s,this.la=r,this.key=++ae,this.fa=this.ia=!1}function ue(t){t.fa=!0,t.listener=null,t.proxy=null,t.src=null,t.la=null}function he(t,e,n){for(const s in t)e.call(n,t[s],s,t)}function le(t){const e={};for(const n in t)e[n]=t[n];return e}const de="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");function fe(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<de.length;e++)n=de[e],Object.prototype.hasOwnProperty.call(s,n)&&(t[n]=s[n])}}function ge(t){this.src=t,this.g={},this.h=0}function me(t,e){var n=e.type;if(n in t.g){var s,r=t.g[n],i=Ot(r,e);(s=0<=i)&&Array.prototype.splice.call(r,i,1),s&&(ue(e),0==t.g[n].length&&(delete t.g[n],t.h--))}}function pe(t,e,n,s){for(var r=0;r<t.length;++r){var i=t[r];if(!i.fa&&i.listener==e&&i.capture==!!n&&i.la==s)return r}return-1}ge.prototype.add=function(t,e,n,s,r){var i=t.toString();(t=this.g[i])||(t=this.g[i]=[],this.h++);var o=pe(t,e,s,r);return-1<o?(e=t[o],n||(e.ia=!1)):((e=new ce(e,this.src,i,!!s,r)).ia=n,t.push(e)),e};var ye="closure_lm_"+(1e6*Math.random()|0),ve={};function we(t,e,n,s,r){if(s&&s.once)return _e(t,e,n,s,r);if(Array.isArray(e)){for(var i=0;i<e.length;i++)we(t,e[i],n,s,r);return null}return n=De(n),t&&t[oe]?t.O(e,n,St(s)?!!s.capture:!!s,r):Ee(t,e,n,!1,s,r)}function Ee(t,e,n,s,r,i){if(!e)throw Error("Invalid event type");var o=St(r)?!!r.capture:!!r,a=Ce(t);if(a||(t[ye]=a=new ge(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=Se;return t}(),n.proxy=s,s.src=t,s.listener=n,t.addEventListener)Bt||(r=o),void 0===r&&(r=!1),t.addEventListener(e.toString(),s,r);else if(t.attachEvent)t.attachEvent(Te(e.toString()),s);else{if(!t.addListener||!t.removeListener)throw Error("addEventListener and attachEvent are unavailable.");t.addListener(s)}return n}function _e(t,e,n,s,r){if(Array.isArray(e)){for(var i=0;i<e.length;i++)_e(t,e[i],n,s,r);return null}return n=De(n),t&&t[oe]?t.P(e,n,St(s)?!!s.capture:!!s,r):Ee(t,e,n,!0,s,r)}function be(t,e,n,s,r){if(Array.isArray(e))for(var i=0;i<e.length;i++)be(t,e[i],n,s,r);else s=St(s)?!!s.capture:!!s,n=De(n),t&&t[oe]?(t=t.i,(e=String(e).toString())in t.g&&(-1<(n=pe(i=t.g[e],n,s,r))&&(ue(i[n]),Array.prototype.splice.call(i,n,1),0==i.length&&(delete t.g[e],t.h--)))):t&&(t=Ce(t))&&(e=t.g[e.toString()],t=-1,e&&(t=pe(e,n,s,r)),(n=-1<t?e[t]:null)&&Ie(n))}function Ie(t){if("number"!=typeof t&&t&&!t.fa){var e=t.src;if(e&&e[oe])me(e.i,t);else{var n=t.type,s=t.proxy;e.removeEventListener?e.removeEventListener(n,s,t.capture):e.detachEvent?e.detachEvent(Te(n),s):e.addListener&&e.removeListener&&e.removeListener(s),(n=Ce(e))?(me(n,t),0==n.h&&(n.src=null,e[ye]=null)):ue(t)}}}function Te(t){return t in ve?ve[t]:ve[t]="on"+t}function Se(t,e){if(t.fa)t=!0;else{e=new re(e,this);var n=t.listener,s=t.la||t.src;t.ia&&Ie(t),t=n.call(s,e)}return t}function Ce(t){return(t=t[ye])instanceof ge?t:null}var Ae="__closure_events_fn_"+(1e9*Math.random()>>>0);function De(t){return"function"==typeof t?t:(t[Ae]||(t[Ae]=function(e){return t.handleEvent(e)}),t[Ae])}function ke(){xt.call(this),this.i=new ge(this),this.S=this,this.J=null}function Ne(t,e){var n,s=t.J;if(s)for(n=[];s;s=s.J)n.push(s);if(t=t.S,s=e.type||e,"string"==typeof e)e=new Ft(e,t);else if(e instanceof Ft)e.target=e.target||t;else{var r=e;fe(e=new Ft(s,t),r)}if(r=!0,n)for(var i=n.length-1;0<=i;i--){var o=e.g=n[i];r=Re(o,s,!0,e)&&r}if(r=Re(o=e.g=t,s,!0,e)&&r,r=Re(o,s,!1,e)&&r,n)for(i=0;i<n.length;i++)r=Re(o=e.g=n[i],s,!1,e)&&r}function Re(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.fa&&o.capture==n){var a=o.listener,c=o.la||o.src;o.ia&&me(t.i,o),r=!1!==a.call(c,s)&&r}}return r&&!s.defaultPrevented}Lt(ke,xt),ke.prototype[oe]=!0,ke.prototype.removeEventListener=function(t,e,n,s){be(this,t,e,n,s)},ke.prototype.N=function(){if(ke.$.N.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++)ue(n[s]);delete e.g[t],e.h--}}this.J=null},ke.prototype.O=function(t,e,n,s){return this.i.add(String(t),e,!1,n,s)},ke.prototype.P=function(t,e,n,s){return this.i.add(String(t),e,!0,n,s)};var Le=It.JSON.stringify;function xe(){var t=Ue;let e=null;return t.g&&(e=t.g,t.g=t.g.next,t.g||(t.h=null),e.next=null),e}var Oe=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 Me),(t=>t.reset()));class Me{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 Pe(t){var e=1;t=t.split(":");const n=[];for(;0<e&&t.length;)n.push(t.shift()),e--;return t.length&&n.push(t.join(":")),n}function Fe(t){It.setTimeout((()=>{throw t}),0)}let Be,Ve=!1,Ue=new class{constructor(){this.h=this.g=null}add(t,e){const n=Oe.get();n.set(t,e),this.h?this.h.next=n:this.g=n,this.h=n}},qe=()=>{const t=It.Promise.resolve(void 0);Be=()=>{t.then(je)}};var je=()=>{for(var t;t=xe();){try{t.h.call(t.g)}catch(t){Fe(t)}var e=Oe;e.j(t),100>e.h&&(e.h++,t.next=e.g,e.g=t)}Ve=!1};function $e(t,e){ke.call(this),this.h=t||1,this.g=e||It,this.j=Nt(this.qb,this),this.l=Date.now()}function ze(t){t.ga=!1,t.T&&(t.g.clearTimeout(t.T),t.T=null)}function Ke(t,e,n){if("function"==typeof t)n&&(t=Nt(t,n));else{if(!t||"function"!=typeof t.handleEvent)throw Error("Invalid listener argument");t=Nt(t.handleEvent,t)}return 2147483647<Number(e)?-1:It.setTimeout(t,e||0)}function He(t){t.g=Ke((()=>{t.g=null,t.i&&(t.i=!1,He(t))}),t.j);const e=t.h;t.h=null,t.m.apply(null,e)}Lt($e,ke),(wt=$e.prototype).ga=!1,wt.T=null,wt.qb=function(){if(this.ga){var t=Date.now()-this.l;0<t&&t<.8*this.h?this.T=this.g.setTimeout(this.j,this.h-t):(this.T&&(this.g.clearTimeout(this.T),this.T=null),Ne(this,"tick"),this.ga&&(ze(this),this.start()))}},wt.start=function(){this.ga=!0,this.T||(this.T=this.g.setTimeout(this.j,this.h),this.l=Date.now())},wt.N=function(){$e.$.N.call(this),ze(this),delete this.g};class Ge extends xt{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:He(this)}N(){super.N(),this.g&&(It.clearTimeout(this.g),this.g=null,this.i=!1,this.h=null)}}function Qe(t){xt.call(this),this.h=t,this.g={}}Lt(Qe,xt);var We=[];function Ye(t,e,n,s){Array.isArray(n)||(n&&(We[0]=n.toString()),n=We);for(var r=0;r<n.length;r++){var i=we(e,n[r],s||t.handleEvent,!1,t.h||t);if(!i)break;t.g[i.key]=i}}function Xe(t){he(t.g,(function(t,e){this.g.hasOwnProperty(e)&&Ie(t)}),t),t.g={}}function Je(){this.g=!0}function Ze(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 Le(n)}catch(t){return e}}(t,n)+(s?" "+s:"")}))}Qe.prototype.N=function(){Qe.$.N.call(this),Xe(this)},Qe.prototype.handleEvent=function(){throw Error("EventHandler.handleEvent not implemented")},Je.prototype.Ea=function(){this.g=!1},Je.prototype.info=function(){};var tn={},en=null;function nn(){return en=en||new ke}function sn(t){Ft.call(this,tn.Ta,t)}function rn(t){const e=nn();Ne(e,new sn(e))}function on(t,e){Ft.call(this,tn.STAT_EVENT,t),this.stat=e}function an(t){const e=nn();Ne(e,new on(e,t))}function cn(t,e){Ft.call(this,tn.Ua,t),this.size=e}function un(t,e){if("function"!=typeof t)throw Error("Fn must not be null and must be a function");return It.setTimeout((function(){t()}),e)}tn.Ta="serverreachability",Lt(sn,Ft),tn.STAT_EVENT="statevent",Lt(on,Ft),tn.Ua="timingevent",Lt(cn,Ft);var hn={NO_ERROR:0,rb:1,Eb:2,Db:3,yb:4,Cb:5,Fb:6,Qa:7,TIMEOUT:8,Ib:9},ln={wb:"complete",Sb:"success",Ra:"error",Qa:"abort",Kb:"ready",Lb:"readystatechange",TIMEOUT:"timeout",Gb:"incrementaldata",Jb:"progress",zb:"downloadprogress",$b:"uploadprogress"};function dn(){}function fn(t){return t.h||(t.h=t.i())}function gn(){}dn.prototype.h=null;var mn,pn={OPEN:"a",vb:"b",Ra:"c",Hb:"d"};function yn(){Ft.call(this,"d")}function vn(){Ft.call(this,"c")}function wn(){}function En(t,e,n,s){this.l=t,this.j=e,this.m=n,this.W=s||1,this.U=new Qe(this),this.P=bn,t=Wt?125:void 0,this.V=new $e(t),this.I=null,this.i=!1,this.s=this.A=this.v=this.L=this.G=this.Y=this.B=null,this.F=[],this.g=null,this.C=0,this.o=this.u=null,this.ca=-1,this.J=!1,this.O=0,this.M=null,this.ba=this.K=this.aa=this.S=!1,this.h=new _n}function _n(){this.i=null,this.g="",this.h=!1}Lt(yn,Ft),Lt(vn,Ft),Lt(wn,dn),wn.prototype.g=function(){return new XMLHttpRequest},wn.prototype.i=function(){return{}},mn=new wn;var bn=45e3,In={},Tn={};function Sn(t,e,n){t.L=1,t.v=zn(Vn(e)),t.s=n,t.S=!0,Cn(t,null)}function Cn(t,e){t.G=Date.now(),Nn(t),t.A=Vn(t.v);var n=t.A,s=t.W;Array.isArray(s)||(s=[String(s)]),ss(n.i,"t",s),t.C=0,n=t.l.J,t.h=new _n,t.g=sr(t.l,n?e:null,!t.s),0<t.O&&(t.M=new Ge(Nt(t.Pa,t,t.g),t.O)),Ye(t.U,t.g,"readystatechange",t.nb),e=t.I?le(t.I):{},t.s?(t.u||(t.u="POST"),e["Content-Type"]="application/x-www-form-urlencoded",t.g.ha(t.A,t.u,t.s,e)):(t.u="GET",t.g.ha(t.A,t.u,null,e)),rn(),function(t,e,n,s,r,i){t.info((function(){if(t.g)if(i)for(var o="",a=i.split("&"),c=0;c<a.length;c++){var u=a[c].split("=");if(1<u.length){var h=u[0];u=u[1];var l=h.split("_");o=2<=l.length&&"type"==l[1]?o+(h+"=")+u+"&":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.W,t.s)}function An(t){return!!t.g&&("GET"==t.u&&2!=t.L&&t.l.Ha)}function Dn(t,e,n){let s,r=!0;for(;!t.J&&t.C<n.length;){if(s=kn(t,n),s==Tn){4==e&&(t.o=4,an(14),r=!1),Ze(t.j,t.m,null,"[Incomplete Response]");break}if(s==In){t.o=4,an(15),Ze(t.j,t.m,n,"[Invalid Chunk]"),r=!1;break}Ze(t.j,t.m,s,null),Mn(t,s)}An(t)&&s!=Tn&&s!=In&&(t.h.g="",t.C=0),4!=e||0!=n.length||t.h.h||(t.o=1,an(16),r=!1),t.i=t.i&&r,r?0<n.length&&!t.ba&&(t.ba=!0,(e=t.l).g==t&&e.ca&&!e.M&&(e.l.info("Great, no buffering proxy detected. Bytes received: "+n.length),Ws(e),e.M=!0,an(11))):(Ze(t.j,t.m,n,"[Invalid Chunked Response]"),On(t),xn(t))}function kn(t,e){var n=t.C,s=e.indexOf("\n",n);return-1==s?Tn:(n=Number(e.substring(n,s)),isNaN(n)?In:(s+=1)+n>e.length?Tn:(e=e.slice(s,s+n),t.C=s+n,e))}function Nn(t){t.Y=Date.now()+t.P,Rn(t,t.P)}function Rn(t,e){if(null!=t.B)throw Error("WatchDog timer not null");t.B=un(Nt(t.lb,t),e)}function Ln(t){t.B&&(It.clearTimeout(t.B),t.B=null)}function xn(t){0==t.l.H||t.J||Js(t.l,t)}function On(t){Ln(t);var e=t.M;e&&"function"==typeof e.sa&&e.sa(),t.M=null,ze(t.V),Xe(t.U),t.g&&(e=t.g,t.g=null,e.abort(),e.sa())}function Mn(t,e){try{var n=t.l;if(0!=n.H&&(n.g==t||hs(n.i,t)))if(!t.K&&hs(n.i,t)&&3==n.H){try{var s=n.Ja.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.G+3e3<t.G))break t;Xs(n),qs(n)}Qs(n),an(18)}}else n.Fa=r[1],0<n.Fa-n.V&&37500>r[2]&&n.G&&0==n.A&&!n.v&&(n.v=un(Nt(n.ib,n),6e3));if(1>=us(n.i)&&n.oa){try{n.oa()}catch(t){}n.oa=void 0}}else tr(n,11)}else if((t.K||n.g==t)&&Xs(n),!Vt(e))for(r=n.Ja.g.parse(e),e=0;e<r.length;e++){let u=r[e];if(n.V=u[0],u=u[1],2==n.H)if("c"==u[0]){n.K=u[1],n.pa=u[2];const e=u[3];null!=e&&(n.ra=e,n.l.info("VER="+n.ra));const r=u[4];null!=r&&(n.Ga=r,n.l.info("SVER="+n.Ga));const h=u[5];null!=h&&"number"==typeof h&&0<h&&(s=1.5*h,n.L=s,n.l.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.i;i.g||-1==t.indexOf("spdy")&&-1==t.indexOf("quic")&&-1==t.indexOf("h2")||(i.j=i.l,i.g=new Set,i.h&&(ls(i,i.h),i.h=null))}if(s.F){const t=l.g?l.g.getResponseHeader("X-HTTP-Session-Id"):null;t&&(s.Da=t,$n(s.I,s.F,t))}}n.H=3,n.h&&n.h.Ba(),n.ca&&(n.S=Date.now()-t.G,n.l.info("Handshake RTT: "+n.S+"ms"));var o=t;if((s=n).wa=nr(s,s.J?s.pa:null,s.Y),o.K){ds(s.i,o);var a=o,c=s.L;c&&a.setTimeout(c),a.B&&(Ln(a),Nn(a)),s.g=o}else Gs(s);0<n.j.length&&$s(n)}else"stop"!=u[0]&&"close"!=u[0]||tr(n,7);else 3==n.H&&("stop"==u[0]||"close"==u[0]?"stop"==u[0]?tr(n,7):Us(n):"noop"!=u[0]&&n.h&&n.h.Aa(u),n.A=0)}rn()}catch(t){}}function Pn(t,e){if(t.forEach&&"function"==typeof t.forEach)t.forEach(e,void 0);else if(Tt(t)||"string"==typeof t)Array.prototype.forEach.call(t,e,void 0);else for(var n=function(t){if(t.ta&&"function"==typeof t.ta)return t.ta();if(!t.Z||"function"!=typeof t.Z){if("undefined"!=typeof Map&&t instanceof Map)return Array.from(t.keys());if(!("undefined"!=typeof Set&&t instanceof Set)){if(Tt(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.Z&&"function"==typeof t.Z)return t.Z();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(Tt(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)}(wt=En.prototype).setTimeout=function(t){this.P=t},wt.nb=function(t){t=t.target;const e=this.M;e&&3==Os(t)?e.l():this.Pa(t)},wt.Pa=function(t){try{if(t==this.g)t:{const h=Os(this.g);var e=this.g.Ia();this.g.da();if(!(3>h)&&(3!=h||Wt||this.g&&(this.h.h||this.g.ja()||Ms(this.g)))){this.J||4!=h||7==e||rn(),Ln(this);var n=this.g.da();this.ca=n;e:if(An(this)){var s=Ms(this.g);t="";var r=s.length,i=4==Os(this.g);if(!this.h.i){if("undefined"==typeof TextDecoder){On(this),xn(this);var o="";break e}this.h.i=new It.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.ja();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.W,h,n),this.i){if(this.aa&&!this.K){e:{if(this.g){var a,c=this.g;if((a=c.g?c.g.getResponseHeader("X-HTTP-Initial-Response"):null)&&!Vt(a)){var u=a;break e}}u=null}if(!(n=u)){this.i=!1,this.o=3,an(12),On(this),xn(this);break t}Ze(this.j,this.m,n,"Initial handshake response via X-HTTP-Initial-Response"),this.K=!0,Mn(this,n)}this.S?(Dn(this,h,o),Wt&&this.i&&3==h&&(Ye(this.U,this.V,"tick",this.mb),this.V.start())):(Ze(this.j,this.m,o,null),Mn(this,o)),4==h&&On(this),this.i&&!this.J&&(4==h?Js(this.l,this):(this.i=!1,Nn(this)))}else(function(t){const e={};t=(t.g&&2<=Os(t)&&t.g.getAllResponseHeaders()||"").split("\r\n");for(let s=0;s<t.length;s++){if(Vt(t[s]))continue;var n=Pe(t[s]);const r=n[0];if("string"!=typeof(n=n[1]))continue;n=n.trim();const i=e[r]||[];e[r]=i,i.push(n)}!function(t,e){for(const n in t)e.call(void 0,t[n],n,t)}(e,(function(t){return t.join(", ")}))})(this.g),400==n&&0<o.indexOf("Unknown SID")?(this.o=3,an(12)):(this.o=0,an(13)),On(this),xn(this)}}}catch(t){}},wt.mb=function(){if(this.g){var t=Os(this.g),e=this.g.ja();this.C<e.length&&(Ln(this),Dn(this,t,e),this.i&&4!=t&&Nn(this))}},wt.cancel=function(){this.J=!0,On(this)},wt.lb=function(){this.B=null;const t=Date.now();0<=t-this.Y?(function(t,e){t.info((function(){return"TIMEOUT: "+e}))}(this.j,this.A),2!=this.L&&(rn(),an(17)),On(this),this.o=2,xn(this)):Rn(this,this.Y-t)};var Fn=RegExp("^(?:([^:/?#.]+):)?(?://(?:([^\\\\/?#]*)@)?([^\\\\/?#]*?)(?::([0-9]+))?(?=[\\\\/?#]|$))?([^?#]+)?(?:\\?([^#]*))?(?:#([\\s\\S]*))?$");function Bn(t){if(this.g=this.s=this.j="",this.m=null,this.o=this.l="",this.h=!1,t instanceof Bn){this.h=t.h,Un(this,t.j),this.s=t.s,this.g=t.g,qn(this,t.m),this.l=t.l;var e=t.i,n=new Zn;n.i=e.i,e.g&&(n.g=new Map(e.g),n.h=e.h),jn(this,n),this.o=t.o}else t&&(e=String(t).match(Fn))?(this.h=!1,Un(this,e[1]||"",!0),this.s=Kn(e[2]||""),this.g=Kn(e[3]||"",!0),qn(this,e[4]),this.l=Kn(e[5]||"",!0),jn(this,e[6]||"",!0),this.o=Kn(e[7]||"")):(this.h=!1,this.i=new Zn(null,this.h))}function Vn(t){return new Bn(t)}function Un(t,e,n){t.j=n?Kn(e,!0):e,t.j&&(t.j=t.j.replace(/:$/,""))}function qn(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 jn(t,e,n){e instanceof Zn?(t.i=e,function(t,e){e&&!t.j&&(ts(t),t.i=null,t.g.forEach((function(t,e){var n=e.toLowerCase();e!=n&&(es(this,e),ss(this,n,t))}),t)),t.j=e}(t.i,t.h)):(n||(e=Hn(e,Xn)),t.i=new Zn(e,t.h))}function $n(t,e,n){t.i.set(e,n)}function zn(t){return $n(t,"zx",Math.floor(2147483648*Math.random()).toString(36)+Math.abs(Math.floor(2147483648*Math.random())^Date.now()).toString(36)),t}function Kn(t,e){return t?e?decodeURI(t.replace(/%25/g,"%2525")):decodeURIComponent(t):""}function Hn(t,e,n){return"string"==typeof t?(t=encodeURI(t).replace(e,Gn),n&&(t=t.replace(/%25([0-9a-fA-F]{2})/g,"%$1")),t):null}function Gn(t){return"%"+((t=t.charCodeAt(0))>>4&15).toString(16)+(15&t).toString(16)}Bn.prototype.toString=function(){var t=[],e=this.j;e&&t.push(Hn(e,Qn,!0),":");var n=this.g;return(n||"file"==e)&&(t.push("//"),(e=this.s)&&t.push(Hn(e,Qn,!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(Hn(n,"/"==n.charAt(0)?Yn:Wn,!0))),(n=this.i.toString())&&t.push("?",n),(n=this.o)&&t.push("#",Hn(n,Jn)),t.join("")};var Qn=/[#\/\?@]/g,Wn=/[#\?:]/g,Yn=/[#\?]/g,Xn=/[#\?@]/g,Jn=/#/g;function Zn(t,e){this.h=this.g=null,this.i=t||null,this.j=!!e}function ts(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 es(t,e){ts(t),e=rs(t,e),t.g.has(e)&&(t.i=null,t.h-=t.g.get(e).length,t.g.delete(e))}function ns(t,e){return ts(t),e=rs(t,e),t.g.has(e)}function ss(t,e,n){es(t,e),0<n.length&&(t.i=null,t.g.set(rs(t,e),Mt(n)),t.h+=n.length)}function rs(t,e){return e=String(e),t.j&&(e=e.toLowerCase()),e}(wt=Zn.prototype).add=function(t,e){ts(this),this.i=null,t=rs(this,t);var n=this.g.get(t);return n||this.g.set(t,n=[]),n.push(e),this.h+=1,this},wt.forEach=function(t,e){ts(this),this.g.forEach((function(n,s){n.forEach((function(n){t.call(e,n,s,this)}),this)}),this)},wt.ta=function(){ts(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},wt.Z=function(t){ts(this);let e=[];if("string"==typeof t)ns(this,t)&&(e=e.concat(this.g.get(rs(this,t))));else{t=Array.from(this.g.values());for(let n=0;n<t.length;n++)e=e.concat(t[n])}return e},wt.set=function(t,e){return ts(this),this.i=null,ns(this,t=rs(this,t))&&(this.h-=this.g.get(t).length),this.g.set(t,[e]),this.h+=1,this},wt.get=function(t,e){return t&&0<(t=this.Z(t)).length?String(t[0]):e},wt.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.Z(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("&")};var is=class{constructor(t,e){this.g=t,this.map=e}};function os(t){this.l=t||as,It.PerformanceNavigationTiming?t=0<(t=It.performance.getEntriesByType("navigation")).length&&("hq"==t[0].nextHopProtocol||"h2"==t[0].nextHopProtocol):t=!!(It.g&&It.g.Ka&&It.g.Ka()&&It.g.Ka().dc),this.j=t?this.l:1,this.g=null,1<this.j&&(this.g=new Set),this.h=null,this.i=[]}var as=10;function cs(t){return!!t.h||!!t.g&&t.g.size>=t.j}function us(t){return t.h?1:t.g?t.g.size:0}function hs(t,e){return t.h?t.h==e:!!t.g&&t.g.has(e)}function ls(t,e){t.g?t.g.add(e):t.h=e}function ds(t,e){t.h&&t.h==e?t.h=null:t.g&&t.g.has(e)&&t.g.delete(e)}function fs(t){if(null!=t.h)return t.i.concat(t.h.F);if(null!=t.g&&0!==t.g.size){let e=t.i;for(const n of t.g.values())e=e.concat(n.F);return e}return Mt(t.i)}os.prototype.cancel=function(){if(this.i=fs(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()}};var gs=class{stringify(t){return It.JSON.stringify(t,void 0)}parse(t){return It.JSON.parse(t,void 0)}};function ms(){this.g=new gs}function ps(t,e,n){const s=n||"";try{Pn(t,(function(t,n){let r=t;St(t)&&(r=Le(t)),e.push(s+n+"="+encodeURIComponent(r))}))}catch(t){throw e.push(s+"type="+encodeURIComponent("_badmap")),t}}function ys(t,e,n,s,r){try{e.onload=null,e.onerror=null,e.onabort=null,e.ontimeout=null,r(s)}catch(t){}}function vs(t){this.l=t.ec||null,this.j=t.ob||!1}function ws(t,e){ke.call(this),this.F=t,this.u=e,this.m=void 0,this.readyState=Es,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}Lt(vs,dn),vs.prototype.g=function(){return new ws(this.l,this.j)},vs.prototype.i=function(t){return function(){return t}}({}),Lt(ws,ke);var Es=0;function _s(t){t.j.read().then(t.Xa.bind(t)).catch(t.ka.bind(t))}function bs(t){t.readyState=4,t.l=null,t.j=null,t.A=null,Is(t)}function Is(t){t.onreadystatechange&&t.onreadystatechange.call(t)}(wt=ws.prototype).open=function(t,e){if(this.readyState!=Es)throw this.abort(),Error("Error reopening a connection");this.C=t,this.B=e,this.readyState=1,Is(this)},wt.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.F||It).fetch(new Request(this.B,e)).then(this.$a.bind(this),this.ka.bind(this))},wt.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,bs(this)),this.readyState=Es},wt.$a=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,Is(this)),this.g&&(this.readyState=3,Is(this),this.g)))if("arraybuffer"===this.responseType)t.arrayBuffer().then(this.Ya.bind(this),this.ka.bind(this));else if(void 0!==It.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;_s(this)}else t.text().then(this.Za.bind(this),this.ka.bind(this))},wt.Xa=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?bs(this):Is(this),3==this.readyState&&_s(this)}},wt.Za=function(t){this.g&&(this.response=this.responseText=t,bs(this))},wt.Ya=function(t){this.g&&(this.response=t,bs(this))},wt.ka=function(){this.g&&bs(this)},wt.setRequestHeader=function(t,e){this.v.append(t,e)},wt.getResponseHeader=function(t){return this.h&&this.h.get(t.toLowerCase())||""},wt.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(ws.prototype,"withCredentials",{get:function(){return"include"===this.m},set:function(t){this.m=t?"include":"same-origin"}});var Ts=It.JSON.parse;function Ss(t){ke.call(this),this.headers=new Map,this.u=t||null,this.h=!1,this.C=this.g=null,this.I="",this.m=0,this.j="",this.l=this.G=this.v=this.F=!1,this.B=0,this.A=null,this.K=Cs,this.L=this.M=!1}Lt(Ss,ke);var Cs="",As=/^https?$/i,Ds=["POST","PUT"];function ks(t,e){t.h=!1,t.g&&(t.l=!0,t.g.abort(),t.l=!1),t.j=e,t.m=5,Ns(t),Ls(t)}function Ns(t){t.F||(t.F=!0,Ne(t,"complete"),Ne(t,"error"))}function Rs(t){if(t.h&&void 0!==bt&&(!t.C[1]||4!=Os(t)||2!=t.da()))if(t.v&&4==Os(t))Ke(t.La,0,t);else if(Ne(t,"readystatechange"),4==Os(t)){t.h=!1;try{const o=t.da();t:switch(o){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===o){var r=String(t.I).match(Fn)[1]||null;!r&&It.self&&It.self.location&&(r=It.self.location.protocol.slice(0,-1)),s=!As.test(r?r.toLowerCase():"")}n=s}if(n)Ne(t,"complete"),Ne(t,"success");else{t.m=6;try{var i=2<Os(t)?t.g.statusText:""}catch(t){i=""}t.j=i+" ["+t.da()+"]",Ns(t)}}finally{Ls(t)}}}function Ls(t,e){if(t.g){xs(t);const n=t.g,s=t.C[0]?()=>{}:null;t.g=null,t.C=null,e||Ne(t,"ready");try{n.onreadystatechange=s}catch(t){}}}function xs(t){t.g&&t.L&&(t.g.ontimeout=null),t.A&&(It.clearTimeout(t.A),t.A=null)}function Os(t){return t.g?t.g.readyState:0}function Ms(t){try{if(!t.g)return null;if("response"in t.g)return t.g.response;switch(t.K){case Cs:case"text":return t.g.responseText;case"arraybuffer":if("mozResponseArrayBuffer"in t.g)return t.g.mozResponseArrayBuffer}return null}catch(t){return null}}function Ps(t){let e="";return he(t,(function(t,n){e+=n,e+=":",e+=t,e+="\r\n"})),e}function Fs(t,e,n){t:{for(s in n){var s=!1;break t}s=!0}s||(n=Ps(n),"string"==typeof t?null!=n&&encodeURIComponent(String(n)):$n(t,e,n))}function Bs(t,e,n){return n&&n.internalChannelParams&&n.internalChannelParams[t]||e}function Vs(t){this.Ga=0,this.j=[],this.l=new Je,this.pa=this.wa=this.I=this.Y=this.g=this.Da=this.F=this.na=this.o=this.U=this.s=null,this.fb=this.W=0,this.cb=Bs("failFast",!1,t),this.G=this.v=this.u=this.m=this.h=null,this.aa=!0,this.Fa=this.V=-1,this.ba=this.A=this.C=0,this.ab=Bs("baseRetryDelayMs",5e3,t),this.hb=Bs("retryDelaySeedMs",1e4,t),this.eb=Bs("forwardChannelMaxRetries",2,t),this.xa=Bs("forwardChannelRequestTimeoutMs",2e4,t),this.va=t&&t.xmlHttpFactory||void 0,this.Ha=t&&t.useFetchStreams||!1,this.L=void 0,this.J=t&&t.supportsCrossDomainXhr||!1,this.K="",this.i=new os(t&&t.concurrentRequestLimit),this.Ja=new ms,this.P=t&&t.fastHandshake||!1,this.O=t&&t.encodeInitMessageHeaders||!1,this.P&&this.O&&(this.O=!1),this.bb=t&&t.bc||!1,t&&t.Ea&&this.l.Ea(),t&&t.forceLongPolling&&(this.aa=!1),this.ca=!this.P&&this.aa&&t&&t.detectBufferingProxy||!1,this.qa=void 0,t&&t.longPollingTimeout&&0<t.longPollingTimeout&&(this.qa=t.longPollingTimeout),this.oa=void 0,this.S=0,this.M=!1,this.ma=this.B=null}function Us(t){if(js(t),3==t.H){var e=t.W++,n=Vn(t.I);if($n(n,"SID",t.K),$n(n,"RID",e),$n(n,"TYPE","terminate"),Ks(t,n),(e=new En(t,t.l,e)).L=2,e.v=zn(Vn(n)),n=!1,It.navigator&&It.navigator.sendBeacon)try{n=It.navigator.sendBeacon(e.v.toString(),"")}catch(t){}!n&&It.Image&&((new Image).src=e.v,n=!0),n||(e.g=sr(e.l,null),e.g.ha(e.v)),e.G=Date.now(),Nn(e)}er(t)}function qs(t){t.g&&(Ws(t),t.g.cancel(),t.g=null)}function js(t){qs(t),t.u&&(It.clearTimeout(t.u),t.u=null),Xs(t),t.i.cancel(),t.m&&("number"==typeof t.m&&It.clearTimeout(t.m),t.m=null)}function $s(t){if(!cs(t.i)&&!t.m){t.m=!0;var e=t.Na;Be||qe(),Ve||(Be(),Ve=!0),Ue.add(e,t),t.C=0}}function zs(t,e){var n;n=e?e.m:t.W++;const s=Vn(t.I);$n(s,"SID",t.K),$n(s,"RID",n),$n(s,"AID",t.V),Ks(t,s),t.o&&t.s&&Fs(s,t.o,t.s),n=new En(t,t.l,n,t.C+1),null===t.o&&(n.I=t.s),e&&(t.j=e.F.concat(t.j)),e=Hs(t,n,1e3),n.setTimeout(Math.round(.5*t.xa)+Math.round(.5*t.xa*Math.random())),ls(t.i,n),Sn(n,s,e)}function Ks(t,e){t.na&&he(t.na,(function(t,n){$n(e,n,t)})),t.h&&Pn({},(function(t,n){$n(e,n,t)}))}function Hs(t,e,n){n=Math.min(t.j.length,n);var s=t.h?Nt(t.h.Va,t.h,t):null;t:{var r=t.j;let e=-1;for(;;){const t=["count="+n];-1==e?0<n?(e=r[0].g,t.push("ofs="+e)):e=0:t.push("ofs="+e);let i=!0;for(let o=0;o<n;o++){let n=r[o].g;const a=r[o].map;if(n-=e,0>n)e=Math.max(0,r[o].g-100),i=!1;else try{ps(a,t,"req"+n+"_")}catch(t){s&&s(a)}}if(i){s=t.join("&");break t}}}return t=t.j.splice(0,n),e.F=t,s}function Gs(t){if(!t.g&&!t.u){t.ba=1;var e=t.Ma;Be||qe(),Ve||(Be(),Ve=!0),Ue.add(e,t),t.A=0}}function Qs(t){return!(t.g||t.u||3<=t.A)&&(t.ba++,t.u=un(Nt(t.Ma,t),Zs(t,t.A)),t.A++,!0)}function Ws(t){null!=t.B&&(It.clearTimeout(t.B),t.B=null)}function Ys(t){t.g=new En(t,t.l,"rpc",t.ba),null===t.o&&(t.g.I=t.s),t.g.O=0;var e=Vn(t.wa);$n(e,"RID","rpc"),$n(e,"SID",t.K),$n(e,"AID",t.V),$n(e,"CI",t.G?"0":"1"),!t.G&&t.qa&&$n(e,"TO",t.qa),$n(e,"TYPE","xmlhttp"),Ks(t,e),t.o&&t.s&&Fs(e,t.o,t.s),t.L&&t.g.setTimeout(t.L);var n=t.g;t=t.pa,n.L=1,n.v=zn(Vn(e)),n.s=null,n.S=!0,Cn(n,t)}function Xs(t){null!=t.v&&(It.clearTimeout(t.v),t.v=null)}function Js(t,e){var n=null;if(t.g==e){Xs(t),Ws(t),t.g=null;var s=2}else{if(!hs(t.i,e))return;n=e.F,ds(t.i,e),s=1}if(0!=t.H)if(e.i)if(1==s){n=e.s?e.s.length:0,e=Date.now()-e.G;var r=t.C;Ne(s=nn(),new cn(s,n)),$s(t)}else Gs(t);else if(3==(r=e.o)||0==r&&0<e.ca||!(1==s&&function(t,e){return!(us(t.i)>=t.i.j-(t.m?1:0)||(t.m?(t.j=e.F.concat(t.j),0):1==t.H||2==t.H||t.C>=(t.cb?0:t.eb)||(t.m=un(Nt(t.Na,t,e),Zs(t,t.C)),t.C++,0)))}(t,e)||2==s&&Qs(t)))switch(n&&0<n.length&&(e=t.i,e.i=e.i.concat(n)),r){case 1:tr(t,5);break;case 4:tr(t,10);break;case 3:tr(t,6);break;default:tr(t,2)}}function Zs(t,e){let n=t.ab+Math.floor(Math.random()*t.hb);return t.isActive()||(n*=2),n*e}function tr(t,e){if(t.l.info("Error code "+e),2==e){var n=null;t.h&&(n=null);var s=Nt(t.pb,t);n||(n=new Bn("//www.google.com/images/cleardot.gif"),It.location&&"http"==It.location.protocol||Un(n,"https"),zn(n)),function(t,e){const n=new Je;if(It.Image){const s=new Image;s.onload=Rt(ys,n,s,"TestLoadImage: loaded",!0,e),s.onerror=Rt(ys,n,s,"TestLoadImage: error",!1,e),s.onabort=Rt(ys,n,s,"TestLoadImage: abort",!1,e),s.ontimeout=Rt(ys,n,s,"TestLoadImage: timeout",!1,e),It.setTimeout((function(){s.ontimeout&&s.ontimeout()}),1e4),s.src=t}else e(!1)}(n.toString(),s)}else an(2);t.H=0,t.h&&t.h.za(e),er(t),js(t)}function er(t){if(t.H=0,t.ma=[],t.h){const e=fs(t.i);0==e.length&&0==t.j.length||(Pt(t.ma,e),Pt(t.ma,t.j),t.i.i.length=0,Mt(t.j),t.j.length=0),t.h.ya()}}function nr(t,e,n){var s=n instanceof Bn?Vn(n):new Bn(n);if(""!=s.g)e&&(s.g=e+"."+s.g),qn(s,s.m);else{var r=It.location;s=r.protocol,e=e?e+"."+r.hostname:r.hostname,r=+r.port;var i=new Bn(null);s&&Un(i,s),e&&(i.g=e),r&&qn(i,r),n&&(i.l=n),s=i}return n=t.F,e=t.Da,n&&e&&$n(s,n,e),$n(s,"VER",t.ra),Ks(t,s),s}function sr(t,e,n){if(e&&!t.J)throw Error("Can't create secondary domain capable XhrIo object.");return(e=n&&t.Ha&&!t.va?new Ss(new vs({ob:!0})):new Ss(t.va)).Oa(t.J),e}function rr(){}function ir(){if(Gt&&!(10<=Number(se)))throw Error("Environmental error: no available transport.")}function or(t,e){ke.call(this),this.g=new Vs(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.Ca&&(t?t["X-WebChannel-Client-Profile"]=e.Ca:t={"X-WebChannel-Client-Profile":e.Ca}),this.g.U=t,(t=e&&e.cc)&&!Vt(t)&&(this.g.o=t),this.A=e&&e.supportsCrossDomainXhr||!1,this.v=e&&e.sendRawJson||!1,(e=e&&e.httpSessionIdParam)&&!Vt(e)&&(this.g.F=e,null!==(t=this.h)&&e in t&&(e in(t=this.h)&&delete t[e])),this.j=new ur(this)}function ar(t){yn.call(this),t.__headers__&&(this.headers=t.__headers__,this.statusCode=t.__status__,delete t.__headers__,delete t.__status__);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 cr(){vn.call(this),this.status=1}function ur(t){this.g=t}function hr(){this.blockSize=-1,this.blockSize=64,this.g=Array(4),this.m=Array(this.blockSize),this.i=this.h=0,this.reset()}function lr(t,e,n){n||(n=0);var s=Array(16);if("string"==typeof e)for(var r=0;16>r;++r)s[r]=e.charCodeAt(n++)|e.charCodeAt(n++)<<8|e.charCodeAt(n++)<<16|e.charCodeAt(n++)<<24;else for(r=0;16>r;++r)s[r]=e[n++]|e[n++]<<8|e[n++]<<16|e[n++]<<24;e=t.g[0],n=t.g[1],r=t.g[2];var i=t.g[3],o=e+(i^n&(r^i))+s[0]+3614090360&4294967295;o=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=(n=(r=(i=(e=n+(o<<7&4294967295|o>>>25))+((o=i+(r^e&(n^r))+s[1]+3905402710&4294967295)<<12&4294967295|o>>>20))+((o=r+(n^i&(e^n))+s[2]+606105819&4294967295)<<17&4294967295|o>>>15))+((o=n+(e^r&(i^e))+s[3]+3250441966&4294967295)<<22&4294967295|o>>>10))+((o=e+(i^n&(r^i))+s[4]+4118548399&4294967295)<<7&4294967295|o>>>25))+((o=i+(r^e&(n^r))+s[5]+1200080426&4294967295)<<12&4294967295|o>>>20))+((o=r+(n^i&(e^n))+s[6]+2821735955&4294967295)<<17&4294967295|o>>>15))+((o=n+(e^r&(i^e))+s[7]+4249261313&4294967295)<<22&4294967295|o>>>10))+((o=e+(i^n&(r^i))+s[8]+1770035416&4294967295)<<7&4294967295|o>>>25))+((o=i+(r^e&(n^r))+s[9]+2336552879&4294967295)<<12&4294967295|o>>>20))+((o=r+(n^i&(e^n))+s[10]+4294925233&4294967295)<<17&4294967295|o>>>15))+((o=n+(e^r&(i^e))+s[11]+2304563134&4294967295)<<22&4294967295|o>>>10))+((o=e+(i^n&(r^i))+s[12]+1804603682&4294967295)<<7&4294967295|o>>>25))+((o=i+(r^e&(n^r))+s[13]+4254626195&4294967295)<<12&4294967295|o>>>20))+((o=r+(n^i&(e^n))+s[14]+2792965006&4294967295)<<17&4294967295|o>>>15))+((o=n+(e^r&(i^e))+s[15]+1236535329&4294967295)<<22&4294967295|o>>>10))+((o=e+(r^i&(n^r))+s[1]+4129170786&4294967295)<<5&4294967295|o>>>27))+((o=i+(n^r&(e^n))+s[6]+3225465664&4294967295)<<9&4294967295|o>>>23))+((o=r+(e^n&(i^e))+s[11]+643717713&4294967295)<<14&4294967295|o>>>18))+((o=n+(i^e&(r^i))+s[0]+3921069994&4294967295)<<20&4294967295|o>>>12))+((o=e+(r^i&(n^r))+s[5]+3593408605&4294967295)<<5&4294967295|o>>>27))+((o=i+(n^r&(e^n))+s[10]+38016083&4294967295)<<9&4294967295|o>>>23))+((o=r+(e^n&(i^e))+s[15]+3634488961&4294967295)<<14&4294967295|o>>>18))+((o=n+(i^e&(r^i))+s[4]+3889429448&4294967295)<<20&4294967295|o>>>12))+((o=e+(r^i&(n^r))+s[9]+568446438&4294967295)<<5&4294967295|o>>>27))+((o=i+(n^r&(e^n))+s[14]+3275163606&4294967295)<<9&4294967295|o>>>23))+((o=r+(e^n&(i^e))+s[3]+4107603335&4294967295)<<14&4294967295|o>>>18))+((o=n+(i^e&(r^i))+s[8]+1163531501&4294967295)<<20&4294967295|o>>>12))+((o=e+(r^i&(n^r))+s[13]+2850285829&4294967295)<<5&4294967295|o>>>27))+((o=i+(n^r&(e^n))+s[2]+4243563512&4294967295)<<9&4294967295|o>>>23))+((o=r+(e^n&(i^e))+s[7]+1735328473&4294967295)<<14&4294967295|o>>>18))+((o=n+(i^e&(r^i))+s[12]+2368359562&4294967295)<<20&4294967295|o>>>12))+((o=e+(n^r^i)+s[5]+4294588738&4294967295)<<4&4294967295|o>>>28))+((o=i+(e^n^r)+s[8]+2272392833&4294967295)<<11&4294967295|o>>>21))+((o=r+(i^e^n)+s[11]+1839030562&4294967295)<<16&4294967295|o>>>16))+((o=n+(r^i^e)+s[14]+4259657740&4294967295)<<23&4294967295|o>>>9))+((o=e+(n^r^i)+s[1]+2763975236&4294967295)<<4&4294967295|o>>>28))+((o=i+(e^n^r)+s[4]+1272893353&4294967295)<<11&4294967295|o>>>21))+((o=r+(i^e^n)+s[7]+4139469664&4294967295)<<16&4294967295|o>>>16))+((o=n+(r^i^e)+s[10]+3200236656&4294967295)<<23&4294967295|o>>>9))+((o=e+(n^r^i)+s[13]+681279174&4294967295)<<4&4294967295|o>>>28))+((o=i+(e^n^r)+s[0]+3936430074&4294967295)<<11&4294967295|o>>>21))+((o=r+(i^e^n)+s[3]+3572445317&4294967295)<<16&4294967295|o>>>16))+((o=n+(r^i^e)+s[6]+76029189&4294967295)<<23&4294967295|o>>>9))+((o=e+(n^r^i)+s[9]+3654602809&4294967295)<<4&4294967295|o>>>28))+((o=i+(e^n^r)+s[12]+3873151461&4294967295)<<11&4294967295|o>>>21))+((o=r+(i^e^n)+s[15]+530742520&4294967295)<<16&4294967295|o>>>16))+((o=n+(r^i^e)+s[2]+3299628645&4294967295)<<23&4294967295|o>>>9))+((o=e+(r^(n|~i))+s[0]+4096336452&4294967295)<<6&4294967295|o>>>26))+((o=i+(n^(e|~r))+s[7]+1126891415&4294967295)<<10&4294967295|o>>>22))+((o=r+(e^(i|~n))+s[14]+2878612391&4294967295)<<15&4294967295|o>>>17))+((o=n+(i^(r|~e))+s[5]+4237533241&4294967295)<<21&4294967295|o>>>11))+((o=e+(r^(n|~i))+s[12]+1700485571&4294967295)<<6&4294967295|o>>>26))+((o=i+(n^(e|~r))+s[3]+2399980690&4294967295)<<10&4294967295|o>>>22))+((o=r+(e^(i|~n))+s[10]+4293915773&4294967295)<<15&4294967295|o>>>17))+((o=n+(i^(r|~e))+s[1]+2240044497&4294967295)<<21&4294967295|o>>>11))+((o=e+(r^(n|~i))+s[8]+1873313359&4294967295)<<6&4294967295|o>>>26))+((o=i+(n^(e|~r))+s[15]+4264355552&4294967295)<<10&4294967295|o>>>22))+((o=r+(e^(i|~n))+s[6]+2734768916&4294967295)<<15&4294967295|o>>>17))+((o=n+(i^(r|~e))+s[13]+1309151649&4294967295)<<21&4294967295|o>>>11))+((i=(e=n+((o=e+(r^(n|~i))+s[4]+4149444226&4294967295)<<6&4294967295|o>>>26))+((o=i+(n^(e|~r))+s[11]+3174756917&4294967295)<<10&4294967295|o>>>22))^((r=i+((o=r+(e^(i|~n))+s[2]+718787259&4294967295)<<15&4294967295|o>>>17))|~e))+s[9]+3951481745&4294967295,t.g[0]=t.g[0]+e&4294967295,t.g[1]=t.g[1]+(r+(o<<21&4294967295|o>>>11))&4294967295,t.g[2]=t.g[2]+r&4294967295,t.g[3]=t.g[3]+i&4294967295}function dr(t,e){this.h=e;for(var n=[],s=!0,r=t.length-1;0<=r;r--){var i=0|t[r];s&&i==e||(n[r]=i,s=!1)}this.g=n}(wt=Ss.prototype).Oa=function(t){this.M=t},wt.ha=function(t,e,n,s){if(this.g)throw Error("[goog.net.XhrIo] Object is active with another request="+this.I+"; newUri="+t);e=e?e.toUpperCase():"GET",this.I=t,this.j="",this.m=0,this.F=!1,this.h=!0,this.g=this.u?this.u.g():mn.g(),this.C=this.u?fn(this.u):fn(mn),this.g.onreadystatechange=Nt(this.La,this);try{this.G=!0,this.g.open(e,String(t),!0),this.G=!1}catch(t){return void ks(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=It.FormData&&t instanceof It.FormData,!(0<=Ot(Ds,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.K&&(this.g.responseType=this.K),"withCredentials"in this.g&&this.g.withCredentials!==this.M&&(this.g.withCredentials=this.M);try{xs(this),0<this.B&&((this.L=function(t){return Gt&&"number"==typeof t.timeout&&void 0!==t.ontimeout}(this.g))?(this.g.timeout=this.B,this.g.ontimeout=Nt(this.ua,this)):this.A=Ke(this.ua,this.B,this)),this.v=!0,this.g.send(t),this.v=!1}catch(t){ks(this,t)}},wt.ua=function(){void 0!==bt&&this.g&&(this.j="Timed out after "+this.B+"ms, aborting",this.m=8,Ne(this,"timeout"),this.abort(8))},wt.abort=function(t){this.g&&this.h&&(this.h=!1,this.l=!0,this.g.abort(),this.l=!1,this.m=t||7,Ne(this,"complete"),Ne(this,"abort"),Ls(this))},wt.N=function(){this.g&&(this.h&&(this.h=!1,this.l=!0,this.g.abort(),this.l=!1),Ls(this,!0)),Ss.$.N.call(this)},wt.La=function(){this.s||(this.G||this.v||this.l?Rs(this):this.kb())},wt.kb=function(){Rs(this)},wt.isActive=function(){return!!this.g},wt.da=function(){try{return 2<Os(this)?this.g.status:-1}catch(t){return-1}},wt.ja=function(){try{return this.g?this.g.responseText:""}catch(t){return""}},wt.Wa=function(t){if(this.g){var e=this.g.responseText;return t&&0==e.indexOf(t)&&(e=e.substring(t.length)),Ts(e)}},wt.Ia=function(){return this.m},wt.Sa=function(){return"string"==typeof this.j?this.j:String(this.j)},(wt=Vs.prototype).ra=8,wt.H=1,wt.Na=function(t){if(this.m)if(this.m=null,1==this.H){if(!t){this.W=Math.floor(1e5*Math.random()),t=this.W++;const r=new En(this,this.l,t);let i=this.s;if(this.U&&(i?(i=le(i),fe(i,this.U)):i=this.U),null!==this.o||this.O||(r.I=i,i=null),this.P)t:{for(var e=0,n=0;n<this.j.length;n++){var s=this.j[n];if(void 0===(s="__data__"in s.map&&"string"==typeof(s=s.map.__data__)?s.length:void 0))break;if(4096<(e+=s)){e=n;break t}if(4096===e||n===this.j.length-1){e=n+1;break t}}e=1e3}else e=1e3;e=Hs(this,r,e),$n(n=Vn(this.I),"RID",t),$n(n,"CVER",22),this.F&&$n(n,"X-HTTP-Session-Id",this.F),Ks(this,n),i&&(this.O?e="headers="+encodeURIComponent(String(Ps(i)))+"&"+e:this.o&&Fs(n,this.o,i)),ls(this.i,r),this.bb&&$n(n,"TYPE","init"),this.P?($n(n,"$req",e),$n(n,"SID","null"),r.aa=!0,Sn(r,n,null)):Sn(r,n,e),this.H=2}}else 3==this.H&&(t?zs(this,t):0==this.j.length||cs(this.i)||zs(this))},wt.Ma=function(){if(this.u=null,Ys(this),this.ca&&!(this.M||null==this.g||0>=this.S)){var t=2*this.S;this.l.info("BP detection timer enabled: "+t),this.B=un(Nt(this.jb,this),t)}},wt.jb=function(){this.B&&(this.B=null,this.l.info("BP detection timeout reached."),this.l.info("Buffering proxy detected and switch to long-polling!"),this.G=!1,this.M=!0,an(10),qs(this),Ys(this))},wt.ib=function(){null!=this.v&&(this.v=null,qs(this),Qs(this),an(19))},wt.pb=function(t){t?(this.l.info("Successfully pinged google.com"),an(2)):(this.l.info("Failed to ping google.com"),an(1))},wt.isActive=function(){return!!this.h&&this.h.isActive(this)},(wt=rr.prototype).Ba=function(){},wt.Aa=function(){},wt.za=function(){},wt.ya=function(){},wt.isActive=function(){return!0},wt.Va=function(){},ir.prototype.g=function(t,e){return new or(t,e)},Lt(or,ke),or.prototype.m=function(){this.g.h=this.j,this.A&&(this.g.J=!0);var t=this.g,e=this.l,n=this.h||void 0;an(0),t.Y=e,t.na=n||{},t.G=t.aa,t.I=nr(t,null,t.Y),$s(t)},or.prototype.close=function(){Us(this.g)},or.prototype.u=function(t){var e=this.g;if("string"==typeof t){var n={};n.__data__=t,t=n}else this.v&&((n={}).__data__=Le(t),t=n);e.j.push(new is(e.fb++,t)),3==e.H&&$s(e)},or.prototype.N=function(){this.g.h=null,delete this.j,Us(this.g),delete this.g,or.$.N.call(this)},Lt(ar,yn),Lt(cr,vn),Lt(ur,rr),ur.prototype.Ba=function(){Ne(this.g,"a")},ur.prototype.Aa=function(t){Ne(this.g,new ar(t))},ur.prototype.za=function(t){Ne(this.g,new cr)},ur.prototype.ya=function(){Ne(this.g,"b")},Lt(hr,(function(){this.blockSize=-1})),hr.prototype.reset=function(){this.g[0]=1732584193,this.g[1]=4023233417,this.g[2]=2562383102,this.g[3]=271733878,this.i=this.h=0},hr.prototype.j=function(t,e){void 0===e&&(e=t.length);for(var n=e-this.blockSize,s=this.m,r=this.h,i=0;i<e;){if(0==r)for(;i<=n;)lr(this,t,i),i+=this.blockSize;if("string"==typeof t){for(;i<e;)if(s[r++]=t.charCodeAt(i++),r==this.blockSize){lr(this,s),r=0;break}}else for(;i<e;)if(s[r++]=t[i++],r==this.blockSize){lr(this,s),r=0;break}}this.h=r,this.i+=e},hr.prototype.l=function(){var t=Array((56>this.h?this.blockSize:2*this.blockSize)-this.h);t[0]=128;for(var e=1;e<t.length-8;++e)t[e]=0;var n=8*this.i;for(e=t.length-8;e<t.length;++e)t[e]=255&n,n/=256;for(this.j(t),t=Array(16),e=n=0;4>e;++e)for(var s=0;32>s;s+=8)t[n++]=this.g[e]>>>s&255;return t};var fr={};function gr(t){return-128<=t&&128>t?function(t,e){var n=fr;return Object.prototype.hasOwnProperty.call(n,t)?n[t]:n[t]=e(t)}(t,(function(t){return new dr([0|t],0>t?-1:0)})):new dr([0|t],0>t?-1:0)}function mr(t){if(isNaN(t)||!isFinite(t))return yr;if(0>t)return br(mr(-t));for(var e=[],n=1,s=0;t>=n;s++)e[s]=t/n|0,n*=pr;return new dr(e,0)}var pr=4294967296,yr=gr(0),vr=gr(1),wr=gr(16777216);function Er(t){if(0!=t.h)return!1;for(var e=0;e<t.g.length;e++)if(0!=t.g[e])return!1;return!0}function _r(t){return-1==t.h}function br(t){for(var e=t.g.length,n=[],s=0;s<e;s++)n[s]=~t.g[s];return new dr(n,~t.h).add(vr)}function Ir(t,e){return t.add(br(e))}function Tr(t,e){for(;(65535&t[e])!=t[e];)t[e+1]+=t[e]>>>16,t[e]&=65535,e++}function Sr(t,e){this.g=t,this.h=e}function Cr(t,e){if(Er(e))throw Error("division by zero");if(Er(t))return new Sr(yr,yr);if(_r(t))return e=Cr(br(t),e),new Sr(br(e.g),br(e.h));if(_r(e))return e=Cr(t,br(e)),new Sr(br(e.g),e.h);if(30<t.g.length){if(_r(t)||_r(e))throw Error("slowDivide_ only works with positive integers.");for(var n=vr,s=e;0>=s.X(t);)n=Ar(n),s=Ar(s);var r=Dr(n,1),i=Dr(s,1);for(s=Dr(s,2),n=Dr(n,2);!Er(s);){var o=i.add(s);0>=o.X(t)&&(r=r.add(n),i=o),s=Dr(s,1),n=Dr(n,1)}return e=Ir(t,r.R(e)),new Sr(r,e)}for(r=yr;0<=t.X(e);){for(n=Math.max(1,Math.floor(t.ea()/e.ea())),s=48>=(s=Math.ceil(Math.log(n)/Math.LN2))?1:Math.pow(2,s-48),o=(i=mr(n)).R(e);_r(o)||0<o.X(t);)o=(i=mr(n-=s)).R(e);Er(i)&&(i=vr),r=r.add(i),t=Ir(t,o)}return new Sr(r,t)}function Ar(t){for(var e=t.g.length+1,n=[],s=0;s<e;s++)n[s]=t.D(s)<<1|t.D(s-1)>>>31;return new dr(n,t.h)}function Dr(t,e){var n=e>>5;e%=32;for(var s=t.g.length-n,r=[],i=0;i<s;i++)r[i]=0<e?t.D(i+n)>>>e|t.D(i+n+1)<<32-e:t.D(i+n);return new dr(r,t.h)}(wt=dr.prototype).ea=function(){if(_r(this))return-br(this).ea();for(var t=0,e=1,n=0;n<this.g.length;n++){var s=this.D(n);t+=(0<=s?s:pr+s)*e,e*=pr}return t},wt.toString=function(t){if(2>(t=t||10)||36<t)throw Error("radix out of range: "+t);if(Er(this))return"0";if(_r(this))return"-"+br(this).toString(t);for(var e=mr(Math.pow(t,6)),n=this,s="";;){var r=Cr(n,e).g,i=((0<(n=Ir(n,r.R(e))).g.length?n.g[0]:n.h)>>>0).toString(t);if(Er(n=r))return i+s;for(;6>i.length;)i="0"+i;s=i+s}},wt.D=function(t){return 0>t?0:t<this.g.length?this.g[t]:this.h},wt.X=function(t){return _r(t=Ir(this,t))?-1:Er(t)?0:1},wt.abs=function(){return _r(this)?br(this):this},wt.add=function(t){for(var e=Math.max(this.g.length,t.g.length),n=[],s=0,r=0;r<=e;r++){var i=s+(65535&this.D(r))+(65535&t.D(r)),o=(i>>>16)+(this.D(r)>>>16)+(t.D(r)>>>16);s=o>>>16,i&=65535,o&=65535,n[r]=o<<16|i}return new dr(n,-2147483648&n[n.length-1]?-1:0)},wt.R=function(t){if(Er(this)||Er(t))return yr;if(_r(this))return _r(t)?br(this).R(br(t)):br(br(this).R(t));if(_r(t))return br(this.R(br(t)));if(0>this.X(wr)&&0>t.X(wr))return mr(this.ea()*t.ea());for(var e=this.g.length+t.g.length,n=[],s=0;s<2*e;s++)n[s]=0;for(s=0;s<this.g.length;s++)for(var r=0;r<t.g.length;r++){var i=this.D(s)>>>16,o=65535&this.D(s),a=t.D(r)>>>16,c=65535&t.D(r);n[2*s+2*r]+=o*c,Tr(n,2*s+2*r),n[2*s+2*r+1]+=i*c,Tr(n,2*s+2*r+1),n[2*s+2*r+1]+=o*a,Tr(n,2*s+2*r+1),n[2*s+2*r+2]+=i*a,Tr(n,2*s+2*r+2)}for(s=0;s<e;s++)n[s]=n[2*s+1]<<16|n[2*s];for(s=e;s<2*e;s++)n[s]=0;return new dr(n,0)},wt.gb=function(t){return Cr(this,t).h},wt.and=function(t){for(var e=Math.max(this.g.length,t.g.length),n=[],s=0;s<e;s++)n[s]=this.D(s)&t.D(s);return new dr(n,this.h&t.h)},wt.or=function(t){for(var e=Math.max(this.g.length,t.g.length),n=[],s=0;s<e;s++)n[s]=this.D(s)|t.D(s);return new dr(n,this.h|t.h)},wt.xor=function(t){for(var e=Math.max(this.g.length,t.g.length),n=[],s=0;s<e;s++)n[s]=this.D(s)^t.D(s);return new dr(n,this.h^t.h)},ir.prototype.createWebChannel=ir.prototype.g,or.prototype.send=or.prototype.u,or.prototype.open=or.prototype.m,or.prototype.close=or.prototype.close,hn.NO_ERROR=0,hn.TIMEOUT=8,hn.HTTP_ERROR=6,ln.COMPLETE="complete",gn.EventType=pn,pn.OPEN="a",pn.CLOSE="b",pn.ERROR="c",pn.MESSAGE="d",ke.prototype.listen=ke.prototype.O,Ss.prototype.listenOnce=Ss.prototype.P,Ss.prototype.getLastError=Ss.prototype.Sa,Ss.prototype.getLastErrorCode=Ss.prototype.Ia,Ss.prototype.getStatus=Ss.prototype.da,Ss.prototype.getResponseJson=Ss.prototype.Wa,Ss.prototype.getResponseText=Ss.prototype.ja,Ss.prototype.send=Ss.prototype.ha,Ss.prototype.setWithCredentials=Ss.prototype.Oa,hr.prototype.digest=hr.prototype.l,hr.prototype.reset=hr.prototype.reset,hr.prototype.update=hr.prototype.j,dr.prototype.add=dr.prototype.add,dr.prototype.multiply=dr.prototype.R,dr.prototype.modulo=dr.prototype.gb,dr.prototype.compare=dr.prototype.X,dr.prototype.toNumber=dr.prototype.ea,dr.prototype.toString=dr.prototype.toString,dr.prototype.getBits=dr.prototype.D,dr.fromNumber=mr,dr.fromString=function t(e,n){if(0==e.length)throw Error("number format error: empty string");if(2>(n=n||10)||36<n)throw Error("radix out of range: "+n);if("-"==e.charAt(0))return br(t(e.substring(1),n));if(0<=e.indexOf("-"))throw Error('number format error: interior "-" character');for(var s=mr(Math.pow(n,8)),r=yr,i=0;i<e.length;i+=8){var o=Math.min(8,e.length-i),a=parseInt(e.substring(i,i+o),n);8>o?(o=mr(Math.pow(n,o)),r=r.R(o).add(mr(a))):r=(r=r.R(s)).add(mr(a))}return r};var kr=_t.createWebChannelTransport=function(){return new ir},Nr=_t.getStatEventTarget=function(){return nn()},Rr=_t.ErrorCode=hn,Lr=_t.EventType=ln,xr=_t.Event=tn,Or=_t.Stat={xb:0,Ab:1,Bb:2,Ub:3,Zb:4,Wb:5,Xb:6,Vb:7,Tb:8,Yb:9,PROXY:10,NOPROXY:11,Rb:12,Nb:13,Ob:14,Mb:15,Pb:16,Qb:17,tb:18,sb:19,ub:20},Mr=(_t.FetchXmlHttpFactory=vs,_t.WebChannel=gn),Pr=_t.XhrIo=Ss,Fr=_t.Md5=hr,Br=_t.Integer=dr;const Vr="@firebase/firestore";class Ur{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}}Ur.UNAUTHENTICATED=new Ur(null),Ur.GOOGLE_CREDENTIALS=new Ur("google-credentials-uid"),Ur.FIRST_PARTY=new Ur("first-party-uid"),Ur.MOCK_USER=new Ur("mock-user");let qr="10.4.0";const jr=new D("@firebase/firestore");function $r(){return jr.logLevel}function zr(t,...e){if(jr.logLevel<=I.DEBUG){const n=e.map(Gr);jr.debug(`Firestore (${qr}): ${t}`,...n)}}function Kr(t,...e){if(jr.logLevel<=I.ERROR){const n=e.map(Gr);jr.error(`Firestore (${qr}): ${t}`,...n)}}function Hr(t,...e){if(jr.logLevel<=I.WARN){const n=e.map(Gr);jr.warn(`Firestore (${qr}): ${t}`,...n)}}function Gr(t){if("string"==typeof t)return t;try{return function(t){return JSON.stringify(t)}(t)}catch(e){return t}}function Qr(t="Unexpected state"){const e=`FIRESTORE (${qr}) INTERNAL ASSERTION FAILED: `+t;throw Kr(e),new Error(e)}function Wr(t,e){t||Qr()}function Yr(t,e){return t}const Xr={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 Jr extends d{constructor(t,e){super(t,e),this.code=t,this.message=e,this.toString=()=>`${this.name}: [code=${this.code}]: ${this.message}`}}class Zr{constructor(){this.promise=new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}}class ti{constructor(t,e){this.user=e,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization",`Bearer ${t}`)}}class ei{getToken(){return Promise.resolve(null)}invalidateToken(){}start(t,e){t.enqueueRetryable((()=>e(Ur.UNAUTHENTICATED)))}shutdown(){}}class ni{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 si{constructor(t){this.t=t,this.currentUser=Ur.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 Zr;this.o=()=>{this.i++,this.currentUser=this.u(),r.resolve(),r=new Zr,t.enqueueRetryable((()=>s(this.currentUser)))};const i=()=>{const e=r;t.enqueueRetryable((async()=>{await e.promise,await s(this.currentUser)}))},o=t=>{zr("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):(zr("FirebaseAuthCredentialsProvider","Auth not yet detected"),r.resolve(),r=new Zr)}}),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?(zr("FirebaseAuthCredentialsProvider","getToken aborted due to token change."),this.getToken()):e?(Wr("string"==typeof e.accessToken),new ti(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 Wr(null===t||"string"==typeof t),new Ur(t)}}class ri{constructor(t,e,n){this.l=t,this.h=e,this.P=n,this.type="FirstParty",this.user=Ur.FIRST_PARTY,this.I=new Map}T(){return this.P?this.P():null}get headers(){this.I.set("X-Goog-AuthUser",this.l);const t=this.T();return t&&this.I.set("Authorization",t),this.h&&this.I.set("X-Goog-Iam-Authorization-Token",this.h),this.I}}class ii{constructor(t,e,n){this.l=t,this.h=e,this.P=n}getToken(){return Promise.resolve(new ri(this.l,this.h,this.P))}start(t,e){t.enqueueRetryable((()=>e(Ur.FIRST_PARTY)))}shutdown(){}invalidateToken(){}}class oi{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 ai{constructor(t){this.A=t,this.forceRefresh=!1,this.appCheck=null,this.R=null}start(t,e){const n=t=>{null!=t.error&&zr("FirebaseAppCheckTokenProvider",`Error getting App Check token; using placeholder token instead. Error: ${t.error.message}`);const n=t.token!==this.R;return this.R=t.token,zr("FirebaseAppCheckTokenProvider",`Received ${n?"new":"existing"} token.`),n?e(t.token):Promise.resolve()};this.o=e=>{t.enqueueRetryable((()=>n(e)))};const s=t=>{zr("FirebaseAppCheckTokenProvider","AppCheck detected"),this.appCheck=t,this.appCheck.addTokenListener(this.o)};this.A.onInit((t=>s(t))),setTimeout((()=>{if(!this.appCheck){const t=this.A.getImmediate({optional:!0});t?s(t):zr("FirebaseAppCheckTokenProvider","AppCheck not yet detected")}}),0)}getToken(){const t=this.forceRefresh;return this.forceRefresh=!1,this.appCheck?this.appCheck.getToken(t).then((t=>t?(Wr("string"==typeof t.token),this.R=t.token,new oi(t.token)):null)):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.appCheck&&this.appCheck.removeTokenListener(this.o)}}function ci(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 ui{static V(){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=62*Math.floor(256/62);let n="";for(;n.length<20;){const s=ci(40);for(let r=0;r<s.length;++r)n.length<20&&s[r]<e&&(n+=t.charAt(s[r]%62))}return n}}function hi(t,e){return t<e?-1:t>e?1:0}function li(t,e,n){return t.length===e.length&&t.every(((t,s)=>n(t,e[s])))}class di{constructor(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new Jr(Xr.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new Jr(Xr.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new Jr(Xr.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new Jr(Xr.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t)}static now(){return di.fromMillis(Date.now())}static fromDate(t){return di.fromMillis(t.getTime())}static fromMillis(t){const e=Math.floor(t/1e3),n=Math.floor(1e6*(t-1e3*e));return new di(e,n)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(t){return this.seconds===t.seconds?hi(this.nanoseconds,t.nanoseconds):hi(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 fi{constructor(t){this.timestamp=t}static fromTimestamp(t){return new fi(t)}static min(){return new fi(new di(0,0))}static max(){return new fi(new di(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 gi{constructor(t,e,n){void 0===e?e=0:e>t.length&&Qr(),void 0===n?n=t.length-e:n>t.length-e&&Qr(),this.segments=t,this.offset=e,this.len=n}get length(){return this.len}isEqual(t){return 0===gi.comparator(this,t)}child(t){const e=this.segments.slice(this.offset,this.limit());return t instanceof gi?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 mi extends gi{construct(t,e,n){return new mi(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 Jr(Xr.INVALID_ARGUMENT,`Invalid segment (${n}). Paths must not contain // in them.`);e.push(...n.split("/").filter((t=>t.length>0)))}return new mi(e)}static emptyPath(){return new mi([])}}const pi=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class yi extends gi{construct(t,e,n){return new yi(t,e,n)}static isValidIdentifier(t){return pi.test(t)}canonicalString(){return this.toArray().map((t=>(t=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),yi.isValidIdentifier(t)||(t="`"+t+"`"),t))).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&"__name__"===this.get(0)}static keyField(){return new yi(["__name__"])}static fromServerFormat(t){const e=[];let n="",s=0;const r=()=>{if(0===n.length)throw new Jr(Xr.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 Jr(Xr.INVALID_ARGUMENT,"Path has trailing escape character: "+t);const e=t[s+1];if("\\"!==e&&"."!==e&&"`"!==e)throw new Jr(Xr.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 Jr(Xr.INVALID_ARGUMENT,"Unterminated ` in path: "+t);return new yi(e)}static emptyPath(){return new yi([])}}class vi{constructor(t){this.path=t}static fromPath(t){return new vi(mi.fromString(t))}static fromName(t){return new vi(mi.fromString(t).popFirst(5))}static empty(){return new vi(mi.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===mi.comparator(this.path,t.path)}toString(){return this.path.toString()}static comparator(t,e){return mi.comparator(t.path,e.path)}static isDocumentKey(t){return t.length%2==0}static fromSegments(t){return new vi(new mi(t.slice()))}}class wi{constructor(t,e,n,s){this.indexId=t,this.collectionGroup=e,this.fields=n,this.indexState=s}}wi.UNKNOWN_ID=-1;function Ei(t,e){const n=t.toTimestamp().seconds,s=t.toTimestamp().nanoseconds+1,r=fi.fromTimestamp(1e9===s?new di(n+1,0):new di(n,s));return new bi(r,vi.empty(),e)}function _i(t){return new bi(t.readTime,t.key,-1)}class bi{constructor(t,e,n){this.readTime=t,this.documentKey=e,this.largestBatchId=n}static min(){return new bi(fi.min(),vi.empty(),-1)}static max(){return new bi(fi.max(),vi.empty(),-1)}}function Ii(t,e){let n=t.readTime.compareTo(e.readTime);return 0!==n?n:(n=vi.comparator(t.documentKey,e.documentKey),0!==n?n:hi(t.largestBatchId,e.largestBatchId))}const Ti="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.";class Si{constructor(){this.onCommittedListeners=[]}addOnCommittedListener(t){this.onCommittedListeners.push(t)}raiseOnCommittedEvent(){this.onCommittedListeners.forEach((t=>t()))}}async function Ci(t){if(t.code!==Xr.FAILED_PRECONDITION||t.message!==Ti)throw t;zr("LocalStore","Unexpectedly lost primary lease")}class Ai{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&&Qr(),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(e,this.error):this.wrapSuccess(t,this.result):new Ai(((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 Ai?e:Ai.resolve(e)}catch(t){return Ai.reject(t)}}wrapSuccess(t,e){return t?this.wrapUserFunction((()=>t(e))):Ai.resolve(e)}wrapFailure(t,e){return t?this.wrapUserFunction((()=>t(e))):Ai.reject(e)}static resolve(t){return new Ai(((e,n)=>{e(t)}))}static reject(t){return new Ai(((e,n)=>{n(t)}))}static waitFor(t){return new Ai(((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=Ai.resolve(!1);for(const n of t)e=e.next((t=>t?Ai.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 Ai(((n,s)=>{const r=t.length,i=new Array(r);let o=0;for(let a=0;a<r;a++){const c=a;e(t[c]).next((t=>{i[c]=t,++o,o===r&&n(i)}),(t=>s(t)))}}))}static doWhile(t,e){return new Ai(((n,s)=>{const r=()=>{!0===t()?e().next((()=>{r()}),s):n()};r()}))}}function Di(t){return"IndexedDbTransactionError"===t.name}class ki{constructor(t,e){this.previousValue=t,e&&(e.sequenceNumberHandler=t=>this.oe(t),this._e=t=>e.writeSequenceNumber(t))}oe(t){return this.previousValue=Math.max(t,this.previousValue),this.previousValue}next(){const t=++this.previousValue;return this._e&&this._e(t),t}}function Ni(t){return null==t}function Ri(t){return 0===t&&1/t==-1/0}function Li(t){return"number"==typeof t&&Number.isInteger(t)&&!Ri(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}ki.ae=-1;const xi=["mutationQueues","mutations","documentMutations","remoteDocuments","targets","owner","targetGlobal","targetDocuments","clientMetadata","remoteDocumentGlobal","collectionParents","bundles","namedQueries"],Oi=["mutationQueues","mutations","documentMutations","remoteDocumentsV14","targets","owner","targetGlobal","targetDocuments","clientMetadata","remoteDocumentGlobal","collectionParents","bundles","namedQueries","documentOverlays"],Mi=Oi;function Pi(t){let e=0;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e++;return e}function Fi(t,e){for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}function Bi(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}class Vi{constructor(t,e){this.comparator=t,this.root=e||qi.EMPTY}insert(t,e){return new Vi(this.comparator,this.root.insert(t,e,this.comparator).copy(null,null,qi.BLACK,null,null))}remove(t){return new Vi(this.comparator,this.root.remove(t,this.comparator).copy(null,null,qi.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 Ui(this.root,null,this.comparator,!1)}getIteratorFrom(t){return new Ui(this.root,t,this.comparator,!1)}getReverseIterator(){return new Ui(this.root,null,this.comparator,!0)}getReverseIteratorFrom(t){return new Ui(this.root,t,this.comparator,!0)}}class Ui{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 qi{constructor(t,e,n,s,r){this.key=t,this.value=e,this.color=null!=n?n:qi.RED,this.left=null!=s?s:qi.EMPTY,this.right=null!=r?r:qi.EMPTY,this.size=this.left.size+1+this.right.size}copy(t,e,n,s,r){return new qi(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 qi.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 qi.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,qi.RED,null,this.right.left);return this.right.copy(null,null,this.color,t,null)}rotateRight(){const t=this.copy(null,null,qi.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 Qr();if(this.right.isRed())throw Qr();const t=this.left.check();if(t!==this.right.check())throw Qr();return t+(this.isRed()?0:1)}}qi.EMPTY=null,qi.RED=!0,qi.BLACK=!1,qi.EMPTY=new class{constructor(){this.size=0}get key(){throw Qr()}get value(){throw Qr()}get color(){throw Qr()}get left(){throw Qr()}get right(){throw Qr()}copy(t,e,n,s,r){return this}insert(t,e,n){return new qi(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 ji{constructor(t){this.comparator=t,this.data=new Vi(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 $i(this.data.getIterator())}getIteratorFrom(t){return new $i(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 ji))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 ji(this.comparator);return e.data=t,e}}class $i{constructor(t){this.iter=t}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}}class zi{constructor(t){this.fields=t,t.sort(yi.comparator)}static empty(){return new zi([])}unionWith(t){let e=new ji(yi.comparator);for(const t of this.fields)e=e.add(t);for(const n of t)e=e.add(n);return new zi(e.toArray())}covers(t){for(const e of this.fields)if(e.isPrefixOf(t))return!0;return!1}isEqual(t){return li(this.fields,t.fields,((t,e)=>t.isEqual(e)))}}class Ki extends Error{constructor(){super(...arguments),this.name="Base64DecodeError"}}class Hi{constructor(t){this.binaryString=t}static fromBase64String(t){const e=function(t){try{return atob(t)}catch(t){throw"undefined"!=typeof DOMException&&t instanceof DOMException?new Ki("Invalid base64 string: "+t):t}}(t);return new Hi(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 Hi(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 hi(this.binaryString,t.binaryString)}isEqual(t){return this.binaryString===t.binaryString}}Hi.EMPTY_BYTE_STRING=new Hi("");const Gi=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function Qi(t){if(Wr(!!t),"string"==typeof t){let e=0;const n=Gi.exec(t);if(Wr(!!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:Wi(t.seconds),nanos:Wi(t.nanos)}}function Wi(t){return"number"==typeof t?t:"string"==typeof t?Number(t):0}function Yi(t){return"string"==typeof t?Hi.fromBase64String(t):Hi.fromUint8Array(t)}function Xi(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 Ji(t){const e=t.mapValue.fields.__previous_value__;return Xi(e)?Ji(e):e}function Zi(t){const e=Qi(t.mapValue.fields.__local_write_time__.timestampValue);return new di(e.seconds,e.nanos)}class to{constructor(t,e,n,s,r,i,o,a,c){this.databaseId=t,this.appId=e,this.persistenceKey=n,this.host=s,this.ssl=r,this.forceLongPolling=i,this.autoDetectLongPolling=o,this.longPollingOptions=a,this.useFetchStreams=c}}class eo{constructor(t,e){this.projectId=t,this.database=e||"(default)"}static empty(){return new eo("","")}get isDefaultDatabase(){return"(default)"===this.database}isEqual(t){return t instanceof eo&&t.projectId===this.projectId&&t.database===this.database}}const no={mapValue:{fields:{__type__:{stringValue:"__max__"}}}};function so(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?Xi(t)?4:yo(t)?9007199254740991:10:Qr()}function ro(t,e){if(t===e)return!0;const n=so(t);if(n!==so(e))return!1;switch(n){case 0:case 9007199254740991:return!0;case 1:return t.booleanValue===e.booleanValue;case 4:return Zi(t).isEqual(Zi(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=Qi(t.timestampValue),s=Qi(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 Yi(t.bytesValue).isEqual(Yi(e.bytesValue))}(t,e);case 7:return t.referenceValue===e.referenceValue;case 8:return function(t,e){return Wi(t.geoPointValue.latitude)===Wi(e.geoPointValue.latitude)&&Wi(t.geoPointValue.longitude)===Wi(e.geoPointValue.longitude)}(t,e);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return Wi(t.integerValue)===Wi(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){const n=Wi(t.doubleValue),s=Wi(e.doubleValue);return n===s?Ri(n)===Ri(s):isNaN(n)&&isNaN(s)}return!1}(t,e);case 9:return li(t.arrayValue.values||[],e.arrayValue.values||[],ro);case 10:return function(t,e){const n=t.mapValue.fields||{},s=e.mapValue.fields||{};if(Pi(n)!==Pi(s))return!1;for(const t in n)if(n.hasOwnProperty(t)&&(void 0===s[t]||!ro(n[t],s[t])))return!1;return!0}(t,e);default:return Qr()}}function io(t,e){return void 0!==(t.values||[]).find((t=>ro(t,e)))}function oo(t,e){if(t===e)return 0;const n=so(t),s=so(e);if(n!==s)return hi(n,s);switch(n){case 0:case 9007199254740991:return 0;case 1:return hi(t.booleanValue,e.booleanValue);case 2:return function(t,e){const n=Wi(t.integerValue||t.doubleValue),s=Wi(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 ao(t.timestampValue,e.timestampValue);case 4:return ao(Zi(t),Zi(e));case 5:return hi(t.stringValue,e.stringValue);case 6:return function(t,e){const n=Yi(t),s=Yi(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=hi(n[t],s[t]);if(0!==e)return e}return hi(n.length,s.length)}(t.referenceValue,e.referenceValue);case 8:return function(t,e){const n=hi(Wi(t.latitude),Wi(e.latitude));return 0!==n?n:hi(Wi(t.longitude),Wi(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=oo(n[t],s[t]);if(e)return e}return hi(n.length,s.length)}(t.arrayValue,e.arrayValue);case 10:return function(t,e){if(t===no.mapValue&&e===no.mapValue)return 0;if(t===no.mapValue)return 1;if(e===no.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=hi(s[t],i[t]);if(0!==e)return e;const o=oo(n[s[t]],r[i[t]]);if(0!==o)return o}return hi(s.length,i.length)}(t.mapValue,e.mapValue);default:throw Qr()}}function ao(t,e){if("string"==typeof t&&"string"==typeof e&&t.length===e.length)return hi(t,e);const n=Qi(t),s=Qi(e),r=hi(n.seconds,s.seconds);return 0!==r?r:hi(n.nanos,s.nanos)}function co(t){return uo(t)}function uo(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=Qi(t);return`time(${e.seconds},${e.nanos})`}(t.timestampValue):"stringValue"in t?t.stringValue:"bytesValue"in t?function(t){return Yi(t).toBase64()}(t.bytesValue):"referenceValue"in t?function(t){return vi.fromName(t).toString()}(t.referenceValue):"geoPointValue"in t?function(t){return`geo(${t.latitude},${t.longitude})`}(t.geoPointValue):"arrayValue"in t?function(t){let e="[",n=!0;for(const s of t.values||[])n?n=!1:e+=",",e+=uo(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}:${uo(t.fields[r])}`;return n+"}"}(t.mapValue):Qr()}function ho(t){return!!t&&"integerValue"in t}function lo(t){return!!t&&"arrayValue"in t}function fo(t){return!!t&&"nullValue"in t}function go(t){return!!t&&"doubleValue"in t&&isNaN(Number(t.doubleValue))}function mo(t){return!!t&&"mapValue"in t}function po(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 Fi(t.mapValue.fields,((t,n)=>e.mapValue.fields[t]=po(n))),e}if(t.arrayValue){const e={arrayValue:{values:[]}};for(let n=0;n<(t.arrayValue.values||[]).length;++n)e.arrayValue.values[n]=po(t.arrayValue.values[n]);return e}return Object.assign({},t)}function yo(t){return"__max__"===(((t.mapValue||{}).fields||{}).__type__||{}).stringValue}class vo{constructor(t){this.value=t}static empty(){return new vo({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)],!mo(e))return null;return e=(e.mapValue.fields||{})[t.lastSegment()],e||null}}set(t,e){this.getFieldsMap(t.popLast())[t.lastSegment()]=po(e)}setAll(t){let e=yi.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()]=po(t):s.push(r.lastSegment())}));const r=this.getFieldsMap(e);this.applyChanges(r,n,s)}delete(t){const e=this.field(t.popLast());mo(e)&&e.mapValue.fields&&delete e.mapValue.fields[t.lastSegment()]}isEqual(t){return ro(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)];mo(s)&&s.mapValue.fields||(s={mapValue:{fields:{}}},e.mapValue.fields[t.get(n)]=s),e=s}return e.mapValue.fields}applyChanges(t,e,n){Fi(e,((e,n)=>t[e]=n));for(const e of n)delete t[e]}clone(){return new vo(po(this.value))}}function wo(t){const e=[];return Fi(t.fields,((t,n)=>{const s=new yi([t]);if(mo(n)){const t=wo(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 zi(e)}class Eo{constructor(t,e,n,s,r,i,o){this.key=t,this.documentType=e,this.version=n,this.readTime=s,this.createTime=r,this.data=i,this.documentState=o}static newInvalidDocument(t){return new Eo(t,0,fi.min(),fi.min(),fi.min(),vo.empty(),0)}static newFoundDocument(t,e,n,s){return new Eo(t,1,e,fi.min(),n,s,0)}static newNoDocument(t,e){return new Eo(t,2,e,fi.min(),fi.min(),vo.empty(),0)}static newUnknownDocument(t,e){return new Eo(t,3,e,fi.min(),fi.min(),vo.empty(),2)}convertToFoundDocument(t,e){return!this.createTime.isEqual(fi.min())||2!==this.documentType&&0!==this.documentType||(this.createTime=t),this.version=t,this.documentType=1,this.data=e,this.documentState=0,this}convertToNoDocument(t){return this.version=t,this.documentType=2,this.data=vo.empty(),this.documentState=0,this}convertToUnknownDocument(t){return this.version=t,this.documentType=3,this.data=vo.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=fi.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 Eo&&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 Eo(this.key,this.documentType,this.version,this.readTime,this.createTime,this.data.clone(),this.documentState)}toString(){return`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, {createTime: ${this.createTime}}), {documentType: ${this.documentType}}), {documentState: ${this.documentState}})`}}class _o{constructor(t,e){this.position=t,this.inclusive=e}}function bo(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()?vi.comparator(vi.fromName(o.referenceValue),n.key):oo(o,n.data.field(i.field)),"desc"===i.dir&&(s*=-1),0!==s)break}return s}function Io(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(!ro(t.position[n],e.position[n]))return!1;return!0}class To{constructor(t,e="asc"){this.field=t,this.dir=e}}function So(t,e){return t.dir===e.dir&&t.field.isEqual(e.field)}class Co{}class Ao extends Co{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.createKeyFieldInFilter(t,e,n):new Mo(t,e,n):"array-contains"===e?new Vo(t,n):"in"===e?new Uo(t,n):"not-in"===e?new qo(t,n):"array-contains-any"===e?new jo(t,n):new Ao(t,e,n)}static createKeyFieldInFilter(t,e,n){return"in"===e?new Po(t,n):new Fo(t,n)}matches(t){const e=t.data.field(this.field);return"!="===this.op?null!==e&&this.matchesComparison(oo(e,this.value)):null!==e&&so(this.value)===so(e)&&this.matchesComparison(oo(e,this.value))}matchesComparison(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 Qr()}}isInequality(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}getFlattenedFilters(){return[this]}getFilters(){return[this]}getFirstInequalityField(){return this.isInequality()?this.field:null}}class Do extends Co{constructor(t,e){super(),this.filters=t,this.op=e,this.ce=null}static create(t,e){return new Do(t,e)}matches(t){return ko(this)?void 0===this.filters.find((e=>!e.matches(t))):void 0!==this.filters.find((e=>e.matches(t)))}getFlattenedFilters(){return null!==this.ce||(this.ce=this.filters.reduce(((t,e)=>t.concat(e.getFlattenedFilters())),[])),this.ce}getFilters(){return Object.assign([],this.filters)}getFirstInequalityField(){const t=this.le((t=>t.isInequality()));return null!==t?t.field:null}le(t){for(const e of this.getFlattenedFilters())if(t(e))return e;return null}}function ko(t){return"and"===t.op}function No(t){return Ro(t)&&ko(t)}function Ro(t){for(const e of t.filters)if(e instanceof Do)return!1;return!0}function Lo(t){if(t instanceof Ao)return t.field.canonicalString()+t.op.toString()+co(t.value);if(No(t))return t.filters.map((t=>Lo(t))).join(",");{const e=t.filters.map((t=>Lo(t))).join(",");return`${t.op}(${e})`}}function xo(t,e){return t instanceof Ao?function(t,e){return e instanceof Ao&&t.op===e.op&&t.field.isEqual(e.field)&&ro(t.value,e.value)}(t,e):t instanceof Do?function(t,e){return e instanceof Do&&t.op===e.op&&t.filters.length===e.filters.length&&t.filters.reduce(((t,n,s)=>t&&xo(n,e.filters[s])),!0)}(t,e):void Qr()}function Oo(t){return t instanceof Ao?function(t){return`${t.field.canonicalString()} ${t.op} ${co(t.value)}`}(t):t instanceof Do?function(t){return t.op.toString()+" {"+t.getFilters().map(Oo).join(" ,")+"}"}(t):"Filter"}class Mo extends Ao{constructor(t,e,n){super(t,e,n),this.key=vi.fromName(n.referenceValue)}matches(t){const e=vi.comparator(t.key,this.key);return this.matchesComparison(e)}}class Po extends Ao{constructor(t,e){super(t,"in",e),this.keys=Bo("in",e)}matches(t){return this.keys.some((e=>e.isEqual(t.key)))}}class Fo extends Ao{constructor(t,e){super(t,"not-in",e),this.keys=Bo("not-in",e)}matches(t){return!this.keys.some((e=>e.isEqual(t.key)))}}function Bo(t,e){var n;return((null===(n=e.arrayValue)||void 0===n?void 0:n.values)||[]).map((t=>vi.fromName(t.referenceValue)))}class Vo extends Ao{constructor(t,e){super(t,"array-contains",e)}matches(t){const e=t.data.field(this.field);return lo(e)&&io(e.arrayValue,this.value)}}class Uo extends Ao{constructor(t,e){super(t,"in",e)}matches(t){const e=t.data.field(this.field);return null!==e&&io(this.value.arrayValue,e)}}class qo extends Ao{constructor(t,e){super(t,"not-in",e)}matches(t){if(io(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;const e=t.data.field(this.field);return null!==e&&!io(this.value.arrayValue,e)}}class jo extends Ao{constructor(t,e){super(t,"array-contains-any",e)}matches(t){const e=t.data.field(this.field);return!(!lo(e)||!e.arrayValue.values)&&e.arrayValue.values.some((t=>io(this.value.arrayValue,t)))}}class $o{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.he=null}}function zo(t,e=null,n=[],s=[],r=null,i=null,o=null){return new $o(t,e,n,s,r,i,o)}function Ko(t){const e=Yr(t);if(null===e.he){let t=e.path.canonicalString();null!==e.collectionGroup&&(t+="|cg:"+e.collectionGroup),t+="|f:",t+=e.filters.map((t=>Lo(t))).join(","),t+="|ob:",t+=e.orderBy.map((t=>function(t){return t.field.canonicalString()+t.dir}(t))).join(","),Ni(e.limit)||(t+="|l:",t+=e.limit),e.startAt&&(t+="|lb:",t+=e.startAt.inclusive?"b:":"a:",t+=e.startAt.position.map((t=>co(t))).join(",")),e.endAt&&(t+="|ub:",t+=e.endAt.inclusive?"a:":"b:",t+=e.endAt.position.map((t=>co(t))).join(",")),e.he=t}return e.he}function Ho(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(!So(t.orderBy[n],e.orderBy[n]))return!1;if(t.filters.length!==e.filters.length)return!1;for(let n=0;n<t.filters.length;n++)if(!xo(t.filters[n],e.filters[n]))return!1;return t.collectionGroup===e.collectionGroup&&!!t.path.isEqual(e.path)&&!!Io(t.startAt,e.startAt)&&Io(t.endAt,e.endAt)}function Go(t){return vi.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}class Qo{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.Pe=null,this.Ie=null,this.de=null,this.startAt,this.endAt}}function Wo(t,e,n,s,r,i,o,a){return new Qo(t,e,n,s,r,i,o,a)}function Yo(t){return new Qo(t)}function Xo(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 Jo(t){return t.explicitOrderBy.length>0?t.explicitOrderBy[0].field:null}function Zo(t){for(const e of t.filters){const t=e.getFirstInequalityField();if(null!==t)return t}return null}function ta(t){return null!==t.collectionGroup}function ea(t){const e=Yr(t);if(null===e.Pe){e.Pe=[];const t=Zo(e),n=Jo(e);if(null!==t&&null===n)t.isKeyField()||e.Pe.push(new To(t)),e.Pe.push(new To(yi.keyField(),"asc"));else{let t=!1;for(const n of e.explicitOrderBy)e.Pe.push(n),n.field.isKeyField()&&(t=!0);if(!t){const t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.Pe.push(new To(yi.keyField(),t))}}}return e.Pe}function na(t){const e=Yr(t);return e.Ie||(e.Ie=sa(e,ea(t))),e.Ie}function sa(t,e){if("F"===t.limitType)return zo(t.path,t.collectionGroup,e,t.filters,t.limit,t.startAt,t.endAt);{e=e.map((t=>{const e="desc"===t.dir?"asc":"desc";return new To(t.field,e)}));const n=t.endAt?new _o(t.endAt.position,t.endAt.inclusive):null,s=t.startAt?new _o(t.startAt.position,t.startAt.inclusive):null;return zo(t.path,t.collectionGroup,e,t.filters,t.limit,n,s)}}function ra(t,e,n){return new Qo(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),e,n,t.startAt,t.endAt)}function ia(t,e){return Ho(na(t),na(e))&&t.limitType===e.limitType}function oa(t){return`${Ko(na(t))}|lt:${t.limitType}`}function aa(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=>Oo(t))).join(", ")}]`),Ni(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=>co(t))).join(",")),t.endAt&&(e+=", endAt: ",e+=t.endAt.inclusive?"a:":"b:",e+=t.endAt.position.map((t=>co(t))).join(",")),`Target(${e})`}(na(t))}; limitType=${t.limitType})`}function ca(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):vi.isDocumentKey(t.path)?t.path.isEqual(n):t.path.isImmediateParentOf(n)}(t,e)&&function(t,e){for(const n of ea(t))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=bo(t,e,n);return t.inclusive?s<=0:s<0}(t.startAt,ea(t),e))&&!(t.endAt&&!function(t,e,n){const s=bo(t,e,n);return t.inclusive?s>=0:s>0}(t.endAt,ea(t),e))}(t,e)}function ua(t){return t.collectionGroup||(t.path.length%2==1?t.path.lastSegment():t.path.get(t.path.length-2))}function ha(t){return(e,n)=>{let s=!1;for(const r of ea(t)){const t=la(r,e,n);if(0!==t)return t;s=s||r.field.isKeyField()}return 0}}function la(t,e,n){const s=t.field.isKeyField()?vi.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?oo(s,r):Qr()}(t.field,e,n);switch(t.dir){case"asc":return s;case"desc":return-1*s;default:return Qr()}}class da{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){Fi(this.inner,((e,n)=>{for(const[e,s]of n)t(e,s)}))}isEmpty(){return Bi(this.inner)}size(){return this.innerSize}}const fa=new Vi(vi.comparator);function ga(){return fa}const ma=new Vi(vi.comparator);function pa(...t){let e=ma;for(const n of t)e=e.insert(n.key,n);return e}function ya(t){let e=ma;return t.forEach(((t,n)=>e=e.insert(t,n.overlayedDocument))),e}function va(){return Ea()}function wa(){return Ea()}function Ea(){return new da((t=>t.toString()),((t,e)=>t.isEqual(e)))}const _a=new Vi(vi.comparator),ba=new ji(vi.comparator);function Ia(...t){let e=ba;for(const n of t)e=e.add(n);return e}const Ta=new ji(hi);function Sa(){return Ta}function Ca(t,e){if(t.useProto3Json){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:Ri(e)?"-0":e}}function Aa(t){return{integerValue:""+t}}function Da(t,e){return Li(e)?Aa(e):Ca(t,e)}class ka{constructor(){this._=void 0}}function Na(t,e,n){return t instanceof xa?function(t,e){const n={fields:{__type__:{stringValue:"server_timestamp"},__local_write_time__:{timestampValue:{seconds:t.seconds,nanos:t.nanoseconds}}}};return e&&Xi(e)&&(e=Ji(e)),e&&(n.fields.__previous_value__=e),{mapValue:n}}(n,e):t instanceof Oa?Ma(t,e):t instanceof Pa?Fa(t,e):function(t,e){const n=La(t,e),s=Va(n)+Va(t.Te);return ho(n)&&ho(t.Te)?Aa(s):Ca(t.serializer,s)}(t,e)}function Ra(t,e,n){return t instanceof Oa?Ma(t,e):t instanceof Pa?Fa(t,e):n}function La(t,e){return t instanceof Ba?function(t){return ho(t)||function(t){return!!t&&"doubleValue"in t}(t)}(e)?e:{integerValue:0}:null}class xa extends ka{}class Oa extends ka{constructor(t){super(),this.elements=t}}function Ma(t,e){const n=Ua(e);for(const e of t.elements)n.some((t=>ro(t,e)))||n.push(e);return{arrayValue:{values:n}}}class Pa extends ka{constructor(t){super(),this.elements=t}}function Fa(t,e){let n=Ua(e);for(const e of t.elements)n=n.filter((t=>!ro(t,e)));return{arrayValue:{values:n}}}class Ba extends ka{constructor(t,e){super(),this.serializer=t,this.Te=e}}function Va(t){return Wi(t.integerValue||t.doubleValue)}function Ua(t){return lo(t)&&t.arrayValue.values?t.arrayValue.values.slice():[]}class qa{constructor(t,e){this.version=t,this.transformResults=e}}class ja{constructor(t,e){this.updateTime=t,this.exists=e}static none(){return new ja}static exists(t){return new ja(void 0,t)}static updateTime(t){return new ja(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 $a(t,e){return void 0!==t.updateTime?e.isFoundDocument()&&e.version.isEqual(t.updateTime):void 0===t.exists||t.exists===e.isFoundDocument()}class za{}function Ka(t,e){if(!t.hasLocalMutations||e&&0===e.fields.length)return null;if(null===e)return t.isNoDocument()?new ec(t.key,ja.none()):new Ya(t.key,t.data,ja.none());{const n=t.data,s=vo.empty();let r=new ji(yi.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 Xa(t.key,s,new zi(r.toArray()),ja.none())}}function Ha(t,e,n){t instanceof Ya?function(t,e,n){const s=t.value.clone(),r=Za(t.fieldTransforms,e,n.transformResults);s.setAll(r),e.convertToFoundDocument(n.version,s).setHasCommittedMutations()}(t,e,n):t instanceof Xa?function(t,e,n){if(!$a(t.precondition,e))return void e.convertToUnknownDocument(n.version);const s=Za(t.fieldTransforms,e,n.transformResults),r=e.data;r.setAll(Ja(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 Ga(t,e,n,s){return t instanceof Ya?function(t,e,n,s){if(!$a(t.precondition,e))return n;const r=t.value.clone(),i=tc(t.fieldTransforms,s,e);return r.setAll(i),e.convertToFoundDocument(e.version,r).setHasLocalMutations(),null}(t,e,n,s):t instanceof Xa?function(t,e,n,s){if(!$a(t.precondition,e))return n;const r=tc(t.fieldTransforms,s,e),i=e.data;return i.setAll(Ja(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 $a(t.precondition,e)?(e.convertToNoDocument(e.version).setHasLocalMutations(),null):n}(t,e,n)}function Qa(t,e){let n=null;for(const s of t.fieldTransforms){const t=e.data.field(s.field),r=La(s.transform,t||null);null!=r&&(null===n&&(n=vo.empty()),n.set(s.field,r))}return n||null}function Wa(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)&&li(t,e,((t,e)=>function(t,e){return t.field.isEqual(e.field)&&function(t,e){return t instanceof Oa&&e instanceof Oa||t instanceof Pa&&e instanceof Pa?li(t.elements,e.elements,ro):t instanceof Ba&&e instanceof Ba?ro(t.Te,e.Te):t instanceof xa&&e instanceof xa}(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 Ya extends za{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 Xa extends za{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 Ja(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 Za(t,e,n){const s=new Map;Wr(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,Ra(o,a,n[r]))}return s}function tc(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,Na(t,i,e))}return s}class ec extends za{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class nc extends za{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}class sc{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)&&Ha(s,t,n[e])}}applyToLocalView(t,e){for(const n of this.baseMutations)n.key.isEqual(t.key)&&(e=Ga(n,t,e,this.localWriteTime));for(const n of this.mutations)n.key.isEqual(t.key)&&(e=Ga(n,t,e,this.localWriteTime));return e}applyToLocalDocumentSet(t,e){const n=wa();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=Ka(i,o);null!==a&&n.set(s.key,a),i.isValidDocument()||i.convertToNoDocument(fi.min())})),n}keys(){return this.mutations.reduce(((t,e)=>t.add(e.key)),Ia())}isEqual(t){return this.batchId===t.batchId&&li(this.mutations,t.mutations,((t,e)=>Wa(t,e)))&&li(this.baseMutations,t.baseMutations,((t,e)=>Wa(t,e)))}}class rc{constructor(t,e,n,s){this.batch=t,this.commitVersion=e,this.mutationResults=n,this.docVersions=s}static from(t,e,n){Wr(t.mutations.length===n.length);let s=_a;const r=t.mutations;for(let t=0;t<r.length;t++)s=s.insert(r[t].key,n[t].version);return new rc(t,e,n,s)}}class ic{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 oc{constructor(t,e){this.count=t,this.unchangedNames=e}}var ac,cc;function uc(t){switch(t){default:return Qr();case Xr.CANCELLED:case Xr.UNKNOWN:case Xr.DEADLINE_EXCEEDED:case Xr.RESOURCE_EXHAUSTED:case Xr.INTERNAL:case Xr.UNAVAILABLE:case Xr.UNAUTHENTICATED:return!1;case Xr.INVALID_ARGUMENT:case Xr.NOT_FOUND:case Xr.ALREADY_EXISTS:case Xr.PERMISSION_DENIED:case Xr.FAILED_PRECONDITION:case Xr.ABORTED:case Xr.OUT_OF_RANGE:case Xr.UNIMPLEMENTED:case Xr.DATA_LOSS:return!0}}function hc(t){if(void 0===t)return Kr("GRPC error has no .code"),Xr.UNKNOWN;switch(t){case ac.OK:return Xr.OK;case ac.CANCELLED:return Xr.CANCELLED;case ac.UNKNOWN:return Xr.UNKNOWN;case ac.DEADLINE_EXCEEDED:return Xr.DEADLINE_EXCEEDED;case ac.RESOURCE_EXHAUSTED:return Xr.RESOURCE_EXHAUSTED;case ac.INTERNAL:return Xr.INTERNAL;case ac.UNAVAILABLE:return Xr.UNAVAILABLE;case ac.UNAUTHENTICATED:return Xr.UNAUTHENTICATED;case ac.INVALID_ARGUMENT:return Xr.INVALID_ARGUMENT;case ac.NOT_FOUND:return Xr.NOT_FOUND;case ac.ALREADY_EXISTS:return Xr.ALREADY_EXISTS;case ac.PERMISSION_DENIED:return Xr.PERMISSION_DENIED;case ac.FAILED_PRECONDITION:return Xr.FAILED_PRECONDITION;case ac.ABORTED:return Xr.ABORTED;case ac.OUT_OF_RANGE:return Xr.OUT_OF_RANGE;case ac.UNIMPLEMENTED:return Xr.UNIMPLEMENTED;case ac.DATA_LOSS:return Xr.DATA_LOSS;default:return Qr()}}(cc=ac||(ac={}))[cc.OK=0]="OK",cc[cc.CANCELLED=1]="CANCELLED",cc[cc.UNKNOWN=2]="UNKNOWN",cc[cc.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",cc[cc.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",cc[cc.NOT_FOUND=5]="NOT_FOUND",cc[cc.ALREADY_EXISTS=6]="ALREADY_EXISTS",cc[cc.PERMISSION_DENIED=7]="PERMISSION_DENIED",cc[cc.UNAUTHENTICATED=16]="UNAUTHENTICATED",cc[cc.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",cc[cc.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",cc[cc.ABORTED=10]="ABORTED",cc[cc.OUT_OF_RANGE=11]="OUT_OF_RANGE",cc[cc.UNIMPLEMENTED=12]="UNIMPLEMENTED",cc[cc.INTERNAL=13]="INTERNAL",cc[cc.UNAVAILABLE=14]="UNAVAILABLE",cc[cc.DATA_LOSS=15]="DATA_LOSS";let lc=null;function dc(){return new TextEncoder}const fc=new Br([4294967295,4294967295],0);function gc(t){const e=dc().encode(t),n=new Fr;return n.update(e),new Uint8Array(n.digest())}function mc(t){const e=new DataView(t.buffer),n=e.getUint32(0,!0),s=e.getUint32(4,!0),r=e.getUint32(8,!0),i=e.getUint32(12,!0);return[new Br([n,s],0),new Br([r,i],0)]}class pc{constructor(t,e,n){if(this.bitmap=t,this.padding=e,this.hashCount=n,e<0||e>=8)throw new yc(`Invalid padding: ${e}`);if(n<0)throw new yc(`Invalid hash count: ${n}`);if(t.length>0&&0===this.hashCount)throw new yc(`Invalid hash count: ${n}`);if(0===t.length&&0!==e)throw new yc(`Invalid padding when bitmap length is 0: ${e}`);this.Ae=8*t.length-e,this.Re=Br.fromNumber(this.Ae)}Ve(t,e,n){let s=t.add(e.multiply(Br.fromNumber(n)));return 1===s.compare(fc)&&(s=new Br([s.getBits(0),s.getBits(1)],0)),s.modulo(this.Re).toNumber()}me(t){return 0!=(this.bitmap[Math.floor(t/8)]&1<<t%8)}mightContain(t){if(0===this.Ae)return!1;const e=gc(t),[n,s]=mc(e);for(let t=0;t<this.hashCount;t++){const e=this.Ve(n,s,t);if(!this.me(e))return!1}return!0}static create(t,e,n){const s=t%8==0?0:8-t%8,r=new Uint8Array(Math.ceil(t/8)),i=new pc(r,s,e);return n.forEach((t=>i.insert(t))),i}insert(t){if(0===this.Ae)return;const e=gc(t),[n,s]=mc(e);for(let t=0;t<this.hashCount;t++){const e=this.Ve(n,s,t);this.fe(e)}}fe(t){const e=Math.floor(t/8),n=t%8;this.bitmap[e]|=1<<n}}class yc extends Error{constructor(){super(...arguments),this.name="BloomFilterError"}}class vc{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,wc.createSynthesizedTargetChangeForCurrentChange(t,e,n)),new vc(fi.min(),s,new Vi(hi),ga(),Ia())}}class wc{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 wc(n,e,Ia(),Ia(),Ia())}}class Ec{constructor(t,e,n,s){this.ge=t,this.removedTargetIds=e,this.key=n,this.pe=s}}class _c{constructor(t,e){this.targetId=t,this.ye=e}}class bc{constructor(t,e,n=Hi.EMPTY_BYTE_STRING,s=null){this.state=t,this.targetIds=e,this.resumeToken=n,this.cause=s}}class Ic{constructor(){this.we=0,this.Se=Cc(),this.be=Hi.EMPTY_BYTE_STRING,this.De=!1,this.Ce=!0}get current(){return this.De}get resumeToken(){return this.be}get ve(){return 0!==this.we}get Fe(){return this.Ce}Me(t){t.approximateByteSize()>0&&(this.Ce=!0,this.be=t)}xe(){let t=Ia(),e=Ia(),n=Ia();return this.Se.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:Qr()}})),new wc(this.be,this.De,t,e,n)}Oe(){this.Ce=!1,this.Se=Cc()}Ne(t,e){this.Ce=!0,this.Se=this.Se.insert(t,e)}Be(t){this.Ce=!0,this.Se=this.Se.remove(t)}Le(){this.we+=1}ke(){this.we-=1}qe(){this.Ce=!0,this.De=!0}}class Tc{constructor(t){this.Qe=t,this.Ke=new Map,this.$e=ga(),this.Ue=Sc(),this.We=new Vi(hi)}Ge(t){for(const e of t.ge)t.pe&&t.pe.isFoundDocument()?this.ze(e,t.pe):this.je(e,t.key,t.pe);for(const e of t.removedTargetIds)this.je(e,t.key,t.pe)}He(t){this.forEachTarget(t,(e=>{const n=this.Je(e);switch(t.state){case 0:this.Ye(e)&&n.Me(t.resumeToken);break;case 1:n.ke(),n.ve||n.Oe(),n.Me(t.resumeToken);break;case 2:n.ke(),n.ve||this.removeTarget(e);break;case 3:this.Ye(e)&&(n.qe(),n.Me(t.resumeToken));break;case 4:this.Ye(e)&&(this.Ze(e),n.Me(t.resumeToken));break;default:Qr()}}))}forEachTarget(t,e){t.targetIds.length>0?t.targetIds.forEach(e):this.Ke.forEach(((t,n)=>{this.Ye(n)&&e(n)}))}Xe(t){const e=t.targetId,n=t.ye.count,s=this.et(e);if(s){const r=s.target;if(Go(r))if(0===n){const t=new vi(r.path);this.je(e,t,Eo.newNoDocument(t,fi.min()))}else Wr(1===n);else{const s=this.tt(e);if(s!==n){const n=this.nt(t),r=n?this.rt(n,t,s):1;if(0!==r){this.Ze(e);const t=2===r?"TargetPurposeExistenceFilterMismatchBloom":"TargetPurposeExistenceFilterMismatch";this.We=this.We.insert(e,t)}null==lc||lc.it(function(t,e,n,s,r){var i,o,a,c,u,h;const l={localCacheCount:t,existenceFilterCount:e.count,databaseId:n.database,projectId:n.projectId},d=e.unchangedNames;return d&&(l.bloomFilter={applied:0===r,hashCount:null!==(i=null==d?void 0:d.hashCount)&&void 0!==i?i:0,bitmapLength:null!==(c=null===(a=null===(o=null==d?void 0:d.bits)||void 0===o?void 0:o.bitmap)||void 0===a?void 0:a.length)&&void 0!==c?c:0,padding:null!==(h=null===(u=null==d?void 0:d.bits)||void 0===u?void 0:u.padding)&&void 0!==h?h:0,mightContain:t=>{var e;return null!==(e=null==s?void 0:s.mightContain(t))&&void 0!==e&&e}}),l}(s,t.ye,this.Qe.st(),n,r))}}}}nt(t){const e=t.ye.unchangedNames;if(!e||!e.bits)return null;const{bits:{bitmap:n="",padding:s=0},hashCount:r=0}=e;let i,o;try{i=Yi(n).toUint8Array()}catch(t){if(t instanceof Ki)return Hr("Decoding the base64 bloom filter in existence filter failed ("+t.message+"); ignoring the bloom filter and falling back to full re-query."),null;throw t}try{o=new pc(i,s,r)}catch(t){return Hr(t instanceof yc?"BloomFilter error: ":"Applying bloom filter failed: ",t),null}return 0===o.Ae?null:o}rt(t,e,n){return e.ye.count===n-this.ot(t,e.targetId)?0:2}ot(t,e){const n=this.Qe.getRemoteKeysForTarget(e);let s=0;return n.forEach((n=>{const r=this.Qe.st(),i=`projects/${r.projectId}/databases/${r.database}/documents/${n.path.canonicalString()}`;t.mightContain(i)||(this.je(e,n,null),s++)})),s}_t(t){const e=new Map;this.Ke.forEach(((n,s)=>{const r=this.et(s);if(r){if(n.current&&Go(r.target)){const e=new vi(r.target.path);null!==this.$e.get(e)||this.ut(s,e)||this.je(s,e,Eo.newNoDocument(e,t))}n.Fe&&(e.set(s,n.xe()),n.Oe())}}));let n=Ia();this.Ue.forEach(((t,e)=>{let s=!0;e.forEachWhile((t=>{const e=this.et(t);return!e||"TargetPurposeLimboResolution"===e.purpose||(s=!1,!1)})),s&&(n=n.add(t))})),this.$e.forEach(((e,n)=>n.setReadTime(t)));const s=new vc(t,e,this.We,this.$e,n);return this.$e=ga(),this.Ue=Sc(),this.We=new Vi(hi),s}ze(t,e){if(!this.Ye(t))return;const n=this.ut(t,e.key)?2:0;this.Je(t).Ne(e.key,n),this.$e=this.$e.insert(e.key,e),this.Ue=this.Ue.insert(e.key,this.ct(e.key).add(t))}je(t,e,n){if(!this.Ye(t))return;const s=this.Je(t);this.ut(t,e)?s.Ne(e,1):s.Be(e),this.Ue=this.Ue.insert(e,this.ct(e).delete(t)),n&&(this.$e=this.$e.insert(e,n))}removeTarget(t){this.Ke.delete(t)}tt(t){const e=this.Je(t).xe();return this.Qe.getRemoteKeysForTarget(t).size+e.addedDocuments.size-e.removedDocuments.size}Le(t){this.Je(t).Le()}Je(t){let e=this.Ke.get(t);return e||(e=new Ic,this.Ke.set(t,e)),e}ct(t){let e=this.Ue.get(t);return e||(e=new ji(hi),this.Ue=this.Ue.insert(t,e)),e}Ye(t){const e=null!==this.et(t);return e||zr("WatchChangeAggregator","Detected inactive target",t),e}et(t){const e=this.Ke.get(t);return e&&e.ve?null:this.Qe.lt(t)}Ze(t){this.Ke.set(t,new Ic),this.Qe.getRemoteKeysForTarget(t).forEach((e=>{this.je(t,e,null)}))}ut(t,e){return this.Qe.getRemoteKeysForTarget(t).has(e)}}function Sc(){return new Vi(vi.comparator)}function Cc(){return new Vi(vi.comparator)}const Ac={asc:"ASCENDING",desc:"DESCENDING"},Dc={"<":"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"},kc={and:"AND",or:"OR"};class Nc{constructor(t,e){this.databaseId=t,this.useProto3Json=e}}function Rc(t,e){return t.useProto3Json||Ni(e)?e:{value:e}}function Lc(t,e){return t.useProto3Json?`${new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+e.nanoseconds).slice(-9)}Z`:{seconds:""+e.seconds,nanos:e.nanoseconds}}function xc(t,e){return t.useProto3Json?e.toBase64():e.toUint8Array()}function Oc(t,e){return Lc(t,e.toTimestamp())}function Mc(t){return Wr(!!t),fi.fromTimestamp(function(t){const e=Qi(t);return new di(e.seconds,e.nanos)}(t))}function Pc(t,e){return function(t){return new mi(["projects",t.projectId,"databases",t.database])}(t).child("documents").child(e).canonicalString()}function Fc(t){const e=mi.fromString(t);return Wr(su(e)),e}function Bc(t,e){return Pc(t.databaseId,e.path)}function Vc(t,e){const n=Fc(e);if(n.get(1)!==t.databaseId.projectId)throw new Jr(Xr.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 Jr(Xr.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new vi($c(n))}function Uc(t,e){return Pc(t.databaseId,e)}function qc(t){const e=Fc(t);return 4===e.length?mi.emptyPath():$c(e)}function jc(t){return new mi(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function $c(t){return Wr(t.length>4&&"documents"===t.get(4)),t.popFirst(5)}function zc(t,e,n){return{name:Bc(t,e),fields:n.value.mapValue.fields}}function Kc(t,e){let n;if(e instanceof Ya)n={update:zc(t,e.key,e.value)};else if(e instanceof ec)n={delete:Bc(t,e.key)};else if(e instanceof Xa)n={update:zc(t,e.key,e.data),updateMask:nu(e.fieldMask)};else{if(!(e instanceof nc))return Qr();n={verify:Bc(t,e.key)}}return e.fieldTransforms.length>0&&(n.updateTransforms=e.fieldTransforms.map((t=>function(t,e){const n=e.transform;if(n instanceof xa)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof Oa)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof Pa)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof Ba)return{fieldPath:e.field.canonicalString(),increment:n.Te};throw Qr()}(0,t)))),e.precondition.isNone||(n.currentDocument=function(t,e){return void 0!==e.updateTime?{updateTime:Oc(t,e.updateTime)}:void 0!==e.exists?{exists:e.exists}:Qr()}(t,e.precondition)),n}function Hc(t,e){return{documents:[Uc(t,e.path)]}}function Gc(t,e){const n={structuredQuery:{}},s=e.path;null!==e.collectionGroup?(n.parent=Uc(t,s),n.structuredQuery.from=[{collectionId:e.collectionGroup,allDescendants:!0}]):(n.parent=Uc(t,s.popLast()),n.structuredQuery.from=[{collectionId:s.lastSegment()}]);const r=function(t){if(0!==t.length)return eu(Do.create(t,"and"))}(e.filters);r&&(n.structuredQuery.where=r);const i=function(t){if(0!==t.length)return t.map((t=>function(t){return{field:Zc(t.field),direction:Yc(t.dir)}}(t)))}(e.orderBy);i&&(n.structuredQuery.orderBy=i);const o=Rc(t,e.limit);return null!==o&&(n.structuredQuery.limit=o),e.startAt&&(n.structuredQuery.startAt=function(t){return{before:t.inclusive,values:t.position}}(e.startAt)),e.endAt&&(n.structuredQuery.endAt=function(t){return{before:!t.inclusive,values:t.position}}(e.endAt)),n}function Qc(t){let e=qc(t.parent);const n=t.structuredQuery,s=n.from?n.from.length:0;let r=null;if(s>0){Wr(1===s);const t=n.from[0];t.allDescendants?r=t.collectionId:e=e.child(t.collectionId)}let i=[];n.where&&(i=function(t){const e=Wc(t);return e instanceof Do&&No(e)?e.getFilters():[e]}(n.where));let o=[];n.orderBy&&(o=function(t){return t.map((t=>function(t){return new To(tu(t.field),function(t){switch(t){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}}(t.direction))}(t)))}(n.orderBy));let a=null;n.limit&&(a=function(t){let e;return e="object"==typeof t?t.value:t,Ni(e)?null:e}(n.limit));let c=null;n.startAt&&(c=function(t){const e=!!t.before,n=t.values||[];return new _o(n,e)}(n.startAt));let u=null;return n.endAt&&(u=function(t){const e=!t.before,n=t.values||[];return new _o(n,e)}(n.endAt)),Wo(e,r,o,i,a,"F",c,u)}function Wc(t){return void 0!==t.unaryFilter?function(t){switch(t.unaryFilter.op){case"IS_NAN":const e=tu(t.unaryFilter.field);return Ao.create(e,"==",{doubleValue:NaN});case"IS_NULL":const n=tu(t.unaryFilter.field);return Ao.create(n,"==",{nullValue:"NULL_VALUE"});case"IS_NOT_NAN":const s=tu(t.unaryFilter.field);return Ao.create(s,"!=",{doubleValue:NaN});case"IS_NOT_NULL":const r=tu(t.unaryFilter.field);return Ao.create(r,"!=",{nullValue:"NULL_VALUE"});default:return Qr()}}(t):void 0!==t.fieldFilter?function(t){return Ao.create(tu(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 Qr()}}(t.fieldFilter.op),t.fieldFilter.value)}(t):void 0!==t.compositeFilter?function(t){return Do.create(t.compositeFilter.filters.map((t=>Wc(t))),function(t){switch(t){case"AND":return"and";case"OR":return"or";default:return Qr()}}(t.compositeFilter.op))}(t):Qr()}function Yc(t){return Ac[t]}function Xc(t){return Dc[t]}function Jc(t){return kc[t]}function Zc(t){return{fieldPath:t.canonicalString()}}function tu(t){return yi.fromServerFormat(t.fieldPath)}function eu(t){return t instanceof Ao?function(t){if("=="===t.op){if(go(t.value))return{unaryFilter:{field:Zc(t.field),op:"IS_NAN"}};if(fo(t.value))return{unaryFilter:{field:Zc(t.field),op:"IS_NULL"}}}else if("!="===t.op){if(go(t.value))return{unaryFilter:{field:Zc(t.field),op:"IS_NOT_NAN"}};if(fo(t.value))return{unaryFilter:{field:Zc(t.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:Zc(t.field),op:Xc(t.op),value:t.value}}}(t):t instanceof Do?function(t){const e=t.getFilters().map((t=>eu(t)));return 1===e.length?e[0]:{compositeFilter:{op:Jc(t.op),filters:e}}}(t):Qr()}function nu(t){const e=[];return t.fields.forEach((t=>e.push(t.canonicalString()))),{fieldPaths:e}}function su(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)}class ru{constructor(t,e,n,s,r=fi.min(),i=fi.min(),o=Hi.EMPTY_BYTE_STRING,a=null){this.target=t,this.targetId=e,this.purpose=n,this.sequenceNumber=s,this.snapshotVersion=r,this.lastLimboFreeSnapshotVersion=i,this.resumeToken=o,this.expectedCount=a}withSequenceNumber(t){return new ru(this.target,this.targetId,this.purpose,t,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken,this.expectedCount)}withResumeToken(t,e){return new ru(this.target,this.targetId,this.purpose,this.sequenceNumber,e,this.lastLimboFreeSnapshotVersion,t,null)}withExpectedCount(t){return new ru(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken,t)}withLastLimboFreeSnapshotVersion(t){return new ru(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,t,this.resumeToken,this.expectedCount)}}class iu{constructor(t){this.ht=t}}function ou(t){const e=Qc({parent:t.parent,structuredQuery:t.structuredQuery});return"LAST"===t.limitType?ra(e,e.limit,"L"):e}class au{constructor(){}dt(t,e){this.Tt(t,e),e.Et()}Tt(t,e){if("nullValue"in t)this.At(e,5);else if("booleanValue"in t)this.At(e,10),e.Rt(t.booleanValue?1:0);else if("integerValue"in t)this.At(e,15),e.Rt(Wi(t.integerValue));else if("doubleValue"in t){const n=Wi(t.doubleValue);isNaN(n)?this.At(e,13):(this.At(e,15),Ri(n)?e.Rt(0):e.Rt(n))}else if("timestampValue"in t){const n=t.timestampValue;this.At(e,20),"string"==typeof n?e.Vt(n):(e.Vt(`${n.seconds||""}`),e.Rt(n.nanos||0))}else if("stringValue"in t)this.ft(t.stringValue,e),this.gt(e);else if("bytesValue"in t)this.At(e,30),e.yt(Yi(t.bytesValue)),this.gt(e);else if("referenceValue"in t)this.wt(t.referenceValue,e);else if("geoPointValue"in t){const n=t.geoPointValue;this.At(e,45),e.Rt(n.latitude||0),e.Rt(n.longitude||0)}else"mapValue"in t?yo(t)?this.At(e,Number.MAX_SAFE_INTEGER):(this.St(t.mapValue,e),this.gt(e)):"arrayValue"in t?(this.bt(t.arrayValue,e),this.gt(e)):Qr()}ft(t,e){this.At(e,25),this.Dt(t,e)}Dt(t,e){e.Vt(t)}St(t,e){const n=t.fields||{};this.At(e,55);for(const t of Object.keys(n))this.ft(t,e),this.Tt(n[t],e)}bt(t,e){const n=t.values||[];this.At(e,50);for(const t of n)this.Tt(t,e)}wt(t,e){this.At(e,37),vi.fromName(t).path.forEach((t=>{this.At(e,60),this.Dt(t,e)}))}At(t,e){t.Rt(e)}gt(t){t.Rt(2)}}au.Ct=new au;class cu{constructor(){this.an=new uu}addToCollectionParentIndex(t,e){return this.an.add(e),Ai.resolve()}getCollectionParents(t,e){return Ai.resolve(this.an.getEntries(e))}addFieldIndex(t,e){return Ai.resolve()}deleteFieldIndex(t,e){return Ai.resolve()}deleteAllFieldIndexes(t){return Ai.resolve()}createTargetIndexes(t,e){return Ai.resolve()}getDocumentsMatchingTarget(t,e){return Ai.resolve(null)}getIndexType(t,e){return Ai.resolve(0)}getFieldIndexes(t,e){return Ai.resolve([])}getNextCollectionGroupToUpdate(t){return Ai.resolve(null)}getMinOffset(t,e){return Ai.resolve(bi.min())}getMinOffsetFromCollectionGroup(t,e){return Ai.resolve(bi.min())}updateCollectionGroup(t,e,n){return Ai.resolve()}updateIndexEntries(t,e){return Ai.resolve()}}class uu{constructor(){this.index={}}add(t){const e=t.lastSegment(),n=t.popLast(),s=this.index[e]||new ji(mi.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 ji(mi.comparator)).toArray()}}new Uint8Array(0);class hu{constructor(t,e,n){this.cacheSizeCollectionThreshold=t,this.percentileToCollect=e,this.maximumSequenceNumbersToCollect=n}static withCacheSize(t){return new hu(t,hu.DEFAULT_COLLECTION_PERCENTILE,hu.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)}}hu.DEFAULT_COLLECTION_PERCENTILE=10,hu.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,hu.DEFAULT=new hu(41943040,hu.DEFAULT_COLLECTION_PERCENTILE,hu.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),hu.DISABLED=new hu(-1,0,0);class lu{constructor(t){this.Nn=t}next(){return this.Nn+=2,this.Nn}static Bn(){return new lu(0)}static Ln(){return new lu(-1)}}class du{constructor(){this.changes=new da((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,Eo.newInvalidDocument(t).setReadTime(e))}getEntry(t,e){this.assertNotApplied();const n=this.changes.get(e);return void 0!==n?Ai.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 fu{constructor(t,e){this.overlayedDocument=t,this.mutatedFields=e}}class gu{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.remoteDocumentCache.getEntry(t,e)))).next((t=>(null!==n&&Ga(n.mutation,t,zi.empty(),di.now()),t)))}getDocuments(t,e){return this.remoteDocumentCache.getEntries(t,e).next((e=>this.getLocalViewOfDocuments(t,e,Ia()).next((()=>e))))}getLocalViewOfDocuments(t,e,n=Ia()){const s=va();return this.populateOverlays(t,s,e).next((()=>this.computeViews(t,e,s,n).next((t=>{let e=pa();return t.forEach(((t,n)=>{e=e.insert(t,n.overlayedDocument)})),e}))))}getOverlayedDocuments(t,e){const n=va();return this.populateOverlays(t,n,e).next((()=>this.computeViews(t,e,n,Ia())))}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=ga();const i=Ea(),o=Ea();return e.forEach(((t,e)=>{const o=n.get(e.key);s.has(e.key)&&(void 0===o||o.mutation instanceof Xa)?r=r.insert(e.key,e):void 0!==o?(i.set(e.key,o.mutation.getFieldMask()),Ga(o.mutation,e,o.mutation.getFieldMask(),di.now())):i.set(e.key,zi.empty())})),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 fu(e,null!==(n=i.get(t))&&void 0!==n?n:null))})),o)))}recalculateAndSaveOverlays(t,e){const n=Ea();let s=new Vi(((t,e)=>t-e)),r=Ia();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)||zi.empty();o=r.applyToLocalView(i,o),n.set(t,o);const a=(s.get(r.batchId)||Ia()).add(t);s=s.insert(r.batchId,a)}))})).next((()=>{const i=[],o=s.getReverseIterator();for(;o.hasNext();){const s=o.getNext(),a=s.key,c=s.value,u=wa();c.forEach((t=>{if(!r.has(t)){const s=Ka(e.get(t),n.get(t));null!==s&&u.set(t,s),r=r.add(t)}})),i.push(this.documentOverlayCache.saveOverlays(t,a,u))}return Ai.waitFor(i)})).next((()=>n))}recalculateAndSaveOverlaysForDocumentKeys(t,e){return this.remoteDocumentCache.getEntries(t,e).next((e=>this.recalculateAndSaveOverlays(t,e)))}getDocumentsMatchingQuery(t,e,n,s){return function(t){return vi.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}(e)?this.getDocumentsMatchingDocumentQuery(t,e.path):ta(e)?this.getDocumentsMatchingCollectionGroupQuery(t,e,n,s):this.getDocumentsMatchingCollectionQuery(t,e,n,s)}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):Ai.resolve(va());let o=-1,a=r;return i.next((e=>Ai.forEach(e,((e,n)=>(o<n.largestBatchId&&(o=n.largestBatchId),r.get(e)?Ai.resolve():this.remoteDocumentCache.getEntry(t,e).next((t=>{a=a.insert(e,t)}))))).next((()=>this.populateOverlays(t,e,r))).next((()=>this.computeViews(t,a,e,Ia()))).next((t=>({batchId:o,changes:ya(t)})))))}))}getDocumentsMatchingDocumentQuery(t,e){return this.getDocument(t,new vi(e)).next((t=>{let e=pa();return t.isFoundDocument()&&(e=e.insert(t.key,t)),e}))}getDocumentsMatchingCollectionGroupQuery(t,e,n,s){const r=e.collectionGroup;let i=pa();return this.indexManager.getCollectionParents(t,r).next((o=>Ai.forEach(o,(o=>{const a=function(t,e){return new Qo(e,null,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(e,o.child(r));return this.getDocumentsMatchingCollectionQuery(t,a,n,s).next((t=>{t.forEach(((t,e)=>{i=i.insert(t,e)}))}))})).next((()=>i))))}getDocumentsMatchingCollectionQuery(t,e,n,s){let r;return this.documentOverlayCache.getOverlaysForCollection(t,e.path,n.largestBatchId).next((i=>(r=i,this.remoteDocumentCache.getDocumentsMatchingQuery(t,e,n,r,s)))).next((t=>{r.forEach(((e,n)=>{const s=n.getKey();null===t.get(s)&&(t=t.insert(s,Eo.newInvalidDocument(s)))}));let n=pa();return t.forEach(((t,s)=>{const i=r.get(t);void 0!==i&&Ga(i.mutation,s,zi.empty(),di.now()),ca(e,s)&&(n=n.insert(t,s))})),n}))}}class mu{constructor(t){this.serializer=t,this.lr=new Map,this.hr=new Map}getBundleMetadata(t,e){return Ai.resolve(this.lr.get(e))}saveBundleMetadata(t,e){return this.lr.set(e.id,function(t){return{id:t.id,version:t.version,createTime:Mc(t.createTime)}}(e)),Ai.resolve()}getNamedQuery(t,e){return Ai.resolve(this.hr.get(e))}saveNamedQuery(t,e){return this.hr.set(e.name,function(t){return{name:t.name,query:ou(t.bundledQuery),readTime:Mc(t.readTime)}}(e)),Ai.resolve()}}class pu{constructor(){this.overlays=new Vi(vi.comparator),this.Pr=new Map}getOverlay(t,e){return Ai.resolve(this.overlays.get(e))}getOverlays(t,e){const n=va();return Ai.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.It(t,e,s)})),Ai.resolve()}removeOverlaysForBatchId(t,e,n){const s=this.Pr.get(n);return void 0!==s&&(s.forEach((t=>this.overlays=this.overlays.remove(t))),this.Pr.delete(n)),Ai.resolve()}getOverlaysForCollection(t,e,n){const s=va(),r=e.length+1,i=new vi(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 Ai.resolve(s)}getOverlaysForCollectionGroup(t,e,n,s){let r=new Vi(((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=va(),r=r.insert(t.largestBatchId,e)),e.set(t.getKey(),t)}}const o=va(),a=r.getIterator();for(;a.hasNext()&&(a.getNext().value.forEach(((t,e)=>o.set(t,e))),!(o.size()>=s)););return Ai.resolve(o)}It(t,e,n){const s=this.overlays.get(n.key);if(null!==s){const t=this.Pr.get(s.largestBatchId).delete(n.key);this.Pr.set(s.largestBatchId,t)}this.overlays=this.overlays.insert(n.key,new ic(e,n));let r=this.Pr.get(e);void 0===r&&(r=Ia(),this.Pr.set(e,r)),this.Pr.set(e,r.add(n.key))}}class yu{constructor(){this.Ir=new ji(vu.dr),this.Tr=new ji(vu.Er)}isEmpty(){return this.Ir.isEmpty()}addReference(t,e){const n=new vu(t,e);this.Ir=this.Ir.add(n),this.Tr=this.Tr.add(n)}Ar(t,e){t.forEach((t=>this.addReference(t,e)))}removeReference(t,e){this.Rr(new vu(t,e))}Vr(t,e){t.forEach((t=>this.removeReference(t,e)))}mr(t){const e=new vi(new mi([])),n=new vu(e,t),s=new vu(e,t+1),r=[];return this.Tr.forEachInRange([n,s],(t=>{this.Rr(t),r.push(t.key)})),r}gr(){this.Ir.forEach((t=>this.Rr(t)))}Rr(t){this.Ir=this.Ir.delete(t),this.Tr=this.Tr.delete(t)}pr(t){const e=new vi(new mi([])),n=new vu(e,t),s=new vu(e,t+1);let r=Ia();return this.Tr.forEachInRange([n,s],(t=>{r=r.add(t.key)})),r}containsKey(t){const e=new vu(t,0),n=this.Ir.firstAfterOrEqual(e);return null!==n&&t.isEqual(n.key)}}class vu{constructor(t,e){this.key=t,this.yr=e}static dr(t,e){return vi.comparator(t.key,e.key)||hi(t.yr,e.yr)}static Er(t,e){return hi(t.yr,e.yr)||vi.comparator(t.key,e.key)}}class wu{constructor(t,e){this.indexManager=t,this.referenceDelegate=e,this.mutationQueue=[],this.wr=1,this.Sr=new ji(vu.dr)}checkEmpty(t){return Ai.resolve(0===this.mutationQueue.length)}addMutationBatch(t,e,n,s){const r=this.wr;this.wr++,this.mutationQueue.length>0&&this.mutationQueue[this.mutationQueue.length-1];const i=new sc(r,e,n,s);this.mutationQueue.push(i);for(const e of s)this.Sr=this.Sr.add(new vu(e.key,r)),this.indexManager.addToCollectionParentIndex(t,e.key.path.popLast());return Ai.resolve(i)}lookupMutationBatch(t,e){return Ai.resolve(this.br(e))}getNextMutationBatchAfterBatchId(t,e){const n=e+1,s=this.Dr(n),r=s<0?0:s;return Ai.resolve(this.mutationQueue.length>r?this.mutationQueue[r]:null)}getHighestUnacknowledgedBatchId(){return Ai.resolve(0===this.mutationQueue.length?-1:this.wr-1)}getAllMutationBatches(t){return Ai.resolve(this.mutationQueue.slice())}getAllMutationBatchesAffectingDocumentKey(t,e){const n=new vu(e,0),s=new vu(e,Number.POSITIVE_INFINITY),r=[];return this.Sr.forEachInRange([n,s],(t=>{const e=this.br(t.yr);r.push(e)})),Ai.resolve(r)}getAllMutationBatchesAffectingDocumentKeys(t,e){let n=new ji(hi);return e.forEach((t=>{const e=new vu(t,0),s=new vu(t,Number.POSITIVE_INFINITY);this.Sr.forEachInRange([e,s],(t=>{n=n.add(t.yr)}))})),Ai.resolve(this.Cr(n))}getAllMutationBatchesAffectingQuery(t,e){const n=e.path,s=n.length+1;let r=n;vi.isDocumentKey(r)||(r=r.child(""));const i=new vu(new vi(r),0);let o=new ji(hi);return this.Sr.forEachWhile((t=>{const e=t.key.path;return!!n.isPrefixOf(e)&&(e.length===s&&(o=o.add(t.yr)),!0)}),i),Ai.resolve(this.Cr(o))}Cr(t){const e=[];return t.forEach((t=>{const n=this.br(t);null!==n&&e.push(n)})),e}removeMutationBatch(t,e){Wr(0===this.vr(e.batchId,"removed")),this.mutationQueue.shift();let n=this.Sr;return Ai.forEach(e.mutations,(s=>{const r=new vu(s.key,e.batchId);return n=n.delete(r),this.referenceDelegate.markPotentiallyOrphaned(t,s.key)})).next((()=>{this.Sr=n}))}xn(t){}containsKey(t,e){const n=new vu(e,0),s=this.Sr.firstAfterOrEqual(n);return Ai.resolve(e.isEqual(s&&s.key))}performConsistencyCheck(t){return this.mutationQueue.length,Ai.resolve()}vr(t,e){return this.Dr(t)}Dr(t){return 0===this.mutationQueue.length?0:t-this.mutationQueue[0].batchId}br(t){const e=this.Dr(t);return e<0||e>=this.mutationQueue.length?null:this.mutationQueue[e]}}class Eu{constructor(t){this.Fr=t,this.docs=new Vi(vi.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.Fr(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 Ai.resolve(n?n.document.mutableCopy():Eo.newInvalidDocument(e))}getEntries(t,e){let n=ga();return e.forEach((t=>{const e=this.docs.get(t);n=n.insert(t,e?e.document.mutableCopy():Eo.newInvalidDocument(t))})),Ai.resolve(n)}getDocumentsMatchingQuery(t,e,n,s){let r=ga();const i=e.path,o=new vi(i.child("")),a=this.docs.getIteratorFrom(o);for(;a.hasNext();){const{key:t,value:{document:o}}=a.getNext();if(!i.isPrefixOf(t.path))break;t.path.length>i.length+1||Ii(_i(o),n)<=0||(s.has(o.key)||ca(e,o))&&(r=r.insert(o.key,o.mutableCopy()))}return Ai.resolve(r)}getAllFromCollectionGroup(t,e,n,s){Qr()}Mr(t,e){return Ai.forEach(this.docs,(t=>e(t)))}newChangeBuffer(t){return new _u(this)}getSize(t){return Ai.resolve(this.size)}}class _u extends du{constructor(t){super(),this.ur=t}applyChanges(t){const e=[];return this.changes.forEach(((n,s)=>{s.isValidDocument()?e.push(this.ur.addEntry(t,s)):this.ur.removeEntry(n)})),Ai.waitFor(e)}getFromCache(t,e){return this.ur.getEntry(t,e)}getAllFromCache(t,e){return this.ur.getEntries(t,e)}}class bu{constructor(t){this.persistence=t,this.Or=new da((t=>Ko(t)),Ho),this.lastRemoteSnapshotVersion=fi.min(),this.highestTargetId=0,this.Nr=0,this.Br=new yu,this.targetCount=0,this.Lr=lu.Bn()}forEachTarget(t,e){return this.Or.forEach(((t,n)=>e(n))),Ai.resolve()}getLastRemoteSnapshotVersion(t){return Ai.resolve(this.lastRemoteSnapshotVersion)}getHighestSequenceNumber(t){return Ai.resolve(this.Nr)}allocateTargetId(t){return this.highestTargetId=this.Lr.next(),Ai.resolve(this.highestTargetId)}setTargetsMetadata(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.Nr&&(this.Nr=e),Ai.resolve()}Qn(t){this.Or.set(t.target,t);const e=t.targetId;e>this.highestTargetId&&(this.Lr=new lu(e),this.highestTargetId=e),t.sequenceNumber>this.Nr&&(this.Nr=t.sequenceNumber)}addTargetData(t,e){return this.Qn(e),this.targetCount+=1,Ai.resolve()}updateTargetData(t,e){return this.Qn(e),Ai.resolve()}removeTargetData(t,e){return this.Or.delete(e.target),this.Br.mr(e.targetId),this.targetCount-=1,Ai.resolve()}removeTargets(t,e,n){let s=0;const r=[];return this.Or.forEach(((i,o)=>{o.sequenceNumber<=e&&null===n.get(o.targetId)&&(this.Or.delete(i),r.push(this.removeMatchingKeysForTargetId(t,o.targetId)),s++)})),Ai.waitFor(r).next((()=>s))}getTargetCount(t){return Ai.resolve(this.targetCount)}getTargetData(t,e){const n=this.Or.get(e)||null;return Ai.resolve(n)}addMatchingKeys(t,e,n){return this.Br.Ar(e,n),Ai.resolve()}removeMatchingKeys(t,e,n){this.Br.Vr(e,n);const s=this.persistence.referenceDelegate,r=[];return s&&e.forEach((e=>{r.push(s.markPotentiallyOrphaned(t,e))})),Ai.waitFor(r)}removeMatchingKeysForTargetId(t,e){return this.Br.mr(e),Ai.resolve()}getMatchingKeysForTargetId(t,e){const n=this.Br.pr(e);return Ai.resolve(n)}containsKey(t,e){return Ai.resolve(this.Br.containsKey(e))}}class Iu{constructor(t,e){this.kr={},this.overlays={},this.qr=new ki(0),this.Qr=!1,this.Qr=!0,this.referenceDelegate=t(this),this.Kr=new bu(this),this.indexManager=new cu,this.remoteDocumentCache=function(t){return new Eu(t)}((t=>this.referenceDelegate.$r(t))),this.serializer=new iu(e),this.Ur=new mu(this.serializer)}start(){return Promise.resolve()}shutdown(){return this.Qr=!1,Promise.resolve()}get started(){return this.Qr}setDatabaseDeletedListener(){}setNetworkEnabled(){}getIndexManager(t){return this.indexManager}getDocumentOverlayCache(t){let e=this.overlays[t.toKey()];return e||(e=new pu,this.overlays[t.toKey()]=e),e}getMutationQueue(t,e){let n=this.kr[t.toKey()];return n||(n=new wu(e,this.referenceDelegate),this.kr[t.toKey()]=n),n}getTargetCache(){return this.Kr}getRemoteDocumentCache(){return this.remoteDocumentCache}getBundleCache(){return this.Ur}runTransaction(t,e,n){zr("MemoryPersistence","Starting transaction:",t);const s=new Tu(this.qr.next());return this.referenceDelegate.Wr(),n(s).next((t=>this.referenceDelegate.Gr(s).next((()=>t)))).toPromise().then((t=>(s.raiseOnCommittedEvent(),t)))}zr(t,e){return Ai.or(Object.values(this.kr).map((n=>()=>n.containsKey(t,e))))}}class Tu extends Si{constructor(t){super(),this.currentSequenceNumber=t}}class Su{constructor(t){this.persistence=t,this.jr=new yu,this.Hr=null}static Jr(t){return new Su(t)}get Yr(){if(this.Hr)return this.Hr;throw Qr()}addReference(t,e,n){return this.jr.addReference(n,e),this.Yr.delete(n.toString()),Ai.resolve()}removeReference(t,e,n){return this.jr.removeReference(n,e),this.Yr.add(n.toString()),Ai.resolve()}markPotentiallyOrphaned(t,e){return this.Yr.add(e.toString()),Ai.resolve()}removeTarget(t,e){this.jr.mr(e.targetId).forEach((t=>this.Yr.add(t.toString())));const n=this.persistence.getTargetCache();return n.getMatchingKeysForTargetId(t,e.targetId).next((t=>{t.forEach((t=>this.Yr.add(t.toString())))})).next((()=>n.removeTargetData(t,e)))}Wr(){this.Hr=new Set}Gr(t){const e=this.persistence.getRemoteDocumentCache().newChangeBuffer();return Ai.forEach(this.Yr,(n=>{const s=vi.fromPath(n);return this.Zr(t,s).next((t=>{t||e.removeEntry(s,fi.min())}))})).next((()=>(this.Hr=null,e.apply(t))))}updateLimboDocument(t,e){return this.Zr(t,e).next((t=>{t?this.Yr.delete(e.toString()):this.Yr.add(e.toString())}))}$r(t){return 0}Zr(t,e){return Ai.or([()=>Ai.resolve(this.jr.containsKey(e)),()=>this.persistence.getTargetCache().containsKey(t,e),()=>this.persistence.zr(t,e)])}}class Cu{constructor(t,e,n,s){this.targetId=t,this.fromCache=e,this.Qi=n,this.Ki=s}static $i(t,e){let n=Ia(),s=Ia();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 Cu(t,e.fromCache,n,s)}}class Au{constructor(){this._documentReadCount=0}get documentReadCount(){return this._documentReadCount}incrementDocumentReadCount(t){this._documentReadCount+=t}}class Du{constructor(){this.Ui=!1,this.Wi=!1,this.Gi=100,this.zi=8}initialize(t,e){this.ji=t,this.indexManager=e,this.Ui=!0}getDocumentsMatchingQuery(t,e,n,s){const r={result:null};return this.Hi(t,e).next((t=>{r.result=t})).next((()=>{if(!r.result)return this.Ji(t,e,s,n).next((t=>{r.result=t}))})).next((()=>{if(r.result)return;const n=new Au;return this.Yi(t,e,n).next((s=>{if(r.result=s,this.Wi)return this.Zi(t,e,n,s.size)}))})).next((()=>r.result))}Zi(t,e,n,s){return n.documentReadCount<this.Gi?($r()<=I.DEBUG&&zr("QueryEngine","SDK will not create cache indexes for query:",aa(e),"since it only creates cache indexes for collection contains","more than or equal to",this.Gi,"documents"),Ai.resolve()):($r()<=I.DEBUG&&zr("QueryEngine","Query:",aa(e),"scans",n.documentReadCount,"local documents and returns",s,"documents as results."),n.documentReadCount>this.zi*s?($r()<=I.DEBUG&&zr("QueryEngine","The SDK decides to create cache indexes for query:",aa(e),"as using cache indexes may help improve performance."),this.indexManager.createTargetIndexes(t,na(e))):Ai.resolve())}Hi(t,e){if(Xo(e))return Ai.resolve(null);let n=na(e);return this.indexManager.getIndexType(t,n).next((s=>0===s?null:(null!==e.limit&&1===s&&(e=ra(e,null,"F"),n=na(e)),this.indexManager.getDocumentsMatchingTarget(t,n).next((s=>{const r=Ia(...s);return this.ji.getDocuments(t,r).next((s=>this.indexManager.getMinOffset(t,n).next((n=>{const i=this.Xi(e,s);return this.es(e,i,r,n.readTime)?this.Hi(t,ra(e,null,"F")):this.ts(t,i,e,n)}))))})))))}Ji(t,e,n,s){return Xo(e)||s.isEqual(fi.min())?Ai.resolve(null):this.ji.getDocuments(t,n).next((r=>{const i=this.Xi(e,r);return this.es(e,i,n,s)?Ai.resolve(null):($r()<=I.DEBUG&&zr("QueryEngine","Re-using previous result from %s to execute query: %s",s.toString(),aa(e)),this.ts(t,i,e,Ei(s,-1)).next((t=>t)))}))}Xi(t,e){let n=new ji(ha(t));return e.forEach(((e,s)=>{ca(t,s)&&(n=n.add(s))})),n}es(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)}Yi(t,e,n){return $r()<=I.DEBUG&&zr("QueryEngine","Using full collection scan to execute query:",aa(e)),this.ji.getDocumentsMatchingQuery(t,e,bi.min(),n)}ts(t,e,n,s){return this.ji.getDocumentsMatchingQuery(t,n,s).next((t=>(e.forEach((e=>{t=t.insert(e.key,e)})),t)))}}class ku{constructor(t,e,n,s){this.persistence=t,this.ns=e,this.serializer=s,this.rs=new Vi(hi),this.ss=new da((t=>Ko(t)),Ho),this.os=new Map,this._s=t.getRemoteDocumentCache(),this.Kr=t.getTargetCache(),this.Ur=t.getBundleCache(),this.us(n)}us(t){this.documentOverlayCache=this.persistence.getDocumentOverlayCache(t),this.indexManager=this.persistence.getIndexManager(t),this.mutationQueue=this.persistence.getMutationQueue(t,this.indexManager),this.localDocuments=new gu(this._s,this.mutationQueue,this.documentOverlayCache,this.indexManager),this._s.setIndexManager(this.indexManager),this.ns.initialize(this.localDocuments,this.indexManager)}collectGarbage(t){return this.persistence.runTransaction("Collect garbage","readwrite-primary",(e=>t.collect(e,this.rs)))}}function Nu(t,e,n,s){return new ku(t,e,n,s)}async function Ru(t,e){const n=Yr(t);return await n.persistence.runTransaction("Handle user change","readonly",(t=>{let s;return n.mutationQueue.getAllMutationBatches(t).next((r=>(s=r,n.us(e),n.mutationQueue.getAllMutationBatches(t)))).next((e=>{const r=[],i=[];let o=Ia();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=>({cs:t,removedBatchIds:r,addedBatchIds:i})))}))}))}function Lu(t){const e=Yr(t);return e.persistence.runTransaction("Get last remote snapshot version","readonly",(t=>e.Kr.getLastRemoteSnapshotVersion(t)))}function xu(t,e,n){let s=Ia(),r=Ia();return n.forEach((t=>s=s.add(t))),e.getEntries(t,s).next((t=>{let s=ga();return n.forEach(((n,i)=>{const o=t.get(n);i.isFoundDocument()!==o.isFoundDocument()&&(r=r.add(n)),i.isNoDocument()&&i.version.isEqual(fi.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)):zr("LocalStore","Ignoring outdated watch update for ",n,". Current version:",o.version," Watch version:",i.version)})),{ls:s,hs:r}}))}function Ou(t,e){const n=Yr(t);return n.persistence.runTransaction("Get next mutation batch","readonly",(t=>(void 0===e&&(e=-1),n.mutationQueue.getNextMutationBatchAfterBatchId(t,e))))}function Mu(t,e){const n=Yr(t);return n.persistence.runTransaction("Allocate target","readwrite",(t=>{let s;return n.Kr.getTargetData(t,e).next((r=>r?(s=r,Ai.resolve(s)):n.Kr.allocateTargetId(t).next((r=>(s=new ru(e,r,"TargetPurposeListen",t.currentSequenceNumber),n.Kr.addTargetData(t,s).next((()=>s)))))))})).then((t=>{const s=n.rs.get(t.targetId);return(null===s||t.snapshotVersion.compareTo(s.snapshotVersion)>0)&&(n.rs=n.rs.insert(t.targetId,t),n.ss.set(e,t.targetId)),t}))}async function Pu(t,e,n){const s=Yr(t),r=s.rs.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(!Di(t))throw t;zr("LocalStore",`Failed to update sequence numbers for target ${e}: ${t}`)}s.rs=s.rs.remove(e),s.ss.delete(r.target)}function Fu(t,e,n){const s=Yr(t);let r=fi.min(),i=Ia();return s.persistence.runTransaction("Execute query","readwrite",(t=>function(t,e,n){const s=Yr(t),r=s.ss.get(n);return void 0!==r?Ai.resolve(s.rs.get(r)):s.Kr.getTargetData(e,n)}(s,t,na(e)).next((e=>{if(e)return r=e.lastLimboFreeSnapshotVersion,s.Kr.getMatchingKeysForTargetId(t,e.targetId).next((t=>{i=t}))})).next((()=>s.ns.getDocumentsMatchingQuery(t,e,n?r:fi.min(),n?i:Ia()))).next((t=>(Bu(s,ua(e),t),{documents:t,Ps:i})))))}function Bu(t,e,n){let s=t.os.get(e)||fi.min();n.forEach(((t,e)=>{e.readTime.compareTo(s)>0&&(s=e.readTime)})),t.os.set(e,s)}class Vu{constructor(){this.activeTargetIds=Sa()}Rs(t){this.activeTargetIds=this.activeTargetIds.add(t)}Vs(t){this.activeTargetIds=this.activeTargetIds.delete(t)}As(){const t={activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()};return JSON.stringify(t)}}class Uu{constructor(){this.ro=new Vu,this.io={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}addPendingMutation(t){}updateMutationState(t,e,n){}addLocalQueryTarget(t){return this.ro.Rs(t),this.io[t]||"not-current"}updateQueryState(t,e,n){this.io[t]=e}removeLocalQueryTarget(t){this.ro.Vs(t)}isLocalQueryTarget(t){return this.ro.activeTargetIds.has(t)}clearQueryState(t){delete this.io[t]}getAllActiveQueryTargets(){return this.ro.activeTargetIds}isActiveQueryTarget(t){return this.ro.activeTargetIds.has(t)}start(){return this.ro=new Vu,Promise.resolve()}handleUserChange(t,e,n){}setOnlineState(t){}shutdown(){}writeSequenceNumber(t){}notifyBundleLoaded(t){}}class qu{so(t){}shutdown(){}}class ju{constructor(){this.oo=()=>this._o(),this.ao=()=>this.uo(),this.co=[],this.lo()}so(t){this.co.push(t)}shutdown(){window.removeEventListener("online",this.oo),window.removeEventListener("offline",this.ao)}lo(){window.addEventListener("online",this.oo),window.addEventListener("offline",this.ao)}_o(){zr("ConnectivityMonitor","Network connectivity changed: AVAILABLE");for(const t of this.co)t(0)}uo(){zr("ConnectivityMonitor","Network connectivity changed: UNAVAILABLE");for(const t of this.co)t(1)}static C(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener}}let $u=null;function zu(){return null===$u?$u=268435456+Math.round(2147483648*Math.random()):$u++,"0x"+$u.toString(16)}const Ku={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery"};class Hu{constructor(t){this.ho=t.ho,this.Po=t.Po}Io(t){this.To=t}Eo(t){this.Ao=t}onMessage(t){this.Ro=t}close(){this.Po()}send(t){this.ho(t)}Vo(){this.To()}mo(t){this.Ao(t)}fo(t){this.Ro(t)}}const Gu="WebChannelConnection";class Qu extends class{constructor(t){this.databaseInfo=t,this.databaseId=t.databaseId;const e=t.ssl?"https":"http",n=encodeURIComponent(this.databaseId.projectId),s=encodeURIComponent(this.databaseId.database);this.po=e+"://"+t.host,this.yo=`projects/${n}/databases/${s}`,this.wo="(default)"===this.databaseId.database?`project_id=${n}`:`project_id=${n}&database_id=${s}`}get So(){return!1}bo(t,e,n,s,r){const i=zu(),o=this.Do(t,e);zr("RestConnection",`Sending RPC '${t}' ${i}:`,o,n);const a={"google-cloud-resource-prefix":this.yo,"x-goog-request-params":this.wo};return this.Co(a,s,r),this.vo(t,o,a,n).then((e=>(zr("RestConnection",`Received RPC '${t}' ${i}: `,e),e)),(e=>{throw Hr("RestConnection",`RPC '${t}' ${i} failed with error: `,e,"url: ",o,"request:",n),e}))}Fo(t,e,n,s,r,i){return this.bo(t,e,n,s,r)}Co(t,e,n){t["X-Goog-Api-Client"]="gl-js/ fire/"+qr,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))}Do(t,e){const n=Ku[t];return`${this.po}/v1/${e}:${n}`}}{constructor(t){super(t),this.forceLongPolling=t.forceLongPolling,this.autoDetectLongPolling=t.autoDetectLongPolling,this.useFetchStreams=t.useFetchStreams,this.longPollingOptions=t.longPollingOptions}vo(t,e,n,s){const r=zu();return new Promise(((i,o)=>{const a=new Pr;a.setWithCredentials(!0),a.listenOnce(Lr.COMPLETE,(()=>{try{switch(a.getLastErrorCode()){case Rr.NO_ERROR:const e=a.getResponseJson();zr(Gu,`XHR for RPC '${t}' ${r} received:`,JSON.stringify(e)),i(e);break;case Rr.TIMEOUT:zr(Gu,`RPC '${t}' ${r} timed out`),o(new Jr(Xr.DEADLINE_EXCEEDED,"Request time out"));break;case Rr.HTTP_ERROR:const n=a.getStatus();if(zr(Gu,`RPC '${t}' ${r} failed with status:`,n,"response text:",a.getResponseText()),n>0){let t=a.getResponseJson();Array.isArray(t)&&(t=t[0]);const e=null==t?void 0:t.error;if(e&&e.status&&e.message){const t=function(t){const e=t.toLowerCase().replace(/_/g,"-");return Object.values(Xr).indexOf(e)>=0?e:Xr.UNKNOWN}(e.status);o(new Jr(t,e.message))}else o(new Jr(Xr.UNKNOWN,"Server responded with status "+a.getStatus()))}else o(new Jr(Xr.UNAVAILABLE,"Connection failed."));break;default:Qr()}}finally{zr(Gu,`RPC '${t}' ${r} completed.`)}}));const c=JSON.stringify(s);zr(Gu,`RPC '${t}' ${r} sending request:`,s),a.send(e,"POST",c,n,15)}))}Mo(t,e,n){const s=zu(),r=[this.po,"/","google.firestore.v1.Firestore","/",t,"/channel"],i=kr(),o=Nr(),a={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},c=this.longPollingOptions.timeoutSeconds;void 0!==c&&(a.longPollingTimeout=Math.round(1e3*c)),this.useFetchStreams&&(a.useFetchStreams=!0),this.Co(a.initMessageHeaders,e,n),a.encodeInitMessageHeaders=!0;const u=r.join("");zr(Gu,`Creating RPC '${t}' stream ${s}: ${u}`,a);const h=i.createWebChannel(u,a);let l=!1,d=!1;const f=new Hu({ho:e=>{d?zr(Gu,`Not sending because RPC '${t}' stream ${s} is closed:`,e):(l||(zr(Gu,`Opening RPC '${t}' stream ${s} transport.`),h.open(),l=!0),zr(Gu,`RPC '${t}' stream ${s} sending:`,e),h.send(e))},Po:()=>h.close()}),g=(t,e,n)=>{t.listen(e,(t=>{try{n(t)}catch(t){setTimeout((()=>{throw t}),0)}}))};return g(h,Mr.EventType.OPEN,(()=>{d||zr(Gu,`RPC '${t}' stream ${s} transport opened.`)})),g(h,Mr.EventType.CLOSE,(()=>{d||(d=!0,zr(Gu,`RPC '${t}' stream ${s} transport closed`),f.mo())})),g(h,Mr.EventType.ERROR,(e=>{d||(d=!0,Hr(Gu,`RPC '${t}' stream ${s} transport errored:`,e),f.mo(new Jr(Xr.UNAVAILABLE,"The operation could not be completed")))})),g(h,Mr.EventType.MESSAGE,(e=>{var n;if(!d){const r=e.data[0];Wr(!!r);const i=r,o=i.error||(null===(n=i[0])||void 0===n?void 0:n.error);if(o){zr(Gu,`RPC '${t}' stream ${s} received error:`,o);const e=o.status;let n=function(t){const e=ac[t];if(void 0!==e)return hc(e)}(e),r=o.message;void 0===n&&(n=Xr.INTERNAL,r="Unknown error status: "+e+" with message "+o.message),d=!0,f.mo(new Jr(n,r)),h.close()}else zr(Gu,`RPC '${t}' stream ${s} received:`,r),f.fo(r)}})),g(o,xr.STAT_EVENT,(e=>{e.stat===Or.PROXY?zr(Gu,`RPC '${t}' stream ${s} detected buffering proxy`):e.stat===Or.NOPROXY&&zr(Gu,`RPC '${t}' stream ${s} detected no buffering proxy`)})),setTimeout((()=>{f.Vo()}),0),f}}function Wu(){return"undefined"!=typeof document?document:null}function Yu(t){return new Nc(t,!0)}class Xu{constructor(t,e,n=1e3,s=1.5,r=6e4){this._i=t,this.timerId=e,this.xo=n,this.Oo=s,this.No=r,this.Bo=0,this.Lo=null,this.ko=Date.now(),this.reset()}reset(){this.Bo=0}qo(){this.Bo=this.No}Qo(t){this.cancel();const e=Math.floor(this.Bo+this.Ko()),n=Math.max(0,Date.now()-this.ko),s=Math.max(0,e-n);s>0&&zr("ExponentialBackoff",`Backing off for ${s} ms (base delay: ${this.Bo} ms, delay with jitter: ${e} ms, last attempt: ${n} ms ago)`),this.Lo=this._i.enqueueAfterDelay(this.timerId,s,(()=>(this.ko=Date.now(),t()))),this.Bo*=this.Oo,this.Bo<this.xo&&(this.Bo=this.xo),this.Bo>this.No&&(this.Bo=this.No)}$o(){null!==this.Lo&&(this.Lo.skipDelay(),this.Lo=null)}cancel(){null!==this.Lo&&(this.Lo.cancel(),this.Lo=null)}Ko(){return(Math.random()-.5)*this.Bo}}class Ju{constructor(t,e,n,s,r,i,o,a){this._i=t,this.Uo=n,this.Wo=s,this.connection=r,this.authCredentialsProvider=i,this.appCheckCredentialsProvider=o,this.listener=a,this.state=0,this.Go=0,this.zo=null,this.jo=null,this.stream=null,this.Ho=new Xu(t,e)}Jo(){return 1===this.state||5===this.state||this.Yo()}Yo(){return 2===this.state||3===this.state}start(){4!==this.state?this.auth():this.Zo()}async stop(){this.Jo()&&await this.close(0)}Xo(){this.state=0,this.Ho.reset()}e_(){this.Yo()&&null===this.zo&&(this.zo=this._i.enqueueAfterDelay(this.Uo,6e4,(()=>this.t_())))}n_(t){this.r_(),this.stream.send(t)}async t_(){if(this.Yo())return this.close(0)}r_(){this.zo&&(this.zo.cancel(),this.zo=null)}i_(){this.jo&&(this.jo.cancel(),this.jo=null)}async close(t,e){this.r_(),this.i_(),this.Ho.cancel(),this.Go++,4!==t?this.Ho.reset():e&&e.code===Xr.RESOURCE_EXHAUSTED?(Kr(e.toString()),Kr("Using maximum backoff delay to prevent overloading the backend."),this.Ho.qo()):e&&e.code===Xr.UNAUTHENTICATED&&3!==this.state&&(this.authCredentialsProvider.invalidateToken(),this.appCheckCredentialsProvider.invalidateToken()),null!==this.stream&&(this.s_(),this.stream.close(),this.stream=null),this.state=t,await this.listener.Eo(e)}s_(){}auth(){this.state=1;const t=this.o_(this.Go),e=this.Go;Promise.all([this.authCredentialsProvider.getToken(),this.appCheckCredentialsProvider.getToken()]).then((([t,n])=>{this.Go===e&&this.__(t,n)}),(e=>{t((()=>{const t=new Jr(Xr.UNKNOWN,"Fetching auth token failed: "+e.message);return this.a_(t)}))}))}__(t,e){const n=this.o_(this.Go);this.stream=this.u_(t,e),this.stream.Io((()=>{n((()=>(this.state=2,this.jo=this._i.enqueueAfterDelay(this.Wo,1e4,(()=>(this.Yo()&&(this.state=3),Promise.resolve()))),this.listener.Io())))})),this.stream.Eo((t=>{n((()=>this.a_(t)))})),this.stream.onMessage((t=>{n((()=>this.onMessage(t)))}))}Zo(){this.state=5,this.Ho.Qo((async()=>{this.state=0,this.start()}))}a_(t){return zr("PersistentStream",`close with error: ${t}`),this.stream=null,this.close(4,t)}o_(t){return e=>{this._i.enqueueAndForget((()=>this.Go===t?e():(zr("PersistentStream","stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())))}}}class Zu extends Ju{constructor(t,e,n,s,r,i){super(t,"listen_stream_connection_backoff","listen_stream_idle","health_check_timeout",e,n,s,i),this.serializer=r}u_(t,e){return this.connection.Mo("Listen",t,e)}onMessage(t){this.Ho.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:Qr()}(e.targetChange.targetChangeType||"NO_CHANGE"),r=e.targetChange.targetIds||[],i=function(t,e){return t.useProto3Json?(Wr(void 0===e||"string"==typeof e),Hi.fromBase64String(e||"")):(Wr(void 0===e||e instanceof Uint8Array),Hi.fromUint8Array(e||new Uint8Array))}(t,e.targetChange.resumeToken),o=e.targetChange.cause,a=o&&function(t){const e=void 0===t.code?Xr.UNKNOWN:hc(t.code);return new Jr(e,t.message||"")}(o);n=new bc(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=Vc(t,s.document.name),i=Mc(s.document.updateTime),o=s.document.createTime?Mc(s.document.createTime):fi.min(),a=new vo({mapValue:{fields:s.document.fields}}),c=Eo.newFoundDocument(r,i,o,a),u=s.targetIds||[],h=s.removedTargetIds||[];n=new Ec(u,h,c.key,c)}else if("documentDelete"in e){e.documentDelete;const s=e.documentDelete;s.document;const r=Vc(t,s.document),i=s.readTime?Mc(s.readTime):fi.min(),o=Eo.newNoDocument(r,i),a=s.removedTargetIds||[];n=new Ec([],a,o.key,o)}else if("documentRemove"in e){e.documentRemove;const s=e.documentRemove;s.document;const r=Vc(t,s.document),i=s.removedTargetIds||[];n=new Ec([],i,r,null)}else{if(!("filter"in e))return Qr();{e.filter;const t=e.filter;t.targetId;const{count:s=0,unchangedNames:r}=t,i=new oc(s,r),o=t.targetId;n=new _c(o,i)}}return n}(this.serializer,t),n=function(t){if(!("targetChange"in t))return fi.min();const e=t.targetChange;return e.targetIds&&e.targetIds.length?fi.min():e.readTime?Mc(e.readTime):fi.min()}(t);return this.listener.c_(e,n)}l_(t){const e={};e.database=jc(this.serializer),e.addTarget=function(t,e){let n;const s=e.target;if(n=Go(s)?{documents:Hc(t,s)}:{query:Gc(t,s)},n.targetId=e.targetId,e.resumeToken.approximateByteSize()>0){n.resumeToken=xc(t,e.resumeToken);const s=Rc(t,e.expectedCount);null!==s&&(n.expectedCount=s)}else if(e.snapshotVersion.compareTo(fi.min())>0){n.readTime=Lc(t,e.snapshotVersion.toTimestamp());const s=Rc(t,e.expectedCount);null!==s&&(n.expectedCount=s)}return n}(this.serializer,t);const n=function(t,e){const n=function(t){switch(t){case"TargetPurposeListen":return null;case"TargetPurposeExistenceFilterMismatch":return"existence-filter-mismatch";case"TargetPurposeExistenceFilterMismatchBloom":return"existence-filter-mismatch-bloom";case"TargetPurposeLimboResolution":return"limbo-document";default:return Qr()}}(e.purpose);return null==n?null:{"goog-listen-tags":n}}(this.serializer,t);n&&(e.labels=n),this.n_(e)}h_(t){const e={};e.database=jc(this.serializer),e.removeTarget=t,this.n_(e)}}class th extends Ju{constructor(t,e,n,s,r,i){super(t,"write_stream_connection_backoff","write_stream_idle","health_check_timeout",e,n,s,i),this.serializer=r,this.P_=!1}get I_(){return this.P_}start(){this.P_=!1,this.lastStreamToken=void 0,super.start()}s_(){this.P_&&this.d_([])}u_(t,e){return this.connection.Mo("Write",t,e)}onMessage(t){if(Wr(!!t.streamToken),this.lastStreamToken=t.streamToken,this.P_){this.Ho.reset();const e=function(t,e){return t&&t.length>0?(Wr(void 0!==e),t.map((t=>function(t,e){let n=t.updateTime?Mc(t.updateTime):Mc(e);return n.isEqual(fi.min())&&(n=Mc(e)),new qa(n,t.transformResults||[])}(t,e)))):[]}(t.writeResults,t.commitTime),n=Mc(t.commitTime);return this.listener.T_(n,e)}return Wr(!t.writeResults||0===t.writeResults.length),this.P_=!0,this.listener.E_()}A_(){const t={};t.database=jc(this.serializer),this.n_(t)}d_(t){const e={streamToken:this.lastStreamToken,writes:t.map((t=>Kc(this.serializer,t)))};this.n_(e)}}class eh extends class{}{constructor(t,e,n,s){super(),this.authCredentials=t,this.appCheckCredentials=e,this.connection=n,this.serializer=s,this.R_=!1}V_(){if(this.R_)throw new Jr(Xr.FAILED_PRECONDITION,"The client has already been terminated.")}bo(t,e,n){return this.V_(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([s,r])=>this.connection.bo(t,e,n,s,r))).catch((t=>{throw"FirebaseError"===t.name?(t.code===Xr.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Jr(Xr.UNKNOWN,t.toString())}))}Fo(t,e,n,s){return this.V_(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([r,i])=>this.connection.Fo(t,e,n,r,i,s))).catch((t=>{throw"FirebaseError"===t.name?(t.code===Xr.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Jr(Xr.UNKNOWN,t.toString())}))}terminate(){this.R_=!0}}class nh{constructor(t,e){this.asyncQueue=t,this.onlineStateHandler=e,this.state="Unknown",this.f_=0,this.g_=null,this.p_=!0}y_(){0===this.f_&&(this.w_("Unknown"),this.g_=this.asyncQueue.enqueueAfterDelay("online_state_timeout",1e4,(()=>(this.g_=null,this.S_("Backend didn't respond within 10 seconds."),this.w_("Offline"),Promise.resolve()))))}b_(t){"Online"===this.state?this.w_("Unknown"):(this.f_++,this.f_>=1&&(this.D_(),this.S_(`Connection failed 1 times. Most recent error: ${t.toString()}`),this.w_("Offline")))}set(t){this.D_(),this.f_=0,"Online"===t&&(this.p_=!1),this.w_(t)}w_(t){t!==this.state&&(this.state=t,this.onlineStateHandler(t))}S_(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.p_?(Kr(e),this.p_=!1):zr("OnlineStateTracker",e)}D_(){null!==this.g_&&(this.g_.cancel(),this.g_=null)}}class sh{constructor(t,e,n,s,r){this.localStore=t,this.datastore=e,this.asyncQueue=n,this.remoteSyncer={},this.C_=[],this.v_=new Map,this.F_=new Set,this.M_=[],this.x_=r,this.x_.so((t=>{n.enqueueAndForget((async()=>{dh(this)&&(zr("RemoteStore","Restarting streams for network reachability change."),await async function(t){const e=Yr(t);e.F_.add(4),await ih(e),e.O_.set("Unknown"),e.F_.delete(4),await rh(e)}(this))}))})),this.O_=new nh(n,s)}}async function rh(t){if(dh(t))for(const e of t.M_)await e(!0)}async function ih(t){for(const e of t.M_)await e(!1)}function oh(t,e){const n=Yr(t);n.v_.has(e.targetId)||(n.v_.set(e.targetId,e),lh(n)?hh(n):Nh(n).Yo()&&ch(n,e))}function ah(t,e){const n=Yr(t),s=Nh(n);n.v_.delete(e),s.Yo()&&uh(n,e),0===n.v_.size&&(s.Yo()?s.e_():dh(n)&&n.O_.set("Unknown"))}function ch(t,e){if(t.N_.Le(e.targetId),e.resumeToken.approximateByteSize()>0||e.snapshotVersion.compareTo(fi.min())>0){const n=t.remoteSyncer.getRemoteKeysForTarget(e.targetId).size;e=e.withExpectedCount(n)}Nh(t).l_(e)}function uh(t,e){t.N_.Le(e),Nh(t).h_(e)}function hh(t){t.N_=new Tc({getRemoteKeysForTarget:e=>t.remoteSyncer.getRemoteKeysForTarget(e),lt:e=>t.v_.get(e)||null,st:()=>t.datastore.serializer.databaseId}),Nh(t).start(),t.O_.y_()}function lh(t){return dh(t)&&!Nh(t).Jo()&&t.v_.size>0}function dh(t){return 0===Yr(t).F_.size}function fh(t){t.N_=void 0}async function gh(t){t.v_.forEach(((e,n)=>{ch(t,e)}))}async function mh(t,e){fh(t),lh(t)?(t.O_.b_(e),hh(t)):t.O_.set("Unknown")}async function ph(t,e,n){if(t.O_.set("Online"),e instanceof bc&&2===e.state&&e.cause)try{await async function(t,e){const n=e.cause;for(const s of e.targetIds)t.v_.has(s)&&(await t.remoteSyncer.rejectListen(s,n),t.v_.delete(s),t.N_.removeTarget(s))}(t,e)}catch(n){zr("RemoteStore","Failed to remove targets %s: %s ",e.targetIds.join(","),n),await yh(t,n)}else if(e instanceof Ec?t.N_.Ge(e):e instanceof _c?t.N_.Xe(e):t.N_.He(e),!n.isEqual(fi.min()))try{const e=await Lu(t.localStore);n.compareTo(e)>=0&&await function(t,e){const n=t.N_._t(e);return n.targetChanges.forEach(((n,s)=>{if(n.resumeToken.approximateByteSize()>0){const r=t.v_.get(s);r&&t.v_.set(s,r.withResumeToken(n.resumeToken,e))}})),n.targetMismatches.forEach(((e,n)=>{const s=t.v_.get(e);if(!s)return;t.v_.set(e,s.withResumeToken(Hi.EMPTY_BYTE_STRING,s.snapshotVersion)),uh(t,e);const r=new ru(s.target,e,n,s.sequenceNumber);ch(t,r)})),t.remoteSyncer.applyRemoteEvent(n)}(t,n)}catch(e){zr("RemoteStore","Failed to raise snapshot:",e),await yh(t,e)}}async function yh(t,e,n){if(!Di(e))throw e;t.F_.add(1),await ih(t),t.O_.set("Offline"),n||(n=()=>Lu(t.localStore)),t.asyncQueue.enqueueRetryable((async()=>{zr("RemoteStore","Retrying IndexedDB access"),await n(),t.F_.delete(1),await rh(t)}))}function vh(t,e){return e().catch((n=>yh(t,n,e)))}async function wh(t){const e=Yr(t),n=Rh(e);let s=e.C_.length>0?e.C_[e.C_.length-1].batchId:-1;for(;Eh(e);)try{const t=await Ou(e.localStore,s);if(null===t){0===e.C_.length&&n.e_();break}s=t.batchId,_h(e,t)}catch(t){await yh(e,t)}bh(e)&&Ih(e)}function Eh(t){return dh(t)&&t.C_.length<10}function _h(t,e){t.C_.push(e);const n=Rh(t);n.Yo()&&n.I_&&n.d_(e.mutations)}function bh(t){return dh(t)&&!Rh(t).Jo()&&t.C_.length>0}function Ih(t){Rh(t).start()}async function Th(t){Rh(t).A_()}async function Sh(t){const e=Rh(t);for(const n of t.C_)e.d_(n.mutations)}async function Ch(t,e,n){const s=t.C_.shift(),r=rc.from(s,e,n);await vh(t,(()=>t.remoteSyncer.applySuccessfulWrite(r))),await wh(t)}async function Ah(t,e){e&&Rh(t).I_&&await async function(t,e){if(function(t){return uc(t)&&t!==Xr.ABORTED}(e.code)){const n=t.C_.shift();Rh(t).Xo(),await vh(t,(()=>t.remoteSyncer.rejectFailedWrite(n.batchId,e))),await wh(t)}}(t,e),bh(t)&&Ih(t)}async function Dh(t,e){const n=Yr(t);n.asyncQueue.verifyOperationInProgress(),zr("RemoteStore","RemoteStore received new credentials");const s=dh(n);n.F_.add(3),await ih(n),s&&n.O_.set("Unknown"),await n.remoteSyncer.handleCredentialChange(e),n.F_.delete(3),await rh(n)}async function kh(t,e){const n=Yr(t);e?(n.F_.delete(2),await rh(n)):e||(n.F_.add(2),await ih(n),n.O_.set("Unknown"))}function Nh(t){return t.B_||(t.B_=function(t,e,n){const s=Yr(t);return s.V_(),new Zu(e,s.connection,s.authCredentials,s.appCheckCredentials,s.serializer,n)}(t.datastore,t.asyncQueue,{Io:gh.bind(null,t),Eo:mh.bind(null,t),c_:ph.bind(null,t)}),t.M_.push((async e=>{e?(t.B_.Xo(),lh(t)?hh(t):t.O_.set("Unknown")):(await t.B_.stop(),fh(t))}))),t.B_}function Rh(t){return t.L_||(t.L_=function(t,e,n){const s=Yr(t);return s.V_(),new th(e,s.connection,s.authCredentials,s.appCheckCredentials,s.serializer,n)}(t.datastore,t.asyncQueue,{Io:Th.bind(null,t),Eo:Ah.bind(null,t),E_:Sh.bind(null,t),T_:Ch.bind(null,t)}),t.M_.push((async e=>{e?(t.L_.Xo(),await wh(t)):(await t.L_.stop(),t.C_.length>0&&(zr("RemoteStore",`Stopping write stream with ${t.C_.length} pending writes`),t.C_=[]))}))),t.L_}class Lh{constructor(t,e,n,s,r){this.asyncQueue=t,this.timerId=e,this.targetTimeMs=n,this.op=s,this.removalCallback=r,this.deferred=new Zr,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch((t=>{}))}get promise(){return this.deferred.promise}static createAndSchedule(t,e,n,s,r){const i=Date.now()+n,o=new Lh(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 Jr(Xr.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 xh(t,e){if(Kr("AsyncQueue",`${e}: ${t}`),Di(t))return new Jr(Xr.UNAVAILABLE,`${e}: ${t}`);throw t}class Oh{constructor(t){this.comparator=t?(e,n)=>t(e,n)||vi.comparator(e.key,n.key):(t,e)=>vi.comparator(t.key,e.key),this.keyedMap=pa(),this.sortedSet=new Vi(this.comparator)}static emptySet(t){return new Oh(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 Oh))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 Oh;return n.comparator=this.comparator,n.keyedMap=t,n.sortedSet=e,n}}class Mh{constructor(){this.k_=new Vi(vi.comparator)}track(t){const e=t.doc.key,n=this.k_.get(e);n?0!==t.type&&3===n.type?this.k_=this.k_.insert(e,t):3===t.type&&1!==n.type?this.k_=this.k_.insert(e,{type:n.type,doc:t.doc}):2===t.type&&2===n.type?this.k_=this.k_.insert(e,{type:2,doc:t.doc}):2===t.type&&0===n.type?this.k_=this.k_.insert(e,{type:0,doc:t.doc}):1===t.type&&0===n.type?this.k_=this.k_.remove(e):1===t.type&&2===n.type?this.k_=this.k_.insert(e,{type:1,doc:n.doc}):0===t.type&&1===n.type?this.k_=this.k_.insert(e,{type:2,doc:t.doc}):Qr():this.k_=this.k_.insert(e,t)}q_(){const t=[];return this.k_.inorderTraversal(((e,n)=>{t.push(n)})),t}}class Ph{constructor(t,e,n,s,r,i,o,a,c){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=c}static fromInitialDocuments(t,e,n,s,r){const i=[];return e.forEach((t=>{i.push({type:0,doc:t})})),new Ph(t,e,Oh.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)&&ia(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 Fh{constructor(){this.Q_=void 0,this.listeners=[]}}class Bh{constructor(){this.queries=new da((t=>oa(t)),ia),this.onlineState="Unknown",this.K_=new Set}}async function Vh(t,e){const n=Yr(t),s=e.query;let r=!1,i=n.queries.get(s);if(i||(r=!0,i=new Fh),r)try{i.Q_=await n.onListen(s)}catch(t){const n=xh(t,`Initialization of query '${aa(e.query)}' failed`);return void e.onError(n)}n.queries.set(s,i),i.listeners.push(e),e.U_(n.onlineState),i.Q_&&e.W_(i.Q_)&&$h(n)}async function Uh(t,e){const n=Yr(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 qh(t,e){const n=Yr(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.W_(t)&&(s=!0);r.Q_=t}}s&&$h(n)}function jh(t,e,n){const s=Yr(t),r=s.queries.get(e);if(r)for(const t of r.listeners)t.onError(n);s.queries.delete(e)}function $h(t){t.K_.forEach((t=>{t.next()}))}class zh{constructor(t,e,n){this.query=t,this.G_=e,this.z_=!1,this.j_=null,this.onlineState="Unknown",this.options=n||{}}W_(t){if(!this.options.includeMetadataChanges){const e=[];for(const n of t.docChanges)3!==n.type&&e.push(n);t=new Ph(t.query,t.docs,t.oldDocs,e,t.mutatedKeys,t.fromCache,t.syncStateChanged,!0,t.hasCachedResults)}let e=!1;return this.z_?this.H_(t)&&(this.G_.next(t),e=!0):this.J_(t,this.onlineState)&&(this.Y_(t),e=!0),this.j_=t,e}onError(t){this.G_.error(t)}U_(t){this.onlineState=t;let e=!1;return this.j_&&!this.z_&&this.J_(this.j_,t)&&(this.Y_(this.j_),e=!0),e}J_(t,e){if(!t.fromCache)return!0;const n="Offline"!==e;return(!this.options.Z_||!n)&&(!t.docs.isEmpty()||t.hasCachedResults||"Offline"===e)}H_(t){if(t.docChanges.length>0)return!0;const e=this.j_&&this.j_.hasPendingWrites!==t.hasPendingWrites;return!(!t.syncStateChanged&&!e)&&!0===this.options.includeMetadataChanges}Y_(t){t=Ph.fromInitialDocuments(t.query,t.docs,t.mutatedKeys,t.fromCache,t.hasCachedResults),this.z_=!0,this.G_.next(t)}}class Kh{constructor(t){this.key=t}}class Hh{constructor(t){this.key=t}}class Gh{constructor(t,e){this.query=t,this.oa=e,this._a=null,this.hasCachedResults=!1,this.current=!1,this.aa=Ia(),this.mutatedKeys=Ia(),this.ua=ha(t),this.ca=new Oh(this.ua)}get la(){return this.oa}ha(t,e){const n=e?e.Pa:new Mh,s=e?e.ca:this.ca;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,c="L"===this.query.limitType&&s.size===this.query.limit?s.first():null;if(t.inorderTraversal(((t,e)=>{const u=s.get(t),h=ca(this.query,e)?e:null,l=!!u&&this.mutatedKeys.has(u.key),d=!!h&&(h.hasLocalMutations||this.mutatedKeys.has(h.key)&&h.hasCommittedMutations);let f=!1;u&&h?u.data.isEqual(h.data)?l!==d&&(n.track({type:3,doc:h}),f=!0):this.Ia(u,h)||(n.track({type:2,doc:h}),f=!0,(a&&this.ua(h,a)>0||c&&this.ua(h,c)<0)&&(o=!0)):!u&&h?(n.track({type:0,doc:h}),f=!0):u&&!h&&(n.track({type:1,doc:u}),f=!0,(a||c)&&(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{ca:i,Pa:n,es:o,mutatedKeys:r}}Ia(t,e){return t.hasLocalMutations&&e.hasCommittedMutations&&!e.hasLocalMutations}applyChanges(t,e,n){const s=this.ca;this.ca=t.ca,this.mutatedKeys=t.mutatedKeys;const r=t.Pa.q_();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 Qr()}};return n(t)-n(e)}(t.type,e.type)||this.ua(t.doc,e.doc))),this.da(n);const i=e?this.Ta():[],o=0===this.aa.size&&this.current?1:0,a=o!==this._a;return this._a=o,0!==r.length||a?{snapshot:new Ph(this.query,t.ca,s,r,t.mutatedKeys,0===o,a,!1,!!n&&n.resumeToken.approximateByteSize()>0),Ea:i}:{Ea:i}}U_(t){return this.current&&"Offline"===t?(this.current=!1,this.applyChanges({ca:this.ca,Pa:new Mh,mutatedKeys:this.mutatedKeys,es:!1},!1)):{Ea:[]}}Aa(t){return!this.oa.has(t)&&!!this.ca.has(t)&&!this.ca.get(t).hasLocalMutations}da(t){t&&(t.addedDocuments.forEach((t=>this.oa=this.oa.add(t))),t.modifiedDocuments.forEach((t=>{})),t.removedDocuments.forEach((t=>this.oa=this.oa.delete(t))),this.current=t.current)}Ta(){if(!this.current)return[];const t=this.aa;this.aa=Ia(),this.ca.forEach((t=>{this.Aa(t.key)&&(this.aa=this.aa.add(t.key))}));const e=[];return t.forEach((t=>{this.aa.has(t)||e.push(new Hh(t))})),this.aa.forEach((n=>{t.has(n)||e.push(new Kh(n))})),e}Ra(t){this.oa=t.Ps,this.aa=Ia();const e=this.ha(t.documents);return this.applyChanges(e,!0)}Va(){return Ph.fromInitialDocuments(this.query,this.ca,this.mutatedKeys,0===this._a,this.hasCachedResults)}}class Qh{constructor(t,e,n){this.query=t,this.targetId=e,this.view=n}}class Wh{constructor(t){this.key=t,this.ma=!1}}class Yh{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.fa={},this.ga=new da((t=>oa(t)),ia),this.pa=new Map,this.ya=new Set,this.wa=new Vi(vi.comparator),this.Sa=new Map,this.ba=new yu,this.Da={},this.Ca=new Map,this.va=lu.Ln(),this.onlineState="Unknown",this.Fa=void 0}get isPrimaryClient(){return!0===this.Fa}}async function Xh(t,e){const n=ml(t);let s,r;const i=n.ga.get(e);if(i)s=i.targetId,n.sharedClientState.addLocalQueryTarget(s),r=i.view.Va();else{const t=await Mu(n.localStore,na(e)),i=n.sharedClientState.addLocalQueryTarget(t.targetId);s=t.targetId,r=await Jh(n,e,s,"current"===i,t.resumeToken),n.isPrimaryClient&&oh(n.remoteStore,t)}return r}async function Jh(t,e,n,s,r){t.Ma=(e,n,s)=>async function(t,e,n,s){let r=e.view.ha(n);r.es&&(r=await Fu(t.localStore,e.query,!1).then((({documents:t})=>e.view.ha(t,r))));const i=s&&s.targetChanges.get(e.targetId),o=e.view.applyChanges(r,t.isPrimaryClient,i);return ul(t,e.targetId,o.Ea),o.snapshot}(t,e,n,s);const i=await Fu(t.localStore,e,!0),o=new Gh(e,i.Ps),a=o.ha(i.documents),c=wc.createSynthesizedTargetChangeForCurrentChange(n,s&&"Offline"!==t.onlineState,r),u=o.applyChanges(a,t.isPrimaryClient,c);ul(t,n,u.Ea);const h=new Qh(e,n,o);return t.ga.set(e,h),t.pa.has(n)?t.pa.get(n).push(e):t.pa.set(n,[e]),u.snapshot}async function Zh(t,e){const n=Yr(t),s=n.ga.get(e),r=n.pa.get(s.targetId);if(r.length>1)return n.pa.set(s.targetId,r.filter((t=>!ia(t,e)))),void n.ga.delete(e);n.isPrimaryClient?(n.sharedClientState.removeLocalQueryTarget(s.targetId),n.sharedClientState.isActiveQueryTarget(s.targetId)||await Pu(n.localStore,s.targetId,!1).then((()=>{n.sharedClientState.clearQueryState(s.targetId),ah(n.remoteStore,s.targetId),al(n,s.targetId)})).catch(Ci)):(al(n,s.targetId),await Pu(n.localStore,s.targetId,!0))}async function tl(t,e){const n=Yr(t);try{const t=await function(t,e){const n=Yr(t),s=e.snapshotVersion;let r=n.rs;return n.persistence.runTransaction("Apply remote event","readwrite-primary",(t=>{const i=n._s.newChangeBuffer({trackRemovals:!0});r=n.rs;const o=[];e.targetChanges.forEach(((i,a)=>{const c=r.get(a);if(!c)return;o.push(n.Kr.removeMatchingKeys(t,i.removedDocuments,a).next((()=>n.Kr.addMatchingKeys(t,i.addedDocuments,a))));let u=c.withSequenceNumber(t.currentSequenceNumber);null!==e.targetMismatches.get(a)?u=u.withResumeToken(Hi.EMPTY_BYTE_STRING,fi.min()).withLastLimboFreeSnapshotVersion(fi.min()):i.resumeToken.approximateByteSize()>0&&(u=u.withResumeToken(i.resumeToken,s)),r=r.insert(a,u),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}(c,u,i)&&o.push(n.Kr.updateTargetData(t,u))}));let a=ga(),c=Ia();if(e.documentUpdates.forEach((s=>{e.resolvedLimboDocuments.has(s)&&o.push(n.persistence.referenceDelegate.updateLimboDocument(t,s))})),o.push(xu(t,i,e.documentUpdates).next((t=>{a=t.ls,c=t.hs}))),!s.isEqual(fi.min())){const e=n.Kr.getLastRemoteSnapshotVersion(t).next((e=>n.Kr.setTargetsMetadata(t,t.currentSequenceNumber,s)));o.push(e)}return Ai.waitFor(o).next((()=>i.apply(t))).next((()=>n.localDocuments.getLocalViewOfDocuments(t,a,c))).next((()=>a))})).then((t=>(n.rs=r,t)))}(n.localStore,e);e.targetChanges.forEach(((t,e)=>{const s=n.Sa.get(e);s&&(Wr(t.addedDocuments.size+t.modifiedDocuments.size+t.removedDocuments.size<=1),t.addedDocuments.size>0?s.ma=!0:t.modifiedDocuments.size>0?Wr(s.ma):t.removedDocuments.size>0&&(Wr(s.ma),s.ma=!1))})),await dl(n,t,e)}catch(t){await Ci(t)}}function el(t,e,n){const s=Yr(t);if(s.isPrimaryClient&&0===n||!s.isPrimaryClient&&1===n){const t=[];s.ga.forEach(((n,s)=>{const r=s.view.U_(e);r.snapshot&&t.push(r.snapshot)})),function(t,e){const n=Yr(t);n.onlineState=e;let s=!1;n.queries.forEach(((t,n)=>{for(const t of n.listeners)t.U_(e)&&(s=!0)})),s&&$h(n)}(s.eventManager,e),t.length&&s.fa.c_(t),s.onlineState=e,s.isPrimaryClient&&s.sharedClientState.setOnlineState(e)}}async function nl(t,e,n){const s=Yr(t);s.sharedClientState.updateQueryState(e,"rejected",n);const r=s.Sa.get(e),i=r&&r.key;if(i){let t=new Vi(vi.comparator);t=t.insert(i,Eo.newNoDocument(i,fi.min()));const n=Ia().add(i),r=new vc(fi.min(),new Map,new Vi(hi),t,n);await tl(s,r),s.wa=s.wa.remove(i),s.Sa.delete(e),ll(s)}else await Pu(s.localStore,e,!1).then((()=>al(s,e,n))).catch(Ci)}async function sl(t,e){const n=Yr(t),s=e.batch.batchId;try{const t=await function(t,e){const n=Yr(t);return n.persistence.runTransaction("Acknowledge batch","readwrite-primary",(t=>{const s=e.batch.keys(),r=n._s.newChangeBuffer({trackRemovals:!0});return function(t,e,n,s){const r=n.batch,i=r.keys();let o=Ai.resolve();return i.forEach((t=>{o=o.next((()=>s.getEntry(e,t))).next((e=>{const i=n.docVersions.get(t);Wr(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=Ia();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);ol(n,s,null),il(n,s),n.sharedClientState.updateMutationState(s,"acknowledged"),await dl(n,t)}catch(t){await Ci(t)}}async function rl(t,e,n){const s=Yr(t);try{const t=await function(t,e){const n=Yr(t);return n.persistence.runTransaction("Reject batch","readwrite-primary",(t=>{let s;return n.mutationQueue.lookupMutationBatch(t,e).next((e=>(Wr(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);ol(s,e,n),il(s,e),s.sharedClientState.updateMutationState(e,"rejected",n),await dl(s,t)}catch(n){await Ci(n)}}function il(t,e){(t.Ca.get(e)||[]).forEach((t=>{t.resolve()})),t.Ca.delete(e)}function ol(t,e,n){const s=Yr(t);let r=s.Da[s.currentUser.toKey()];if(r){const t=r.get(e);t&&(n?t.reject(n):t.resolve(),r=r.remove(e)),s.Da[s.currentUser.toKey()]=r}}function al(t,e,n=null){t.sharedClientState.removeLocalQueryTarget(e);for(const s of t.pa.get(e))t.ga.delete(s),n&&t.fa.xa(s,n);t.pa.delete(e),t.isPrimaryClient&&t.ba.mr(e).forEach((e=>{t.ba.containsKey(e)||cl(t,e)}))}function cl(t,e){t.ya.delete(e.path.canonicalString());const n=t.wa.get(e);null!==n&&(ah(t.remoteStore,n),t.wa=t.wa.remove(e),t.Sa.delete(n),ll(t))}function ul(t,e,n){for(const s of n)s instanceof Kh?(t.ba.addReference(s.key,e),hl(t,s)):s instanceof Hh?(zr("SyncEngine","Document no longer in limbo: "+s.key),t.ba.removeReference(s.key,e),t.ba.containsKey(s.key)||cl(t,s.key)):Qr()}function hl(t,e){const n=e.key,s=n.path.canonicalString();t.wa.get(n)||t.ya.has(s)||(zr("SyncEngine","New document in limbo: "+n),t.ya.add(s),ll(t))}function ll(t){for(;t.ya.size>0&&t.wa.size<t.maxConcurrentLimboResolutions;){const e=t.ya.values().next().value;t.ya.delete(e);const n=new vi(mi.fromString(e)),s=t.va.next();t.Sa.set(s,new Wh(n)),t.wa=t.wa.insert(n,s),oh(t.remoteStore,new ru(na(Yo(n.path)),s,"TargetPurposeLimboResolution",ki.ae))}}async function dl(t,e,n){const s=Yr(t),r=[],i=[],o=[];s.ga.isEmpty()||(s.ga.forEach(((t,a)=>{o.push(s.Ma(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=Cu.$i(a.targetId,t);i.push(e)}})))})),await Promise.all(o),s.fa.c_(r),await async function(t,e){const n=Yr(t);try{await n.persistence.runTransaction("notifyLocalViewChanges","readwrite",(t=>Ai.forEach(e,(e=>Ai.forEach(e.Qi,(s=>n.persistence.referenceDelegate.addReference(t,e.targetId,s))).next((()=>Ai.forEach(e.Ki,(s=>n.persistence.referenceDelegate.removeReference(t,e.targetId,s)))))))))}catch(t){if(!Di(t))throw t;zr("LocalStore","Failed to update sequence numbers: "+t)}for(const t of e){const e=t.targetId;if(!t.fromCache){const t=n.rs.get(e),s=t.snapshotVersion,r=t.withLastLimboFreeSnapshotVersion(s);n.rs=n.rs.insert(e,r)}}}(s.localStore,i))}async function fl(t,e){const n=Yr(t);if(!n.currentUser.isEqual(e)){zr("SyncEngine","User change. New user:",e.toKey());const t=await Ru(n.localStore,e);n.currentUser=e,function(t,e){t.Ca.forEach((t=>{t.forEach((t=>{t.reject(new Jr(Xr.CANCELLED,e))}))})),t.Ca.clear()}(n,"'waitForPendingWrites' promise is rejected due to a user change."),n.sharedClientState.handleUserChange(e,t.removedBatchIds,t.addedBatchIds),await dl(n,t.cs)}}function gl(t,e){const n=Yr(t),s=n.Sa.get(e);if(s&&s.ma)return Ia().add(s.key);{let t=Ia();const s=n.pa.get(e);if(!s)return t;for(const e of s){const s=n.ga.get(e);t=t.unionWith(s.view.la)}return t}}function ml(t){const e=Yr(t);return e.remoteStore.remoteSyncer.applyRemoteEvent=tl.bind(null,e),e.remoteStore.remoteSyncer.getRemoteKeysForTarget=gl.bind(null,e),e.remoteStore.remoteSyncer.rejectListen=nl.bind(null,e),e.fa.c_=qh.bind(null,e.eventManager),e.fa.xa=jh.bind(null,e.eventManager),e}function pl(t){const e=Yr(t);return e.remoteStore.remoteSyncer.applySuccessfulWrite=sl.bind(null,e),e.remoteStore.remoteSyncer.rejectFailedWrite=rl.bind(null,e),e}class yl{constructor(){this.synchronizeTabs=!1}async initialize(t){this.serializer=Yu(t.databaseInfo.databaseId),this.sharedClientState=this.createSharedClientState(t),this.persistence=this.createPersistence(t),await this.persistence.start(),this.localStore=this.createLocalStore(t),this.gcScheduler=this.createGarbageCollectionScheduler(t,this.localStore),this.indexBackfillerScheduler=this.createIndexBackfillerScheduler(t,this.localStore)}createGarbageCollectionScheduler(t,e){return null}createIndexBackfillerScheduler(t,e){return null}createLocalStore(t){return Nu(this.persistence,new Du,t.initialUser,this.serializer)}createPersistence(t){return new Iu(Su.Jr,this.serializer)}createSharedClientState(t){return new Uu}async terminate(){this.gcScheduler&&this.gcScheduler.stop(),await this.sharedClientState.shutdown(),await this.persistence.shutdown()}}class vl{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=>el(this.syncEngine,t,1),this.remoteStore.remoteSyncer.handleCredentialChange=fl.bind(null,this.syncEngine),await kh(this.remoteStore,this.syncEngine.isPrimaryClient))}createEventManager(t){return new Bh}createDatastore(t){const e=Yu(t.databaseInfo.databaseId),n=function(t){return new Qu(t)}(t.databaseInfo);return function(t,e,n,s){return new eh(t,e,n,s)}(t.authCredentials,t.appCheckCredentials,n,e)}createRemoteStore(t){return function(t,e,n,s,r){return new sh(t,e,n,s,r)}(this.localStore,this.datastore,t.asyncQueue,(t=>el(this.syncEngine,t,0)),ju.C()?new ju:new qu)}createSyncEngine(t,e){return function(t,e,n,s,r,i,o){const a=new Yh(t,e,n,s,r,i);return o&&(a.Fa=!0),a}(this.localStore,this.remoteStore,this.eventManager,this.sharedClientState,t.initialUser,t.maxConcurrentLimboResolutions,e)}terminate(){return async function(t){const e=Yr(t);zr("RemoteStore","RemoteStore shutting down."),e.F_.add(5),await ih(e),e.x_.shutdown(),e.O_.set("Unknown")}(this.remoteStore)}}class wl{constructor(t){this.observer=t,this.muted=!1}next(t){this.observer.next&&this.Ba(this.observer.next,t)}error(t){this.observer.error?this.Ba(this.observer.error,t):Kr("Uncaught Error in snapshot listener:",t.toString())}La(){this.muted=!0}Ba(t,e){this.muted||setTimeout((()=>{this.muted||t(e)}),0)}}class El{constructor(t,e,n,s){this.authCredentials=t,this.appCheckCredentials=e,this.asyncQueue=n,this.databaseInfo=s,this.user=Ur.UNAUTHENTICATED,this.clientId=ui.V(),this.authCredentialListener=()=>Promise.resolve(),this.appCheckCredentialListener=()=>Promise.resolve(),this.authCredentials.start(n,(async t=>{zr("FirestoreClient","Received user=",t.uid),await this.authCredentialListener(t),this.user=t})),this.appCheckCredentials.start(n,(t=>(zr("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 Jr(Xr.FAILED_PRECONDITION,"The client has already been terminated.")}terminate(){this.asyncQueue.enterRestrictedMode();const t=new Zr;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=xh(e,"Failed to shutdown persistence");t.reject(n)}})),t.promise}}async function _l(t,e){t.asyncQueue.verifyOperationInProgress(),zr("FirestoreClient","Initializing OfflineComponentProvider");const n=await t.getConfiguration();await e.initialize(n);let s=n.initialUser;t.setCredentialChangeListener((async t=>{s.isEqual(t)||(await Ru(e.localStore,t),s=t)})),e.persistence.setDatabaseDeletedListener((()=>t.terminate())),t._offlineComponents=e}async function bl(t,e){t.asyncQueue.verifyOperationInProgress();const n=await Tl(t);zr("FirestoreClient","Initializing OnlineComponentProvider");const s=await t.getConfiguration();await e.initialize(n,s),t.setCredentialChangeListener((t=>Dh(e.remoteStore,t))),t.setAppCheckTokenChangeListener(((t,n)=>Dh(e.remoteStore,n))),t._onlineComponents=e}function Il(t){return"FirebaseError"===t.name?t.code===Xr.FAILED_PRECONDITION||t.code===Xr.UNIMPLEMENTED:!("undefined"!=typeof DOMException&&t instanceof DOMException)||22===t.code||20===t.code||11===t.code}async function Tl(t){if(!t._offlineComponents)if(t._uninitializedComponentsProvider){zr("FirestoreClient","Using user provided OfflineComponentProvider");try{await _l(t,t._uninitializedComponentsProvider._offline)}catch(e){const n=e;if(!Il(n))throw n;Hr("Error using user provided cache. Falling back to memory cache: "+n),await _l(t,new yl)}}else zr("FirestoreClient","Using default OfflineComponentProvider"),await _l(t,new yl);return t._offlineComponents}async function Sl(t){return t._onlineComponents||(t._uninitializedComponentsProvider?(zr("FirestoreClient","Using user provided OnlineComponentProvider"),await bl(t,t._uninitializedComponentsProvider._online)):(zr("FirestoreClient","Using default OnlineComponentProvider"),await bl(t,new vl))),t._onlineComponents}function Cl(t){return Sl(t).then((t=>t.syncEngine))}async function Al(t){const e=await Sl(t),n=e.eventManager;return n.onListen=Xh.bind(null,e.syncEngine),n.onUnlisten=Zh.bind(null,e.syncEngine),n}function Dl(t,e,n={}){const s=new Zr;return t.asyncQueue.enqueueAndForget((async()=>function(t,e,n,s,r){const i=new wl({next:n=>{e.enqueueAndForget((()=>Uh(t,o))),n.fromCache&&"server"===s.source?r.reject(new Jr(Xr.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 zh(n,i,{includeMetadataChanges:!0,Z_:!0});return Vh(t,o)}(await Al(t),t.asyncQueue,e,n,s))),s.promise}function kl(t){const e={};return void 0!==t.timeoutSeconds&&(e.timeoutSeconds=t.timeoutSeconds),e}const Nl=new Map;function Rl(t,e,n){if(!n)throw new Jr(Xr.INVALID_ARGUMENT,`Function ${t}() cannot be called with an empty ${e}.`)}function Ll(t){if(!vi.isDocumentKey(t))throw new Jr(Xr.INVALID_ARGUMENT,`Invalid document reference. Document references must have an even number of segments, but ${t} has ${t.length}.`)}function xl(t){if(vi.isDocumentKey(t))throw new Jr(Xr.INVALID_ARGUMENT,`Invalid collection reference. Collection references must have an odd number of segments, but ${t} has ${t.length}.`)}function Ol(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":Qr()}function Ml(t,e){if("_delegate"in t&&(t=t._delegate),!(t instanceof e)){if(e.name===t.constructor.name)throw new Jr(Xr.INVALID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{const n=Ol(t);throw new Jr(Xr.INVALID_ARGUMENT,`Expected type '${e.name}', but it was: ${n}`)}}return t}class Pl{constructor(t){var e,n;if(void 0===t.host){if(void 0!==t.ssl)throw new Jr(Xr.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,this.localCache=t.localCache,void 0===t.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==t.cacheSizeBytes&&t.cacheSizeBytes<1048576)throw new Jr(Xr.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=t.cacheSizeBytes}(function(t,e,n,s){if(!0===e&&!0===s)throw new Jr(Xr.INVALID_ARGUMENT,`${t} and ${n} cannot be used together.`)})("experimentalForceLongPolling",t.experimentalForceLongPolling,"experimentalAutoDetectLongPolling",t.experimentalAutoDetectLongPolling),this.experimentalForceLongPolling=!!t.experimentalForceLongPolling,this.experimentalForceLongPolling?this.experimentalAutoDetectLongPolling=!1:void 0===t.experimentalAutoDetectLongPolling?this.experimentalAutoDetectLongPolling=!0:this.experimentalAutoDetectLongPolling=!!t.experimentalAutoDetectLongPolling,this.experimentalLongPollingOptions=kl(null!==(n=t.experimentalLongPollingOptions)&&void 0!==n?n:{}),function(t){if(void 0!==t.timeoutSeconds){if(isNaN(t.timeoutSeconds))throw new Jr(Xr.INVALID_ARGUMENT,`invalid long polling timeout: ${t.timeoutSeconds} (must not be NaN)`);if(t.timeoutSeconds<5)throw new Jr(Xr.INVALID_ARGUMENT,`invalid long polling timeout: ${t.timeoutSeconds} (minimum allowed value is 5)`);if(t.timeoutSeconds>30)throw new Jr(Xr.INVALID_ARGUMENT,`invalid long polling timeout: ${t.timeoutSeconds} (maximum allowed value is 30)`)}}(this.experimentalLongPollingOptions),this.useFetchStreams=!!t.useFetchStreams}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&&function(t,e){return t.timeoutSeconds===e.timeoutSeconds}(this.experimentalLongPollingOptions,t.experimentalLongPollingOptions)&&this.ignoreUndefinedProperties===t.ignoreUndefinedProperties&&this.useFetchStreams===t.useFetchStreams}}class Fl{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 Pl({}),this._settingsFrozen=!1}get app(){if(!this._app)throw new Jr(Xr.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 Jr(Xr.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 Pl(t),void 0!==t.credentials&&(this._authCredentials=function(t){if(!t)return new ei;switch(t.type){case"firstParty":return new ii(t.sessionIndex||"0",t.iamToken||null,t.authTokenFactory||null);case"provider":return t.client;default:throw new Jr(Xr.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=Nl.get(t);e&&(zr("ComponentProvider","Removing Datastore"),Nl.delete(t),e.terminate())}(this),Promise.resolve()}}function Bl(t,e,n,s={}){var i;const o=(t=Ml(t,Fl))._getSettings(),a=`${e}:${n}`;if("firestore.googleapis.com"!==o.host&&o.host!==a&&Hr("Host has been set in both settings() and connectFirestoreEmulator(), emulator host will be used."),t._setSettings(Object.assign(Object.assign({},o),{host:a,ssl:!1})),s.mockUserToken){let e,n;if("string"==typeof s.mockUserToken)e=s.mockUserToken,n=Ur.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,i=t.sub||t.user_id;if(!i)throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");const o=Object.assign({iss:`https://securetoken.google.com/${n}`,aud:n,iat:s,exp:s+3600,auth_time:s,sub:i,user_id:i,firebase:{sign_in_provider:"custom",identities:{}}},t);return[r(JSON.stringify({alg:"none",type:"JWT"})),r(JSON.stringify(o)),""].join(".")}(s.mockUserToken,null===(i=t._app)||void 0===i?void 0:i.options.projectId);const o=s.mockUserToken.sub||s.mockUserToken.user_id;if(!o)throw new Jr(Xr.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");n=new Ur(o)}t._authCredentials=new ni(new ti(e,n))}}class Vl{constructor(t,e,n){this.converter=e,this._query=n,this.type="query",this.firestore=t}withConverter(t){return new Vl(this.firestore,t,this._query)}}class Ul{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 ql(this.firestore,this.converter,this._key.path.popLast())}withConverter(t){return new Ul(this.firestore,t,this._key)}}class ql extends Vl{constructor(t,e,n){super(t,e,Yo(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 Ul(this.firestore,null,new vi(t))}withConverter(t){return new ql(this.firestore,t,this._path)}}function jl(t,e,...n){if(t=y(t),Rl("collection","path",e),t instanceof Fl){const s=mi.fromString(e,...n);return xl(s),new ql(t,null,s)}{if(!(t instanceof Ul||t instanceof ql))throw new Jr(Xr.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const s=t._path.child(mi.fromString(e,...n));return xl(s),new ql(t.firestore,null,s)}}class $l{constructor(){this.Za=Promise.resolve(),this.Xa=[],this.eu=!1,this.tu=[],this.nu=null,this.ru=!1,this.iu=!1,this.su=[],this.Ho=new Xu(this,"async_queue_retry"),this.ou=()=>{const t=Wu();t&&zr("AsyncQueue","Visibility state changed to "+t.visibilityState),this.Ho.$o()};const t=Wu();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.ou)}get isShuttingDown(){return this.eu}enqueueAndForget(t){this.enqueue(t)}enqueueAndForgetEvenWhileRestricted(t){this._u(),this.au(t)}enterRestrictedMode(t){if(!this.eu){this.eu=!0,this.iu=t||!1;const e=Wu();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("visibilitychange",this.ou)}}enqueue(t){if(this._u(),this.eu)return new Promise((()=>{}));const e=new Zr;return this.au((()=>this.eu&&this.iu?Promise.resolve():(t().then(e.resolve,e.reject),e.promise))).then((()=>e.promise))}enqueueRetryable(t){this.enqueueAndForget((()=>(this.Xa.push(t),this.uu())))}async uu(){if(0!==this.Xa.length){try{await this.Xa[0](),this.Xa.shift(),this.Ho.reset()}catch(t){if(!Di(t))throw t;zr("AsyncQueue","Operation failed with retryable error: "+t)}this.Xa.length>0&&this.Ho.Qo((()=>this.uu()))}}au(t){const e=this.Za.then((()=>(this.ru=!0,t().catch((t=>{this.nu=t,this.ru=!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 Kr("INTERNAL UNHANDLED ERROR: ",e),t})).then((t=>(this.ru=!1,t))))));return this.Za=e,e}enqueueAfterDelay(t,e,n){this._u(),this.su.indexOf(t)>-1&&(e=0);const s=Lh.createAndSchedule(this,t,e,n,(t=>this.cu(t)));return this.tu.push(s),s}_u(){this.nu&&Qr()}verifyOperationInProgress(){}async lu(){let t;do{t=this.Za,await t}while(t!==this.Za)}hu(t){for(const e of this.tu)if(e.timerId===t)return!0;return!1}Pu(t){return this.lu().then((()=>{this.tu.sort(((t,e)=>t.targetTimeMs-e.targetTimeMs));for(const e of this.tu)if(e.skipDelay(),"all"!==t&&e.timerId===t)break;return this.lu()}))}Iu(t){this.su.push(t)}cu(t){const e=this.tu.indexOf(t);this.tu.splice(e,1)}}class zl extends Fl{constructor(t,e,n,s){super(t,e,n,s),this.type="firestore",this._queue=new $l,this._persistenceKey=(null==s?void 0:s.name)||"[DEFAULT]"}_terminate(){return this._firestoreClient||Hl(this),this._firestoreClient.terminate()}}function Kl(t){return t._firestoreClient||Hl(t),t._firestoreClient.verifyNotTerminated(),t._firestoreClient}function Hl(t){var e,n,s;const r=t._freezeSettings(),i=function(t,e,n,s){return new to(t,e,n,s.host,s.ssl,s.experimentalForceLongPolling,s.experimentalAutoDetectLongPolling,kl(s.experimentalLongPollingOptions),s.useFetchStreams)}(t._databaseId,(null===(e=t._app)||void 0===e?void 0:e.options.appId)||"",t._persistenceKey,r);t._firestoreClient=new El(t._authCredentials,t._appCheckCredentials,t._queue,i),(null===(n=r.localCache)||void 0===n?void 0:n._offlineComponentProvider)&&(null===(s=r.localCache)||void 0===s?void 0:s._onlineComponentProvider)&&(t._firestoreClient._uninitializedComponentsProvider={_offlineKind:r.localCache.kind,_offline:r.localCache._offlineComponentProvider,_online:r.localCache._onlineComponentProvider})}class Gl{constructor(t){this._byteString=t}static fromBase64String(t){try{return new Gl(Hi.fromBase64String(t))}catch(t){throw new Jr(Xr.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+t)}}static fromUint8Array(t){return new Gl(Hi.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 Ql{constructor(...t){for(let e=0;e<t.length;++e)if(0===t[e].length)throw new Jr(Xr.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new yi(t)}isEqual(t){return this._internalPath.isEqual(t._internalPath)}}class Wl{constructor(t){this._methodName=t}}class Yl{constructor(t,e){if(!isFinite(t)||t<-90||t>90)throw new Jr(Xr.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new Jr(Xr.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 hi(this._lat,t._lat)||hi(this._long,t._long)}}const Xl=/^__.*__$/;class Jl{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return null!==this.fieldMask?new Xa(t,this.data,this.fieldMask,e,this.fieldTransforms):new Ya(t,this.data,e,this.fieldTransforms)}}function Zl(t){switch(t){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw Qr()}}class td{constructor(t,e,n,s,r,i){this.settings=t,this.databaseId=e,this.serializer=n,this.ignoreUndefinedProperties=s,void 0===r&&this.du(),this.fieldTransforms=r||[],this.fieldMask=i||[]}get path(){return this.settings.path}get Tu(){return this.settings.Tu}Eu(t){return new td(Object.assign(Object.assign({},this.settings),t),this.databaseId,this.serializer,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}Au(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),s=this.Eu({path:n,Ru:!1});return s.Vu(t),s}mu(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),s=this.Eu({path:n,Ru:!1});return s.du(),s}fu(t){return this.Eu({path:void 0,Ru:!0})}gu(t){return ld(t,this.settings.methodName,this.settings.pu||!1,this.path,this.settings.yu)}contains(t){return void 0!==this.fieldMask.find((e=>t.isPrefixOf(e)))||void 0!==this.fieldTransforms.find((e=>t.isPrefixOf(e.field)))}du(){if(this.path)for(let t=0;t<this.path.length;t++)this.Vu(this.path.get(t))}Vu(t){if(0===t.length)throw this.gu("Document fields must not be empty");if(Zl(this.Tu)&&Xl.test(t))throw this.gu('Document fields cannot begin and end with "__"')}}class ed{constructor(t,e,n){this.databaseId=t,this.ignoreUndefinedProperties=e,this.serializer=n||Yu(t)}wu(t,e,n,s=!1){return new td({Tu:t,methodName:e,yu:n,path:yi.emptyPath(),Ru:!1,pu:s},this.databaseId,this.serializer,this.ignoreUndefinedProperties)}}function nd(t){const e=t._freezeSettings(),n=Yu(t._databaseId);return new ed(t._databaseId,!!e.ignoreUndefinedProperties,n)}function sd(t,e,n,s,r,i={}){const o=t.wu(i.merge||i.mergeFields?2:0,e,n,r);ad("Data must be an object, but it was:",o,s);const a=id(s,o);let c,u;if(i.merge)c=new zi(o.fieldMask),u=o.fieldTransforms;else if(i.mergeFields){const t=[];for(const s of i.mergeFields){const r=cd(e,s,n);if(!o.contains(r))throw new Jr(Xr.INVALID_ARGUMENT,`Field '${r}' is specified in your field mask but missing from your input data.`);dd(t,r)||t.push(r)}c=new zi(t),u=o.fieldTransforms.filter((t=>c.covers(t.field)))}else c=null,u=o.fieldTransforms;return new Jl(new vo(a),c,u)}function rd(t,e){if(od(t=y(t)))return ad("Unsupported field value:",e,t),id(t,e);if(t instanceof Wl)return function(t,e){if(!Zl(e.Tu))throw e.gu(`${t._methodName}() can only be used with update() and set()`);if(!e.path)throw e.gu(`${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.Ru&&4!==e.Tu)throw e.gu("Nested arrays are not supported");return function(t,e){const n=[];let s=0;for(const r of t){let t=rd(r,e.fu(s));null==t&&(t={nullValue:"NULL_VALUE"}),n.push(t),s++}return{arrayValue:{values:n}}}(t,e)}return function(t,e){if(null===(t=y(t)))return{nullValue:"NULL_VALUE"};if("number"==typeof t)return Da(e.serializer,t);if("boolean"==typeof t)return{booleanValue:t};if("string"==typeof t)return{stringValue:t};if(t instanceof Date){const n=di.fromDate(t);return{timestampValue:Lc(e.serializer,n)}}if(t instanceof di){const n=new di(t.seconds,1e3*Math.floor(t.nanoseconds/1e3));return{timestampValue:Lc(e.serializer,n)}}if(t instanceof Yl)return{geoPointValue:{latitude:t.latitude,longitude:t.longitude}};if(t instanceof Gl)return{bytesValue:xc(e.serializer,t._byteString)};if(t instanceof Ul){const n=e.databaseId,s=t.firestore._databaseId;if(!s.isEqual(n))throw e.gu(`Document reference is for database ${s.projectId}/${s.database} but should be for database ${n.projectId}/${n.database}`);return{referenceValue:Pc(t.firestore._databaseId||e.databaseId,t._key.path)}}throw e.gu(`Unsupported field value: ${Ol(t)}`)}(t,e)}function id(t,e){const n={};return Bi(t)?e.path&&e.path.length>0&&e.fieldMask.push(e.path):Fi(t,((t,s)=>{const r=rd(s,e.Au(t));null!=r&&(n[t]=r)})),{mapValue:{fields:n}}}function od(t){return!("object"!=typeof t||null===t||t instanceof Array||t instanceof Date||t instanceof di||t instanceof Yl||t instanceof Gl||t instanceof Ul||t instanceof Wl)}function ad(t,e,n){if(!od(n)||!function(t){return"object"==typeof t&&null!==t&&(Object.getPrototypeOf(t)===Object.prototype||null===Object.getPrototypeOf(t))}(n)){const s=Ol(n);throw"an object"===s?e.gu(t+" a custom object"):e.gu(t+" "+s)}}function cd(t,e,n){if((e=y(e))instanceof Ql)return e._internalPath;if("string"==typeof e)return hd(t,e);throw ld("Field path arguments must be of type string or ",t,!1,void 0,n)}const ud=new RegExp("[~\\*/\\[\\]]");function hd(t,e,n){if(e.search(ud)>=0)throw ld(`Invalid field path (${e}). Paths must not contain '~', '*', '/', '[', or ']'`,t,!1,void 0,n);try{return new Ql(...e.split("."))._internalPath}catch(s){throw ld(`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,t,!1,void 0,n)}}function ld(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 c="";return(i||o)&&(c+=" (found",i&&(c+=` in field ${s}`),o&&(c+=` in document ${r}`),c+=")"),new Jr(Xr.INVALID_ARGUMENT,a+t+c)}function dd(t,e){return t.some((t=>t.isEqual(e)))}class fd{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 Ul(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){if(this._document){if(this._converter){const t=new gd(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(md("DocumentSnapshot.get",t));if(null!==e)return this._userDataWriter.convertValue(e)}}}class gd extends fd{data(){return super.data()}}function md(t,e){return"string"==typeof e?hd(t,e):e instanceof Ql?e._internalPath:e._delegate._internalPath}function pd(t){if("L"===t.limitType&&0===t.explicitOrderBy.length)throw new Jr(Xr.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")}class yd{convertValue(t,e="none"){switch(so(t)){case 0:return null;case 1:return t.booleanValue;case 2:return Wi(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(Yi(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 Qr()}}convertObject(t,e){return this.convertObjectMap(t.fields,e)}convertObjectMap(t,e="none"){const n={};return Fi(t,((t,s)=>{n[t]=this.convertValue(s,e)})),n}convertGeoPoint(t){return new Yl(Wi(t.latitude),Wi(t.longitude))}convertArray(t,e){return(t.values||[]).map((t=>this.convertValue(t,e)))}convertServerTimestamp(t,e){switch(e){case"previous":const n=Ji(t);return null==n?null:this.convertValue(n,e);case"estimate":return this.convertTimestamp(Zi(t));default:return null}}convertTimestamp(t){const e=Qi(t);return new di(e.seconds,e.nanos)}convertDocumentKey(t,e){const n=mi.fromString(t);Wr(su(n));const s=new eo(n.get(1),n.get(3)),r=new vi(n.popFirst(5));return s.isEqual(e)||Kr(`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 vd(t,e,n){let s;return s=t?n&&(n.merge||n.mergeFields)?t.toFirestore(e,n):t.toFirestore(e):e,s}class wd{constructor(t,e){this.hasPendingWrites=t,this.fromCache=e}isEqual(t){return this.hasPendingWrites===t.hasPendingWrites&&this.fromCache===t.fromCache}}class Ed extends fd{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 _d(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(md("DocumentSnapshot.get",t));if(null!==n)return this._userDataWriter.convertValue(n,e.serverTimestamps)}}}class _d extends Ed{data(t={}){return super.data(t)}}class bd{constructor(t,e,n,s){this._firestore=t,this._userDataWriter=e,this._snapshot=s,this.metadata=new wd(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 _d(this._firestore,this._userDataWriter,n.key,n,new wd(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 Jr(Xr.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 _d(t._firestore,t._userDataWriter,n.doc.key,n.doc,new wd(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 _d(t._firestore,t._userDataWriter,e.doc.key,e.doc,new wd(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:Id(e.type),doc:s,oldIndex:r,newIndex:i}}))}}(this,e),this._cachedChangesIncludeMetadataChanges=e),this._cachedChanges}}function Id(t){switch(t){case 0:return"added";case 2:case 3:return"modified";case 1:return"removed";default:return Qr()}}class Td extends yd{constructor(t){super(),this.firestore=t}convertBytes(t){return new Gl(t)}convertReference(t){const e=this.convertDocumentKey(t,this.firestore._databaseId);return new Ul(this.firestore,null,e)}}function Sd(t){t=Ml(t,Vl);const e=Ml(t.firestore,zl),n=Kl(e),s=new Td(e);return pd(t._query),Dl(n,t._query).then((n=>new bd(e,s,t,n)))}function Cd(t,e){const n=Ml(t.firestore,zl),s=function(t,e,...n){if(t=y(t),1===arguments.length&&(e=ui.V()),Rl("doc","path",e),t instanceof Fl){const s=mi.fromString(e,...n);return Ll(s),new Ul(t,null,new vi(s))}{if(!(t instanceof Ul||t instanceof ql))throw new Jr(Xr.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const s=t._path.child(mi.fromString(e,...n));return Ll(s),new Ul(t.firestore,t instanceof ql?t.converter:null,new vi(s))}}(t),r=vd(t.converter,e);return Ad(n,[sd(nd(t.firestore),"addDoc",s._key,r,null!==t.converter,{}).toMutation(s._key,ja.exists(!1))]).then((()=>s))}function Ad(t,e){return function(t,e){const n=new Zr;return t.asyncQueue.enqueueAndForget((async()=>async function(t,e,n){const s=pl(t);try{const t=await function(t,e){const n=Yr(t),s=di.now(),r=e.reduce(((t,e)=>t.add(e.key)),Ia());let i,o;return n.persistence.runTransaction("Locally write mutations","readwrite",(t=>{let a=ga(),c=Ia();return n._s.getEntries(t,r).next((t=>{a=t,a.forEach(((t,e)=>{e.isValidDocument()||(c=c.add(t))}))})).next((()=>n.localDocuments.getOverlayedDocuments(t,a))).next((r=>{i=r;const o=[];for(const t of e){const e=Qa(t,i.get(t.key).overlayedDocument);null!=e&&o.push(new Xa(t.key,e,wo(e.value.mapValue),ja.exists(!0)))}return n.mutationQueue.addMutationBatch(t,s,o,e)})).next((e=>{o=e;const s=e.applyToLocalDocumentSet(i,c);return n.documentOverlayCache.saveOverlays(t,e.batchId,s)}))})).then((()=>({batchId:o.batchId,changes:ya(i)})))}(s.localStore,e);s.sharedClientState.addPendingMutation(t.batchId),function(t,e,n){let s=t.Da[t.currentUser.toKey()];s||(s=new Vi(hi)),s=s.insert(e,n),t.Da[t.currentUser.toKey()]=s}(s,t.batchId,n),await dl(s,t.changes),await wh(s.remoteStore)}catch(t){const e=xh(t,"Failed to persist write");n.reject(e)}}(await Cl(t),e,n))),n.promise}(Kl(t),e)}new WeakMap;!function(t,e=!0){!function(t){qr=t}("10.4.0"),et(new v("firestore",((t,{instanceIdentifier:n,options:s})=>{const r=t.getProvider("app").getImmediate(),i=new zl(new si(t.getProvider("auth-internal")),new ai(t.getProvider("app-check-internal")),function(t,e){if(!Object.prototype.hasOwnProperty.apply(t.options,["projectId"]))throw new Jr(Xr.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');return new eo(t.options.projectId,e)}(r,n),r);return s=Object.assign({useFetchStreams:e},s),i._setSettings(s),i}),"PUBLIC").setMultipleInstances(!0)),ot(Vr,"4.2.0",t),ot(Vr,"4.2.0","esm2017")}();it({apiKey:"AIzaSyDov4cuzedD7XlwtoAwZFmig3JfGuj6COQ",authDomain:"fir-9-geexpro.firebaseapp.com",projectId:"fir-9-geexpro",storageBucket:"fir-9-geexpro.appspot.com",messagingSenderId:"194567428232",appId:"1:194567428232:web:df62437660fa29ec92673d",measurementId:"G-B2C805E45M"});const Dd=function(t,e){const n="string"==typeof t?t:e||"(default)",s=nt("object"==typeof t?t:function(t=Y){const e=J.get(t);if(!e&&t===Y&&u())return it();if(!e)throw st.create("no-app",{appName:t});return e}(),"firestore").getImmediate({identifier:n});if(!s._initialized){const t=c("firestore");t&&Bl(s,...t)}return s}();Sd(jl(Dd,"Signup")).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),console.log(e)})).catch((t=>{console.log(t.message)})),console.log(localStorage.getItem("username"));Sd(jl(Dd,"html_quiz_scores")).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),e.sort(((t,e)=>t.html_score-e.html_score)),e.reverse(),console.log(e);const n=document.getElementById("leaderboardTable");e.forEach(((t,e)=>{const s=document.createElement("tr");s.innerHTML=`<td>${e+1}</td><td>${t.username}</td><td>${t.html_score}</td>`,n.appendChild(s)}))})).catch((t=>{console.log(t.message)})),document.addEventListener("DOMContentLoaded",(function(){const t=document.getElementById("signup-form"),e=document.getElementById("password"),n=document.getElementById("conpassword");t.addEventListener("submit",(async s=>{if(s.preventDefault(),""===e.value||""===n.value)return void alert("Please fill in both password fields");if(e.value!==n.value)return void alert("Passwords do not match");Cd(jl(Dd,"Signup"),{username:t.elements.username.value,email:t.elements.email.value,password:t.elements.password.value,conpass:t.elements.conpass.value}).then((()=>{console.log("Signup successful"),window.location.href="/src/HTML/home.html"})).catch((t=>{console.error("Error adding document: ",t)}))}))})),window.onload=function(){const t=document.getElementById("login-form");t?.addEventListener("submit",(async e=>{e.preventDefault();const n=t.querySelector('input[name="username"]').value,s=t.querySelector('input[name="password"]').value,r=(await Sd(jl(Dd,"Signup"))).docs.find((t=>t.data().username===n));r&&r.data().password===s?(localStorage.setItem("username",n),window.location.href="/src/HTML/home.html"):alert("Invalid username or password. Please try again.")}))},document.addEventListener("DOMContentLoaded",(async function(){document.getElementById("htmlquizform").addEventListener("submit",(async function(t){t.preventDefault();let e=0;console.log("Daba Dis"),document.getElementById("q1-option4").checked&&(e+=4),document.getElementById("q2-option3").checked&&(e+=4),document.getElementById("q3-option1").checked&&(e+=4),document.getElementById("q4-option1").checked&&(e+=4),document.getElementById("q5-option2").checked&&(e+=4),document.getElementById("q6-option3").checked&&(e+=4),document.getElementById("q7-option1").checked&&(e+=4),document.getElementById("q8-option2").checked&&(e+=4),document.getElementById("q9-option2").checked&&(e+=4),document.getElementById("q10-option4").checked&&(e+=4),document.getElementById("q11-option2").checked&&(e+=4),document.getElementById("q12-option1").checked&&(e+=4),document.getElementById("q13-option2").checked&&(e+=4),document.getElementById("q14-option4").checked&&(e+=4),document.getElementById("q15-option1").checked&&(e+=4),console.log(e);const n=jl(Dd,"html_quiz_scores");Sd(n).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),console.log(e)})).catch((t=>{console.log(t.message)})),Cd(n,{username:localStorage.getItem("username"),html_score:e}).then((()=>{alert("Your Score is "+e)}))}))})),document.addEventListener("DOMContentLoaded",(async function(){document.getElementById("jsquizform").addEventListener("submit",(async function(t){t.preventDefault(),console.log("Daba Dis");let e=0;document.getElementById("q1-option1").checked&&(e+=4),document.getElementById("q2-option1").checked&&(e+=4),document.getElementById("q3-option2").checked&&(e+=4),document.getElementById("q4-option2").checked&&(e+=4),document.getElementById("q5-option1").checked&&(e+=4),document.getElementById("q6-option2").checked&&(e+=4),document.getElementById("q7-option3").checked&&(e+=4),document.getElementById("q8-option1").checked&&(e+=4),document.getElementById("q9-option2").checked&&(e+=4),document.getElementById("q10-option1").checked&&(e+=4),document.getElementById("q11-option3").checked&&(e+=4),document.getElementById("q12-option3").checked&&(e+=4),document.getElementById("q13-option1").checked&&(e+=4),document.getElementById("q14-option3").checked&&(e+=4),document.getElementById("q15-option2").checked&&(e+=4),console.log(e);const n=jl(Dd,"js_quiz_scores");Sd(n).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),console.log(e)})).catch((t=>{console.log(t.message)})),Cd(n,{username:localStorage.getItem("username"),js_score:e}).then((()=>{alert("Your Score is "+e)}))}))}));Sd(jl(Dd,"js_quiz_scores")).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),e.sort(((t,e)=>t.html_score-e.html_score)),e.reverse(),console.log(e);const n=document.getElementById("leaderboardTableJS");e.forEach(((t,e)=>{const s=document.createElement("tr");s.innerHTML=`<td>${e+1}</td><td>${t.username}</td><td>${t.js_score}</td>`,n.appendChild(s)}))})).catch((t=>{console.log(t.message)})),document.addEventListener("DOMContentLoaded",(async function(){const t=document.getElementById("reactquizform");console.log(t),t.addEventListener("submit",(async function(t){t.preventDefault(),console.log("Daba Dis");let e=0;document.getElementById("q1-option2").checked&&(e+=4),document.getElementById("q2-option3").checked&&(e+=4),document.getElementById("q3-option1").checked&&(e+=4),document.getElementById("q4-option3").checked&&(e+=4),document.getElementById("q5-option2").checked&&(e+=4),document.getElementById("q6-option3").checked&&(e+=4),document.getElementById("q7-option1").checked&&(e+=4),document.getElementById("q8-option3").checked&&(e+=4),document.getElementById("q9-option3").checked&&(e+=4),document.getElementById("q10-option1").checked&&(e+=4),document.getElementById("q11-option3").checked&&(e+=4),document.getElementById("q12-option3").checked&&(e+=4),document.getElementById("q13-option3").checked&&(e+=4),document.getElementById("q14-option3").checked&&(e+=4),document.getElementById("q15-option4").checked&&(e+=4),console.log(e);const n=jl(Dd,"react_quiz_scores");Sd(n).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),console.log(e)})).catch((t=>{console.log(t.message)})),Cd(n,{username:localStorage.getItem("username"),react_score:e}).then((()=>{alert("Your Score is "+e)}))}))}));Sd(jl(Dd,"react_quiz_scores")).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),e.sort(((t,e)=>t.react_score-e.react_score)),e.reverse(),console.log(e);const n=document.getElementById("leaderboardTableReact");e.forEach(((t,e)=>{const s=document.createElement("tr");s.innerHTML=`<td>${e+1}</td><td>${t.username}</td><td>${t.react_score}</td>`,n.appendChild(s)}))})).catch((t=>{console.log(t.message)})),document.addEventListener("DOMContentLoaded",(async function(){const t=document.getElementById("pythonquizform");console.log(t),t.addEventListener("submit",(async function(t){t.preventDefault(),console.log("Daba Dis");let e=0;document.getElementById("q1-option2").checked&&(e+=4),document.getElementById("q2-option3").checked&&(e+=4),document.getElementById("q3-option3").checked&&(e+=4),document.getElementById("q4-option3").checked&&(e+=4),document.getElementById("q5-option2").checked&&(e+=4),document.getElementById("q6-option2").checked&&(e+=4),document.getElementById("q7-option2").checked&&(e+=4),document.getElementById("q8-option3").checked&&(e+=4),document.getElementById("q9-option1").checked&&(e+=4),document.getElementById("q10-option2").checked&&(e+=4),document.getElementById("q11-option2").checked&&(e+=4),document.getElementById("q12-option2").checked&&(e+=4),document.getElementById("q13-option2").checked&&(e+=4),document.getElementById("q14-option3").checked&&(e+=4),document.getElementById("q15-option1").checked&&(e+=4),console.log(e);const n=jl(Dd,"python_quiz_scores");Sd(n).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),console.log(e)})).catch((t=>{console.log(t.message)})),Cd(n,{username:localStorage.getItem("username"),python_score:e}).then((()=>{alert("Your Score is "+e)}))}))})),document.addEventListener("DOMContentLoaded",(async function(){Sd(jl(Dd,"python_quiz_scores")).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),e.sort(((t,e)=>t.python_score-e.python_score)),e.reverse(),console.log(e);const n=document.getElementById("leaderboardTablePython");e.forEach(((t,e)=>{const s=document.createElement("tr");s.innerHTML=`<td>${e+1}</td><td>${t.username}</td><td>${t.python_score}</td>`,n.appendChild(s)}))})).catch((t=>{console.log(t.message)}))})),document.addEventListener("DOMContentLoaded",(async function(){const t=document.getElementById("djangoquizform");console.log(t),t.addEventListener("submit",(async function(t){t.preventDefault(),console.log("Daba Dis");let e=0;document.getElementById("q1-option4").checked&&(e+=4),document.getElementById("q2-option3").checked&&(e+=4),document.getElementById("q3-option1").checked&&(e+=4),document.getElementById("q4-option1").checked&&(e+=4),document.getElementById("q5-option2").checked&&(e+=4),document.getElementById("q6-option3").checked&&(e+=4),document.getElementById("q7-option1").checked&&(e+=4),document.getElementById("q8-option2").checked&&(e+=4),document.getElementById("q9-option2").checked&&(e+=4),document.getElementById("q10-option4").checked&&(e+=4),document.getElementById("q11-option2").checked&&(e+=4),document.getElementById("q12-option1").checked&&(e+=4),document.getElementById("q13-option2").checked&&(e+=4),document.getElementById("q14-option4").checked&&(e+=4),document.getElementById("q15-option1").checked&&(e+=4),console.log(e);const n=jl(Dd,"django_quiz_scores");Sd(n).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),console.log(e)})).catch((t=>{console.log(t.message)})),Cd(n,{username:localStorage.getItem("username"),django_score:e}).then((()=>{alert("Your Score is "+e)}))}))})),document.addEventListener("DOMContentLoaded",(async function(){Sd(jl(Dd,"django_quiz_scores")).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),e.sort(((t,e)=>t.django_score-e.django_score)),e.reverse(),console.log(e);const n=document.getElementById("leaderboardTableDjango");e.forEach(((t,e)=>{const s=document.createElement("tr");s.innerHTML=`<td>${e+1}</td><td>${t.username}</td><td>${t.django_score}</td>`,n.appendChild(s)}))})).catch((t=>{console.log(t.message)}))})),document.addEventListener("DOMContentLoaded",(async function(){const t=document.getElementById("javaquizform");console.log(t),t.addEventListener("submit",(async function(t){t.preventDefault(),console.log("Daba Dis");let e=0;document.getElementById("q1-option2").checked&&(e+=4),document.getElementById("q2-option3").checked&&(e+=4),document.getElementById("q3-option1").checked&&(e+=4),document.getElementById("q4-option1").checked&&(e+=4),document.getElementById("q5-option2").checked&&(e+=4),document.getElementById("q6-option3").checked&&(e+=4),document.getElementById("q7-option1").checked&&(e+=4),document.getElementById("q8-option2").checked&&(e+=4),document.getElementById("q9-option2").checked&&(e+=4),document.getElementById("q10-option4").checked&&(e+=4),document.getElementById("q11-option2").checked&&(e+=4),document.getElementById("q12-option1").checked&&(e+=4),document.getElementById("q13-option2").checked&&(e+=4),document.getElementById("q14-option4").checked&&(e+=4),document.getElementById("q15-option1").checked&&(e+=4),console.log(e);const n=jl(Dd,"java_quiz_scores");Sd(n).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),console.log(e)})).catch((t=>{console.log(t.message)})),Cd(n,{username:localStorage.getItem("username"),java_score:e}).then((()=>{alert("Your Score is "+e)}))}))})),document.addEventListener("DOMContentLoaded",(async function(){Sd(jl(Dd,"java_quiz_scores")).then((t=>{let e=[];t.docs.forEach((t=>{e.push({...t.data(),id:t.id})})),e.sort(((t,e)=>t.java_score-e.java_score)),e.reverse(),console.log(e);const n=document.getElementById("leaderboardTableJava");e.forEach(((t,e)=>{const s=document.createElement("tr");s.innerHTML=`<td>${e+1}</td><td>${t.username}</td><td>${t.java_score}</td>`,n.appendChild(s)}))})).catch((t=>{console.log(t.message)}))}))})();