import{_registerComponent as t,registerVersion as e,_getProvider as n,getApp as r,_removeServiceInstance as s,SDK_VERSION as i}from"https://www.gstatic.com/firebasejs/9.16.0/firebase-app.js";const o=function(t){const e=[];let n=0;for(let r=0;r>6|192,e[n++]=63&s|128):55296==(64512&s)&&r+1>18|240,e[n++]=s>>12&63|128,e[n++]=s>>6&63|128,e[n++]=63&s|128):(e[n++]=s>>12|224,e[n++]=s>>6&63|128,e[n++]=63&s|128)}return e},a={byteToCharMap_:null,charToByteMap_:null,byteToCharMapWebSafe_:null,charToByteMapWebSafe_:null,ENCODED_VALS_BASE:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",get ENCODED_VALS(){return this.ENCODED_VALS_BASE+"+/="},get ENCODED_VALS_WEBSAFE(){return this.ENCODED_VALS_BASE+"-_."},HAS_NATIVE_SUPPORT:"function"==typeof atob,encodeByteArray(t,e){if(!Array.isArray(t))throw Error("encodeByteArray takes an array as a parameter");this.init_();const n=e?this.byteToCharMapWebSafe_:this.byteToCharMap_,r=[];for(let e=0;e>2,c=(3&s)<<4|o>>4;let h=(15&o)<<2|u>>6,d=63&u;a||(d=64,i||(h=64)),r.push(n[l],n[c],n[h],n[d])}return r.join("")},encodeString(t,e){return this.HAS_NATIVE_SUPPORT&&!e?btoa(t):this.encodeByteArray(o(t),e)},decodeString(t,e){return this.HAS_NATIVE_SUPPORT&&!e?atob(t):function(t){const e=[];let n=0,r=0;for(;n191&&s<224){const i=t[n++];e[r++]=String.fromCharCode((31&s)<<6|63&i)}else if(s>239&&s<365){const i=((7&s)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536;e[r++]=String.fromCharCode(55296+(i>>10)),e[r++]=String.fromCharCode(56320+(1023&i))}else{const i=t[n++],o=t[n++];e[r++]=String.fromCharCode((15&s)<<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>4;if(r.push(u),64!==o){const t=i<<4&240|o>>2;if(r.push(t),64!==a){const t=o<<6&192|a;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_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(t)]=t,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(t)]=t)}}},u=function(t){return function(t){const e=o(t);return a.encodeByteArray(e,!0)}(t).replace(/\./g,"")};const l=()=>function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("Unable to locate global object.")}().__FIREBASE_DEFAULTS__,c=()=>{if("undefined"==typeof document)return;let t;try{t=document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/)}catch(t){return}const e=t&&function(t){try{return a.decodeString(t,!0)}catch(t){console.error("base64Decode failed: ",t)}return null}(t[1]);return e&&JSON.parse(e)},h=()=>{try{return l()||(()=>{if("undefined"==typeof process||void 0===process.env)return;const t=process.env.__FIREBASE_DEFAULTS__;return t?JSON.parse(t):void 0})()||c()}catch(t){return void console.info(`Unable to get __FIREBASE_DEFAULTS__ due to: ${t}`)}},d=t=>{const e=(t=>{var e,n;return null===(n=null===(e=h())||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 r=parseInt(e.substring(n+1),10);return"["===e[0]?[e.substring(1,n-1),r]:[e.substring(0,n),r]};class f extends Error{constructor(t,e,n){super(e),this.code=t,this.customData=n,this.name="FirebaseError",Object.setPrototypeOf(this,f.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,p.prototype.create)}}class p{constructor(t,e,n){this.service=t,this.serviceName=e,this.errors=n}create(t,...e){const n=e[0]||{},r=`${this.service}/${t}`,s=this.errors[t],i=s?function(t,e){return t.replace(m,((t,n)=>{const r=e[n];return null!=r?String(r):`<${n}?>`}))}(s,n):"Error",o=`${this.serviceName}: ${i} (${r}).`;return new f(r,o,n)}}const m=/\{\$([^}]+)}/g;function g(t,e){if(t===e)return!0;const n=Object.keys(t),r=Object.keys(e);for(const s of n){if(!r.includes(s))return!1;const n=t[s],i=e[s];if(y(n)&&y(i)){if(!g(n,i))return!1}else if(n!==i)return!1}for(const t of r)if(!n.includes(t))return!1;return!0}function y(t){return null!==t&&"object"==typeof t}function w(t){return t&&t._delegate?t._delegate:t}var _;!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"}(_||(_={}));const v={debug:_.DEBUG,verbose:_.VERBOSE,info:_.INFO,warn:_.WARN,error:_.ERROR,silent:_.SILENT},b=_.INFO,E={[_.DEBUG]:"log",[_.VERBOSE]:"log",[_.INFO]:"info",[_.WARN]:"warn",[_.ERROR]:"error"},T=(t,e,...n)=>{if(e`${this.name}: [code=${this.code}]: ${this.message}`}}class Y{constructor(){this.promise=new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}}class J{constructor(t,e){this.user=e,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization",`Bearer ${t}`)}}class X{getToken(){return Promise.resolve(null)}invalidateToken(){}start(t,e){t.enqueueRetryable((()=>e(S.UNAUTHENTICATED)))}shutdown(){}}class Z{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 tt{constructor(t){this.auth=null,t.onInit((t=>{this.auth=t}))}getToken(){return this.auth?this.auth.getToken().then((t=>t?(C("string"==typeof t.accessToken),new J(t.accessToken,new S(this.auth.getUid()))):null)):Promise.resolve(null)}invalidateToken(){}start(t,e){}shutdown(){}}class et{constructor(t,e,n,r){this.t=t,this.i=e,this.o=n,this.u=r,this.type="FirstParty",this.user=S.FIRST_PARTY,this.h=new Map}l(){return this.u?this.u():(C(!("object"!=typeof this.t||null===this.t||!this.t.auth||!this.t.auth.getAuthHeaderValueForFirstParty)),this.t.auth.getAuthHeaderValueForFirstParty([]))}get headers(){this.h.set("X-Goog-AuthUser",this.i);const t=this.l();return t&&this.h.set("Authorization",t),this.o&&this.h.set("X-Goog-Iam-Authorization-Token",this.o),this.h}}class nt{constructor(t,e,n,r){this.t=t,this.i=e,this.o=n,this.u=r}getToken(){return Promise.resolve(new et(this.t,this.i,this.o,this.u))}start(t,e){t.enqueueRetryable((()=>e(S.FIRST_PARTY)))}shutdown(){}invalidateToken(){}}class rt{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 st{constructor(t){this.m=t,this.appCheck=null,t.onInit((t=>{this.appCheck=t}))}getToken(){return this.appCheck?this.appCheck.getToken().then((t=>t?(C("string"==typeof t.token),new rt(t.token)):null)):Promise.resolve(null)}invalidateToken(){}start(t,e){}shutdown(){}}class it{constructor(t,e,n,r,s,i,o,a){this.databaseId=t,this.appId=e,this.persistenceKey=n,this.host=r,this.ssl=s,this.forceLongPolling=i,this.autoDetectLongPolling=o,this.useFetchStreams=a}}class ot{constructor(t,e){this.projectId=t,this.database=e||"(default)"}static empty(){return new ot("","")}get isDefaultDatabase(){return"(default)"===this.database}isEqual(t){return t instanceof ot&&t.projectId===this.projectId&&t.database===this.database}}class at{constructor(t,e,n){void 0===e?e=0:e>t.length&&R(),void 0===n?n=t.length-e:n>t.length-e&&R(),this.segments=t,this.offset=e,this.len=n}get length(){return this.len}isEqual(t){return 0===at.comparator(this,t)}child(t){const e=this.segments.slice(this.offset,this.limit());return t instanceof at?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.lengths)return 1}return t.lengthe.length?1:0}}class ut extends at{construct(t,e,n){return new ut(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 K(L,`Invalid segment (${n}). Paths must not contain // in them.`);e.push(...n.split("/").filter((t=>t.length>0)))}return new ut(e)}static emptyPath(){return new ut([])}}const lt=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class ct extends at{construct(t,e,n){return new ct(t,e,n)}static isValidIdentifier(t){return lt.test(t)}canonicalString(){return this.toArray().map((t=>(t=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),ct.isValidIdentifier(t)||(t="`"+t+"`"),t))).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&"__name__"===this.get(0)}static keyField(){return new ct(["__name__"])}static fromServerFormat(t){const e=[];let n="",r=0;const s=()=>{if(0===n.length)throw new K(L,`Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`);e.push(n),n=""};let i=!1;for(;r=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===ut.comparator(this.path,t.path)}toString(){return this.path.toString()}static comparator(t,e){return ut.comparator(t.path,e.path)}static isDocumentKey(t){return t.length%2==0}static fromSegments(t){return new ht(new ut(t.slice()))}}function dt(t,e,n){if(!n)throw new K(L,`Function ${t}() cannot be called with an empty ${e}.`)}function ft(t){if(!ht.isDocumentKey(t))throw new K(L,`Invalid document reference. Document references must have an even number of segments, but ${t} has ${t.length}.`)}function pt(t){if(ht.isDocumentKey(t))throw new K(L,`Invalid collection reference. Collection references must have an odd number of segments, but ${t} has ${t.length}.`)}function mt(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":R()}function gt(t,e){if("_delegate"in t&&(t=t._delegate),!(t instanceof e)){if(e.name===t.constructor.name)throw new K(L,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{const n=mt(t);throw new K(L,`Expected type '${e.name}', but it was: ${n}`)}}return t}function yt(t,e){if(e<=0)throw new K(L,`Function ${t}() requires a positive number, but it was: ${e}.`)}function wt(t){return null==t}function _t(t){return 0===t&&1/t==-1/0}const vt={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery"};var bt,Et;function Tt(t){if(void 0===t)return D("RPC_ERROR","HTTP error has no status"),x;switch(t){case 200:return"ok";case 400:return j;case 401:return $;case 403:return B;case 404:return M;case 409:return W;case 416:return H;case 429:return U;case 499:return q;case 500:return x;case 501:return G;case 503:return z;case 504:return P;default:return t>=200&&t<300?"ok":t>=400&&t<500?j:t>=500&&t<600?Q:x}}(Et=bt||(bt={}))[Et.OK=0]="OK",Et[Et.CANCELLED=1]="CANCELLED",Et[Et.UNKNOWN=2]="UNKNOWN",Et[Et.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",Et[Et.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",Et[Et.NOT_FOUND=5]="NOT_FOUND",Et[Et.ALREADY_EXISTS=6]="ALREADY_EXISTS",Et[Et.PERMISSION_DENIED=7]="PERMISSION_DENIED",Et[Et.UNAUTHENTICATED=16]="UNAUTHENTICATED",Et[Et.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",Et[Et.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",Et[Et.ABORTED=10]="ABORTED",Et[Et.OUT_OF_RANGE=11]="OUT_OF_RANGE",Et[Et.UNIMPLEMENTED=12]="UNIMPLEMENTED",Et[Et.INTERNAL=13]="INTERNAL",Et[Et.UNAVAILABLE=14]="UNAVAILABLE",Et[Et.DATA_LOSS=15]="DATA_LOSS";class St extends class{constructor(t){this.databaseInfo=t,this.databaseId=t.databaseId;const e=t.ssl?"https":"http";this.p=e+"://"+t.host,this.g="projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database+"/documents"}get v(){return!1}I(t,e,n,r,s){const i=this.T(t,e);F("RestConnection","Sending: ",i,n);const o={};return this.A(o,r,s),this.R(t,i,o,n).then((t=>(F("RestConnection","Received: ",t),t)),(e=>{throw V("RestConnection",`${t} failed with error: `,e,"url: ",i,"request:",n),e}))}P(t,e,n,r,s,i){return this.I(t,e,n,r,s)}A(t,e,n){t["X-Goog-Api-Client"]="gl-js/ fire/"+A,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))}T(t,e){const n=vt[t];return`${this.p}/v1/${e}:${n}`}}{constructor(t,e){super(t),this.V=e}$(t,e){throw new Error("Not supported by FetchConnection")}async R(t,e,n,r){var s;const i=JSON.stringify(r);let o;try{o=await this.V(e,{method:"POST",headers:n,body:i})}catch(t){const e=t;throw new K(Tt(e.status),"Request failed with error: "+e.statusText)}if(!o.ok){let t=await o.json();Array.isArray(t)&&(t=t[0]);const e=null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.message;throw new K(Tt(o.status),`Request failed with error: ${null!=e?e:o.statusText}`)}return o.json()}}function At(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;ee?1:0}function Ft(t,e,n){return t.length===e.length&&t.every(((t,r)=>n(t,e[r])))}function Dt(t){let e=0;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e++;return e}function Vt(t,e){for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}class Nt{constructor(t){this.binaryString=t}static fromBase64String(t){const e=atob(t);return new Nt(e)}static fromUint8Array(t){const e=function(t){let e="";for(let n=0;nt=1e9)throw new K(L,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new K(L,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new K(L,"Timestamp seconds out of range: "+t)}static now(){return xt.fromMillis(Date.now())}static fromDate(t){return xt.fromMillis(t.getTime())}static fromMillis(t){const e=Math.floor(t/1e3),n=Math.floor(1e6*(t-1e3*e));return new xt(e,n)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(t){return this.seconds===t.seconds?kt(this.nanoseconds,t.nanoseconds):kt(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")}}function Lt(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 Pt(t){const e=t.mapValue.fields.__previous_value__;return Lt(e)?Pt(e):e}function Mt(t){const e=Ct(t.mapValue.fields.__local_write_time__.timestampValue);return new xt(e.seconds,e.nanos)}const Bt={fields:{__type__:{stringValue:"__max__"}}};function $t(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?Lt(t)?4:function(t){return"__max__"===(((t.mapValue||{}).fields||{}).__type__||{}).stringValue}(t)?9007199254740991:10:R()}function Ut(t,e){if(t===e)return!0;const n=$t(t);if(n!==$t(e))return!1;switch(n){case 0:case 9007199254740991:return!0;case 1:return t.booleanValue===e.booleanValue;case 4:return Mt(t).isEqual(Mt(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=Ct(t.timestampValue),r=Ct(e.timestampValue);return n.seconds===r.seconds&&n.nanos===r.nanos}(t,e);case 5:return t.stringValue===e.stringValue;case 6:return function(t,e){return qt(t.bytesValue).isEqual(qt(e.bytesValue))}(t,e);case 7:return t.referenceValue===e.referenceValue;case 8:return function(t,e){return Ot(t.geoPointValue.latitude)===Ot(e.geoPointValue.latitude)&&Ot(t.geoPointValue.longitude)===Ot(e.geoPointValue.longitude)}(t,e);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return Ot(t.integerValue)===Ot(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){const n=Ot(t.doubleValue),r=Ot(e.doubleValue);return n===r?_t(n)===_t(r):isNaN(n)&&isNaN(r)}return!1}(t,e);case 9:return Ft(t.arrayValue.values||[],e.arrayValue.values||[],Ut);case 10:return function(t,e){const n=t.mapValue.fields||{},r=e.mapValue.fields||{};if(Dt(n)!==Dt(r))return!1;for(const t in n)if(n.hasOwnProperty(t)&&(void 0===r[t]||!Ut(n[t],r[t])))return!1;return!0}(t,e);default:return R()}}function jt(t,e){return void 0!==(t.values||[]).find((t=>Ut(t,e)))}function Wt(t,e){if(t===e)return 0;const n=$t(t),r=$t(e);if(n!==r)return kt(n,r);switch(n){case 0:case 9007199254740991:return 0;case 1:return kt(t.booleanValue,e.booleanValue);case 2:return function(t,e){const n=Ot(t.integerValue||t.doubleValue),r=Ot(e.integerValue||e.doubleValue);return nr?1:n===r?0:isNaN(n)?isNaN(r)?0:-1:1}(t,e);case 3:return Ht(t.timestampValue,e.timestampValue);case 4:return Ht(Mt(t),Mt(e));case 5:return kt(t.stringValue,e.stringValue);case 6:return function(t,e){const n=qt(t),r=qt(e);return n.compareTo(r)}(t.bytesValue,e.bytesValue);case 7:return function(t,e){const n=t.split("/"),r=e.split("/");for(let t=0;te.mapValue.fields[t]=Jt(n))),e}if(t.arrayValue){const e={arrayValue:{values:[]}};for(let n=0;n<(t.arrayValue.values||[]).length;++n)e.arrayValue.values[n]=Jt(t.arrayValue.values[n]);return e}return Object.assign({},t)}class Xt{constructor(t,e){this.position=t,this.inclusive=e}}function Zt(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":return t>0;case">=":return t>=0;default:return R()}}isInequality(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}getFlattenedFilters(){return[this]}getFilters(){return[this]}getFirstInequalityField(){return this.isInequality()?this.field:null}}class ne extends te{constructor(t,e){super(),this.filters=t,this.op=e,this.D=null}static create(t,e){return new ne(t,e)}matches(t){return"and"===this.op?void 0===this.filters.find((e=>!e.matches(t))):void 0!==this.filters.find((e=>e.matches(t)))}getFlattenedFilters(){return null!==this.D||(this.D=this.filters.reduce(((t,e)=>t.concat(e.getFlattenedFilters())),[])),this.D}getFilters(){return Object.assign([],this.filters)}getFirstInequalityField(){const t=this.F((t=>t.isInequality()));return null!==t?t.field:null}F(t){for(const e of this.getFlattenedFilters())if(t(e))return e;return null}}function re(t,e){return t instanceof ee?function(t,e){return e instanceof ee&&t.op===e.op&&t.field.isEqual(e.field)&&Ut(t.value,e.value)}(t,e):t instanceof ne?function(t,e){return e instanceof ne&&t.op===e.op&&t.filters.length===e.filters.length&&t.filters.reduce(((t,n,r)=>t&&re(n,e.filters[r])),!0)}(t,e):void R()}class se extends ee{constructor(t,e,n){super(t,e,n),this.key=ht.fromName(n.referenceValue)}matches(t){const e=ht.comparator(t.key,this.key);return this.matchesComparison(e)}}class ie extends ee{constructor(t,e){super(t,"in",e),this.keys=ae("in",e)}matches(t){return this.keys.some((e=>e.isEqual(t.key)))}}class oe extends ee{constructor(t,e){super(t,"not-in",e),this.keys=ae("not-in",e)}matches(t){return!this.keys.some((e=>e.isEqual(t.key)))}}function ae(t,e){var n;return((null===(n=e.arrayValue)||void 0===n?void 0:n.values)||[]).map((t=>ht.fromName(t.referenceValue)))}class ue extends ee{constructor(t,e){super(t,"array-contains",e)}matches(t){const e=t.data.field(this.field);return Qt(e)&&jt(e.arrayValue,this.value)}}class le extends ee{constructor(t,e){super(t,"in",e)}matches(t){const e=t.data.field(this.field);return null!==e&&jt(this.value.arrayValue,e)}}class ce extends ee{constructor(t,e){super(t,"not-in",e)}matches(t){if(jt(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;const e=t.data.field(this.field);return null!==e&&!jt(this.value.arrayValue,e)}}class he extends ee{constructor(t,e){super(t,"array-contains-any",e)}matches(t){const e=t.data.field(this.field);return!(!Qt(e)||!e.arrayValue.values)&&e.arrayValue.values.some((t=>jt(this.value.arrayValue,t)))}}class de{constructor(t,e="asc"){this.field=t,this.dir=e}}function fe(t,e){return t.dir===e.dir&&t.field.isEqual(e.field)}class pe{constructor(t){this.timestamp=t}static fromTimestamp(t){return new pe(t)}static min(){return new pe(new xt(0,0))}static max(){return new pe(new xt(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 me{constructor(t,e){this.comparator=t,this.root=e||ye.EMPTY}insert(t,e){return new me(this.comparator,this.root.insert(t,e,this.comparator).copy(null,null,ye.BLACK,null,null))}remove(t){return new me(this.comparator,this.root.remove(t,this.comparator).copy(null,null,ye.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 r=this.comparator(t,n.key);if(0===r)return e+n.left.size;r<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 ge(this.root,null,this.comparator,!1)}getIteratorFrom(t){return new ge(this.root,t,this.comparator,!1)}getReverseIterator(){return new ge(this.root,null,this.comparator,!0)}getReverseIteratorFrom(t){return new ge(this.root,t,this.comparator,!0)}}class ge{constructor(t,e,n,r){this.isReverse=r,this.nodeStack=[];let s=1;for(;!t.isEmpty();)if(s=e?n(t.key,e):1,e&&r&&(s*=-1),s<0)t=this.isReverse?t.left:t.right;else{if(0===s){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 ye{constructor(t,e,n,r,s){this.key=t,this.value=e,this.color=null!=n?n:ye.RED,this.left=null!=r?r:ye.EMPTY,this.right=null!=s?s:ye.EMPTY,this.size=this.left.size+1+this.right.size}copy(t,e,n,r,s){return new ye(null!=t?t:this.key,null!=e?e:this.value,null!=n?n:this.color,null!=r?r:this.left,null!=s?s: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 r=this;const s=n(t,r.key);return r=s<0?r.copy(null,null,null,r.left.insert(t,e,n),null):0===s?r.copy(null,e,null,null,null):r.copy(null,null,null,null,r.right.insert(t,e,n)),r.fixUp()}removeMin(){if(this.left.isEmpty())return ye.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,r=this;if(e(t,r.key)<0)r.left.isEmpty()||r.left.isRed()||r.left.left.isRed()||(r=r.moveRedLeft()),r=r.copy(null,null,null,r.left.remove(t,e),null);else{if(r.left.isRed()&&(r=r.rotateRight()),r.right.isEmpty()||r.right.isRed()||r.right.left.isRed()||(r=r.moveRedRight()),0===e(t,r.key)){if(r.right.isEmpty())return ye.EMPTY;n=r.right.min(),r=r.copy(n.key,n.value,null,null,r.right.removeMin())}r=r.copy(null,null,null,null,r.right.remove(t,e))}return r.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,ye.RED,null,this.right.left);return this.right.copy(null,null,this.color,t,null)}rotateRight(){const t=this.copy(null,null,ye.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 R();if(this.right.isRed())throw R();const t=this.left.check();if(t!==this.right.check())throw R();return t+(this.isRed()?0:1)}}ye.EMPTY=null,ye.RED=!0,ye.BLACK=!1,ye.EMPTY=new class{constructor(){this.size=0}get key(){throw R()}get value(){throw R()}get color(){throw R()}get left(){throw R()}get right(){throw R()}copy(t,e,n,r,s){return this}insert(t,e,n){return new ye(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 we{constructor(t){this.comparator=t,this.data=new me(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 r=n.getNext();if(this.comparator(r.key,t[1])>=0)return;e(r.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 _e(this.data.getIterator())}getIteratorFrom(t){return new _e(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{e=e.add(t)})),e}isEqual(t){if(!(t instanceof we))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,r=n.getNext().key;if(0!==this.comparator(t,r))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 we(this.comparator);return e.data=t,e}}class _e{constructor(t){this.iter=t}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}}class ve{constructor(t){this.fields=t,t.sort(ct.comparator)}static empty(){return new ve([])}unionWith(t){let e=new we(ct.comparator);for(const t of this.fields)e=e.add(t);for(const n of t)e=e.add(n);return new ve(e.toArray())}covers(t){for(const e of this.fields)if(e.isPrefixOf(t))return!0;return!1}isEqual(t){return Ft(this.fields,t.fields,((t,e)=>t.isEqual(e)))}}class be{constructor(t){this.value=t}static empty(){return new be({mapValue:{}})}field(t){if(t.isEmpty())return this.value;{let e=this.value;for(let n=0;n{if(!e.isImmediateParentOf(s)){const t=this.getFieldsMap(e);this.applyChanges(t,n,r),n={},r=[],e=s.popLast()}t?n[s.lastSegment()]=Jt(t):r.push(s.lastSegment())}));const s=this.getFieldsMap(e);this.applyChanges(s,n,r)}delete(t){const e=this.field(t.popLast());Yt(e)&&e.mapValue.fields&&delete e.mapValue.fields[t.lastSegment()]}isEqual(t){return Ut(this.value,t.value)}getFieldsMap(t){let e=this.value;e.mapValue.fields||(e.mapValue={fields:{}});for(let n=0;nt[e]=n));for(const e of n)delete t[e]}clone(){return new be(Jt(this.value))}}class Ee{constructor(t,e,n,r,s,i,o){this.key=t,this.documentType=e,this.version=n,this.readTime=r,this.createTime=s,this.data=i,this.documentState=o}static newInvalidDocument(t){return new Ee(t,0,pe.min(),pe.min(),pe.min(),be.empty(),0)}static newFoundDocument(t,e,n,r){return new Ee(t,1,e,pe.min(),n,r,0)}static newNoDocument(t,e){return new Ee(t,2,e,pe.min(),pe.min(),be.empty(),0)}static newUnknownDocument(t,e){return new Ee(t,3,e,pe.min(),pe.min(),be.empty(),2)}convertToFoundDocument(t,e){return!this.createTime.isEqual(pe.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=be.empty(),this.documentState=0,this}convertToUnknownDocument(t){return this.version=t,this.documentType=3,this.data=be.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=pe.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 Ee&&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 Ee(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 Te{constructor(t,e=null,n=[],r=[],s=null,i=null,o=null){this.path=t,this.collectionGroup=e,this.orderBy=n,this.filters=r,this.limit=s,this.startAt=i,this.endAt=o,this.S=null}}function Se(t,e=null,n=[],r=[],s=null,i=null,o=null){return new Te(t,e,n,r,s,i,o)}class Ae{constructor(t,e=null,n=[],r=[],s=null,i="F",o=null,a=null){this.path=t,this.collectionGroup=e,this.explicitOrderBy=n,this.filters=r,this.limit=s,this.limitType=i,this.startAt=o,this.endAt=a,this.q=null,this.O=null,this.startAt,this.endAt}}function Ie(t){return t.explicitOrderBy.length>0?t.explicitOrderBy[0].field:null}function ke(t){for(const e of t.filters){const t=e.getFirstInequalityField();if(null!==t)return t}return null}function Fe(t){return null!==t.collectionGroup}function De(t){const e=O(t);if(null===e.q){e.q=[];const t=ke(e),n=Ie(e);if(null!==t&&null===n)t.isKeyField()||e.q.push(new de(t)),e.q.push(new de(ct.keyField(),"asc"));else{let t=!1;for(const n of e.explicitOrderBy)e.q.push(n),n.field.isKeyField()&&(t=!0);if(!t){const t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.q.push(new de(ct.keyField(),t))}}}return e.q}function Ve(t){const e=O(t);if(!e.O)if("F"===e.limitType)e.O=Se(e.path,e.collectionGroup,De(e),e.filters,e.limit,e.startAt,e.endAt);else{const t=[];for(const n of De(e)){const e="desc"===n.dir?"asc":"desc";t.push(new de(n.field,e))}const n=e.endAt?new Xt(e.endAt.position,e.endAt.inclusive):null,r=e.startAt?new Xt(e.startAt.position,e.startAt.inclusive):null;e.O=Se(e.path,e.collectionGroup,t,e.filters,e.limit,n,r)}return e.O}function Ne(t,e){e.getFirstInequalityField(),ke(t);const n=t.filters.concat([e]);return new Ae(t.path,t.collectionGroup,t.explicitOrderBy.slice(),n,t.limit,t.limitType,t.startAt,t.endAt)}function Re(t,e){return function(t){return"number"==typeof t&&Number.isInteger(t)&&!_t(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}(e)?function(t){return{integerValue:""+t}}(e):function(t,e){if(t.k){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:_t(e)?"-0":e}}(t,e)}class Ce{constructor(){this._=void 0}}class Oe extends Ce{}class qe extends Ce{constructor(t){super(),this.elements=t}}class xe extends Ce{constructor(t){super(),this.elements=t}}class Le extends Ce{constructor(t,e){super(),this.C=t,this.L=e}}class Pe{constructor(t,e){this.field=t,this.transform=e}}class Me{constructor(t,e){this.updateTime=t,this.exists=e}static none(){return new Me}static exists(t){return new Me(void 0,t)}static updateTime(t){return new Me(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)}}class Be{}class $e extends Be{constructor(t,e,n,r=[]){super(),this.key=t,this.value=e,this.precondition=n,this.fieldTransforms=r,this.type=0}getFieldMask(){return null}}class Ue extends Be{constructor(t,e,n,r,s=[]){super(),this.key=t,this.data=e,this.fieldMask=n,this.precondition=r,this.fieldTransforms=s,this.type=1}getFieldMask(){return this.fieldMask}}class je extends Be{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class We extends Be{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}const He={asc:"ASCENDING",desc:"DESCENDING"},Ge={"<":"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"},Qe={and:"AND",or:"OR"};class ze{constructor(t,e){this.databaseId=t,this.k=e}}function Ke(t,e){return t.k?`${new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+e.nanoseconds).slice(-9)}Z`:{seconds:""+e.seconds,nanos:e.nanoseconds}}function Ye(t,e){return t.k?e.toBase64():e.toUint8Array()}function Je(t,e){return Ke(t,e.toTimestamp())}function Xe(t){return C(!!t),pe.fromTimestamp(function(t){const e=Ct(t);return new xt(e.seconds,e.nanos)}(t))}function Ze(t,e){return function(t){return new ut(["projects",t.projectId,"databases",t.database])}(t).child("documents").child(e).canonicalString()}function tn(t,e){return Ze(t.databaseId,e.path)}function en(t,e){const n=function(t){const e=ut.fromString(t);return C(fn(e)),e}(e);if(n.get(1)!==t.databaseId.projectId)throw new K(L,"Tried to deserialize key from different project: "+n.get(1)+" vs "+t.databaseId.projectId);if(n.get(3)!==t.databaseId.database)throw new K(L,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new ht((C((r=n).length>4&&"documents"===r.get(4)),r.popFirst(5)));var r}function nn(t,e){return Ze(t.databaseId,e)}function rn(t){return new ut(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function sn(t,e,n){return{name:tn(t,e),fields:n.value.mapValue.fields}}function on(t,e){const n={structuredQuery:{}},r=e.path;null!==e.collectionGroup?(n.parent=nn(t,r),n.structuredQuery.from=[{collectionId:e.collectionGroup,allDescendants:!0}]):(n.parent=nn(t,r.popLast()),n.structuredQuery.from=[{collectionId:r.lastSegment()}]);const s=function(t){if(0!==t.length)return hn(ne.create(t,"and"))}(e.filters);s&&(n.structuredQuery.where=s);const i=function(t){if(0!==t.length)return t.map((t=>function(t){return{field:cn(t.field),direction:an(t.dir)}}(t)))}(e.orderBy);i&&(n.structuredQuery.orderBy=i);const o=function(t,e){return t.k||wt(e)?e:{value:e}}(t,e.limit);var a;return null!==o&&(n.structuredQuery.limit=o),e.startAt&&(n.structuredQuery.startAt={before:(a=e.startAt).inclusive,values:a.position}),e.endAt&&(n.structuredQuery.endAt=function(t){return{before:!t.inclusive,values:t.position}}(e.endAt)),n}function an(t){return He[t]}function un(t){return Ge[t]}function ln(t){return Qe[t]}function cn(t){return{fieldPath:t.canonicalString()}}function hn(t){return t instanceof ee?function(t){if("=="===t.op){if(Kt(t.value))return{unaryFilter:{field:cn(t.field),op:"IS_NAN"}};if(zt(t.value))return{unaryFilter:{field:cn(t.field),op:"IS_NULL"}}}else if("!="===t.op){if(Kt(t.value))return{unaryFilter:{field:cn(t.field),op:"IS_NOT_NAN"}};if(zt(t.value))return{unaryFilter:{field:cn(t.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:cn(t.field),op:un(t.op),value:t.value}}}(t):t instanceof ne?function(t){const e=t.getFilters().map((t=>hn(t)));return 1===e.length?e[0]:{compositeFilter:{op:ln(t.op),filters:e}}}(t):R()}function dn(t){const e=[];return t.fields.forEach((t=>e.push(t.canonicalString()))),{fieldPaths:e}}function fn(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)}function pn(t){return new ze(t,!0)}class mn{constructor(t,e,n=1e3,r=1.5,s=6e4){this.M=t,this.timerId=e,this.U=n,this.j=r,this.B=s,this.W=0,this.G=null,this.K=Date.now(),this.reset()}reset(){this.W=0}Y(){this.W=this.B}H(t){this.cancel();const e=Math.floor(this.W+this.J()),n=Math.max(0,Date.now()-this.K),r=Math.max(0,e-n);r>0&&F("ExponentialBackoff",`Backing off for ${r} ms (base delay: ${this.W} ms, delay with jitter: ${e} ms, last attempt: ${n} ms ago)`),this.G=this.M.enqueueAfterDelay(this.timerId,r,(()=>(this.K=Date.now(),t()))),this.W*=this.j,this.Wthis.B&&(this.W=this.B)}X(){null!==this.G&&(this.G.skipDelay(),this.G=null)}cancel(){null!==this.G&&(this.G.cancel(),this.G=null)}J(){return(Math.random()-.5)*this.W}}class gn extends class{}{constructor(t,e,n,r){super(),this.authCredentials=t,this.appCheckCredentials=e,this.connection=n,this.C=r,this.Z=!1}tt(){if(this.Z)throw new K(j,"The client has already been terminated.")}I(t,e,n){return this.tt(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([r,s])=>this.connection.I(t,e,n,r,s))).catch((t=>{throw"FirebaseError"===t.name?(t.code===$&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new K(x,t.toString())}))}P(t,e,n,r){return this.tt(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([s,i])=>this.connection.P(t,e,n,s,i,r))).catch((t=>{throw"FirebaseError"===t.name?(t.code===$&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new K(x,t.toString())}))}terminate(){this.Z=!0}}async function yn(t,e){const n=O(t),r=rn(n.C)+"/documents",s={writes:e.map((t=>function(t,e){let n;if(e instanceof $e)n={update:sn(t,e.key,e.value)};else if(e instanceof je)n={delete:tn(t,e.key)};else if(e instanceof Ue)n={update:sn(t,e.key,e.data),updateMask:dn(e.fieldMask)};else{if(!(e instanceof We))return R();n={verify:tn(t,e.key)}}return e.fieldTransforms.length>0&&(n.updateTransforms=e.fieldTransforms.map((t=>function(t,e){const n=e.transform;if(n instanceof Oe)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof qe)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof xe)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof Le)return{fieldPath:e.field.canonicalString(),increment:n.L};throw R()}(0,t)))),e.precondition.isNone||(n.currentDocument=function(t,e){return void 0!==e.updateTime?{updateTime:Je(t,e.updateTime)}:void 0!==e.exists?{exists:e.exists}:R()}(t,e.precondition)),n}(n.C,t)))};await n.I("Commit",r,s)}async function wn(t,e){const n=O(t),r=rn(n.C)+"/documents",s={documents:e.map((t=>tn(n.C,t)))},i=await n.P("BatchGetDocuments",r,s,e.length),o=new Map;i.forEach((t=>{const e=function(t,e){return"found"in e?function(t,e){C(!!e.found),e.found.name,e.found.updateTime;const n=en(t,e.found.name),r=Xe(e.found.updateTime),s=e.found.createTime?Xe(e.found.createTime):pe.min(),i=new be({mapValue:{fields:e.found.fields}});return Ee.newFoundDocument(n,r,s,i)}(t,e):"missing"in e?function(t,e){C(!!e.missing),C(!!e.readTime);const n=en(t,e.missing),r=Xe(e.readTime);return Ee.newNoDocument(n,r)}(t,e):R()}(n.C,t);o.set(e.key.toString(),e)}));const a=[];return e.forEach((t=>{const e=o.get(t.toString());C(!!e),a.push(e)})),a}const _n=new Map;function vn(t){if(t._terminated)throw new K(j,"The client has already been terminated.");if(!_n.has(t)){F("ComponentProvider","Initializing Datastore");const i=function(t){return new St(t,fetch.bind(null))}((e=t._databaseId,n=t.app.options.appId||"",r=t._persistenceKey,s=t._freezeSettings(),new it(e,n,r,s.host,s.ssl,s.experimentalForceLongPolling,s.experimentalAutoDetectLongPolling,s.useFetchStreams))),o=pn(t._databaseId),a=function(t,e,n,r){return new gn(t,e,n,r)}(t._authCredentials,t._appCheckCredentials,i,o);_n.set(t,a)}var e,n,r,s;return _n.get(t)}class bn{constructor(t){var e;if(void 0===t.host){if(void 0!==t.ssl)throw new K(L,"Can't provide ssl option if host option is not set");this.host="firestore.googleapis.com",this.ssl=!0}else this.host=t.host,this.ssl=null===(e=t.ssl)||void 0===e||e;if(this.credentials=t.credentials,this.ignoreUndefinedProperties=!!t.ignoreUndefinedProperties,void 0===t.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==t.cacheSizeBytes&&t.cacheSizeBytes<1048576)throw new K(L,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=t.cacheSizeBytes}this.experimentalForceLongPolling=!!t.experimentalForceLongPolling,this.experimentalAutoDetectLongPolling=!!t.experimentalAutoDetectLongPolling,this.useFetchStreams=!!t.useFetchStreams,function(t,e,n,r){if(!0===e&&!0===r)throw new K(L,"experimentalForceLongPolling and experimentalAutoDetectLongPolling cannot be used together.")}(0,t.experimentalForceLongPolling,0,t.experimentalAutoDetectLongPolling)}isEqual(t){return this.host===t.host&&this.ssl===t.ssl&&this.credentials===t.credentials&&this.cacheSizeBytes===t.cacheSizeBytes&&this.experimentalForceLongPolling===t.experimentalForceLongPolling&&this.experimentalAutoDetectLongPolling===t.experimentalAutoDetectLongPolling&&this.ignoreUndefinedProperties===t.ignoreUndefinedProperties&&this.useFetchStreams===t.useFetchStreams}}class En{constructor(t,e,n,r){this._authCredentials=t,this._appCheckCredentials=e,this._databaseId=n,this._app=r,this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new bn({}),this._settingsFrozen=!1}get app(){if(!this._app)throw new K(j,"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 K(j,"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 bn(t),void 0!==t.credentials&&(this._authCredentials=function(t){if(!t)return new X;switch(t.type){case"gapi":const e=t.client;return new nt(e,t.sessionIndex||"0",t.iamToken||null,t.authTokenFactory||null);case"provider":return t.client;default:throw new K(L,"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=_n.get(t);e&&(F("ComponentProvider","Removing Datastore"),_n.delete(t),e.terminate())}(this),Promise.resolve()}}function Tn(t,e,r){r||(r="(default)");const s=n(t,"firestore/lite");if(s.isInitialized(r))throw new K(j,"Firestore can only be initialized once per app.");return s.initialize({options:e,instanceIdentifier:r})}function Sn(t,e){const s="object"==typeof t?t:r(),i="string"==typeof t?t:e||"(default)",o=n(s,"firestore/lite").getImmediate({identifier:i});if(!o._initialized){const t=d("firestore");t&&An(o,...t)}return o}function An(t,e,n,r={}){var s;const i=(t=gt(t,En))._getSettings();if("firestore.googleapis.com"!==i.host&&i.host!==e&&V("Host has been set in both settings() and useEmulator(), emulator host will be used"),t._setSettings(Object.assign(Object.assign({},i),{host:`${e}:${n}`,ssl:!1})),r.mockUserToken){let e,n;if("string"==typeof r.mockUserToken)e=r.mockUserToken,n=S.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",r=t.iat||0,s=t.sub||t.user_id;if(!s)throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");const i=Object.assign({iss:`https://securetoken.google.com/${n}`,aud:n,iat:r,exp:r+3600,auth_time:r,sub:s,user_id:s,firebase:{sign_in_provider:"custom",identities:{}}},t);return[u(JSON.stringify({alg:"none",type:"JWT"})),u(JSON.stringify(i)),""].join(".")}(r.mockUserToken,null===(s=t._app)||void 0===s?void 0:s.options.projectId);const i=r.mockUserToken.sub||r.mockUserToken.user_id;if(!i)throw new K(L,"mockUserToken must contain 'sub' or 'user_id' field!");n=new S(i)}t._authCredentials=new Z(new J(e,n))}}function In(t){return t=gt(t,En),s(t.app,"firestore/lite"),t._delete()}class kn{constructor(){this.type="AggregateField"}}class Fn{constructor(t,e){this._data=e,this.type="AggregateQuerySnapshot",this.query=t}data(){return this._data}}class Dn{constructor(t,e,n){this.query=t,this.datastore=e,this.userDataWriter=n}run(){return async function(t,e){const n=O(t),r=function(t,e){const n=on(t,e);return{structuredAggregationQuery:{aggregations:[{count:{},alias:"count_alias"}],structuredQuery:n.structuredQuery},parent:n.parent}}(n.C,Ve(e)),s=r.parent;return n.connection.v||delete r.parent,(await n.P("RunAggregationQuery",s,r,1)).filter((t=>!!t.result)).map((t=>t.result.aggregateFields))}(this.datastore,this.query._query).then((t=>{C(void 0!==t[0]);const e=Object.entries(t[0]).filter((([t,e])=>"count_alias"===t)).map((([t,e])=>this.userDataWriter.convertValue(e)))[0];return C("number"==typeof e),Promise.resolve(new Fn(this.query,{count:e}))}))}}class Vn{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 Rn(this.firestore,this.converter,this._key.path.popLast())}withConverter(t){return new Vn(this.firestore,t,this._key)}}class Nn{constructor(t,e,n){this.converter=e,this._query=n,this.type="query",this.firestore=t}withConverter(t){return new Nn(this.firestore,t,this._query)}}class Rn extends Nn{constructor(t,e,n){super(t,e,new Ae(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 Vn(this.firestore,null,new ht(t))}withConverter(t){return new Rn(this.firestore,t,this._path)}}function Cn(t,e,...n){if(t=w(t),dt("collection","path",e),t instanceof En){const r=ut.fromString(e,...n);return pt(r),new Rn(t,null,r)}{if(!(t instanceof Vn||t instanceof Rn))throw new K(L,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const r=t._path.child(ut.fromString(e,...n));return pt(r),new Rn(t.firestore,null,r)}}function On(t,e){if(t=gt(t,En),dt("collectionGroup","collection id",e),e.indexOf("/")>=0)throw new K(L,`Invalid collection ID '${e}' passed to function collectionGroup(). Collection IDs must not contain '/'.`);return new Nn(t,null,function(t){return new Ae(ut.emptyPath(),t)}(e))}function qn(t,e,...n){if(t=w(t),1===arguments.length&&(e=It.N()),dt("doc","path",e),t instanceof En){const r=ut.fromString(e,...n);return ft(r),new Vn(t,null,new ht(r))}{if(!(t instanceof Vn||t instanceof Rn))throw new K(L,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const r=t._path.child(ut.fromString(e,...n));return ft(r),new Vn(t.firestore,t instanceof Rn?t.converter:null,new ht(r))}}function xn(t,e){return t=w(t),e=w(e),(t instanceof Vn||t instanceof Rn)&&(e instanceof Vn||e instanceof Rn)&&t.firestore===e.firestore&&t.path===e.path&&t.converter===e.converter}function Ln(t,e){return t=w(t),e=w(e),t instanceof Nn&&e instanceof Nn&&t.firestore===e.firestore&&function(t,e){return function(t,e){if(t.limit!==e.limit)return!1;if(t.orderBy.length!==e.orderBy.length)return!1;for(let n=0;n90)throw new K(L,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new K(L,"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 kt(this._lat,t._lat)||kt(this._long,t._long)}}const jn=/^__.*__$/;class Wn{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return null!==this.fieldMask?new Ue(t,this.data,this.fieldMask,e,this.fieldTransforms):new $e(t,this.data,e,this.fieldTransforms)}}class Hn{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return new Ue(t,this.data,this.fieldMask,e,this.fieldTransforms)}}function Gn(t){switch(t){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw R()}}class Qn{constructor(t,e,n,r,s,i){this.settings=t,this.databaseId=e,this.C=n,this.ignoreUndefinedProperties=r,void 0===s&&this.et(),this.fieldTransforms=s||[],this.fieldMask=i||[]}get path(){return this.settings.path}get nt(){return this.settings.nt}rt(t){return new Qn(Object.assign(Object.assign({},this.settings),t),this.databaseId,this.C,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}st(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.rt({path:n,it:!1});return r.ot(t),r}ut(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.rt({path:n,it:!1});return r.et(),r}ct(t){return this.rt({path:void 0,it:!0})}at(t){return fr(t,this.settings.methodName,this.settings.ht||!1,this.path,this.settings.lt)}contains(t){return void 0!==this.fieldMask.find((e=>t.isPrefixOf(e)))||void 0!==this.fieldTransforms.find((e=>t.isPrefixOf(e.field)))}et(){if(this.path)for(let t=0;tu.covers(t.field)))}else u=null,l=o.fieldTransforms;return new Wn(new be(a),u,l)}class Jn extends $n{_toFieldTransform(t){if(2!==t.nt)throw 1===t.nt?t.at(`${this._methodName}() can only appear at the top level of your update data`):t.at(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);return t.fieldMask.push(t.path),null}isEqual(t){return t instanceof Jn}}function Xn(t,e,n){return new Qn({nt:3,lt:e.settings.lt,methodName:t._methodName,it:n},e.databaseId,e.C,e.ignoreUndefinedProperties)}class Zn extends $n{_toFieldTransform(t){return new Pe(t.path,new Oe)}isEqual(t){return t instanceof Zn}}class tr extends $n{constructor(t,e){super(t),this.dt=e}_toFieldTransform(t){const e=Xn(this,t,!0),n=this.dt.map((t=>or(t,e))),r=new qe(n);return new Pe(t.path,r)}isEqual(t){return this===t}}class er extends $n{constructor(t,e){super(t),this.dt=e}_toFieldTransform(t){const e=Xn(this,t,!0),n=this.dt.map((t=>or(t,e))),r=new xe(n);return new Pe(t.path,r)}isEqual(t){return this===t}}class nr extends $n{constructor(t,e){super(t),this.wt=e}_toFieldTransform(t){const e=new Le(t.C,Re(t.C,this.wt));return new Pe(t.path,e)}isEqual(t){return this===t}}function rr(t,e,n,r){const s=t.ft(1,e,n);lr("Data must be an object, but it was:",s,r);const i=[],o=be.empty();Vt(r,((t,r)=>{const a=dr(e,t,n);r=w(r);const u=s.ut(a);if(r instanceof Jn)i.push(a);else{const t=or(r,u);null!=t&&(i.push(a),o.set(a,t))}}));const a=new ve(i);return new Hn(o,a,s.fieldTransforms)}function sr(t,e,n,r,s,i){const o=t.ft(1,e,n),a=[cr(e,r,n)],u=[s];if(i.length%2!=0)throw new K(L,`Function ${e}() needs to be called with an even number of arguments that alternate between field names and values.`);for(let t=0;t=0;--t)if(!pr(l,a[t])){const e=a[t];let n=u[t];n=w(n);const r=o.ut(e);if(n instanceof Jn)l.push(e);else{const t=or(n,r);null!=t&&(l.push(e),c.set(e,t))}}const h=new ve(l);return new Hn(c,h,o.fieldTransforms)}function ir(t,e,n,r=!1){return or(n,t.ft(r?4:3,e))}function or(t,e){if(ur(t=w(t)))return lr("Unsupported field value:",e,t),ar(t,e);if(t instanceof $n)return function(t,e){if(!Gn(e.nt))throw e.at(`${t._methodName}() can only be used with update() and set()`);if(!e.path)throw e.at(`${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.it&&4!==e.nt)throw e.at("Nested arrays are not supported");return function(t,e){const n=[];let r=0;for(const s of t){let t=or(s,e.ct(r));null==t&&(t={nullValue:"NULL_VALUE"}),n.push(t),r++}return{arrayValue:{values:n}}}(t,e)}return function(t,e){if(null===(t=w(t)))return{nullValue:"NULL_VALUE"};if("number"==typeof t)return Re(e.C,t);if("boolean"==typeof t)return{booleanValue:t};if("string"==typeof t)return{stringValue:t};if(t instanceof Date){const n=xt.fromDate(t);return{timestampValue:Ke(e.C,n)}}if(t instanceof xt){const n=new xt(t.seconds,1e3*Math.floor(t.nanoseconds/1e3));return{timestampValue:Ke(e.C,n)}}if(t instanceof Un)return{geoPointValue:{latitude:t.latitude,longitude:t.longitude}};if(t instanceof Pn)return{bytesValue:Ye(e.C,t._byteString)};if(t instanceof Vn){const n=e.databaseId,r=t.firestore._databaseId;if(!r.isEqual(n))throw e.at(`Document reference is for database ${r.projectId}/${r.database} but should be for database ${n.projectId}/${n.database}`);return{referenceValue:Ze(t.firestore._databaseId||e.databaseId,t._key.path)}}throw e.at(`Unsupported field value: ${mt(t)}`)}(t,e)}function ar(t,e){const n={};return function(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}(t)?e.path&&e.path.length>0&&e.fieldMask.push(e.path):Vt(t,((t,r)=>{const s=or(r,e.st(t));null!=s&&(n[t]=s)})),{mapValue:{fields:n}}}function ur(t){return!("object"!=typeof t||null===t||t instanceof Array||t instanceof Date||t instanceof xt||t instanceof Un||t instanceof Pn||t instanceof Vn||t instanceof $n)}function lr(t,e,n){if(!ur(n)||!function(t){return"object"==typeof t&&null!==t&&(Object.getPrototypeOf(t)===Object.prototype||null===Object.getPrototypeOf(t))}(n)){const r=mt(n);throw"an object"===r?e.at(t+" a custom object"):e.at(t+" "+r)}}function cr(t,e,n){if((e=w(e))instanceof Mn)return e._internalPath;if("string"==typeof e)return dr(t,e);throw fr("Field path arguments must be of type string or ",t,!1,void 0,n)}const hr=new RegExp("[~\\*/\\[\\]]");function dr(t,e,n){if(e.search(hr)>=0)throw fr(`Invalid field path (${e}). Paths must not contain '~', '*', '/', '[', or ']'`,t,!1,void 0,n);try{return new Mn(...e.split("."))._internalPath}catch(r){throw fr(`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,t,!1,void 0,n)}}function fr(t,e,n,r,s){const i=r&&!r.isEmpty(),o=void 0!==s;let a=`Function ${e}() called with invalid data`;n&&(a+=" (via `toFirestore()`)"),a+=". ";let u="";return(i||o)&&(u+=" (found",i&&(u+=` in field ${r}`),o&&(u+=` in document ${s}`),u+=")"),new K(L,a+t+u)}function pr(t,e){return t.some((t=>t.isEqual(e)))}class mr{constructor(t,e,n,r,s){this._firestore=t,this._userDataWriter=e,this._key=n,this._document=r,this._converter=s}get id(){return this._key.path.lastSegment()}get ref(){return new Vn(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){if(this._document){if(this._converter){const t=new gr(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(_r("DocumentSnapshot.get",t));if(null!==e)return this._userDataWriter.convertValue(e)}}}class gr extends mr{data(){return super.data()}}class yr{constructor(t,e){this._docs=e,this.query=t}get docs(){return[...this._docs]}get size(){return this.docs.length}get empty(){return 0===this.docs.length}forEach(t,e){this._docs.forEach(t,e)}}function wr(t,e){return t=w(t),e=w(e),t instanceof mr&&e instanceof mr?t._firestore===e._firestore&&t._key.isEqual(e._key)&&(null===t._document?null===e._document:t._document.isEqual(e._document))&&t._converter===e._converter:t instanceof yr&&e instanceof yr&&Ln(t.query,e.query)&&Ft(t.docs,e.docs,wr)}function _r(t,e){return"string"==typeof e?dr(t,e):e instanceof Mn?e._internalPath:e._delegate._internalPath}class vr{}class br extends vr{}function Er(t,e,...n){let r=[];e instanceof vr&&r.push(e),r=r.concat(n),function(t){const e=t.filter((t=>t instanceof Ar)).length,n=t.filter((t=>t instanceof Tr)).length;if(e>1||e>0&&n>0)throw new K(L,"InvalidQuery. When using composite filters, you cannot use more than one filter at the top level. Consider nesting the multiple filters within an `and(...)` statement. For example: change `query(query, where(...), or(...))` to `query(query, and(where(...), or(...)))`.")}(r);for(const e of r)t=e._apply(t);return t}class Tr extends br{constructor(t,e,n){super(),this._field=t,this._op=e,this._value=n,this.type="where"}static _create(t,e,n){return new Tr(t,e,n)}_apply(t){const e=this._parse(t);return Ur(t._query,e),new Nn(t.firestore,t.converter,Ne(t._query,e))}_parse(t){const e=Kn(t.firestore),n=function(t,e,n,r,s,i,o){let a;if(s.isKeyField()){if("array-contains"===i||"array-contains-any"===i)throw new K(L,`Invalid Query. You can't perform '${i}' queries on documentId().`);if("in"===i||"not-in"===i){$r(o,i);const e=[];for(const n of o)e.push(Br(r,t,n));a={arrayValue:{values:e}}}else a=Br(r,t,o)}else"in"!==i&&"not-in"!==i&&"array-contains-any"!==i||$r(o,i),a=ir(n,"where",o,"in"===i||"not-in"===i);return ee.create(s,i,a)}(t._query,0,e,t.firestore._databaseId,this._field,this._op,this._value);return n}}function Sr(t,e,n){const r=e,s=_r("where",t);return Tr._create(s,r,n)}class Ar extends vr{constructor(t,e){super(),this.type=t,this._queryConstraints=e}static _create(t,e){return new Ar(t,e)}_parse(t){const e=this._queryConstraints.map((e=>e._parse(t))).filter((t=>t.getFilters().length>0));return 1===e.length?e[0]:ne.create(e,this._getOperator())}_apply(t){const e=this._parse(t);return 0===e.getFilters().length?t:(function(t,e){let n=t;const r=e.getFlattenedFilters();for(const t of r)Ur(n,t),n=Ne(n,t)}(t._query,e),new Nn(t.firestore,t.converter,Ne(t._query,e)))}_getQueryConstraints(){return this._queryConstraints}_getOperator(){return"and"===this.type?"and":"or"}}function Ir(...t){return t.forEach((t=>Wr("or",t))),Ar._create("or",t)}function kr(...t){return t.forEach((t=>Wr("and",t))),Ar._create("and",t)}class Fr extends br{constructor(t,e){super(),this._field=t,this._direction=e,this.type="orderBy"}static _create(t,e){return new Fr(t,e)}_apply(t){const e=function(t,e,n){if(null!==t.startAt)throw new K(L,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==t.endAt)throw new K(L,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");const r=new de(e,n);return function(t,e){if(null===Ie(t)){const n=ke(t);null!==n&&jr(t,n,e.field)}}(t,r),r}(t._query,this._field,this._direction);return new Nn(t.firestore,t.converter,function(t,e){const n=t.explicitOrderBy.concat([e]);return new Ae(t.path,t.collectionGroup,n,t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(t._query,e))}}function Dr(t,e="asc"){const n=e,r=_r("orderBy",t);return Fr._create(r,n)}class Vr extends br{constructor(t,e,n){super(),this.type=t,this._limit=e,this._limitType=n}static _create(t,e,n){return new Vr(t,e,n)}_apply(t){return new Nn(t.firestore,t.converter,function(t,e,n){return new Ae(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),e,n,t.startAt,t.endAt)}(t._query,this._limit,this._limitType))}}function Nr(t){return yt("limit",t),Vr._create("limit",t,"F")}function Rr(t){return yt("limitToLast",t),Vr._create("limitToLast",t,"L")}class Cr extends br{constructor(t,e,n){super(),this.type=t,this._docOrFields=e,this._inclusive=n}static _create(t,e,n){return new Cr(t,e,n)}_apply(t){const e=Mr(t,this.type,this._docOrFields,this._inclusive);return new Nn(t.firestore,t.converter,function(t,e){return new Ae(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,e,t.endAt)}(t._query,e))}}function Or(...t){return Cr._create("startAt",t,!0)}function qr(...t){return Cr._create("startAfter",t,!1)}class xr extends br{constructor(t,e,n){super(),this.type=t,this._docOrFields=e,this._inclusive=n}static _create(t,e,n){return new xr(t,e,n)}_apply(t){const e=Mr(t,this.type,this._docOrFields,this._inclusive);return new Nn(t.firestore,t.converter,function(t,e){return new Ae(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,e)}(t._query,e))}}function Lr(...t){return xr._create("endBefore",t,!1)}function Pr(...t){return xr._create("endAt",t,!0)}function Mr(t,e,n,r){if(n[0]=w(n[0]),n[0]instanceof mr)return function(t,e,n,r,s){if(!r)throw new K(M,`Can't use a DocumentSnapshot that doesn't exist for ${n}().`);const i=[];for(const n of De(t))if(n.field.isKeyField())i.push(Gt(e,r.key));else{const t=r.data.field(n.field);if(Lt(t))throw new K(L,'Invalid query. You are trying to start or end a query using a document for which the field "'+n.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===t){const t=n.field.canonicalString();throw new K(L,`Invalid query. You are trying to start or end a query using a document for which the field '${t}' (used as the orderBy) does not exist.`)}i.push(t)}return new Xt(i,s)}(t._query,t.firestore._databaseId,e,n[0]._document,r);{const s=Kn(t.firestore);return function(t,e,n,r,s,i){const o=t.explicitOrderBy;if(s.length>o.length)throw new K(L,`Too many arguments provided to ${r}(). The number of arguments must be less than or equal to the number of orderBy() clauses`);const a=[];for(let i=0;i10)throw new K(L,`Invalid Query. '${e.toString()}' filters support a maximum of 10 elements in the value array.`)}function Ur(t,e){if(e.isInequality()){const n=ke(t),r=e.field;if(null!==n&&!n.isEqual(r))throw new K(L,`Invalid query. All where filters with an inequality (<, <=, !=, not-in, >, or >=) must be on the same field. But you have inequality filters on '${n.toString()}' and '${r.toString()}'`);const s=Ie(t);null!==s&&jr(t,r,s)}const n=function(t,e){for(const n of t)for(const t of n.getFlattenedFilters())if(e.indexOf(t.op)>=0)return t.op;return null}(t.filters,function(t){switch(t){case"!=":return["!=","not-in"];case"array-contains":return["array-contains","array-contains-any","not-in"];case"in":return["array-contains-any","in","not-in"];case"array-contains-any":return["array-contains","array-contains-any","in","not-in"];case"not-in":return["array-contains","array-contains-any","in","not-in","!="];default:return[]}}(e.op));if(null!==n)throw n===e.op?new K(L,`Invalid query. You cannot use more than one '${e.op.toString()}' filter.`):new K(L,`Invalid query. You cannot use '${e.op.toString()}' filters with '${n.toString()}' filters.`)}function jr(t,e,n){if(!n.isEqual(e))throw new K(L,`Invalid query. You have a where filter with an inequality (<, <=, !=, not-in, >, or >=) on field '${e.toString()}' and so you must also use '${e.toString()}' as your first argument to orderBy(), but your first orderBy() is on field '${n.toString()}' instead.`)}function Wr(t,e){if(!(e instanceof Tr||e instanceof Ar))throw new K(L,`Function ${t}() requires AppliableConstraints created with a call to 'where(...)', 'or(...)', or 'and(...)'.`)}function Hr(t,e,n){let r;return r=t?n&&(n.merge||n.mergeFields)?t.toFirestore(e,n):t.toFirestore(e):e,r}class Gr extends class{convertValue(t,e="none"){switch($t(t)){case 0:return null;case 1:return t.booleanValue;case 2:return Ot(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(qt(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 R()}}convertObject(t,e){const n={};return Vt(t.fields,((t,r)=>{n[t]=this.convertValue(r,e)})),n}convertGeoPoint(t){return new Un(Ot(t.latitude),Ot(t.longitude))}convertArray(t,e){return(t.values||[]).map((t=>this.convertValue(t,e)))}convertServerTimestamp(t,e){switch(e){case"previous":const n=Pt(t);return null==n?null:this.convertValue(n,e);case"estimate":return this.convertTimestamp(Mt(t));default:return null}}convertTimestamp(t){const e=Ct(t);return new xt(e.seconds,e.nanos)}convertDocumentKey(t,e){const n=ut.fromString(t);C(fn(n));const r=new ot(n.get(1),n.get(3)),s=new ht(n.popFirst(5));return r.isEqual(e)||D(`Document ${s} contains a document reference within a different database (${r.projectId}/${r.database}) which is not supported. It will be treated as a reference in the current database (${e.projectId}/${e.database}) instead.`),s}}{constructor(t){super(),this.firestore=t}convertBytes(t){return new Pn(t)}convertReference(t){const e=this.convertDocumentKey(t,this.firestore._databaseId);return new Vn(this.firestore,null,e)}}function Qr(t){const e=vn((t=gt(t,Vn)).firestore),n=new Gr(t.firestore);return wn(e,[t._key]).then((e=>{C(1===e.length);const r=e[0];return new mr(t.firestore,n,t._key,r.isFoundDocument()?r:null,t.converter)}))}function zr(t){!function(t){if("L"===t.limitType&&0===t.explicitOrderBy.length)throw new K(G,"limitToLast() queries require specifying at least one orderBy() clause")}((t=gt(t,Nn))._query);const e=vn(t.firestore),n=new Gr(t.firestore);return async function(t,e){const n=O(t),r=on(n.C,Ve(e));return(await n.P("RunQuery",r.parent,{structuredQuery:r.structuredQuery})).filter((t=>!!t.document)).map((t=>function(t,e,n){const r=en(t,e.name),s=Xe(e.updateTime),i=e.createTime?Xe(e.createTime):pe.min(),o=new be({mapValue:{fields:e.fields}});return Ee.newFoundDocument(r,s,i,o)}(n.C,t.document)))}(e,t._query).then((e=>{const r=e.map((e=>new gr(t.firestore,n,e.key,e,t.converter)));return"L"===t._query.limitType&&r.reverse(),new yr(t,r)}))}function Kr(t,e,n){const r=Hr((t=gt(t,Vn)).converter,e,n),s=Yn(Kn(t.firestore),"setDoc",t._key,r,null!==t.converter,n);return yn(vn(t.firestore),[s.toMutation(t._key,Me.none())])}function Yr(t,e,n,...r){const s=Kn((t=gt(t,Vn)).firestore);let i;return i="string"==typeof(e=w(e))||e instanceof Mn?sr(s,"updateDoc",t._key,e,n,r):rr(s,"updateDoc",t._key,e),yn(vn(t.firestore),[i.toMutation(t._key,Me.exists(!0))])}function Jr(t){return yn(vn((t=gt(t,Vn)).firestore),[new je(t._key,Me.none())])}function Xr(t,e){const n=qn(t=gt(t,Rn)),r=Hr(t.converter,e),s=Yn(Kn(t.firestore),"addDoc",n._key,r,null!==n.converter,{});return yn(vn(t.firestore),[s.toMutation(n._key,Me.exists(!1))]).then((()=>n))}function Zr(t){const e=gt(t.firestore,En),n=vn(e),r=new Gr(e);return new Dn(t,n,r).run()}function ts(t,e){return Ln(t.query,e.query)&&g(t.data(),e.data())}function es(){return new Jn("deleteField")}function ns(){return new Zn("serverTimestamp")}function rs(...t){return new tr("arrayUnion",t)}function ss(...t){return new er("arrayRemove",t)}function is(t){return new nr("increment",t)}class os{constructor(t,e){this._firestore=t,this._commitHandler=e,this._mutations=[],this._committed=!1,this._dataReader=Kn(t)}set(t,e,n){this._verifyNotCommitted();const r=as(t,this._firestore),s=Hr(r.converter,e,n),i=Yn(this._dataReader,"WriteBatch.set",r._key,s,null!==r.converter,n);return this._mutations.push(i.toMutation(r._key,Me.none())),this}update(t,e,n,...r){this._verifyNotCommitted();const s=as(t,this._firestore);let i;return i="string"==typeof(e=w(e))||e instanceof Mn?sr(this._dataReader,"WriteBatch.update",s._key,e,n,r):rr(this._dataReader,"WriteBatch.update",s._key,e),this._mutations.push(i.toMutation(s._key,Me.exists(!0))),this}delete(t){this._verifyNotCommitted();const e=as(t,this._firestore);return this._mutations=this._mutations.concat(new je(e._key,Me.none())),this}commit(){return this._verifyNotCommitted(),this._committed=!0,this._mutations.length>0?this._commitHandler(this._mutations):Promise.resolve()}_verifyNotCommitted(){if(this._committed)throw new K(j,"A write batch can no longer be used after commit() has been called.")}}function as(t,e){if((t=w(t)).firestore!==e)throw new K(L,"Provided document reference is from a different Firestore instance.");return t}function us(t){const e=vn(t=gt(t,En));return new os(t,(t=>yn(e,t)))}class ls{constructor(t){this.datastore=t,this.readVersions=new Map,this.mutations=[],this.committed=!1,this.lastWriteError=null,this.writtenDocs=new Set}async lookup(t){if(this.ensureCommitNotCalled(),this.mutations.length>0)throw new K(L,"Firestore transactions require all reads to be executed before all writes.");const e=await wn(this.datastore,t);return e.forEach((t=>this.recordVersion(t))),e}set(t,e){this.write(e.toMutation(t,this.precondition(t))),this.writtenDocs.add(t.toString())}update(t,e){try{this.write(e.toMutation(t,this.preconditionForUpdate(t)))}catch(t){this.lastWriteError=t}this.writtenDocs.add(t.toString())}delete(t){this.write(new je(t,this.precondition(t))),this.writtenDocs.add(t.toString())}async commit(){if(this.ensureCommitNotCalled(),this.lastWriteError)throw this.lastWriteError;const t=this.readVersions;this.mutations.forEach((e=>{t.delete(e.key.toString())})),t.forEach(((t,e)=>{const n=ht.fromPath(e);this.mutations.push(new We(n,this.precondition(n)))})),await yn(this.datastore,this.mutations),this.committed=!0}recordVersion(t){let e;if(t.isFoundDocument())e=t.version;else{if(!t.isNoDocument())throw R();e=pe.min()}const n=this.readVersions.get(t.key.toString());if(n){if(!e.isEqual(n))throw new K(W,"Document version changed between two reads.")}else this.readVersions.set(t.key.toString(),e)}precondition(t){const e=this.readVersions.get(t.toString());return!this.writtenDocs.has(t.toString())&&e?e.isEqual(pe.min())?Me.exists(!1):Me.updateTime(e):Me.none()}preconditionForUpdate(t){const e=this.readVersions.get(t.toString());if(!this.writtenDocs.has(t.toString())&&e){if(e.isEqual(pe.min()))throw new K(L,"Can't update a document that doesn't exist.");return Me.updateTime(e)}return Me.exists(!0)}write(t){this.ensureCommitNotCalled(),this.mutations.push(t)}ensureCommitNotCalled(){}}const cs={maxAttempts:5};class hs{constructor(t,e,n,r,s){this.asyncQueue=t,this.datastore=e,this.options=n,this.updateFunction=r,this.deferred=s,this.yt=n.maxAttempts,this.gt=new mn(this.asyncQueue,"transaction_retry")}run(){this.yt-=1,this._t()}_t(){this.gt.H((async()=>{const t=new ls(this.datastore),e=this.vt(t);e&&e.then((e=>{this.asyncQueue.enqueueAndForget((()=>t.commit().then((()=>{this.deferred.resolve(e)})).catch((t=>{this.bt(t)}))))})).catch((t=>{this.bt(t)}))}))}vt(t){try{const e=this.updateFunction(t);return!wt(e)&&e.catch&&e.then?e:(this.deferred.reject(Error("Transaction callback must return a Promise")),null)}catch(t){return this.deferred.reject(t),null}}bt(t){this.yt>0&&this.Et(t)?(this.yt-=1,this.asyncQueue.enqueueAndForget((()=>(this._t(),Promise.resolve())))):this.deferred.reject(t)}Et(t){if("FirebaseError"===t.name){const e=t.code;return"aborted"===e||"failed-precondition"===e||"already-exists"===e||!function(t){switch(t){default:return R();case q:case x:case P:case U:case Q:case z:case $:return!1;case L:case M:case"already-exists":case B:case j:case W:case H:case G:case"data-loss":return!0}}(e)}return!1}}function ds(){return"undefined"!=typeof document?document:null}class fs{constructor(t,e,n,r,s){this.asyncQueue=t,this.timerId=e,this.targetTimeMs=n,this.op=r,this.removalCallback=s,this.deferred=new Y,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch((t=>{}))}static createAndSchedule(t,e,n,r,s){const i=Date.now()+n,o=new fs(t,e,i,r,s);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 K(q,"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)}}class ps{constructor(){this.It=Promise.resolve(),this.Tt=[],this.At=!1,this.Rt=[],this.Pt=null,this.Vt=!1,this.$t=!1,this.Nt=[],this.gt=new mn(this,"async_queue_retry"),this.Dt=()=>{const t=ds();t&&F("AsyncQueue","Visibility state changed to "+t.visibilityState),this.gt.X()};const t=ds();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.Dt)}get isShuttingDown(){return this.At}enqueueAndForget(t){this.enqueue(t)}enqueueAndForgetEvenWhileRestricted(t){this.Ft(),this.xt(t)}enterRestrictedMode(t){if(!this.At){this.At=!0,this.$t=t||!1;const e=ds();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("visibilitychange",this.Dt)}}enqueue(t){if(this.Ft(),this.At)return new Promise((()=>{}));const e=new Y;return this.xt((()=>this.At&&this.$t?Promise.resolve():(t().then(e.resolve,e.reject),e.promise))).then((()=>e.promise))}enqueueRetryable(t){this.enqueueAndForget((()=>(this.Tt.push(t),this.St())))}async St(){if(0!==this.Tt.length){try{await this.Tt[0](),this.Tt.shift(),this.gt.reset()}catch(t){if(!function(t){return"IndexedDbTransactionError"===t.name}(t))throw t;F("AsyncQueue","Operation failed with retryable error: "+t)}this.Tt.length>0&&this.gt.H((()=>this.St()))}}xt(t){const e=this.It.then((()=>(this.Vt=!0,t().catch((t=>{this.Pt=t,this.Vt=!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 D("INTERNAL UNHANDLED ERROR: ",e),t})).then((t=>(this.Vt=!1,t))))));return this.It=e,e}enqueueAfterDelay(t,e,n){this.Ft(),this.Nt.indexOf(t)>-1&&(e=0);const r=fs.createAndSchedule(this,t,e,n,(t=>this.qt(t)));return this.Rt.push(r),r}Ft(){this.Pt&&R()}verifyOperationInProgress(){}async Ot(){let t;do{t=this.It,await t}while(t!==this.It)}kt(t){for(const e of this.Rt)if(e.timerId===t)return!0;return!1}Ct(t){return this.Ot().then((()=>{this.Rt.sort(((t,e)=>t.targetTimeMs-e.targetTimeMs));for(const e of this.Rt)if(e.skipDelay(),"all"!==t&&e.timerId===t)break;return this.Ot()}))}Lt(t){this.Nt.push(t)}qt(t){const e=this.Rt.indexOf(t);this.Rt.splice(e,1)}}class ms{constructor(t,e){this._firestore=t,this._transaction=e,this._dataReader=Kn(t)}get(t){const e=as(t,this._firestore),n=new Gr(this._firestore);return this._transaction.lookup([e._key]).then((t=>{if(!t||1!==t.length)return R();const r=t[0];if(r.isFoundDocument())return new mr(this._firestore,n,r.key,r,e.converter);if(r.isNoDocument())return new mr(this._firestore,n,e._key,null,e.converter);throw R()}))}set(t,e,n){const r=as(t,this._firestore),s=Hr(r.converter,e,n),i=Yn(this._dataReader,"Transaction.set",r._key,s,null!==r.converter,n);return this._transaction.set(r._key,i),this}update(t,e,n,...r){const s=as(t,this._firestore);let i;return i="string"==typeof(e=w(e))||e instanceof Mn?sr(this._dataReader,"Transaction.update",s._key,e,n,r):rr(this._dataReader,"Transaction.update",s._key,e),this._transaction.update(s._key,i),this}delete(t){const e=as(t,this._firestore);return this._transaction.delete(e._key),this}}function gs(t,e,n){const r=vn(t=gt(t,En)),s=Object.assign(Object.assign({},cs),n);!function(t){if(t.maxAttempts<1)throw new K(L,"Max attempts must be at least 1")}(s);const i=new Y;return new hs(new ps,r,s,(n=>e(new ms(t,n))),i).run(),i.promise}A=`${i}_lite`,t(new class{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}}("firestore/lite",((t,{instanceIdentifier:e,options:n})=>{const r=t.getProvider("app").getImmediate(),s=new En(new tt(t.getProvider("auth-internal")),new st(t.getProvider("app-check-internal")),function(t,e){if(!Object.prototype.hasOwnProperty.apply(t.options,["projectId"]))throw new K(L,'"projectId" not provided in firebase.initializeApp.');return new ot(t.options.projectId,e)}(r,e),r);return n&&s._setSettings(n),s}),"PUBLIC").setMultipleInstances(!0)),e("firestore-lite","3.8.1",""),e("firestore-lite","3.8.1","esm2017");export{kn as AggregateField,Fn as AggregateQuerySnapshot,Pn as Bytes,Rn as CollectionReference,Vn as DocumentReference,mr as DocumentSnapshot,Mn as FieldPath,$n as FieldValue,En as Firestore,K as FirestoreError,Un as GeoPoint,Nn as Query,Ar as QueryCompositeFilterConstraint,br as QueryConstraint,gr as QueryDocumentSnapshot,xr as QueryEndAtConstraint,Tr as QueryFieldFilterConstraint,Vr as QueryLimitConstraint,Fr as QueryOrderByConstraint,yr as QuerySnapshot,Cr as QueryStartAtConstraint,xt as Timestamp,ms as Transaction,os as WriteBatch,Xr as addDoc,ts as aggregateQuerySnapshotEqual,kr as and,ss as arrayRemove,rs as arrayUnion,Cn as collection,On as collectionGroup,An as connectFirestoreEmulator,Jr as deleteDoc,es as deleteField,qn as doc,Bn as documentId,Pr as endAt,Lr as endBefore,Zr as getCount,Qr as getDoc,zr as getDocs,Sn as getFirestore,is as increment,Tn as initializeFirestore,Nr as limit,Rr as limitToLast,Ir as or,Dr as orderBy,Er as query,Ln as queryEqual,xn as refEqual,gs as runTransaction,ns as serverTimestamp,Kr as setDoc,k as setLogLevel,wr as snapshotEqual,qr as startAfter,Or as startAt,In as terminate,Yr as updateDoc,Sr as where,us as writeBatch}; //# sourceMappingURL=firebase-firestore-lite.js.map