/*! firebase-admin v5.0.1 */
/*! typedarray.js
    Copyright (c) 2010, Linden Research, Inc.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE. */
/*!
 * Copyright 2017 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* Copied from firebase/firebase-client-js commit abda2f2ee66f0e36ce3f6c4e7acd311ba9f30956 */
(function() {
  var firebase = require('../default-namespace');
  var h,aa=this;function n(a){return void 0!==a}function ba(){}function ca(a){a.Tb=function(){return a.Ve?a.Ve:a.Ve=new a}}
function da(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null";
else if("function"==b&&"undefined"==typeof a.call)return"object";return b}function ea(a){return"array"==da(a)}function fa(a){var b=da(a);return"array"==b||"object"==b&&"number"==typeof a.length}function p(a){return"string"==typeof a}function ga(a){return"number"==typeof a}function ha(a){return"function"==da(a)}function ia(a){var b=typeof a;return"object"==b&&null!=a||"function"==b}function ja(a,b,c){return a.call.apply(a.bind,arguments)}
function ka(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}}function q(a,b,c){q=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?ja:ka;return q.apply(null,arguments)}
function la(a,b){function c(){}c.prototype=b.prototype;a.Bg=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.vg=function(a,c,f){for(var g=Array(arguments.length-2),k=2;k<arguments.length;k++)g[k-2]=arguments[k];return b.prototype[c].apply(a,g)}};function t(a,b){for(var c in a)b.call(void 0,a[c],c,a)}function ma(a,b){var c={},d;for(d in a)c[d]=b.call(void 0,a[d],d,a);return c}function na(a,b){for(var c in a)if(!b.call(void 0,a[c],c,a))return!1;return!0}function oa(a){var b=0,c;for(c in a)b++;return b}function pa(a){for(var b in a)return b}function qa(a){var b=[],c=0,d;for(d in a)b[c++]=a[d];return b}function ra(a){var b=[],c=0,d;for(d in a)b[c++]=d;return b}function sa(a,b){for(var c in a)if(a[c]==b)return!0;return!1}
function ta(a,b,c){for(var d in a)if(b.call(c,a[d],d,a))return d}function ua(a,b){var c=ta(a,b,void 0);return c&&a[c]}function va(a){for(var b in a)return!1;return!0}function wa(a){var b={},c;for(c in a)b[c]=a[c];return b};function xa(a){a=String(a);if(/^\s*$/.test(a)?0:/^[\],:{}\s\u2028\u2029]*$/.test(a.replace(/\\["\\\/bfnrtu]/g,"@").replace(/"[^"\\\n\r\u2028\u2029\x00-\x08\x0a-\x1f]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:[\s\u2028\u2029]*\[)+/g,"")))try{return eval("("+a+")")}catch(b){}throw Error("Invalid JSON string: "+a);}function ya(){this.Dd=void 0}
function za(a,b,c){switch(typeof b){case "string":Aa(b,c);break;case "number":c.push(isFinite(b)&&!isNaN(b)?b:"null");break;case "boolean":c.push(b);break;case "undefined":c.push("null");break;case "object":if(null==b){c.push("null");break}if(ea(b)){var d=b.length;c.push("[");for(var e="",f=0;f<d;f++)c.push(e),e=b[f],za(a,a.Dd?a.Dd.call(b,String(f),e):e,c),e=",";c.push("]");break}c.push("{");d="";for(f in b)Object.prototype.hasOwnProperty.call(b,f)&&(e=b[f],"function"!=typeof e&&(c.push(d),Aa(f,c),
c.push(":"),za(a,a.Dd?a.Dd.call(b,f,e):e,c),d=","));c.push("}");break;case "function":break;default:throw Error("Unknown type: "+typeof b);}}var Ba={'"':'\\"',"\\":"\\\\","/":"\\/","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\x0B":"\\u000b"},Ca=/\uffff/.test("\uffff")?/[\\\"\x00-\x1f\x7f-\uffff]/g:/[\\\"\x00-\x1f\x7f-\xff]/g;
function Aa(a,b){b.push('"',a.replace(Ca,function(a){if(a in Ba)return Ba[a];var b=a.charCodeAt(0),e="\\u";16>b?e+="000":256>b?e+="00":4096>b&&(e+="0");return Ba[a]=e+b.toString(16)}),'"')};function Da(){this.Va=-1};function Ea(){this.Va=-1;this.Va=64;this.M=[];this.Sd=[];this.zf=[];this.xd=[];this.xd[0]=128;for(var a=1;a<this.Va;++a)this.xd[a]=0;this.Md=this.Yb=0;this.reset()}la(Ea,Da);Ea.prototype.reset=function(){this.M[0]=1732584193;this.M[1]=4023233417;this.M[2]=2562383102;this.M[3]=271733878;this.M[4]=3285377520;this.Md=this.Yb=0};
function Fa(a,b,c){c||(c=0);var d=a.zf;if(p(b))for(var e=0;16>e;e++)d[e]=b.charCodeAt(c)<<24|b.charCodeAt(c+1)<<16|b.charCodeAt(c+2)<<8|b.charCodeAt(c+3),c+=4;else for(e=0;16>e;e++)d[e]=b[c]<<24|b[c+1]<<16|b[c+2]<<8|b[c+3],c+=4;for(e=16;80>e;e++){var f=d[e-3]^d[e-8]^d[e-14]^d[e-16];d[e]=(f<<1|f>>>31)&4294967295}b=a.M[0];c=a.M[1];for(var g=a.M[2],k=a.M[3],m=a.M[4],l,e=0;80>e;e++)40>e?20>e?(f=k^c&(g^k),l=1518500249):(f=c^g^k,l=1859775393):60>e?(f=c&g|k&(c|g),l=2400959708):(f=c^g^k,l=3395469782),f=(b<<
5|b>>>27)+f+m+l+d[e]&4294967295,m=k,k=g,g=(c<<30|c>>>2)&4294967295,c=b,b=f;a.M[0]=a.M[0]+b&4294967295;a.M[1]=a.M[1]+c&4294967295;a.M[2]=a.M[2]+g&4294967295;a.M[3]=a.M[3]+k&4294967295;a.M[4]=a.M[4]+m&4294967295}
Ea.prototype.update=function(a,b){if(null!=a){n(b)||(b=a.length);for(var c=b-this.Va,d=0,e=this.Sd,f=this.Yb;d<b;){if(0==f)for(;d<=c;)Fa(this,a,d),d+=this.Va;if(p(a))for(;d<b;){if(e[f]=a.charCodeAt(d),++f,++d,f==this.Va){Fa(this,e);f=0;break}}else for(;d<b;)if(e[f]=a[d],++f,++d,f==this.Va){Fa(this,e);f=0;break}}this.Yb=f;this.Md+=b}};var u=Array.prototype,Ga=u.indexOf?function(a,b,c){return u.indexOf.call(a,b,c)}:function(a,b,c){c=null==c?0:0>c?Math.max(0,a.length+c):c;if(p(a))return p(b)&&1==b.length?a.indexOf(b,c):-1;for(;c<a.length;c++)if(c in a&&a[c]===b)return c;return-1},Ha=u.forEach?function(a,b,c){u.forEach.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=p(a)?a.split(""):a,f=0;f<d;f++)f in e&&b.call(c,e[f],f,a)},Ia=u.filter?function(a,b,c){return u.filter.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=[],f=0,g=p(a)?
a.split(""):a,k=0;k<d;k++)if(k in g){var m=g[k];b.call(c,m,k,a)&&(e[f++]=m)}return e},Ja=u.map?function(a,b,c){return u.map.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=Array(d),f=p(a)?a.split(""):a,g=0;g<d;g++)g in f&&(e[g]=b.call(c,f[g],g,a));return e},Ka=u.reduce?function(a,b,c,d){for(var e=[],f=1,g=arguments.length;f<g;f++)e.push(arguments[f]);d&&(e[0]=q(b,d));return u.reduce.apply(a,e)}:function(a,b,c,d){var e=c;Ha(a,function(c,g){e=b.call(d,e,c,g,a)});return e},La=u.every?function(a,b,
c){return u.every.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=p(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&!b.call(c,e[f],f,a))return!1;return!0};function Ma(a,b){var c=Na(a,b,void 0);return 0>c?null:p(a)?a.charAt(c):a[c]}function Na(a,b,c){for(var d=a.length,e=p(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&b.call(c,e[f],f,a))return f;return-1}function Oa(a,b){var c=Ga(a,b);0<=c&&u.splice.call(a,c,1)}function Pa(a,b){a.sort(b||Qa)}function Qa(a,b){return a>b?1:a<b?-1:0};var v;a:{var Ra=aa.navigator;if(Ra){var Sa=Ra.userAgent;if(Sa){v=Sa;break a}}v=""};var Ta=-1!=v.indexOf("Opera")||-1!=v.indexOf("OPR"),Ua=-1!=v.indexOf("Trident")||-1!=v.indexOf("MSIE"),Va=-1!=v.indexOf("Gecko")&&-1==v.toLowerCase().indexOf("webkit")&&!(-1!=v.indexOf("Trident")||-1!=v.indexOf("MSIE")),Wa=-1!=v.toLowerCase().indexOf("webkit");
(function(){var a="",b;if(Ta&&aa.opera)return a=aa.opera.version,ha(a)?a():a;Va?b=/rv\:([^\);]+)(\)|;)/:Ua?b=/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/:Wa&&(b=/WebKit\/(\S+)/);b&&(a=(a=b.exec(v))?a[1]:"");return Ua&&(b=(b=aa.document)?b.documentMode:void 0,b>parseFloat(a))?String(b):a})();var Xa=null,Ya=null;
function Za(a,b){if(!fa(a))throw Error("encodeByteArray takes an array as a parameter");if(!Xa){Xa={};Ya={};for(var c=0;65>c;c++)Xa[c]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(c),Ya[c]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.".charAt(c)}for(var c=b?Ya:Xa,d=[],e=0;e<a.length;e+=3){var f=a[e],g=e+1<a.length,k=g?a[e+1]:0,m=e+2<a.length,l=m?a[e+2]:0,r=f>>2,f=(f&3)<<4|k>>4,k=(k&15)<<2|l>>6,l=l&63;m||(l=64,g||(k=64));d.push(c[r],c[f],c[k],c[l])}return d.join("")}
;var $a=firebase.Promise;function ab(){var a=this;this.reject=this.resolve=null;this.ra=new $a(function(b,c){a.resolve=b;a.reject=c})}function bb(a,b){return function(c,d){c?a.reject(c):a.resolve(d);ha(b)&&(cb(a.ra),1===b.length?b(c):b(c,d))}}function cb(a){a.then(void 0,ba)};function w(a,b,c,d){var e;d<b?e="at least "+b:d>c&&(e=0===c?"none":"no more than "+c);if(e)throw Error(a+" failed: Was called with "+d+(1===d?" argument.":" arguments.")+" Expects "+e+".");}function x(a,b,c){var d="";switch(b){case 1:d=c?"first":"First";break;case 2:d=c?"second":"Second";break;case 3:d=c?"third":"Third";break;case 4:d=c?"fourth":"Fourth";break;default:throw Error("errorPrefix called with argumentNumber > 4.  Need to update it?");}return a=a+" failed: "+(d+" argument ")}
function z(a,b,c,d){if((!d||n(c))&&!ha(c))throw Error(x(a,b,d)+"must be a valid function.");}function db(a,b,c){if(n(c)&&(!ia(c)||null===c))throw Error(x(a,b,!0)+"must be a valid context object.");};function eb(a){return"undefined"!==typeof JSON&&n(JSON.parse)?JSON.parse(a):xa(a)}function A(a){if("undefined"!==typeof JSON&&n(JSON.stringify))a=JSON.stringify(a);else{var b=[];za(new ya,a,b);a=b.join("")}return a};function fb(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function B(a,b){if(Object.prototype.hasOwnProperty.call(a,b))return a[b]}function gb(a,b){for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&b(c,a[c])};function hb(a){var b=[];gb(a,function(a,d){ea(d)?Ha(d,function(d){b.push(encodeURIComponent(a)+"="+encodeURIComponent(d))}):b.push(encodeURIComponent(a)+"="+encodeURIComponent(d))});return b.length?"&"+b.join("&"):""};function ib(a,b){if(!a)throw jb(b);}function jb(a){return Error("Firebase Database ("+firebase.SDK_VERSION+") INTERNAL ASSERT FAILED: "+a)};function kb(a){for(var b=[],c=0,d=0;d<a.length;d++){var e=a.charCodeAt(d);55296<=e&&56319>=e&&(e-=55296,d++,ib(d<a.length,"Surrogate pair missing trail surrogate."),e=65536+(e<<10)+(a.charCodeAt(d)-56320));128>e?b[c++]=e:(2048>e?b[c++]=e>>6|192:(65536>e?b[c++]=e>>12|224:(b[c++]=e>>18|240,b[c++]=e>>12&63|128),b[c++]=e>>6&63|128),b[c++]=e&63|128)}return b}function lb(a){for(var b=0,c=0;c<a.length;c++){var d=a.charCodeAt(c);128>d?b++:2048>d?b+=2:55296<=d&&56319>=d?(b+=4,c++):b+=3}return b};function mb(a){this.lc=a}mb.prototype.getToken=function(a){return this.lc.INTERNAL.getToken(a).then(null,function(a){return a&&"auth/token-not-initialized"===a.code?(C("Got auth/token-not-initialized error.  Treating as null token."),null):Promise.reject(a)})};function nb(a,b){a.lc.INTERNAL.addAuthTokenListener(b)};function ob(a,b){this.Ka=a;this.ba=b?b:pb}h=ob.prototype;h.Na=function(a,b){return new ob(this.Ka,this.ba.Na(a,b,this.Ka).X(null,null,!1,null,null))};h.remove=function(a){return new ob(this.Ka,this.ba.remove(a,this.Ka).X(null,null,!1,null,null))};h.get=function(a){for(var b,c=this.ba;!c.e();){b=this.Ka(a,c.key);if(0===b)return c.value;0>b?c=c.left:0<b&&(c=c.right)}return null};
function qb(a,b){for(var c,d=a.ba,e=null;!d.e();){c=a.Ka(b,d.key);if(0===c){if(d.left.e())return e?e.key:null;for(d=d.left;!d.right.e();)d=d.right;return d.key}0>c?d=d.left:0<c&&(e=d,d=d.right)}throw Error("Attempted to find predecessor key for a nonexistent key.  What gives?");}h.e=function(){return this.ba.e()};h.count=function(){return this.ba.count()};h.Dc=function(){return this.ba.Dc()};h.cc=function(){return this.ba.cc()};h.ha=function(a){return this.ba.ha(a)};
h.Ub=function(a){return new rb(this.ba,null,this.Ka,!1,a)};h.Vb=function(a,b){return new rb(this.ba,a,this.Ka,!1,b)};h.Xb=function(a,b){return new rb(this.ba,a,this.Ka,!0,b)};h.Te=function(a){return new rb(this.ba,null,this.Ka,!0,a)};function rb(a,b,c,d,e){this.Fd=e||null;this.ie=d;this.Oa=[];for(e=1;!a.e();)if(e=b?c(a.key,b):1,d&&(e*=-1),0>e)a=this.ie?a.left:a.right;else if(0===e){this.Oa.push(a);break}else this.Oa.push(a),a=this.ie?a.right:a.left}
function D(a){if(0===a.Oa.length)return null;var b=a.Oa.pop(),c;c=a.Fd?a.Fd(b.key,b.value):{key:b.key,value:b.value};if(a.ie)for(b=b.left;!b.e();)a.Oa.push(b),b=b.right;else for(b=b.right;!b.e();)a.Oa.push(b),b=b.left;return c}function sb(a){if(0===a.Oa.length)return null;var b;b=a.Oa;b=b[b.length-1];return a.Fd?a.Fd(b.key,b.value):{key:b.key,value:b.value}}function tb(a,b,c,d,e){this.key=a;this.value=b;this.color=null!=c?c:!0;this.left=null!=d?d:pb;this.right=null!=e?e:pb}h=tb.prototype;
h.X=function(a,b,c,d,e){return new tb(null!=a?a:this.key,null!=b?b:this.value,null!=c?c:this.color,null!=d?d:this.left,null!=e?e:this.right)};h.count=function(){return this.left.count()+1+this.right.count()};h.e=function(){return!1};h.ha=function(a){return this.left.ha(a)||a(this.key,this.value)||this.right.ha(a)};function ub(a){return a.left.e()?a:ub(a.left)}h.Dc=function(){return ub(this).key};h.cc=function(){return this.right.e()?this.key:this.right.cc()};
h.Na=function(a,b,c){var d,e;e=this;d=c(a,e.key);e=0>d?e.X(null,null,null,e.left.Na(a,b,c),null):0===d?e.X(null,b,null,null,null):e.X(null,null,null,null,e.right.Na(a,b,c));return vb(e)};function wb(a){if(a.left.e())return pb;a.left.ea()||a.left.left.ea()||(a=xb(a));a=a.X(null,null,null,wb(a.left),null);return vb(a)}
h.remove=function(a,b){var c,d;c=this;if(0>b(a,c.key))c.left.e()||c.left.ea()||c.left.left.ea()||(c=xb(c)),c=c.X(null,null,null,c.left.remove(a,b),null);else{c.left.ea()&&(c=yb(c));c.right.e()||c.right.ea()||c.right.left.ea()||(c=zb(c),c.left.left.ea()&&(c=yb(c),c=zb(c)));if(0===b(a,c.key)){if(c.right.e())return pb;d=ub(c.right);c=c.X(d.key,d.value,null,null,wb(c.right))}c=c.X(null,null,null,null,c.right.remove(a,b))}return vb(c)};h.ea=function(){return this.color};
function vb(a){a.right.ea()&&!a.left.ea()&&(a=Ab(a));a.left.ea()&&a.left.left.ea()&&(a=yb(a));a.left.ea()&&a.right.ea()&&(a=zb(a));return a}function xb(a){a=zb(a);a.right.left.ea()&&(a=a.X(null,null,null,null,yb(a.right)),a=Ab(a),a=zb(a));return a}function Ab(a){return a.right.X(null,null,a.color,a.X(null,null,!0,null,a.right.left),null)}function yb(a){return a.left.X(null,null,a.color,null,a.X(null,null,!0,a.left.right,null))}
function zb(a){return a.X(null,null,!a.color,a.left.X(null,null,!a.left.color,null,null),a.right.X(null,null,!a.right.color,null,null))}function Bb(){}h=Bb.prototype;h.X=function(){return this};h.Na=function(a,b){return new tb(a,b,null)};h.remove=function(){return this};h.count=function(){return 0};h.e=function(){return!0};h.ha=function(){return!1};h.Dc=function(){return null};h.cc=function(){return null};h.ea=function(){return!1};var pb=new Bb;function Cb(a,b){return a&&"object"===typeof a?(E(".sv"in a,"Unexpected leaf node or priority contents"),b[a[".sv"]]):a}function Db(a,b){var c=new Eb;Fb(a,new G(""),function(a,e){Gb(c,a,Hb(e,b))});return c}function Hb(a,b){var c=a.C().H(),c=Cb(c,b),d;if(a.J()){var e=Cb(a.Ca(),b);return e!==a.Ca()||c!==a.C().H()?new Ib(e,H(c)):a}d=a;c!==a.C().H()&&(d=d.fa(new Ib(c)));a.O(I,function(a,c){var e=Hb(c,b);e!==c&&(d=d.T(a,e))});return d};(function(){var a=process.version;if("v0.10.22"===a||"v0.10.23"===a||"v0.10.24"===a){var b=function(a,b,c){this.chunk=a;this.encoding=b;this.callback=c},c=function(a,c,d,e,l){c.objectMode||!1===c.decodeStrings||"string"!==typeof d||(d=new Buffer(d,e));Buffer.isBuffer(d)&&(e="buffer");var r=c.objectMode?1:d.length;c.length+=r;var y=c.length<c.highWaterMark;y||(c.needDrain=!0);c.writing?c.buffer.push(new b(d,e,l)):(c.writelen=r,c.writecb=l,c.writing=!0,c.sync=!0,a._write(d,e,c.onwrite),c.sync=!1);return y},
d=function(a,b,c,d){var e=!0;if(!Buffer.isBuffer(c)&&"string"!==typeof c&&null!==c&&void 0!==c&&!b.objectMode){var r=new TypeError("Invalid non-string/buffer chunk");a.emit("error",r);process.nextTick(function(){d(r)});e=!1}return e},e=function(a,b){var c=Error("write after end");a.emit("error",c);process.nextTick(function(){b(c)})},a=require("_stream_writable");a.prototype.write=function(a,b,k){var m=this._writableState,l=!1;"function"===typeof b&&(k=b,b=null);Buffer.isBuffer(a)?b="buffer":b||(b=
m.defaultEncoding);"function"!==typeof k&&(k=function(){});m.ended?e(this,k):d(this,m,a,k)&&(l=c(this,m,a,b,k));return l};require("_stream_duplex").prototype.write=a.prototype.write}})();function Jb(a,b){this.type=Kb;this.source=a;this.path=b}Jb.prototype.Jc=function(){return this.path.e()?new Jb(this.source,J):new Jb(this.source,K(this.path))};Jb.prototype.toString=function(){return"Operation("+this.path+": "+this.source.toString()+" listen_complete)"};function Lb(a,b,c){this.type=Mb;this.source=a;this.path=b;this.Fa=c}Lb.prototype.Jc=function(a){return this.path.e()?new Lb(this.source,J,this.Fa.Q(a)):new Lb(this.source,K(this.path),this.Fa)};Lb.prototype.toString=function(){return"Operation("+this.path+": "+this.source.toString()+" overwrite: "+this.Fa.toString()+")"};function Nb(){this.Hd=L}Nb.prototype.j=function(a){return this.Hd.P(a)};Nb.prototype.toString=function(){return this.Hd.toString()};function Ob(a){this.rc=a;this.Ad="firebase:"}h=Ob.prototype;h.set=function(a,b){null==b?this.rc.removeItem(this.Ad+a):this.rc.setItem(this.Ad+a,A(b))};h.get=function(a){a=this.rc.getItem(this.Ad+a);return null==a?null:eb(a)};h.remove=function(a){this.rc.removeItem(this.Ad+a)};h.We=!1;h.toString=function(){return this.rc.toString()};function Pb(){this.mc={}}Pb.prototype.set=function(a,b){null==b?delete this.mc[a]:this.mc[a]=b};Pb.prototype.get=function(a){return fb(this.mc,a)?this.mc[a]:null};Pb.prototype.remove=function(a){delete this.mc[a]};Pb.prototype.We=!0;function Qb(a){try{if("undefined"!==typeof window&&"undefined"!==typeof window[a]){var b=window[a];b.setItem("firebase:sentinel","cache");b.removeItem("firebase:sentinel");return new Ob(b)}}catch(c){}return new Pb}var Rb=Qb("localStorage"),Sb=Qb("sessionStorage");function Tb(a,b,c,d,e){this.host=a.toLowerCase();this.domain=this.host.substr(this.host.indexOf(".")+1);this.Pc=b;this.ne=c;this.tg=d;this.ef=e||"";this.Za=Rb.get("host:"+a)||this.host}function Ub(a,b){b!==a.Za&&(a.Za=b,"s-"===a.Za.substr(0,2)&&Rb.set("host:"+a.host,a.Za))}
function Vb(a,b,c){E("string"===typeof b,"typeof type must == string");E("object"===typeof c,"typeof params must == object");if(b===Wb)b=(a.Pc?"wss://":"ws://")+a.Za+"/.ws?";else if(b===Xb)b=(a.Pc?"https://":"http://")+a.Za+"/.lp?";else throw Error("Unknown connection type: "+b);a.host!==a.Za&&(c.ns=a.ne);var d=[];t(c,function(a,b){d.push(b+"="+a)});return b+d.join("&")}Tb.prototype.toString=function(){var a=(this.Pc?"https://":"http://")+this.host;this.ef&&(a+="<"+this.ef+">");return a};var Yb=function(){var a=1;return function(){return a++}}(),E=ib,Zb=jb;function $b(a){try{return(new Buffer(a,"base64")).toString("utf8")}catch(b){C("base64Decode failed: ",b)}return null}function ac(a){var b=kb(a);a=new Ea;a.update(b);var b=[],c=8*a.Md;56>a.Yb?a.update(a.xd,56-a.Yb):a.update(a.xd,a.Va-(a.Yb-56));for(var d=a.Va-1;56<=d;d--)a.Sd[d]=c&255,c/=256;Fa(a,a.Sd);for(d=c=0;5>d;d++)for(var e=24;0<=e;e-=8)b[c]=a.M[d]>>e&255,++c;return Za(b)}
function bc(a){for(var b="",c=0;c<arguments.length;c++)b=fa(arguments[c])?b+bc.apply(null,arguments[c]):"object"===typeof arguments[c]?b+A(arguments[c]):b+arguments[c],b+=" ";return b}var cc=null,dc=!0;
function ec(a,b){ib(!b||!0===a||!1===a,"Can't turn on custom loggers persistently.");!0===a?("undefined"!==typeof console&&("function"===typeof console.log?cc=q(console.log,console):"object"===typeof console.log&&(cc=function(a){console.log(a)})),b&&Sb.set("logging_enabled",!0)):ha(a)?cc=a:(cc=null,Sb.remove("logging_enabled"))}function C(a){!0===dc&&(dc=!1,null===cc&&!0===Sb.get("logging_enabled")&&ec(!0));if(cc){var b=bc.apply(null,arguments);cc(b)}}
function fc(a){return function(){C(a,arguments)}}function gc(a){if("undefined"!==typeof console){var b="FIREBASE INTERNAL ERROR: "+bc.apply(null,arguments);"undefined"!==typeof console.error?console.error(b):console.log(b)}}function hc(a){var b=bc.apply(null,arguments);throw Error("FIREBASE FATAL ERROR: "+b);}function M(a){if("undefined"!==typeof console){var b="FIREBASE WARNING: "+bc.apply(null,arguments);"undefined"!==typeof console.warn?console.warn(b):console.log(b)}}
function ic(a){var b,c,d,e,f,g=a;f=c=a=b="";d=!0;e="https";if(p(g)){var k=g.indexOf("//");0<=k&&(e=g.substring(0,k-1),g=g.substring(k+2));k=g.indexOf("/");-1===k&&(k=g.length);b=g.substring(0,k);f="";g=g.substring(k).split("/");for(k=0;k<g.length;k++)if(0<g[k].length){var m=g[k];try{m=decodeURIComponent(m.replace(/\+/g," "))}catch(l){}f+="/"+m}g=b.split(".");3===g.length?(a=g[1],c=g[0].toLowerCase()):2===g.length&&(a=g[0]);k=b.indexOf(":");0<=k&&(d="https"===e||"wss"===e)}"firebase"===a&&hc(b+" is no longer supported. Please use <YOUR FIREBASE>.firebaseio.com instead");
c&&"undefined"!=c||hc("Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com");d||"undefined"!==typeof window&&window.location&&window.location.protocol&&-1!==window.location.protocol.indexOf("https:")&&M("Insecure Firebase access from a secure page. Please use https in calls to new Firebase().");return{gc:new Tb(b,d,c,"ws"===e||"wss"===e),path:new G(f)}}function jc(a){return ga(a)&&(a!=a||a==Number.POSITIVE_INFINITY||a==Number.NEGATIVE_INFINITY)}function kc(a){a()}
function lc(a,b){if(a===b)return 0;if("[MIN_NAME]"===a||"[MAX_NAME]"===b)return-1;if("[MIN_NAME]"===b||"[MAX_NAME]"===a)return 1;var c=mc(a),d=mc(b);return null!==c?null!==d?0==c-d?a.length-b.length:c-d:-1:null!==d?1:a<b?-1:1}function nc(a,b){if(b&&a in b)return b[a];throw Error("Missing required key ("+a+") in object: "+A(b));}
function oc(a){if("object"!==typeof a||null===a)return A(a);var b=[],c;for(c in a)b.push(c);b.sort();c="{";for(var d=0;d<b.length;d++)0!==d&&(c+=","),c+=A(b[d]),c+=":",c+=oc(a[b[d]]);return c+"}"}function pc(a,b){if(a.length<=b)return[a];for(var c=[],d=0;d<a.length;d+=b)d+b>a?c.push(a.substring(d,a.length)):c.push(a.substring(d,d+b));return c}function qc(a,b){if(ea(a))for(var c=0;c<a.length;++c)b(c,a[c]);else t(a,b)}
function rc(a){E(!jc(a),"Invalid JSON number");var b,c,d,e;0===a?(d=c=0,b=-Infinity===1/a?1:0):(b=0>a,a=Math.abs(a),a>=Math.pow(2,-1022)?(d=Math.min(Math.floor(Math.log(a)/Math.LN2),1023),c=d+1023,d=Math.round(a*Math.pow(2,52-d)-Math.pow(2,52))):(c=0,d=Math.round(a/Math.pow(2,-1074))));e=[];for(a=52;a;--a)e.push(d%2?1:0),d=Math.floor(d/2);for(a=11;a;--a)e.push(c%2?1:0),c=Math.floor(c/2);e.push(b?1:0);e.reverse();b=e.join("");c="";for(a=0;64>a;a+=8)d=parseInt(b.substr(a,8),2).toString(16),1===d.length&&
(d="0"+d),c+=d;return c.toLowerCase()}var sc=/^-?\d{1,10}$/;function mc(a){return sc.test(a)&&(a=Number(a),-2147483648<=a&&2147483647>=a)?a:null}function tc(a){try{a()}catch(b){setTimeout(function(){M("Exception was thrown by user callback.",b.stack||"");throw b;},Math.floor(0))}}function uc(a,b,c){Object.defineProperty(a,b,{get:c})}function vc(a,b){var c=setTimeout(a,b);"object"===typeof c&&c.unref&&c.unref();return c};function wc(a){var b={},c={},d={},e="";try{var f=a.split("."),b=eb($b(f[0])||""),c=eb($b(f[1])||""),e=f[2],d=c.d||{};delete c.d}catch(g){}return{yg:b,He:c,data:d,og:e}}function xc(a){a=wc(a);var b=a.He;return!!a.og&&!!b&&"object"===typeof b&&b.hasOwnProperty("iat")}function yc(a){a=wc(a).He;return"object"===typeof a&&!0===B(a,"admin")};function G(a,b){if(1==arguments.length){this.o=a.split("/");for(var c=0,d=0;d<this.o.length;d++)0<this.o[d].length&&(this.o[c]=this.o[d],c++);this.o.length=c;this.Y=0}else this.o=a,this.Y=b}function N(a,b){var c=O(a);if(null===c)return b;if(c===O(b))return N(K(a),K(b));throw Error("INTERNAL ERROR: innerPath ("+b+") is not within outerPath ("+a+")");}
function zc(a,b){for(var c=a.slice(),d=b.slice(),e=0;e<c.length&&e<d.length;e++){var f=lc(c[e],d[e]);if(0!==f)return f}return c.length===d.length?0:c.length<d.length?-1:1}function O(a){return a.Y>=a.o.length?null:a.o[a.Y]}function Ac(a){return a.o.length-a.Y}function K(a){var b=a.Y;b<a.o.length&&b++;return new G(a.o,b)}function Bc(a){return a.Y<a.o.length?a.o[a.o.length-1]:null}h=G.prototype;
h.toString=function(){for(var a="",b=this.Y;b<this.o.length;b++)""!==this.o[b]&&(a+="/"+this.o[b]);return a||"/"};h.slice=function(a){return this.o.slice(this.Y+(a||0))};h.parent=function(){if(this.Y>=this.o.length)return null;for(var a=[],b=this.Y;b<this.o.length-1;b++)a.push(this.o[b]);return new G(a,0)};
h.n=function(a){for(var b=[],c=this.Y;c<this.o.length;c++)b.push(this.o[c]);if(a instanceof G)for(c=a.Y;c<a.o.length;c++)b.push(a.o[c]);else for(a=a.split("/"),c=0;c<a.length;c++)0<a[c].length&&b.push(a[c]);return new G(b,0)};h.e=function(){return this.Y>=this.o.length};h.Z=function(a){if(Ac(this)!==Ac(a))return!1;for(var b=this.Y,c=a.Y;b<=this.o.length;b++,c++)if(this.o[b]!==a.o[c])return!1;return!0};
h.contains=function(a){var b=this.Y,c=a.Y;if(Ac(this)>Ac(a))return!1;for(;b<this.o.length;){if(this.o[b]!==a.o[c])return!1;++b;++c}return!0};var J=new G("");function Cc(a,b){this.Pa=a.slice();this.Ga=Math.max(1,this.Pa.length);this.Ne=b;for(var c=0;c<this.Pa.length;c++)this.Ga+=lb(this.Pa[c]);Dc(this)}Cc.prototype.push=function(a){0<this.Pa.length&&(this.Ga+=1);this.Pa.push(a);this.Ga+=lb(a);Dc(this)};Cc.prototype.pop=function(){var a=this.Pa.pop();this.Ga-=lb(a);0<this.Pa.length&&--this.Ga};
function Dc(a){if(768<a.Ga)throw Error(a.Ne+"has a key path longer than 768 bytes ("+a.Ga+").");if(32<a.Pa.length)throw Error(a.Ne+"path specified exceeds the maximum depth that can be written (32) or object contains a cycle "+Ec(a));}function Ec(a){return 0==a.Pa.length?"":"in property '"+a.Pa.join(".")+"'"};function Fc(a,b){this.value=a;this.children=b||Gc}var Gc=new ob(function(a,b){return a===b?0:a<b?-1:1});function Hc(a){var b=P;t(a,function(a,d){b=b.set(new G(d),a)});return b}h=Fc.prototype;h.e=function(){return null===this.value&&this.children.e()};function Ic(a,b,c){if(null!=a.value&&c(a.value))return{path:J,value:a.value};if(b.e())return null;var d=O(b);a=a.children.get(d);return null!==a?(b=Ic(a,K(b),c),null!=b?{path:(new G(d)).n(b.path),value:b.value}:null):null}
function Jc(a,b){return Ic(a,b,function(){return!0})}h.subtree=function(a){if(a.e())return this;var b=this.children.get(O(a));return null!==b?b.subtree(K(a)):P};h.set=function(a,b){if(a.e())return new Fc(b,this.children);var c=O(a),d=(this.children.get(c)||P).set(K(a),b),c=this.children.Na(c,d);return new Fc(this.value,c)};
h.remove=function(a){if(a.e())return this.children.e()?P:new Fc(null,this.children);var b=O(a),c=this.children.get(b);return c?(a=c.remove(K(a)),b=a.e()?this.children.remove(b):this.children.Na(b,a),null===this.value&&b.e()?P:new Fc(this.value,b)):this};h.get=function(a){if(a.e())return this.value;var b=this.children.get(O(a));return b?b.get(K(a)):null};
function Kc(a,b,c){if(b.e())return c;var d=O(b);b=Kc(a.children.get(d)||P,K(b),c);d=b.e()?a.children.remove(d):a.children.Na(d,b);return new Fc(a.value,d)}function Lc(a,b){return Mc(a,J,b)}function Mc(a,b,c){var d={};a.children.ha(function(a,f){d[a]=Mc(f,b.n(a),c)});return c(b,a.value,d)}function Nc(a,b,c){return Oc(a,b,J,c)}function Oc(a,b,c,d){var e=a.value?d(c,a.value):!1;if(e)return e;if(b.e())return null;e=O(b);return(a=a.children.get(e))?Oc(a,K(b),c.n(e),d):null}
function Pc(a,b,c){Qc(a,b,J,c)}function Qc(a,b,c,d){if(b.e())return a;a.value&&d(c,a.value);var e=O(b);return(a=a.children.get(e))?Qc(a,K(b),c.n(e),d):P}function Rc(a,b){Sc(a,J,b)}function Sc(a,b,c){a.children.ha(function(a,e){Sc(e,b.n(a),c)});a.value&&c(b,a.value)}function Tc(a,b){a.children.ha(function(a,d){d.value&&b(a,d.value)})}var P=new Fc(null);Fc.prototype.toString=function(){var a={};Rc(this,function(b,c){a[b.toString()]=c.toString()});return A(a)};function Uc(){this.children={};this.Zc=0;this.value=null}function Vc(a,b,c){this.sd=a?a:"";this.Mc=b?b:null;this.A=c?c:new Uc}function Wc(a,b){for(var c=b instanceof G?b:new G(b),d=a,e;null!==(e=O(c));)d=new Vc(e,d,B(d.A.children,e)||new Uc),c=K(c);return d}h=Vc.prototype;h.Ca=function(){return this.A.value};function Xc(a,b){E("undefined"!==typeof b,"Cannot set value to undefined");a.A.value=b;Yc(a)}h.clear=function(){this.A.value=null;this.A.children={};this.A.Zc=0;Yc(this)};
h.gd=function(){return 0<this.A.Zc};h.e=function(){return null===this.Ca()&&!this.gd()};h.O=function(a){var b=this;t(this.A.children,function(c,d){a(new Vc(d,b,c))})};function Zc(a,b,c,d){c&&!d&&b(a);a.O(function(a){Zc(a,b,!0,d)});c&&d&&b(a)}function $c(a,b){for(var c=a.parent();null!==c&&!b(c);)c=c.parent()}h.path=function(){return new G(null===this.Mc?this.sd:this.Mc.path()+"/"+this.sd)};h.name=function(){return this.sd};h.parent=function(){return this.Mc};
function Yc(a){if(null!==a.Mc){var b=a.Mc,c=a.sd,d=a.e(),e=fb(b.A.children,c);d&&e?(delete b.A.children[c],b.A.Zc--,Yc(b)):d||e||(b.A.children[c]=a.A,b.A.Zc++,Yc(b))}};function ad(a){E(ea(a)&&0<a.length,"Requires a non-empty array");this.Af=a;this.Ac={}}ad.prototype.Ee=function(a,b){var c;c=this.Ac[a]||[];var d=c.length;if(0<d){for(var e=Array(d),f=0;f<d;f++)e[f]=c[f];c=e}else c=[];for(d=0;d<c.length;d++)c[d].Ge.apply(c[d].La,Array.prototype.slice.call(arguments,1))};ad.prototype.dc=function(a,b,c){bd(this,a);this.Ac[a]=this.Ac[a]||[];this.Ac[a].push({Ge:b,La:c});(a=this.Re(a))&&b.apply(c,a)};
ad.prototype.Fc=function(a,b,c){bd(this,a);a=this.Ac[a]||[];for(var d=0;d<a.length;d++)if(a[d].Ge===b&&(!c||c===a[d].La)){a.splice(d,1);break}};function bd(a,b){E(Ma(a.Af,function(a){return a===b}),"Unknown event: "+b)};function cd(){ad.call(this,["visible"]);var a,b;"undefined"!==typeof document&&"undefined"!==typeof document.addEventListener&&("undefined"!==typeof document.hidden?(b="visibilitychange",a="hidden"):"undefined"!==typeof document.mozHidden?(b="mozvisibilitychange",a="mozHidden"):"undefined"!==typeof document.msHidden?(b="msvisibilitychange",a="msHidden"):"undefined"!==typeof document.webkitHidden&&(b="webkitvisibilitychange",a="webkitHidden"));this.Kb=!0;if(b){var c=this;document.addEventListener(b,
function(){var b=!document[a];b!==c.Kb&&(c.Kb=b,c.Ee("visible",b))},!1)}}la(cd,ad);cd.prototype.Re=function(a){E("visible"===a,"Unknown event type: "+a);return[this.Kb]};ca(cd);function dd(){this.set={}}h=dd.prototype;h.add=function(a,b){this.set[a]=null!==b?b:!0};h.contains=function(a){return fb(this.set,a)};h.get=function(a){return this.contains(a)?this.set[a]:void 0};h.remove=function(a){delete this.set[a]};h.clear=function(){this.set={}};h.e=function(){return va(this.set)};h.count=function(){return oa(this.set)};function ed(a,b){t(a.set,function(a,d){b(d,a)})}h.keys=function(){var a=[];t(this.set,function(b,c){a.push(c)});return a};var fd=/[\[\].#$\/\u0000-\u001F\u007F]/,gd=/[\[\].#$\u0000-\u001F\u007F]/;function hd(a){return p(a)&&0!==a.length&&!fd.test(a)}function id(a){return null===a||p(a)||ga(a)&&!jc(a)||ia(a)&&fb(a,".sv")}function jd(a,b,c,d){d&&!n(b)||kd(x(a,1,d),b,c)}
function kd(a,b,c){c instanceof G&&(c=new Cc(c,a));if(!n(b))throw Error(a+"contains undefined "+Ec(c));if(ha(b))throw Error(a+"contains a function "+Ec(c)+" with contents: "+b.toString());if(jc(b))throw Error(a+"contains "+b.toString()+" "+Ec(c));if(p(b)&&b.length>10485760/3&&10485760<lb(b))throw Error(a+"contains a string greater than 10485760 utf8 bytes "+Ec(c)+" ('"+b.substring(0,50)+"...')");if(ia(b)){var d=!1,e=!1;gb(b,function(b,g){if(".value"===b)d=!0;else if(".priority"!==b&&".sv"!==b&&(e=
!0,!hd(b)))throw Error(a+" contains an invalid key ("+b+") "+Ec(c)+'.  Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"');c.push(b);kd(a,g,c);c.pop()});if(d&&e)throw Error(a+' contains ".value" child '+Ec(c)+" in addition to actual children.");}}
function ld(a,b){var c,d;for(c=0;c<b.length;c++){d=b[c];for(var e=d.slice(),f=0;f<e.length;f++)if((".priority"!==e[f]||f!==e.length-1)&&!hd(e[f]))throw Error(a+"contains an invalid key ("+e[f]+") in path "+d.toString()+'. Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"');}b.sort(zc);e=null;for(c=0;c<b.length;c++){d=b[c];if(null!==e&&e.contains(d))throw Error(a+"contains a path "+e.toString()+" that is ancestor of another path "+d.toString());e=d}}
function md(a,b,c){var d=x(a,1,!1);if(!ia(b)||ea(b))throw Error(d+" must be an object containing the children to replace.");var e=[];gb(b,function(a,b){var k=new G(a);kd(d,b,c.n(k));if(".priority"===Bc(k)&&!id(b))throw Error(d+"contains an invalid value for '"+k.toString()+"', which must be a valid Firebase priority (a string, finite number, server value, or null).");e.push(k)});ld(d,e)}
function nd(a,b,c){if(jc(c))throw Error(x(a,b,!1)+"is "+c.toString()+", but must be a valid Firebase priority (a string, finite number, server value, or null).");if(!id(c))throw Error(x(a,b,!1)+"must be a valid Firebase priority (a string, finite number, server value, or null).");}
function od(a,b,c){if(!c||n(b))switch(b){case "value":case "child_added":case "child_removed":case "child_changed":case "child_moved":break;default:throw Error(x(a,1,c)+'must be a valid event type: "value", "child_added", "child_removed", "child_changed", or "child_moved".');}}function pd(a,b){if(n(b)&&!hd(b))throw Error(x(a,2,!0)+'was an invalid key: "'+b+'".  Firebase keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]").');}
function qd(a,b){if(!p(b)||0===b.length||gd.test(b))throw Error(x(a,1,!1)+'was an invalid path: "'+b+'". Paths must be non-empty strings and can\'t contain ".", "#", "$", "[", or "]"');}function rd(a,b){if(".info"===O(b))throw Error(a+" failed: Can't modify data under /.info/");}
function td(a,b){var c=b.path.toString(),d;!(d=!p(b.gc.host)||0===b.gc.host.length||!hd(b.gc.ne))&&(d=0!==c.length)&&(c&&(c=c.replace(/^\/*\.info(\/|$)/,"/")),d=!(p(c)&&0!==c.length&&!gd.test(c)));if(d)throw Error(x(a,1,!1)+'must be a valid firebase URL and the path can\'t contain ".", "#", "$", "[", or "]".');};var ud=function(){var a=0,b=[];return function(c){var d=c===a;a=c;for(var e=Array(8),f=7;0<=f;f--)e[f]="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(c%64),c=Math.floor(c/64);E(0===c,"Cannot push at time == 0");c=e.join("");if(d){for(f=11;0<=f&&63===b[f];f--)b[f]=0;b[f]++}else for(f=0;12>f;f++)b[f]=Math.floor(64*Math.random());for(f=0;12>f;f++)c+="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(b[f]);E(20===c.length,"nextPushId: Length should be 20.");
return c}}();function vd(a,b,c){this.type=wd;this.source=xd;this.path=a;this.Mb=b;this.Gd=c}vd.prototype.Jc=function(a){if(this.path.e()){if(null!=this.Mb.value)return E(this.Mb.children.e(),"affectedTree should not have overlapping affected paths."),this;a=this.Mb.subtree(new G(a));return new vd(J,a,this.Gd)}E(O(this.path)===a,"operationForChild called for unrelated child.");return new vd(K(this.path),this.Mb,this.Gd)};
vd.prototype.toString=function(){return"Operation("+this.path+": "+this.source.toString()+" ack write revert="+this.Gd+" affectedTree="+this.Mb+")"};function yd(a,b,c){this.type=zd;this.source=a;this.path=b;this.children=c}yd.prototype.Jc=function(a){if(this.path.e())return a=this.children.subtree(new G(a)),a.e()?null:a.value?new Lb(this.source,J,a.value):new yd(this.source,J,a);E(O(this.path)===a,"Can't get a merge for a child not on the path of the operation");return new yd(this.source,K(this.path),this.children)};yd.prototype.toString=function(){return"Operation("+this.path+": "+this.source.toString()+" merge: "+this.children.toString()+")"};var Mb=0,zd=1,wd=2,Kb=3;function Ad(a,b,c,d){this.be=a;this.Pe=b;this.Fb=c;this.Ce=d;E(!d||b,"Tagged queries must be from server.")}var xd=new Ad(!0,!1,null,!1),Bd=new Ad(!1,!0,null,!1);Ad.prototype.toString=function(){return this.be?"user":this.Ce?"server(queryID="+this.Fb+")":"server"};function Q(a,b,c,d){this.type=a;this.Ia=b;this.Wa=c;this.oe=d;this.Bd=void 0}function Cd(a){return new Q(Dd,a)}var Dd="value";function Ed(a,b,c){this.A=a;this.da=b;this.Qb=c}function Fd(a){return a.da}function Gd(a){return a.Qb}function Hd(a,b){return b.e()?a.da&&!a.Qb:Id(a,O(b))}function Id(a,b){return a.da&&!a.Qb||a.A.Da(b)}Ed.prototype.j=function(){return this.A};function Jd(){}Jd.prototype.Qe=function(){return null};Jd.prototype.ce=function(){return null};var Kd=new Jd;function Ld(a,b,c){this.wf=a;this.Ja=b;this.wd=c}Ld.prototype.Qe=function(a){var b=this.Ja.N;if(Id(b,a))return b.j().Q(a);b=null!=this.wd?new Ed(this.wd,!0,!1):this.Ja.w();return this.wf.nc(a,b)};Ld.prototype.ce=function(a,b,c){var d=null!=this.wd?this.wd:Md(this.Ja);a=this.wf.Td(d,b,1,c,a);return 0===a.length?null:a[0]};function Nd(a){this.g=a}h=Nd.prototype;h.F=function(a,b,c,d,e,f){E(a.vc(this.g),"A node must be indexed if only a child is updated");e=a.Q(b);if(e.P(d).Z(c.P(d))&&e.e()==c.e())return a;null!=f&&(c.e()?a.Da(b)?Od(f,new Q("child_removed",e,b)):E(a.J(),"A child remove without an old child only makes sense on a leaf node"):e.e()?Od(f,new Q("child_added",c,b)):Od(f,new Q("child_changed",c,b,e)));return a.J()&&c.e()?a:a.T(b,c).lb(this.g)};
h.ya=function(a,b,c){null!=c&&(a.J()||a.O(I,function(a,e){b.Da(a)||Od(c,new Q("child_removed",e,a))}),b.J()||b.O(I,function(b,e){if(a.Da(b)){var f=a.Q(b);f.Z(e)||Od(c,new Q("child_changed",e,b,f))}else Od(c,new Q("child_added",e,b))}));return b.lb(this.g)};h.fa=function(a,b){return a.e()?L:a.fa(b)};h.Ma=function(){return!1};h.Sb=function(){return this};function Pd(a){this.ee=new Nd(a.g);this.g=a.g;var b;a.ka?(b=Qd(a),b=a.g.Bc(Rd(a),b)):b=a.g.Ec();this.Rc=b;a.na?(b=Sd(a),a=a.g.Bc(Td(a),b)):a=a.g.Cc();this.sc=a}h=Pd.prototype;h.matches=function(a){return 0>=this.g.compare(this.Rc,a)&&0>=this.g.compare(a,this.sc)};h.F=function(a,b,c,d,e,f){this.matches(new R(b,c))||(c=L);return this.ee.F(a,b,c,d,e,f)};
h.ya=function(a,b,c){b.J()&&(b=L);var d=b.lb(this.g),d=d.fa(L),e=this;b.O(I,function(a,b){e.matches(new R(a,b))||(d=d.T(a,L))});return this.ee.ya(a,d,c)};h.fa=function(a){return a};h.Ma=function(){return!0};h.Sb=function(){return this.ee};function Ud(a,b){this.Od=a;this.Cf=b}function Vd(a){this.U=a}
Vd.prototype.bb=function(a,b,c,d){var e=new Wd,f;if(b.type===Mb)b.source.be?c=Xd(this,a,b.path,b.Fa,c,d,e):(E(b.source.Pe,"Unknown source."),f=b.source.Ce||Gd(a.w())&&!b.path.e(),c=Yd(this,a,b.path,b.Fa,c,d,f,e));else if(b.type===zd)b.source.be?c=Zd(this,a,b.path,b.children,c,d,e):(E(b.source.Pe,"Unknown source."),f=b.source.Ce||Gd(a.w()),c=$d(this,a,b.path,b.children,c,d,f,e));else if(b.type===wd)if(b.Gd)if(b=b.path,null!=c.ic(b))c=a;else{f=new Ld(c,a,d);d=a.N.j();if(b.e()||".priority"===O(b))Fd(a.w())?
b=c.Aa(Md(a)):(b=a.w().j(),E(b instanceof S,"serverChildren would be complete if leaf node"),b=c.oc(b)),b=this.U.ya(d,b,e);else{var g=O(b),k=c.nc(g,a.w());null==k&&Id(a.w(),g)&&(k=d.Q(g));b=null!=k?this.U.F(d,g,k,K(b),f,e):a.N.j().Da(g)?this.U.F(d,g,L,K(b),f,e):d;b.e()&&Fd(a.w())&&(d=c.Aa(Md(a)),d.J()&&(b=this.U.ya(b,d,e)))}d=Fd(a.w())||null!=c.ic(J);c=ae(a,b,d,this.U.Ma())}else c=be(this,a,b.path,b.Mb,c,d,e);else if(b.type===Kb)d=b.path,b=a.w(),f=b.j(),g=b.da||d.e(),c=ce(this,new de(a.N,new Ed(f,
g,b.Qb)),d,c,Kd,e);else throw Zb("Unknown operation type: "+b.type);e=qa(e.eb);d=c;b=d.N;b.da&&(f=b.j().J()||b.j().e(),g=ee(a),(0<e.length||!a.N.da||f&&!b.j().Z(g)||!b.j().C().Z(g.C()))&&e.push(Cd(ee(d))));return new Ud(c,e)};
function ce(a,b,c,d,e,f){var g=b.N;if(null!=d.ic(c))return b;var k;if(c.e())E(Fd(b.w()),"If change path is empty, we must have complete server data"),Gd(b.w())?(e=Md(b),d=d.oc(e instanceof S?e:L)):d=d.Aa(Md(b)),f=a.U.ya(b.N.j(),d,f);else{var m=O(c);if(".priority"==m)E(1==Ac(c),"Can't have a priority with additional path components"),f=g.j(),k=b.w().j(),d=d.Yc(c,f,k),f=null!=d?a.U.fa(f,d):g.j();else{var l=K(c);Id(g,m)?(k=b.w().j(),d=d.Yc(c,g.j(),k),d=null!=d?g.j().Q(m).F(l,d):g.j().Q(m)):d=d.nc(m,
b.w());f=null!=d?a.U.F(g.j(),m,d,l,e,f):g.j()}}return ae(b,f,g.da||c.e(),a.U.Ma())}function Yd(a,b,c,d,e,f,g,k){var m=b.w();g=g?a.U:a.U.Sb();if(c.e())d=g.ya(m.j(),d,null);else if(g.Ma()&&!m.Qb)d=m.j().F(c,d),d=g.ya(m.j(),d,null);else{var l=O(c);if(!Hd(m,c)&&1<Ac(c))return b;var r=K(c);d=m.j().Q(l).F(r,d);d=".priority"==l?g.fa(m.j(),d):g.F(m.j(),l,d,r,Kd,null)}m=m.da||c.e();b=new de(b.N,new Ed(d,m,g.Ma()));return ce(a,b,c,e,new Ld(e,b,f),k)}
function Xd(a,b,c,d,e,f,g){var k=b.N;e=new Ld(e,b,f);if(c.e())g=a.U.ya(b.N.j(),d,g),a=ae(b,g,!0,a.U.Ma());else if(f=O(c),".priority"===f)g=a.U.fa(b.N.j(),d),a=ae(b,g,k.da,k.Qb);else{c=K(c);var m=k.j().Q(f);if(!c.e()){var l=e.Qe(f);d=null!=l?".priority"===Bc(c)&&l.P(c.parent()).e()?l:l.F(c,d):L}m.Z(d)?a=b:(g=a.U.F(k.j(),f,d,c,e,g),a=ae(b,g,k.da,a.U.Ma()))}return a}
function Zd(a,b,c,d,e,f,g){var k=b;Rc(d,function(d,l){var r=c.n(d);Id(b.N,O(r))&&(k=Xd(a,k,r,l,e,f,g))});Rc(d,function(d,l){var r=c.n(d);Id(b.N,O(r))||(k=Xd(a,k,r,l,e,f,g))});return k}function fe(a,b){Rc(b,function(b,d){a=a.F(b,d)});return a}
function $d(a,b,c,d,e,f,g,k){if(b.w().j().e()&&!Fd(b.w()))return b;var m=b;c=c.e()?d:Kc(P,c,d);var l=b.w().j();c.children.ha(function(c,d){if(l.Da(c)){var F=b.w().j().Q(c),F=fe(F,d);m=Yd(a,m,new G(c),F,e,f,g,k)}});c.children.ha(function(c,d){var F=!Id(b.w(),c)&&null==d.value;l.Da(c)||F||(F=b.w().j().Q(c),F=fe(F,d),m=Yd(a,m,new G(c),F,e,f,g,k))});return m}
function be(a,b,c,d,e,f,g){if(null!=e.ic(c))return b;var k=Gd(b.w()),m=b.w();if(null!=d.value){if(c.e()&&m.da||Hd(m,c))return Yd(a,b,c,m.j().P(c),e,f,k,g);if(c.e()){var l=P;m.j().O(ge,function(a,b){l=l.set(new G(a),b)});return $d(a,b,c,l,e,f,k,g)}return b}l=P;Rc(d,function(a){var b=c.n(a);Hd(m,b)&&(l=l.set(a,m.j().P(b)))});return $d(a,b,c,l,e,f,k,g)};function he(){this.tb=[]}function ie(a,b){for(var c=null,d=0;d<b.length;d++){var e=b[d],f=e.Wb();null===c||f.Z(c.Wb())||(a.tb.push(c),c=null);null===c&&(c=new je(f));c.add(e)}c&&a.tb.push(c)}function ke(a,b,c){ie(a,c);le(a,function(a){return a.Z(b)})}function me(a,b,c){ie(a,c);le(a,function(a){return a.contains(b)||b.contains(a)})}
function le(a,b){for(var c=!0,d=0;d<a.tb.length;d++){var e=a.tb[d];if(e)if(e=e.Wb(),b(e)){for(var e=a.tb[d],f=0;f<e.fd.length;f++){var g=e.fd[f];if(null!==g){e.fd[f]=null;var k=g.Rb();cc&&C("event: "+g.toString());tc(k)}}a.tb[d]=null}else c=!1}c&&(a.tb=[])}function je(a){this.qa=a;this.fd=[]}je.prototype.add=function(a){this.fd.push(a)};je.prototype.Wb=function(){return this.qa};function ne(a,b,c,d){this.Yd=b;this.Jd=c;this.Bd=d;this.ed=a}ne.prototype.Wb=function(){var a=this.Jd.ub();return"value"===this.ed?a.path:a.getParent().path};ne.prototype.de=function(){return this.ed};ne.prototype.Rb=function(){return this.Yd.Rb(this)};ne.prototype.toString=function(){return this.Wb().toString()+":"+this.ed+":"+A(this.Jd.Zd())};function oe(a,b,c){this.Yd=a;this.error=b;this.path=c}oe.prototype.Wb=function(){return this.path};oe.prototype.de=function(){return"cancel"};
oe.prototype.Rb=function(){return this.Yd.Rb(this)};oe.prototype.toString=function(){return this.path.toString()+":cancel"};function Wd(){this.eb={}}
function Od(a,b){var c=b.type,d=b.Wa;E("child_added"==c||"child_changed"==c||"child_removed"==c,"Only child changes supported for tracking");E(".priority"!==d,"Only non-priority child changes can be tracked.");var e=B(a.eb,d);if(e){var f=e.type;if("child_added"==c&&"child_removed"==f)a.eb[d]=new Q("child_changed",b.Ia,d,e.Ia);else if("child_removed"==c&&"child_added"==f)delete a.eb[d];else if("child_removed"==c&&"child_changed"==f)a.eb[d]=new Q("child_removed",e.oe,d);else if("child_changed"==c&&
"child_added"==f)a.eb[d]=new Q("child_added",b.Ia,d);else if("child_changed"==c&&"child_changed"==f)a.eb[d]=new Q("child_changed",b.Ia,d,e.oe);else throw Zb("Illegal combination of changes: "+b+" occurred after "+e);}else a.eb[d]=b};function pe(a,b,c){this.f=fc("p:rest:");this.L=a;this.Eb=b;this.Xc=c;this.$={}}function qe(a,b){if(n(b))return"tag$"+b;E(re(a.m),"should have a tag if it's not a default query.");return a.path.toString()}h=pe.prototype;
h.Xe=function(a,b,c,d){var e=a.path.toString();this.f("Listen called for "+e+" "+a.ja());var f=qe(a,c),g={};this.$[f]=g;a=se(a.m);var k=this;te(this,e+".json",a,function(a,b){var r=b;404===a&&(a=r=null);null===a&&k.Eb(e,r,!1,c);B(k.$,f)===g&&d(a?401==a?"permission_denied":"rest_error:"+a:"ok",null)})};h.tf=function(a,b){var c=qe(a,b);delete this.$[c]};h.hf=function(){};h.pe=function(){};h.bf=function(){};h.vd=function(){};h.put=function(){};h.Ye=function(){};h.we=function(){};
function te(a,b,c,d){c=c||{};c.format="export";a.Xc.getToken(!1).then(function(e){(e=e&&e.accessToken)&&(c.auth=e);var f=(a.L.Pc?"https://":"http://")+a.L.host+b+"?"+hb(c);a.f("Sending REST request for "+f);var g=new XMLHttpRequest;g.onreadystatechange=function(){if(d&&4===g.readyState){a.f("REST Response for "+f+" received. status:",g.status,"response:",g.responseText);var b=null;if(200<=g.status&&300>g.status){try{b=eb(g.responseText)}catch(c){M("Failed to parse JSON response for "+f+": "+g.responseText)}d(null,
b)}else 401!==g.status&&404!==g.status&&M("Got unsuccessful REST response for "+f+" Status: "+g.status),d(g.status);d=null}};g.open("GET",f,!0);g.send()})};function ue(){}var ve={};function we(a){return q(a.compare,a)}ue.prototype.kd=function(a,b){return 0!==this.compare(new R("[MIN_NAME]",a),new R("[MIN_NAME]",b))};ue.prototype.Ec=function(){return xe};function ye(a){E(!a.e()&&".priority"!==O(a),"Can't create PathIndex with empty path or .priority key");this.$b=a}la(ye,ue);h=ye.prototype;h.uc=function(a){return!a.P(this.$b).e()};h.compare=function(a,b){var c=a.R.P(this.$b),d=b.R.P(this.$b),c=c.pc(d);return 0===c?lc(a.name,b.name):c};
h.Bc=function(a,b){var c=H(a),c=L.F(this.$b,c);return new R(b,c)};h.Cc=function(){var a=L.F(this.$b,ze);return new R("[MAX_NAME]",a)};h.toString=function(){return this.$b.slice().join("/")};function Ae(){}la(Ae,ue);h=Ae.prototype;h.compare=function(a,b){var c=a.R.C(),d=b.R.C(),c=c.pc(d);return 0===c?lc(a.name,b.name):c};h.uc=function(a){return!a.C().e()};h.kd=function(a,b){return!a.C().Z(b.C())};h.Ec=function(){return xe};h.Cc=function(){return new R("[MAX_NAME]",new Ib("[PRIORITY-POST]",ze))};
h.Bc=function(a,b){var c=H(a);return new R(b,new Ib("[PRIORITY-POST]",c))};h.toString=function(){return".priority"};var I=new Ae;function Be(){}la(Be,ue);h=Be.prototype;h.compare=function(a,b){return lc(a.name,b.name)};h.uc=function(){throw Zb("KeyIndex.isDefinedOn not expected to be called.");};h.kd=function(){return!1};h.Ec=function(){return xe};h.Cc=function(){return new R("[MAX_NAME]",L)};h.Bc=function(a){E(p(a),"KeyIndex indexValue must always be a string.");return new R(a,L)};h.toString=function(){return".key"};
var ge=new Be;function Ce(){}la(Ce,ue);h=Ce.prototype;h.compare=function(a,b){var c=a.R.pc(b.R);return 0===c?lc(a.name,b.name):c};h.uc=function(){return!0};h.kd=function(a,b){return!a.Z(b)};h.Ec=function(){return xe};h.Cc=function(){return De};h.Bc=function(a,b){var c=H(a);return new R(b,c)};h.toString=function(){return".value"};var Ee=new Ce;function Fe(a,b){this.ld=a;this.ac=b}Fe.prototype.get=function(a){var b=B(this.ld,a);if(!b)throw Error("No index defined for "+a);return b===ve?null:b};function Ge(a,b,c){var d=ma(a.ld,function(d,f){var g=B(a.ac,f);E(g,"Missing index implementation for "+f);if(d===ve){if(g.uc(b.R)){for(var k=[],m=c.Ub(He),l=D(m);l;)l.name!=b.name&&k.push(l),l=D(m);k.push(b);return Ie(k,we(g))}return ve}g=c.get(b.name);k=d;g&&(k=k.remove(new R(b.name,g)));return k.Na(b,b.R)});return new Fe(d,a.ac)}
function Je(a,b,c){var d=ma(a.ld,function(a){if(a===ve)return a;var d=c.get(b.name);return d?a.remove(new R(b.name,d)):a});return new Fe(d,a.ac)}var Ke=new Fe({".priority":ve},{".priority":I});function R(a,b){this.name=a;this.R=b}function He(a,b){return new R(a,b)};function Eb(){this.k=this.B=null}Eb.prototype.find=function(a){if(null!=this.B)return this.B.P(a);if(a.e()||null==this.k)return null;var b=O(a);a=K(a);return this.k.contains(b)?this.k.get(b).find(a):null};function Gb(a,b,c){if(b.e())a.B=c,a.k=null;else if(null!==a.B)a.B=a.B.F(b,c);else{null==a.k&&(a.k=new dd);var d=O(b);a.k.contains(d)||a.k.add(d,new Eb);a=a.k.get(d);b=K(b);Gb(a,b,c)}}
function Le(a,b){if(b.e())return a.B=null,a.k=null,!0;if(null!==a.B){if(a.B.J())return!1;var c=a.B;a.B=null;c.O(I,function(b,c){Gb(a,new G(b),c)});return Le(a,b)}return null!==a.k?(c=O(b),b=K(b),a.k.contains(c)&&Le(a.k.get(c),b)&&a.k.remove(c),a.k.e()?(a.k=null,!0):!1):!0}function Fb(a,b,c){null!==a.B?c(b,a.B):a.O(function(a,e){var f=new G(b.toString()+"/"+a);Fb(e,f,c)})}Eb.prototype.O=function(a){null!==this.k&&ed(this.k,function(b,c){a(b,c)})};function Me(a){this.W=a}var Ne=new Me(new Fc(null));function Oe(a,b,c){if(b.e())return new Me(new Fc(c));var d=Jc(a.W,b);if(null!=d){var e=d.path,d=d.value;b=N(e,b);d=d.F(b,c);return new Me(a.W.set(e,d))}a=Kc(a.W,b,new Fc(c));return new Me(a)}function Pe(a,b,c){var d=a;gb(c,function(a,c){d=Oe(d,b.n(a),c)});return d}Me.prototype.Cd=function(a){if(a.e())return Ne;a=Kc(this.W,a,P);return new Me(a)};function Qe(a,b){var c=Jc(a.W,b);return null!=c?a.W.get(c.path).P(N(c.path,b)):null}
function Re(a){var b=[],c=a.W.value;null!=c?c.J()||c.O(I,function(a,c){b.push(new R(a,c))}):a.W.children.ha(function(a,c){null!=c.value&&b.push(new R(a,c.value))});return b}function Se(a,b){if(b.e())return a;var c=Qe(a,b);return null!=c?new Me(new Fc(c)):new Me(a.W.subtree(b))}Me.prototype.e=function(){return this.W.e()};Me.prototype.apply=function(a){return Te(J,this.W,a)};
function Te(a,b,c){if(null!=b.value)return c.F(a,b.value);var d=null;b.children.ha(function(b,f){".priority"===b?(E(null!==f.value,"Priority writes must always be leaf nodes"),d=f.value):c=Te(a.n(b),f,c)});c.P(a).e()||null===d||(c=c.F(a.n(".priority"),d));return c};function Ue(){this.S=Ne;this.la=[];this.yc=-1}function Ve(a,b){for(var c=0;c<a.la.length;c++){var d=a.la[c];if(d.Wc===b)return d}return null}h=Ue.prototype;
h.Cd=function(a){var b=Na(this.la,function(b){return b.Wc===a});E(0<=b,"removeWrite called with nonexistent writeId.");var c=this.la[b];this.la.splice(b,1);for(var d=c.visible,e=!1,f=this.la.length-1;d&&0<=f;){var g=this.la[f];g.visible&&(f>=b&&We(g,c.path)?d=!1:c.path.contains(g.path)&&(e=!0));f--}if(d){if(e)this.S=Xe(this.la,Ye,J),this.yc=0<this.la.length?this.la[this.la.length-1].Wc:-1;else if(c.Fa)this.S=this.S.Cd(c.path);else{var k=this;t(c.children,function(a,b){k.S=k.S.Cd(c.path.n(b))})}return!0}return!1};
h.Aa=function(a,b,c,d){if(c||d){var e=Se(this.S,a);return!d&&e.e()?b:d||null!=b||null!=Qe(e,J)?(e=Xe(this.la,function(b){return(b.visible||d)&&(!c||!(0<=Ga(c,b.Wc)))&&(b.path.contains(a)||a.contains(b.path))},a),b=b||L,e.apply(b)):null}e=Qe(this.S,a);if(null!=e)return e;e=Se(this.S,a);return e.e()?b:null!=b||null!=Qe(e,J)?(b=b||L,e.apply(b)):null};
h.oc=function(a,b){var c=L,d=Qe(this.S,a);if(d)d.J()||d.O(I,function(a,b){c=c.T(a,b)});else if(b){var e=Se(this.S,a);b.O(I,function(a,b){var d=Se(e,new G(a)).apply(b);c=c.T(a,d)});Ha(Re(e),function(a){c=c.T(a.name,a.R)})}else e=Se(this.S,a),Ha(Re(e),function(a){c=c.T(a.name,a.R)});return c};h.Yc=function(a,b,c,d){E(c||d,"Either existingEventSnap or existingServerSnap must exist");a=a.n(b);if(null!=Qe(this.S,a))return null;a=Se(this.S,a);return a.e()?d.P(b):a.apply(d.P(b))};
h.nc=function(a,b,c){a=a.n(b);var d=Qe(this.S,a);return null!=d?d:Id(c,b)?Se(this.S,a).apply(c.j().Q(b)):null};h.ic=function(a){return Qe(this.S,a)};h.Td=function(a,b,c,d,e,f){var g;a=Se(this.S,a);g=Qe(a,J);if(null==g)if(null!=b)g=a.apply(b);else return[];g=g.lb(f);if(g.e()||g.J())return[];b=[];a=we(f);e=e?g.Xb(c,f):g.Vb(c,f);for(f=D(e);f&&b.length<d;)0!==a(f,c)&&b.push(f),f=D(e);return b};
function We(a,b){return a.Fa?a.path.contains(b):!!ta(a.children,function(c,d){return a.path.n(d).contains(b)})}function Ye(a){return a.visible}
function Xe(a,b,c){for(var d=Ne,e=0;e<a.length;++e){var f=a[e];if(b(f)){var g=f.path;if(f.Fa)c.contains(g)?(g=N(c,g),d=Oe(d,g,f.Fa)):g.contains(c)&&(g=N(g,c),d=Oe(d,J,f.Fa.P(g)));else if(f.children)if(c.contains(g))g=N(c,g),d=Pe(d,g,f.children);else{if(g.contains(c))if(g=N(g,c),g.e())d=Pe(d,J,f.children);else if(f=B(f.children,O(g)))f=f.P(K(g)),d=Oe(d,J,f)}else throw Zb("WriteRecord should have .snap or .children");}}return d}function Ze(a,b){this.Jb=a;this.W=b}h=Ze.prototype;
h.Aa=function(a,b,c){return this.W.Aa(this.Jb,a,b,c)};h.oc=function(a){return this.W.oc(this.Jb,a)};h.Yc=function(a,b,c){return this.W.Yc(this.Jb,a,b,c)};h.ic=function(a){return this.W.ic(this.Jb.n(a))};h.Td=function(a,b,c,d,e){return this.W.Td(this.Jb,a,b,c,d,e)};h.nc=function(a,b){return this.W.nc(this.Jb,a,b)};h.n=function(a){return new Ze(this.Jb.n(a),this.W)};function $e(a){this.V=a;this.g=a.m.g}function af(a,b,c,d){var e=[],f=[];Ha(b,function(b){"child_changed"===b.type&&a.g.kd(b.oe,b.Ia)&&f.push(new Q("child_moved",b.Ia,b.Wa))});bf(a,e,"child_removed",b,d,c);bf(a,e,"child_added",b,d,c);bf(a,e,"child_moved",f,d,c);bf(a,e,"child_changed",b,d,c);bf(a,e,Dd,b,d,c);return e}function bf(a,b,c,d,e,f){d=Ia(d,function(a){return a.type===c});Pa(d,q(a.Ff,a));Ha(d,function(c){var d=cf(a,c,f);Ha(e,function(e){e.lf(c.type)&&b.push(e.createEvent(d,a.V))})})}
function cf(a,b,c){"value"!==b.type&&"child_removed"!==b.type&&(b.Bd=c.Se(b.Wa,b.Ia,a.g));return b}$e.prototype.Ff=function(a,b){if(null==a.Wa||null==b.Wa)throw Zb("Should only compare child_ events.");return this.g.compare(new R(a.Wa,a.Ia),new R(b.Wa,b.Ia))};function df(a){this.sa=new Pd(a);this.g=a.g;E(a.xa,"Only valid if limit has been set");this.oa=a.oa;this.Gb=!ef(a)}h=df.prototype;h.F=function(a,b,c,d,e,f){this.sa.matches(new R(b,c))||(c=L);return a.Q(b).Z(c)?a:a.Cb()<this.oa?this.sa.Sb().F(a,b,c,d,e,f):ff(this,a,b,c,e,f)};
h.ya=function(a,b,c){var d;if(b.J()||b.e())d=L.lb(this.g);else if(2*this.oa<b.Cb()&&b.vc(this.g)){d=L.lb(this.g);b=this.Gb?b.Xb(this.sa.sc,this.g):b.Vb(this.sa.Rc,this.g);for(var e=0;0<b.Oa.length&&e<this.oa;){var f=D(b),g;if(g=this.Gb?0>=this.g.compare(this.sa.Rc,f):0>=this.g.compare(f,this.sa.sc))d=d.T(f.name,f.R),e++;else break}}else{d=b.lb(this.g);d=d.fa(L);var k,m,l;if(this.Gb){b=d.Te(this.g);k=this.sa.sc;m=this.sa.Rc;var r=we(this.g);l=function(a,b){return r(b,a)}}else b=d.Ub(this.g),k=this.sa.Rc,
m=this.sa.sc,l=we(this.g);for(var e=0,y=!1;0<b.Oa.length;)f=D(b),!y&&0>=l(k,f)&&(y=!0),(g=y&&e<this.oa&&0>=l(f,m))?e++:d=d.T(f.name,L)}return this.sa.Sb().ya(a,d,c)};h.fa=function(a){return a};h.Ma=function(){return!0};h.Sb=function(){return this.sa.Sb()};
function ff(a,b,c,d,e,f){var g;if(a.Gb){var k=we(a.g);g=function(a,b){return k(b,a)}}else g=we(a.g);E(b.Cb()==a.oa,"");var m=new R(c,d),l=a.Gb?gf(b,a.g):hf(b,a.g),r=a.sa.matches(m);if(b.Da(c)){for(var y=b.Q(c),l=e.ce(a.g,l,a.Gb);null!=l&&(l.name==c||b.Da(l.name));)l=e.ce(a.g,l,a.Gb);e=null==l?1:g(l,m);if(r&&!d.e()&&0<=e)return null!=f&&Od(f,new Q("child_changed",d,c,y)),b.T(c,d);null!=f&&Od(f,new Q("child_removed",y,c));b=b.T(c,L);return null!=l&&a.sa.matches(l)?(null!=f&&Od(f,new Q("child_added",
l.R,l.name)),b.T(l.name,l.R)):b}return d.e()?b:r&&0<=g(l,m)?(null!=f&&(Od(f,new Q("child_removed",l.R,l.name)),Od(f,new Q("child_added",d,c))),b.T(c,d).T(l.name,L)):b};function jf(){this.Pb=this.na=this.Ib=this.ka=this.xa=!1;this.oa=0;this.kb="";this.bc=null;this.xb="";this.Zb=null;this.vb="";this.g=I}var kf=new jf;function ef(a){return""===a.kb?a.ka:"l"===a.kb}function Rd(a){E(a.ka,"Only valid if start has been set");return a.bc}function Qd(a){E(a.ka,"Only valid if start has been set");return a.Ib?a.xb:"[MIN_NAME]"}function Td(a){E(a.na,"Only valid if end has been set");return a.Zb}
function Sd(a){E(a.na,"Only valid if end has been set");return a.Pb?a.vb:"[MAX_NAME]"}function lf(a){var b=new jf;b.xa=a.xa;b.oa=a.oa;b.ka=a.ka;b.bc=a.bc;b.Ib=a.Ib;b.xb=a.xb;b.na=a.na;b.Zb=a.Zb;b.Pb=a.Pb;b.vb=a.vb;b.g=a.g;b.kb=a.kb;return b}h=jf.prototype;h.ke=function(a){var b=lf(this);b.xa=!0;b.oa=a;b.kb="l";return b};h.le=function(a){var b=lf(this);b.xa=!0;b.oa=a;b.kb="r";return b};h.Kd=function(a,b){var c=lf(this);c.ka=!0;n(a)||(a=null);c.bc=a;null!=b?(c.Ib=!0,c.xb=b):(c.Ib=!1,c.xb="");return c};
h.dd=function(a,b){var c=lf(this);c.na=!0;n(a)||(a=null);c.Zb=a;n(b)?(c.Pb=!0,c.vb=b):(c.Ag=!1,c.vb="");return c};function mf(a,b){var c=lf(a);c.g=b;return c}function nf(a){var b={};a.ka&&(b.sp=a.bc,a.Ib&&(b.sn=a.xb));a.na&&(b.ep=a.Zb,a.Pb&&(b.en=a.vb));if(a.xa){b.l=a.oa;var c=a.kb;""===c&&(c=ef(a)?"l":"r");b.vf=c}a.g!==I&&(b.i=a.g.toString());return b}function T(a){return!(a.ka||a.na||a.xa)}function re(a){return T(a)&&a.g==I}
function se(a){var b={};if(re(a))return b;var c;a.g===I?c="$priority":a.g===Ee?c="$value":a.g===ge?c="$key":(E(a.g instanceof ye,"Unrecognized index type!"),c=a.g.toString());b.orderBy=A(c);a.ka&&(b.startAt=A(a.bc),a.Ib&&(b.startAt+=","+A(a.xb)));a.na&&(b.endAt=A(a.Zb),a.Pb&&(b.endAt+=","+A(a.vb)));a.xa&&(ef(a)?b.limitToFirst=a.oa:b.limitToLast=a.oa);return b}h.toString=function(){return A(nf(this))};function Ib(a,b){this.B=a;E(n(this.B)&&null!==this.B,"LeafNode shouldn't be created with null/undefined value.");this.aa=b||L;of(this.aa);this.Bb=null}var pf=["object","boolean","number","string"];h=Ib.prototype;h.J=function(){return!0};h.C=function(){return this.aa};h.fa=function(a){return new Ib(this.B,a)};h.Q=function(a){return".priority"===a?this.aa:L};h.P=function(a){return a.e()?this:".priority"===O(a)?this.aa:L};h.Da=function(){return!1};h.Se=function(){return null};
h.T=function(a,b){return".priority"===a?this.fa(b):b.e()&&".priority"!==a?this:L.T(a,b).fa(this.aa)};h.F=function(a,b){var c=O(a);if(null===c)return b;if(b.e()&&".priority"!==c)return this;E(".priority"!==c||1===Ac(a),".priority must be the last token in a path");return this.T(c,L.F(K(a),b))};h.e=function(){return!1};h.Cb=function(){return 0};h.O=function(){return!1};h.H=function(a){return a&&!this.C().e()?{".value":this.Ca(),".priority":this.C().H()}:this.Ca()};
h.hash=function(){if(null===this.Bb){var a="";this.aa.e()||(a+="priority:"+qf(this.aa.H())+":");var b=typeof this.B,a=a+(b+":"),a="number"===b?a+rc(this.B):a+this.B;this.Bb=ac(a)}return this.Bb};h.Ca=function(){return this.B};h.pc=function(a){if(a===L)return 1;if(a instanceof S)return-1;E(a.J(),"Unknown node type");var b=typeof a.B,c=typeof this.B,d=Ga(pf,b),e=Ga(pf,c);E(0<=d,"Unknown leaf type: "+b);E(0<=e,"Unknown leaf type: "+c);return d===e?"object"===c?0:this.B<a.B?-1:this.B===a.B?0:1:e-d};
h.lb=function(){return this};h.vc=function(){return!0};h.Z=function(a){return a===this?!0:a.J()?this.B===a.B&&this.aa.Z(a.aa):!1};h.toString=function(){return A(this.H(!0))};function rf(a,b){return lc(a.name,b.name)}function sf(a,b){return lc(a,b)};function S(a,b,c){this.k=a;(this.aa=b)&&of(this.aa);a.e()&&E(!this.aa||this.aa.e(),"An empty node cannot have a priority");this.wb=c;this.Bb=null}h=S.prototype;h.J=function(){return!1};h.C=function(){return this.aa||L};h.fa=function(a){return this.k.e()?this:new S(this.k,a,this.wb)};h.Q=function(a){if(".priority"===a)return this.C();a=this.k.get(a);return null===a?L:a};h.P=function(a){var b=O(a);return null===b?this:this.Q(b).P(K(a))};h.Da=function(a){return null!==this.k.get(a)};
h.T=function(a,b){E(b,"We should always be passing snapshot nodes");if(".priority"===a)return this.fa(b);var c=new R(a,b),d,e;b.e()?(d=this.k.remove(a),c=Je(this.wb,c,this.k)):(d=this.k.Na(a,b),c=Ge(this.wb,c,this.k));e=d.e()?L:this.aa;return new S(d,e,c)};h.F=function(a,b){var c=O(a);if(null===c)return b;E(".priority"!==O(a)||1===Ac(a),".priority must be the last token in a path");var d=this.Q(c).F(K(a),b);return this.T(c,d)};h.e=function(){return this.k.e()};h.Cb=function(){return this.k.count()};
var tf=/^(0|[1-9]\d*)$/;h=S.prototype;h.H=function(a){if(this.e())return null;var b={},c=0,d=0,e=!0;this.O(I,function(f,g){b[f]=g.H(a);c++;e&&tf.test(f)?d=Math.max(d,Number(f)):e=!1});if(!a&&e&&d<2*c){var f=[],g;for(g in b)f[g]=b[g];return f}a&&!this.C().e()&&(b[".priority"]=this.C().H());return b};h.hash=function(){if(null===this.Bb){var a="";this.C().e()||(a+="priority:"+qf(this.C().H())+":");this.O(I,function(b,c){var d=c.hash();""!==d&&(a+=":"+b+":"+d)});this.Bb=""===a?"":ac(a)}return this.Bb};
h.Se=function(a,b,c){return(c=uf(this,c))?(a=qb(c,new R(a,b)))?a.name:null:qb(this.k,a)};function gf(a,b){var c;c=(c=uf(a,b))?(c=c.Dc())&&c.name:a.k.Dc();return c?new R(c,a.k.get(c)):null}function hf(a,b){var c;c=(c=uf(a,b))?(c=c.cc())&&c.name:a.k.cc();return c?new R(c,a.k.get(c)):null}h.O=function(a,b){var c=uf(this,a);return c?c.ha(function(a){return b(a.name,a.R)}):this.k.ha(b)};h.Ub=function(a){return this.Vb(a.Ec(),a)};
h.Vb=function(a,b){var c=uf(this,b);if(c)return c.Vb(a,function(a){return a});for(var c=this.k.Vb(a.name,He),d=sb(c);null!=d&&0>b.compare(d,a);)D(c),d=sb(c);return c};h.Te=function(a){return this.Xb(a.Cc(),a)};h.Xb=function(a,b){var c=uf(this,b);if(c)return c.Xb(a,function(a){return a});for(var c=this.k.Xb(a.name,He),d=sb(c);null!=d&&0<b.compare(d,a);)D(c),d=sb(c);return c};h.pc=function(a){return this.e()?a.e()?0:-1:a.J()||a.e()?1:a===ze?-1:0};
h.lb=function(a){if(a===ge||sa(this.wb.ac,a.toString()))return this;var b=this.wb,c=this.k;E(a!==ge,"KeyIndex always exists and isn't meant to be added to the IndexMap.");for(var d=[],e=!1,c=c.Ub(He),f=D(c);f;)e=e||a.uc(f.R),d.push(f),f=D(c);d=e?Ie(d,we(a)):ve;e=a.toString();c=wa(b.ac);c[e]=a;a=wa(b.ld);a[e]=d;return new S(this.k,this.aa,new Fe(a,c))};h.vc=function(a){return a===ge||sa(this.wb.ac,a.toString())};
h.Z=function(a){if(a===this)return!0;if(a.J())return!1;if(this.C().Z(a.C())&&this.k.count()===a.k.count()){var b=this.Ub(I);a=a.Ub(I);for(var c=D(b),d=D(a);c&&d;){if(c.name!==d.name||!c.R.Z(d.R))return!1;c=D(b);d=D(a)}return null===c&&null===d}return!1};function uf(a,b){return b===ge?null:a.wb.get(b.toString())}h.toString=function(){return A(this.H(!0))};function H(a,b){if(null===a)return L;var c=null;"object"===typeof a&&".priority"in a?c=a[".priority"]:"undefined"!==typeof b&&(c=b);E(null===c||"string"===typeof c||"number"===typeof c||"object"===typeof c&&".sv"in c,"Invalid priority type found: "+typeof c);"object"===typeof a&&".value"in a&&null!==a[".value"]&&(a=a[".value"]);if("object"!==typeof a||".sv"in a)return new Ib(a,H(c));if(a instanceof Array){var d=L,e=a;t(e,function(a,b){if(fb(e,b)&&"."!==b.substring(0,1)){var c=H(a);if(c.J()||!c.e())d=
d.T(b,c)}});return d.fa(H(c))}var f=[],g=!1,k=a;gb(k,function(a){if("string"!==typeof a||"."!==a.substring(0,1)){var b=H(k[a]);b.e()||(g=g||!b.C().e(),f.push(new R(a,b)))}});if(0==f.length)return L;var m=Ie(f,rf,function(a){return a.name},sf);if(g){var l=Ie(f,we(I));return new S(m,H(c),new Fe({".priority":l},{".priority":I}))}return new S(m,H(c),Ke)}var vf=Math.log(2);
function wf(a){this.count=parseInt(Math.log(a+1)/vf,10);this.Le=this.count-1;this.Bf=a+1&parseInt(Array(this.count+1).join("1"),2)}function xf(a){var b=!(a.Bf&1<<a.Le);a.Le--;return b}
function Ie(a,b,c,d){function e(b,d){var f=d-b;if(0==f)return null;if(1==f){var l=a[b],r=c?c(l):l;return new tb(r,l.R,!1,null,null)}var l=parseInt(f/2,10)+b,f=e(b,l),y=e(l+1,d),l=a[l],r=c?c(l):l;return new tb(r,l.R,!1,f,y)}a.sort(b);var f=function(b){function d(b,g){var k=r-b,y=r;r-=b;var y=e(k+1,y),k=a[k],F=c?c(k):k,y=new tb(F,k.R,g,null,y);f?f.left=y:l=y;f=y}for(var f=null,l=null,r=a.length,y=0;y<b.count;++y){var F=xf(b),sd=Math.pow(2,b.count-(y+1));F?d(sd,!1):(d(sd,!1),d(sd,!0))}return l}(new wf(a.length));
return null!==f?new ob(d||b,f):new ob(d||b)}function qf(a){return"number"===typeof a?"number:"+rc(a):"string:"+a}function of(a){if(a.J()){var b=a.H();E("string"===typeof b||"number"===typeof b||"object"===typeof b&&fb(b,".sv"),"Priority must be a string or number.")}else E(a===ze||a.e(),"priority of unexpected type.");E(a===ze||a.C().e(),"Priority nodes can't have a priority of their own.")}var L=new S(new ob(sf),null,Ke);function yf(){S.call(this,new ob(sf),L,Ke)}la(yf,S);h=yf.prototype;
h.pc=function(a){return a===this?0:1};h.Z=function(a){return a===this};h.C=function(){return this};h.Q=function(){return L};h.e=function(){return!1};var ze=new yf,xe=new R("[MIN_NAME]",L),De=new R("[MAX_NAME]",ze);function de(a,b){this.N=a;this.Id=b}function ae(a,b,c,d){return new de(new Ed(b,c,d),a.Id)}function ee(a){return a.N.da?a.N.j():null}de.prototype.w=function(){return this.Id};function Md(a){return a.Id.da?a.Id.j():null};function zf(a,b){this.V=a;var c=a.m,d=new Nd(c.g),c=T(c)?new Nd(c.g):c.xa?new df(c):new Pd(c);this.ff=new Vd(c);var e=b.w(),f=b.N,g=d.ya(L,e.j(),null),k=c.ya(L,f.j(),null);this.Ja=new de(new Ed(k,f.da,c.Ma()),new Ed(g,e.da,d.Ma()));this.Ya=[];this.Lf=new $e(a)}function Af(a){return a.V}h=zf.prototype;h.w=function(){return this.Ja.w().j()};h.fb=function(a){var b=Md(this.Ja);return b&&(T(this.V.m)||!a.e()&&!b.Q(O(a)).e())?b.P(a):null};h.e=function(){return 0===this.Ya.length};h.Lb=function(a){this.Ya.push(a)};
h.ib=function(a,b){var c=[];if(b){E(null==a,"A cancel should cancel all event registrations.");var d=this.V.path;Ha(this.Ya,function(a){(a=a.Je(b,d))&&c.push(a)})}if(a){for(var e=[],f=0;f<this.Ya.length;++f){var g=this.Ya[f];if(!g.matches(a))e.push(g);else if(a.Ue()){e=e.concat(this.Ya.slice(f+1));break}}this.Ya=e}else this.Ya=[];return c};
h.bb=function(a,b,c){a.type===zd&&null!==a.source.Fb&&(E(Md(this.Ja),"We should always have a full cache before handling merges"),E(ee(this.Ja),"Missing event cache, even though we have a server cache"));var d=this.Ja;a=this.ff.bb(d,a,b,c);b=this.ff;c=a.Od;E(c.N.j().vc(b.U.g),"Event snap not indexed");E(c.w().j().vc(b.U.g),"Server snap not indexed");E(Fd(a.Od.w())||!Fd(d.w()),"Once a server snap is complete, it should never go back");this.Ja=a.Od;return Bf(this,a.Cf,a.Od.N.j(),null)};
function Cf(a,b){var c=a.Ja.N,d=[];c.j().J()||c.j().O(I,function(a,b){d.push(new Q("child_added",b,a))});c.da&&d.push(Cd(c.j()));return Bf(a,d,c.j(),b)}function Bf(a,b,c,d){return af(a.Lf,b,c,d?[d]:a.Ya)};function Df(a,b){this.qf={};this.Sc=new Ef(a);this.va=b;var c=1E4+2E4*Math.random();vc(q(this.jf,this),Math.floor(c))}Df.prototype.jf=function(){var a=this.Sc.get(),b={},c=!1,d;for(d in a)0<a[d]&&fb(this.qf,d)&&(b[d]=a[d],c=!0);c&&this.va.we(b);vc(q(this.jf,this),Math.floor(6E5*Math.random()))};function Ef(a){this.Df=a;this.od=null}Ef.prototype.get=function(){var a=this.Df.get(),b=wa(a);if(this.od)for(var c in this.od)b[c]-=this.od[c];this.od=a;return b};function Ff(){this.qc={}}function Gf(a,b,c){n(c)||(c=1);fb(a.qc,b)||(a.qc[b]=0);a.qc[b]+=c}Ff.prototype.get=function(){return wa(this.qc)};var Hf={},If={};function Jf(a){a=a.toString();Hf[a]||(Hf[a]=new Ff);return Hf[a]}function Kf(a,b){var c=a.toString();If[c]||(If[c]=b());return If[c]};function Lf(a){this.re=a;this.zd=[];this.Ob=0;this.Ud=-1;this.Db=null}function Mf(a,b,c){a.Ud=b;a.Db=c;a.Ud<a.Ob&&(a.Db(),a.Db=null)}function Nf(a,b,c){for(a.zd[b]=c;a.zd[a.Ob];){var d=a.zd[a.Ob];delete a.zd[a.Ob];for(var e=0;e<d.length;++e)if(d[e]){var f=a;tc(function(){f.re(d[e])})}if(a.Ob===a.Ud){a.Db&&(clearTimeout(a.Db),a.Db(),a.Db=null);break}a.Ob++}};var Wb="websocket",Xb="long_polling";var Of=null,Of=require("faye-websocket").Client;function Pf(a,b,c,d){this.Vd=a;this.f=fc(this.Vd);this.frames=this.wc=null;this.nb=this.ob=this.De=0;this.Ua=Jf(b);a={v:"5"};c&&(a.s=c);d&&(a.ls=d);this.Wd=Vb(b,Wb,a)}var Qf;
Pf.prototype.open=function(a,b){this.gb=b;this.Xf=a;this.f("Websocket connecting to "+this.Wd);this.tc=!1;Rb.set("previous_websocket_failure",!0);try{var c={headers:{"User-Agent":"Firebase/5/"+firebase.SDK_VERSION+"/"+process.platform+"/AdminNode"}},d=process.env,e=0==this.Wd.indexOf("wss://")?d.HTTPS_PROXY||d.https_proxy:d.HTTP_PROXY||d.http_proxy;e&&(c.proxy={origin:e});this.Ha=new Of(this.Wd,[],c)}catch(f){this.f("Error instantiating WebSocket.");(c=f.message||f.data)&&this.f(c);this.ab();return}var g=
this;this.Ha.onopen=function(){g.f("Websocket connected.");g.tc=!0};this.Ha.onclose=function(){g.f("Websocket connection was disconnected.");g.Ha=null;g.ab()};this.Ha.onmessage=function(a){if(null!==g.Ha)if(a=a.data,g.nb+=a.length,Gf(g.Ua,"bytes_received",a.length),Rf(g),null!==g.frames)Sf(g,a);else{a:{E(null===g.frames,"We already have a frame buffer");if(6>=a.length){var b=Number(a);if(!isNaN(b)){g.De=b;g.frames=[];a=null;break a}}g.De=1;g.frames=[]}null!==a&&Sf(g,a)}};this.Ha.onerror=function(a){g.f("WebSocket error.  Closing connection.");
(a=a.message||a.data)&&g.f(a);g.ab()}};Pf.prototype.start=function(){};Pf.isAvailable=function(){var a=!1;if("undefined"!==typeof navigator&&navigator.userAgent){var b=navigator.userAgent.match(/Android ([0-9]{0,}\.[0-9]{0,})/);b&&1<b.length&&4.4>parseFloat(b[1])&&(a=!0)}return!a&&null!==Of&&!Qf};Pf.responsesRequiredToBeHealthy=2;Pf.healthyTimeout=3E4;h=Pf.prototype;h.pd=function(){Rb.remove("previous_websocket_failure")};
function Sf(a,b){a.frames.push(b);if(a.frames.length==a.De){var c=a.frames.join("");a.frames=null;c=eb(c);a.Xf(c)}}h.send=function(a){Rf(this);a=A(a);this.ob+=a.length;Gf(this.Ua,"bytes_sent",a.length);a=pc(a,16384);1<a.length&&Tf(this,String(a.length));for(var b=0;b<a.length;b++)Tf(this,a[b])};h.Qc=function(){this.yb=!0;this.wc&&(clearInterval(this.wc),this.wc=null);this.Ha&&(this.Ha.close(),this.Ha=null)};
h.ab=function(){this.yb||(this.f("WebSocket is closing itself"),this.Qc(),this.gb&&(this.gb(this.tc),this.gb=null))};h.close=function(){this.yb||(this.f("WebSocket is being closed"),this.Qc())};function Rf(a){clearInterval(a.wc);a.wc=setInterval(function(){a.Ha&&Tf(a,"0");Rf(a)},Math.floor(45E3))}function Tf(a,b){try{a.Ha.send(b)}catch(c){a.f("Exception thrown from WebSocket.send():",c.message||c.data,"Closing connection."),setTimeout(q(a.ab,a),0)}};function Uf(a,b,c,d){this.Vd=a;this.f=fc(a);this.gc=b;this.nb=this.ob=0;this.Ua=Jf(b);this.sf=c;this.tc=!1;this.Ab=d;this.Vc=function(a){return Vb(b,Xb,a)}}var Vf,Wf;
Uf.prototype.open=function(a,b){this.Ke=0;this.ia=b;this.af=new Lf(a);this.yb=!1;var c=this;this.qb=setTimeout(function(){c.f("Timed out trying to connect.");c.ab();c.qb=null},Math.floor(3E4));kc(function(){if(!c.yb){c.Sa=new Xf(function(a,b,d,k,m){Yf(c,arguments);if(c.Sa)if(c.qb&&(clearTimeout(c.qb),c.qb=null),c.tc=!0,"start"==a)c.id=b,c.fg=d;else if("close"===a)b?(c.Sa.of=!1,Mf(c.af,b,function(){c.ab()})):c.ab();else throw Error("Unrecognized command received: "+a);},function(a,b){Yf(c,arguments);
Nf(c.af,a,b)},function(){c.ab()},c.Vc);var a={start:"t"};a.ser=Math.floor(1E8*Math.random());c.Sa.sg&&(a.cb=c.Sa.sg);a.v="5";c.sf&&(a.s=c.sf);c.Ab&&(a.ls=c.Ab);a=c.Vc(a);c.f("Connecting via long-poll to "+a);Zf(c.Sa,a,function(){})}})};Uf.prototype.start=function(){var a=this.Sa,b=this.fg;a.me=this.id;a.$e=b;for(a.Qd=!0;$f(a););};
Uf.isAvailable=function(){return Vf||!Wf&&"undefined"!==typeof document&&null!=document.createElement&&!("object"===typeof window&&window.chrome&&window.chrome.extension&&!/^chrome/.test(window.location.href))&&!("object"===typeof Windows&&"object"===typeof Windows.ug)&&!1};h=Uf.prototype;h.pd=function(){};h.Qc=function(){this.yb=!0;this.Sa&&(this.Sa.close(),this.Sa=null);this.Ze&&(document.body.removeChild(this.Ze),this.Ze=null);this.qb&&(clearTimeout(this.qb),this.qb=null)};
h.ab=function(){this.yb||(this.f("Longpoll is closing itself"),this.Qc(),this.ia&&(this.ia(this.tc),this.ia=null))};h.close=function(){this.yb||(this.f("Longpoll is being closed."),this.Qc())};h.send=function(a){a=A(a);this.ob+=a.length;Gf(this.Ua,"bytes_sent",a.length);a=kb(a);a=Za(a,!0);a=pc(a,1840);for(var b=0;b<a.length;b++){var c=this.Sa;c.Nc.push({lg:this.Ke,rg:a.length,Me:a[b]});c.Qd&&$f(c);this.Ke++}};function Yf(a,b){var c=A(b).length;a.nb+=c;Gf(a.Ua,"bytes_received",c)}
function Xf(a,b,c,d){this.Vc=d;this.gb=c;this.te=new dd;this.Nc=[];this.Xd=Math.floor(1E8*Math.random());this.of=!0;this.Ef=a;this.Yf=b}Xf.prototype.close=function(){this.Qd=!1;if(this.rd){this.rd.wg.body.innerHTML="";var a=this;setTimeout(function(){null!==a.rd&&(document.body.removeChild(a.rd),a.rd=null)},Math.floor(0))}if(this.me){var b={disconn:"t"};b.id=this.me;b.pw=this.$e;b=this.Vc(b);ag(b)}if(b=this.gb)this.gb=null,b()};
function $f(a){if(a.Qd&&a.of&&a.te.count()<(0<a.Nc.length?2:1)){a.Xd++;var b={};b.id=a.me;b.pw=a.$e;b.ser=a.Xd;for(var b=a.Vc(b),c="",d=0;0<a.Nc.length;)if(1870>=a.Nc[0].Me.length+30+c.length){var e=a.Nc.shift(),c=c+"&seg"+d+"="+e.lg+"&ts"+d+"="+e.rg+"&d"+d+"="+e.Me;d++}else break;bg(a,b+c,a.Xd);return!0}return!1}function bg(a,b,c){function d(){a.te.remove(c);$f(a)}a.te.add(c,1);var e=setTimeout(d,Math.floor(25E3));Zf(a,b,function(){clearTimeout(e);d()})}function Zf(a,b,c){a.Hf(b,c)}var cg=null;
function ag(a,b){cg||(cg=require("request"));cg(a,function(c,d,e){if(c)throw"Rest request for "+a.url+" failed.";b&&b(e)})}Xf.prototype.Hf=function(a,b){var c=this;ag({url:a,xg:!0},function(a){c.Kf(a);b()})};Xf.prototype.Kf=function(a){eval("var jsonpCB = function(pLPCommand, pRTLPCB) {"+a+"}");jsonpCB(this.Ef,this.Yf)};function dg(a){eg(this,a)}var fg=[Uf,Pf];function eg(a,b){var c=Pf&&Pf.isAvailable(),d=c&&!(Rb.We||!0===Rb.get("previous_websocket_failure"));b.tg&&(c||M("wss:// URL used, but browser isn't known to support websockets.  Trying anyway."),d=!0);if(d)a.Tc=[Pf];else{var e=a.Tc=[];qc(fg,function(a,b){b&&b.isAvailable()&&e.push(b)})}}function gg(a){if(0<a.Tc.length)return a.Tc[0];throw Error("No transports available");};function hg(a,b,c,d,e,f,g){this.id=a;this.f=fc("c:"+this.id+":");this.re=c;this.Ic=d;this.ia=e;this.qe=f;this.L=b;this.yd=[];this.Ie=0;this.rf=new dg(b);this.Ta=0;this.Ab=g;this.f("Connection created");ig(this)}
function ig(a){var b=gg(a.rf);a.I=new b("c:"+a.id+":"+a.Ie++,a.L,void 0,a.Ab);a.ve=b.responsesRequiredToBeHealthy||0;var c=jg(a,a.I),d=kg(a,a.I);a.Uc=a.I;a.Oc=a.I;a.D=null;a.zb=!1;setTimeout(function(){a.I&&a.I.open(c,d)},Math.floor(0));b=b.healthyTimeout||0;0<b&&(a.jd=vc(function(){a.jd=null;a.zb||(a.I&&102400<a.I.nb?(a.f("Connection exceeded healthy timeout but has received "+a.I.nb+" bytes.  Marking connection healthy."),a.zb=!0,a.I.pd()):a.I&&10240<a.I.ob?a.f("Connection exceeded healthy timeout but has sent "+
a.I.ob+" bytes.  Leaving connection alive."):(a.f("Closing unhealthy connection after timeout."),a.close()))},Math.floor(b)))}function kg(a,b){return function(c){b===a.I?(a.I=null,c||0!==a.Ta?1===a.Ta&&a.f("Realtime connection lost."):(a.f("Realtime connection failed."),"s-"===a.L.Za.substr(0,2)&&(Rb.remove("host:"+a.L.host),a.L.Za=a.L.host)),a.close()):b===a.D?(a.f("Secondary connection lost."),c=a.D,a.D=null,a.Uc!==c&&a.Oc!==c||a.close()):a.f("closing an old connection")}}
function jg(a,b){return function(c){if(2!=a.Ta)if(b===a.Oc){var d=nc("t",c);c=nc("d",c);if("c"==d){if(d=nc("t",c),"d"in c)if(c=c.d,"h"===d){var d=c.ts,e=c.v,f=c.h;a.pf=c.s;Ub(a.L,f);0==a.Ta&&(a.I.start(),lg(a,a.I,d),"5"!==e&&M("Protocol version mismatch detected"),c=a.rf,(c=1<c.Tc.length?c.Tc[1]:null)&&mg(a,c))}else if("n"===d){a.f("recvd end transmission on primary");a.Oc=a.D;for(c=0;c<a.yd.length;++c)a.ud(a.yd[c]);a.yd=[];ng(a)}else"s"===d?(a.f("Connection shutdown command received. Shutting down..."),
a.qe&&(a.qe(c),a.qe=null),a.ia=null,a.close()):"r"===d?(a.f("Reset packet received.  New host: "+c),Ub(a.L,c),1===a.Ta?a.close():(og(a),ig(a))):"e"===d?gc("Server Error: "+c):"o"===d?(a.f("got pong on primary."),pg(a),qg(a)):gc("Unknown control packet command: "+d)}else"d"==d&&a.ud(c)}else if(b===a.D)if(d=nc("t",c),c=nc("d",c),"c"==d)"t"in c&&(c=c.t,"a"===c?rg(a):"r"===c?(a.f("Got a reset on secondary, closing it"),a.D.close(),a.Uc!==a.D&&a.Oc!==a.D||a.close()):"o"===c&&(a.f("got pong on secondary."),
a.nf--,rg(a)));else if("d"==d)a.yd.push(c);else throw Error("Unknown protocol layer: "+d);else a.f("message on old connection")}}hg.prototype.ua=function(a){sg(this,{t:"d",d:a})};function ng(a){a.Uc===a.D&&a.Oc===a.D&&(a.f("cleaning up and promoting a connection: "+a.D.Vd),a.I=a.D,a.D=null)}
function rg(a){0>=a.nf?(a.f("Secondary connection is healthy."),a.zb=!0,a.D.pd(),a.D.start(),a.f("sending client ack on secondary"),a.D.send({t:"c",d:{t:"a",d:{}}}),a.f("Ending transmission on primary"),a.I.send({t:"c",d:{t:"n",d:{}}}),a.Uc=a.D,ng(a)):(a.f("sending ping on secondary."),a.D.send({t:"c",d:{t:"p",d:{}}}))}hg.prototype.ud=function(a){pg(this);this.re(a)};function pg(a){a.zb||(a.ve--,0>=a.ve&&(a.f("Primary connection is healthy."),a.zb=!0,a.I.pd()))}
function mg(a,b){a.D=new b("c:"+a.id+":"+a.Ie++,a.L,a.pf);a.nf=b.responsesRequiredToBeHealthy||0;a.D.open(jg(a,a.D),kg(a,a.D));vc(function(){a.D&&(a.f("Timed out trying to upgrade."),a.D.close())},Math.floor(6E4))}function lg(a,b,c){a.f("Realtime connection established.");a.I=b;a.Ta=1;a.Ic&&(a.Ic(c,a.pf),a.Ic=null);0===a.ve?(a.f("Primary connection is healthy."),a.zb=!0):vc(function(){qg(a)},Math.floor(5E3))}
function qg(a){a.zb||1!==a.Ta||(a.f("sending ping on primary."),sg(a,{t:"c",d:{t:"p",d:{}}}))}function sg(a,b){if(1!==a.Ta)throw"Connection is not connected";a.Uc.send(b)}hg.prototype.close=function(){2!==this.Ta&&(this.f("Closing realtime connection."),this.Ta=2,og(this),this.ia&&(this.ia(),this.ia=null))};function og(a){a.f("Shutting down all connections");a.I&&(a.I.close(),a.I=null);a.D&&(a.D.close(),a.D=null);a.jd&&(clearTimeout(a.jd),a.jd=null)};function tg(a,b){this.committed=a;this.snapshot=b};function U(a,b){this.ta=a;this.qa=b}U.prototype.cancel=function(a){w("Firebase.onDisconnect().cancel",0,1,arguments.length);z("Firebase.onDisconnect().cancel",1,a,!0);var b=new ab;this.ta.vd(this.qa,bb(b,a));return b.ra};U.prototype.cancel=U.prototype.cancel;U.prototype.remove=function(a){w("Firebase.onDisconnect().remove",0,1,arguments.length);rd("Firebase.onDisconnect().remove",this.qa);z("Firebase.onDisconnect().remove",1,a,!0);var b=new ab;ug(this.ta,this.qa,null,bb(b,a));return b.ra};
U.prototype.remove=U.prototype.remove;U.prototype.set=function(a,b){w("Firebase.onDisconnect().set",1,2,arguments.length);rd("Firebase.onDisconnect().set",this.qa);jd("Firebase.onDisconnect().set",a,this.qa,!1);z("Firebase.onDisconnect().set",2,b,!0);var c=new ab;ug(this.ta,this.qa,a,bb(c,b));return c.ra};U.prototype.set=U.prototype.set;
U.prototype.Hb=function(a,b,c){w("Firebase.onDisconnect().setWithPriority",2,3,arguments.length);rd("Firebase.onDisconnect().setWithPriority",this.qa);jd("Firebase.onDisconnect().setWithPriority",a,this.qa,!1);nd("Firebase.onDisconnect().setWithPriority",2,b);z("Firebase.onDisconnect().setWithPriority",3,c,!0);var d=new ab;vg(this.ta,this.qa,a,b,bb(d,c));return d.ra};U.prototype.setWithPriority=U.prototype.Hb;
U.prototype.update=function(a,b){w("Firebase.onDisconnect().update",1,2,arguments.length);rd("Firebase.onDisconnect().update",this.qa);if(ea(a)){for(var c={},d=0;d<a.length;++d)c[""+d]=a[d];a=c;M("Passing an Array to Firebase.onDisconnect().update() is deprecated. Use set() if you want to overwrite the existing data, or an Object with integer keys if you really do want to only update some of the children.")}md("Firebase.onDisconnect().update",a,this.qa);z("Firebase.onDisconnect().update",2,b,!0);
c=new ab;wg(this.ta,this.qa,a,bb(c,b));return c.ra};U.prototype.update=U.prototype.update;function V(a,b,c){this.A=a;this.V=b;this.g=c}V.prototype.H=function(){w("Firebase.DataSnapshot.val",0,0,arguments.length);return this.A.H()};V.prototype.val=V.prototype.H;V.prototype.Zd=function(){w("Firebase.DataSnapshot.exportVal",0,0,arguments.length);return this.A.H(!0)};V.prototype.exportVal=V.prototype.Zd;V.prototype.toJSON=function(){w("Firebase.DataSnapshot.toJSON",0,1,arguments.length);return this.Zd()};V.prototype.toJSON=V.prototype.toJSON;
V.prototype.Nf=function(){w("Firebase.DataSnapshot.exists",0,0,arguments.length);return!this.A.e()};V.prototype.exists=V.prototype.Nf;V.prototype.n=function(a){w("Firebase.DataSnapshot.child",0,1,arguments.length);ga(a)&&(a=String(a));qd("Firebase.DataSnapshot.child",a);var b=new G(a),c=this.V.n(b);return new V(this.A.P(b),c,I)};V.prototype.child=V.prototype.n;
V.prototype.Da=function(a){w("Firebase.DataSnapshot.hasChild",1,1,arguments.length);qd("Firebase.DataSnapshot.hasChild",a);var b=new G(a);return!this.A.P(b).e()};V.prototype.hasChild=V.prototype.Da;V.prototype.C=function(){w("Firebase.DataSnapshot.getPriority",0,0,arguments.length);return this.A.C().H()};V.prototype.getPriority=V.prototype.C;
V.prototype.forEach=function(a){w("Firebase.DataSnapshot.forEach",1,1,arguments.length);z("Firebase.DataSnapshot.forEach",1,a,!1);if(this.A.J())return!1;var b=this;return!!this.A.O(this.g,function(c,d){return a(new V(d,b.V.n(c),I))})};V.prototype.forEach=V.prototype.forEach;V.prototype.gd=function(){w("Firebase.DataSnapshot.hasChildren",0,0,arguments.length);return this.A.J()?!1:!this.A.e()};V.prototype.hasChildren=V.prototype.gd;
V.prototype.getKey=function(){w("Firebase.DataSnapshot.key",0,0,arguments.length);return this.V.getKey()};uc(V.prototype,"key",V.prototype.getKey);V.prototype.Cb=function(){w("Firebase.DataSnapshot.numChildren",0,0,arguments.length);return this.A.Cb()};V.prototype.numChildren=V.prototype.Cb;V.prototype.ub=function(){w("Firebase.DataSnapshot.ref",0,0,arguments.length);return this.V};uc(V.prototype,"ref",V.prototype.ub);function xg(a,b,c){this.Nb=a;this.pb=b;this.rb=c||null}h=xg.prototype;h.lf=function(a){return"value"===a};h.createEvent=function(a,b){var c=b.m.g;return new ne("value",this,new V(a.Ia,b.ub(),c))};h.Rb=function(a){var b=this.rb;if("cancel"===a.de()){E(this.pb,"Raising a cancel event on a listener with no cancel callback");var c=this.pb;return function(){c.call(b,a.error)}}var d=this.Nb;return function(){d.call(b,a.Jd)}};h.Je=function(a,b){return this.pb?new oe(this,a,b):null};
h.matches=function(a){return a instanceof xg?a.Nb&&this.Nb?a.Nb===this.Nb&&a.rb===this.rb:!0:!1};h.Ue=function(){return null!==this.Nb};function yg(a,b,c){this.ga=a;this.pb=b;this.rb=c}h=yg.prototype;h.lf=function(a){a="children_added"===a?"child_added":a;return("children_removed"===a?"child_removed":a)in this.ga};h.Je=function(a,b){return this.pb?new oe(this,a,b):null};
h.createEvent=function(a,b){E(null!=a.Wa,"Child events should have a childName.");var c=b.ub().n(a.Wa);return new ne(a.type,this,new V(a.Ia,c,b.m.g),a.Bd)};h.Rb=function(a){var b=this.rb;if("cancel"===a.de()){E(this.pb,"Raising a cancel event on a listener with no cancel callback");var c=this.pb;return function(){c.call(b,a.error)}}var d=this.ga[a.ed];return function(){d.call(b,a.Jd,a.Bd)}};
h.matches=function(a){if(a instanceof yg){if(!this.ga||!a.ga)return!0;if(this.rb===a.rb){var b=oa(a.ga);if(b===oa(this.ga)){if(1===b){var b=pa(a.ga),c=pa(this.ga);return c===b&&(!a.ga[b]||!this.ga[c]||a.ga[b]===this.ga[c])}return na(this.ga,function(b,c){return a.ga[c]===b})}}}return!1};h.Ue=function(){return null!==this.ga};function zg(){this.za={}}h=zg.prototype;h.e=function(){return va(this.za)};h.bb=function(a,b,c){var d=a.source.Fb;if(null!==d)return d=B(this.za,d),E(null!=d,"SyncTree gave us an op for an invalid query."),d.bb(a,b,c);var e=[];t(this.za,function(d){e=e.concat(d.bb(a,b,c))});return e};h.Lb=function(a,b,c,d,e){var f=a.ja(),g=B(this.za,f);if(!g){var g=c.Aa(e?d:null),k=!1;g?k=!0:(g=d instanceof S?c.oc(d):L,k=!1);g=new zf(a,new de(new Ed(g,k,!1),new Ed(d,e,!1)));this.za[f]=g}g.Lb(b);return Cf(g,b)};
h.ib=function(a,b,c){var d=a.ja(),e=[],f=[],g=null!=Ag(this);if("default"===d){var k=this;t(this.za,function(a,d){f=f.concat(a.ib(b,c));a.e()&&(delete k.za[d],T(a.V.m)||e.push(a.V))})}else{var m=B(this.za,d);m&&(f=f.concat(m.ib(b,c)),m.e()&&(delete this.za[d],T(m.V.m)||e.push(m.V)))}g&&null==Ag(this)&&e.push(new W(a.u,a.path));return{jg:e,Mf:f}};function Bg(a){return Ia(qa(a.za),function(a){return!T(a.V.m)})}h.fb=function(a){var b=null;t(this.za,function(c){b=b||c.fb(a)});return b};
function Cg(a,b){if(T(b.m))return Ag(a);var c=b.ja();return B(a.za,c)}function Ag(a){return ua(a.za,function(a){return T(a.V.m)})||null};function Dg(a){this.wa=P;this.hb=new Ue;this.Be={};this.fc={};this.zc=a}function Eg(a,b,c,d,e){var f=a.hb,g=e;E(d>f.yc,"Stacking an older write on top of newer ones");n(g)||(g=!0);f.la.push({path:b,Fa:c,Wc:d,visible:g});g&&(f.S=Oe(f.S,b,c));f.yc=d;return e?Fg(a,new Lb(xd,b,c)):[]}function Gg(a,b,c,d){var e=a.hb;E(d>e.yc,"Stacking an older merge on top of newer ones");e.la.push({path:b,children:c,Wc:d,visible:!0});e.S=Pe(e.S,b,c);e.yc=d;c=Hc(c);return Fg(a,new yd(xd,b,c))}
function Hg(a,b,c){c=c||!1;var d=Ve(a.hb,b);if(a.hb.Cd(b)){var e=P;null!=d.Fa?e=e.set(J,!0):gb(d.children,function(a,b){e=e.set(new G(a),b)});return Fg(a,new vd(d.path,e,c))}return[]}function Ig(a,b,c){c=Hc(c);return Fg(a,new yd(Bd,b,c))}function Jg(a,b,c,d){d=Kg(a,d);if(null!=d){var e=Lg(d);d=e.path;e=e.Fb;b=N(d,b);c=new Lb(new Ad(!1,!0,e,!0),b,c);return Mg(a,d,c)}return[]}
function Ng(a,b,c,d){if(d=Kg(a,d)){var e=Lg(d);d=e.path;e=e.Fb;b=N(d,b);c=Hc(c);c=new yd(new Ad(!1,!0,e,!0),b,c);return Mg(a,d,c)}return[]}
Dg.prototype.Lb=function(a,b){var c=a.path,d=null,e=!1;Pc(this.wa,c,function(a,b){var f=N(a,c);d=d||b.fb(f);e=e||null!=Ag(b)});var f=this.wa.get(c);f?(e=e||null!=Ag(f),d=d||f.fb(J)):(f=new zg,this.wa=this.wa.set(c,f));var g;null!=d?g=!0:(g=!1,d=L,Tc(this.wa.subtree(c),function(a,b){var c=b.fb(J);c&&(d=d.T(a,c))}));var k=null!=Cg(f,a);if(!k&&!T(a.m)){var m=Og(a);E(!(m in this.fc),"View does not exist, but we have a tag");var l=Pg++;this.fc[m]=l;this.Be["_"+l]=m}g=f.Lb(a,b,new Ze(c,this.hb),d,g);k||
e||(f=Cg(f,a),g=g.concat(Qg(this,a,f)));return g};
Dg.prototype.ib=function(a,b,c){var d=a.path,e=this.wa.get(d),f=[];if(e&&("default"===a.ja()||null!=Cg(e,a))){f=e.ib(a,b,c);e.e()&&(this.wa=this.wa.remove(d));e=f.jg;f=f.Mf;b=-1!==Na(e,function(a){return T(a.m)});var g=Nc(this.wa,d,function(a,b){return null!=Ag(b)});if(b&&!g&&(d=this.wa.subtree(d),!d.e()))for(var d=Rg(d),k=0;k<d.length;++k){var m=d[k],l=m.V,m=Sg(this,m);this.zc.ye(Tg(l),Ug(this,l),m.hd,m.G)}if(!g&&0<e.length&&!c)if(b)this.zc.Ld(Tg(a),null);else{var r=this;Ha(e,function(a){a.ja();
var b=r.fc[Og(a)];r.zc.Ld(Tg(a),b)})}Vg(this,e)}return f};Dg.prototype.Aa=function(a,b){var c=this.hb,d=Nc(this.wa,a,function(b,c){var d=N(b,a);if(d=c.fb(d))return d});return c.Aa(a,d,b,!0)};function Rg(a){return Lc(a,function(a,c,d){if(c&&null!=Ag(c))return[Ag(c)];var e=[];c&&(e=Bg(c));t(d,function(a){e=e.concat(a)});return e})}function Vg(a,b){for(var c=0;c<b.length;++c){var d=b[c];if(!T(d.m)){var d=Og(d),e=a.fc[d];delete a.fc[d];delete a.Be["_"+e]}}}
function Tg(a){return T(a.m)&&!re(a.m)?a.ub():a}function Qg(a,b,c){var d=b.path,e=Ug(a,b);c=Sg(a,c);b=a.zc.ye(Tg(b),e,c.hd,c.G);d=a.wa.subtree(d);if(e)E(null==Ag(d.value),"If we're adding a query, it shouldn't be shadowed");else for(e=Lc(d,function(a,b,c){if(!a.e()&&b&&null!=Ag(b))return[Af(Ag(b))];var d=[];b&&(d=d.concat(Ja(Bg(b),function(a){return a.V})));t(c,function(a){d=d.concat(a)});return d}),d=0;d<e.length;++d)c=e[d],a.zc.Ld(Tg(c),Ug(a,c));return b}
function Sg(a,b){var c=b.V,d=Ug(a,c);return{hd:function(){return(b.w()||L).hash()},G:function(b){if("ok"===b){if(d){var f=c.path;if(b=Kg(a,d)){var g=Lg(b);b=g.path;g=g.Fb;f=N(b,f);f=new Jb(new Ad(!1,!0,g,!0),f);b=Mg(a,b,f)}else b=[]}else b=Fg(a,new Jb(Bd,c.path));return b}f="Unknown Error";"too_big"===b?f="The data requested exceeds the maximum size that can be accessed with a single request.":"permission_denied"==b?f="Client doesn't have permission to access the desired data.":"unavailable"==b&&
(f="The service is unavailable");f=Error(b+" at "+c.path.toString()+": "+f);f.code=b.toUpperCase();return a.ib(c,null,f)}}}function Og(a){return a.path.toString()+"$"+a.ja()}function Lg(a){var b=a.indexOf("$");E(-1!==b&&b<a.length-1,"Bad queryKey.");return{Fb:a.substr(b+1),path:new G(a.substr(0,b))}}function Kg(a,b){var c=a.Be,d="_"+b;return d in c?c[d]:void 0}function Ug(a,b){var c=Og(b);return B(a.fc,c)}var Pg=1;
function Mg(a,b,c){var d=a.wa.get(b);E(d,"Missing sync point for query tag that we're tracking");return d.bb(c,new Ze(b,a.hb),null)}function Fg(a,b){return Wg(a,b,a.wa,null,new Ze(J,a.hb))}function Wg(a,b,c,d,e){if(b.path.e())return Xg(a,b,c,d,e);var f=c.get(J);null==d&&null!=f&&(d=f.fb(J));var g=[],k=O(b.path),m=b.Jc(k);if((c=c.children.get(k))&&m)var l=d?d.Q(k):null,k=e.n(k),g=g.concat(Wg(a,m,c,l,k));f&&(g=g.concat(f.bb(b,e,d)));return g}
function Xg(a,b,c,d,e){var f=c.get(J);null==d&&null!=f&&(d=f.fb(J));var g=[];c.children.ha(function(c,f){var l=d?d.Q(c):null,r=e.n(c),y=b.Jc(c);y&&(g=g.concat(Xg(a,y,f,l,r)))});f&&(g=g.concat(f.bb(b,e,d)));return g};function X(a,b,c,d){this.u=a;this.path=b;this.m=c;this.Kc=d}
function Yg(a){var b=null,c=null;a.ka&&(b=Rd(a));a.na&&(c=Td(a));if(a.g===ge){if(a.ka){if("[MIN_NAME]"!=Qd(a))throw Error("Query: When ordering by key, you may only pass one argument to startAt(), endAt(), or equalTo().");if("string"!==typeof b)throw Error("Query: When ordering by key, the argument passed to startAt(), endAt(),or equalTo() must be a string.");}if(a.na){if("[MAX_NAME]"!=Sd(a))throw Error("Query: When ordering by key, you may only pass one argument to startAt(), endAt(), or equalTo().");if("string"!==
typeof c)throw Error("Query: When ordering by key, the argument passed to startAt(), endAt(),or equalTo() must be a string.");}}else if(a.g===I){if(null!=b&&!id(b)||null!=c&&!id(c))throw Error("Query: When ordering by priority, the first argument passed to startAt(), endAt(), or equalTo() must be a valid priority value (null, a number, or a string).");}else if(E(a.g instanceof ye||a.g===Ee,"unknown index type."),null!=b&&"object"===typeof b||null!=c&&"object"===typeof c)throw Error("Query: First argument passed to startAt(), endAt(), or equalTo() cannot be an object.");
}function Zg(a){if(a.ka&&a.na&&a.xa&&(!a.xa||""===a.kb))throw Error("Query: Can't combine startAt(), endAt(), and limit(). Use limitToFirst() or limitToLast() instead.");}function $g(a,b){if(!0===a.Kc)throw Error(b+": You can't combine multiple orderBy calls.");}h=X.prototype;h.ub=function(){w("Query.ref",0,0,arguments.length);return new W(this.u,this.path)};
h.dc=function(a,b,c,d){w("Query.on",2,4,arguments.length);od("Query.on",a,!1);z("Query.on",2,b,!1);var e=ah("Query.on",c,d);if("value"===a)bh(this.u,this,new xg(b,e.cancel||null,e.La||null));else{var f={};f[a]=b;bh(this.u,this,new yg(f,e.cancel,e.La))}return b};
h.Fc=function(a,b,c){w("Query.off",0,3,arguments.length);od("Query.off",a,!0);z("Query.off",2,b,!0);db("Query.off",3,c);var d=null,e=null;"value"===a?d=new xg(b||null,null,c||null):a&&(b&&(e={},e[a]=b),d=new yg(e,null,c||null));e=this.u;d=".info"===O(this.path)?e.md.ib(this,d):e.K.ib(this,d);ke(e.ca,this.path,d)};
h.ag=function(a,b){function c(k){f&&(f=!1,e.Fc(a,c),b&&b.call(d.La,k),g.resolve(k))}w("Query.once",1,4,arguments.length);od("Query.once",a,!1);z("Query.once",2,b,!0);var d=ah("Query.once",arguments[2],arguments[3]),e=this,f=!0,g=new ab;cb(g.ra);this.dc(a,c,function(b){e.Fc(a,c);d.cancel&&d.cancel.call(d.La,b);g.reject(b)});return g.ra};
h.ke=function(a){w("Query.limitToFirst",1,1,arguments.length);if(!ga(a)||Math.floor(a)!==a||0>=a)throw Error("Query.limitToFirst: First argument must be a positive integer.");if(this.m.xa)throw Error("Query.limitToFirst: Limit was already set (by another call to limit, limitToFirst, or limitToLast).");return new X(this.u,this.path,this.m.ke(a),this.Kc)};
h.le=function(a){w("Query.limitToLast",1,1,arguments.length);if(!ga(a)||Math.floor(a)!==a||0>=a)throw Error("Query.limitToLast: First argument must be a positive integer.");if(this.m.xa)throw Error("Query.limitToLast: Limit was already set (by another call to limit, limitToFirst, or limitToLast).");return new X(this.u,this.path,this.m.le(a),this.Kc)};
h.bg=function(a){w("Query.orderByChild",1,1,arguments.length);if("$key"===a)throw Error('Query.orderByChild: "$key" is invalid.  Use Query.orderByKey() instead.');if("$priority"===a)throw Error('Query.orderByChild: "$priority" is invalid.  Use Query.orderByPriority() instead.');if("$value"===a)throw Error('Query.orderByChild: "$value" is invalid.  Use Query.orderByValue() instead.');qd("Query.orderByChild",a);$g(this,"Query.orderByChild");var b=new G(a);if(b.e())throw Error("Query.orderByChild: cannot pass in empty path.  Use Query.orderByValue() instead.");
b=new ye(b);b=mf(this.m,b);Yg(b);return new X(this.u,this.path,b,!0)};h.cg=function(){w("Query.orderByKey",0,0,arguments.length);$g(this,"Query.orderByKey");var a=mf(this.m,ge);Yg(a);return new X(this.u,this.path,a,!0)};h.dg=function(){w("Query.orderByPriority",0,0,arguments.length);$g(this,"Query.orderByPriority");var a=mf(this.m,I);Yg(a);return new X(this.u,this.path,a,!0)};
h.eg=function(){w("Query.orderByValue",0,0,arguments.length);$g(this,"Query.orderByValue");var a=mf(this.m,Ee);Yg(a);return new X(this.u,this.path,a,!0)};h.Kd=function(a,b){w("Query.startAt",0,2,arguments.length);jd("Query.startAt",a,this.path,!0);pd("Query.startAt",b);var c=this.m.Kd(a,b);Zg(c);Yg(c);if(this.m.ka)throw Error("Query.startAt: Starting point was already set (by another call to startAt or equalTo).");n(a)||(b=a=null);return new X(this.u,this.path,c,this.Kc)};
h.dd=function(a,b){w("Query.endAt",0,2,arguments.length);jd("Query.endAt",a,this.path,!0);pd("Query.endAt",b);var c=this.m.dd(a,b);Zg(c);Yg(c);if(this.m.na)throw Error("Query.endAt: Ending point was already set (by another call to endAt or equalTo).");return new X(this.u,this.path,c,this.Kc)};
h.Jf=function(a,b){w("Query.equalTo",1,2,arguments.length);jd("Query.equalTo",a,this.path,!1);pd("Query.equalTo",b);if(this.m.ka)throw Error("Query.equalTo: Starting point was already set (by another call to startAt or equalTo).");if(this.m.na)throw Error("Query.equalTo: Ending point was already set (by another call to endAt or equalTo).");return this.Kd(a,b).dd(a,b)};
h.toString=function(){w("Query.toString",0,0,arguments.length);for(var a=this.path,b="",c=a.Y;c<a.o.length;c++)""!==a.o[c]&&(b+="/"+encodeURIComponent(String(a.o[c])));return this.u.toString()+(b||"/")};h.toJSON=function(){w("Query.toJSON",0,1,arguments.length);return this.toString()};h.ja=function(){var a=oc(nf(this.m));return"{}"===a?"default":a};
h.isEqual=function(a){w("Query.isEqual",1,1,arguments.length);if(!(a instanceof X))throw Error("Query.isEqual failed: First argument must be an instance of firebase.database.Query.");var b=this.u===a.u,c=this.path.Z(a.path),d=this.ja()===a.ja();return b&&c&&d};
function ah(a,b,c){var d={cancel:null,La:null};if(b&&c)d.cancel=b,z(a,3,d.cancel,!0),d.La=c,db(a,4,d.La);else if(b)if("object"===typeof b&&null!==b)d.La=b;else if("function"===typeof b)d.cancel=b;else throw Error(x(a,3,!0)+" must either be a cancel callback or a context object.");return d}X.prototype.on=X.prototype.dc;X.prototype.off=X.prototype.Fc;X.prototype.once=X.prototype.ag;X.prototype.limitToFirst=X.prototype.ke;X.prototype.limitToLast=X.prototype.le;X.prototype.orderByChild=X.prototype.bg;
X.prototype.orderByKey=X.prototype.cg;X.prototype.orderByPriority=X.prototype.dg;X.prototype.orderByValue=X.prototype.eg;X.prototype.startAt=X.prototype.Kd;X.prototype.endAt=X.prototype.dd;X.prototype.equalTo=X.prototype.Jf;X.prototype.toString=X.prototype.toString;X.prototype.isEqual=X.prototype.isEqual;uc(X.prototype,"ref",X.prototype.ub);function ch(a){a instanceof dh||hc("Don't call new Database() directly - please use firebase.database().");this.ta=a;this.ba=new W(a,J);this.INTERNAL=new eh(this)}var fh={TIMESTAMP:{".sv":"timestamp"}};h=ch.prototype;h.app=null;h.gf=function(a){gh(this,"ref");w("database.ref",0,1,arguments.length);return n(a)?this.ba.n(a):this.ba};
h.ig=function(a){gh(this,"database.refFromURL");w("database.refFromURL",1,1,arguments.length);var b=ic(a);td("database.refFromURL",b);var c=b.gc;c.host!==this.ta.L.host&&hc("database.refFromURL: Host name does not match the current database: (found "+c.host+" but expected "+this.ta.L.host+")");return this.gf(b.path.toString())};function gh(a,b){null===a.ta&&hc("Cannot call "+b+" on a deleted database.")}h.Rf=function(){w("database.goOffline",0,0,arguments.length);gh(this,"goOffline");this.ta.$a()};
h.Sf=function(){w("database.goOnline",0,0,arguments.length);gh(this,"goOnline");this.ta.hc()};Object.defineProperty(ch.prototype,"app",{get:function(){return this.ta.app}});function eh(a){this.Xa=a}eh.prototype.delete=function(){gh(this.Xa,"delete");var a=hh.Tb(),b=this.Xa.ta;B(a.jb,b.app.name)!==b&&hc("Database "+b.app.name+" has already been deleted.");b.$a();delete a.jb[b.app.name];this.Xa.ta=null;this.Xa.ba=null;this.Xa=this.Xa.INTERNAL=null;return firebase.Promise.resolve()};
ch.prototype.ref=ch.prototype.gf;ch.prototype.refFromURL=ch.prototype.ig;ch.prototype.goOnline=ch.prototype.Sf;ch.prototype.goOffline=ch.prototype.Rf;eh.prototype["delete"]=eh.prototype.delete;function ih(){return"undefined"!==typeof window&&!!(window.cordova||window.phonegap||window.PhoneGap)&&/ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test("undefined"!==typeof navigator&&"string"===typeof navigator.userAgent?navigator.userAgent:"")};function jh(){ad.call(this,["online"]);this.ec=!0;if("undefined"!==typeof window&&"undefined"!==typeof window.addEventListener&&!ih()){var a=this;window.addEventListener("online",function(){a.ec||(a.ec=!0,a.Ee("online",!0))},!1);window.addEventListener("offline",function(){a.ec&&(a.ec=!1,a.Ee("online",!1))},!1)}}la(jh,ad);jh.prototype.Re=function(a){E("online"===a,"Unknown event type: "+a);return[this.ec]};ca(jh);function kh(a,b,c,d,e,f){this.id=lh++;this.f=fc("p:"+this.id+":");this.nd={};this.$={};this.pa=[];this.Lc=0;this.Hc=[];this.ma=!1;this.Ra=1E3;this.qd=3E5;this.Eb=b;this.Gc=c;this.se=d;this.L=a;this.mb=this.Ea=this.Ab=this.xe=null;this.Xc=e;this.ae=!1;this.he=0;this.Rd=f;this.sb=null;this.Kb=!1;this.Ed={};this.kg=0;this.Oe=!0;this.xc=this.je=null;mh(this,0);cd.Tb().dc("visible",this.$f,this);-1===a.host.indexOf("fblocal")&&jh.Tb().dc("online",this.Zf,this)}var lh=0,nh=0;h=kh.prototype;
h.ua=function(a,b,c){var d=++this.kg;a={r:d,a:a,b:b};this.f(A(a));E(this.ma,"sendRequest call when we're not connected not allowed.");this.Ea.ua(a);c&&(this.Ed[d]=c)};h.Xe=function(a,b,c,d){var e=a.ja(),f=a.path.toString();this.f("Listen called for "+f+" "+e);this.$[f]=this.$[f]||{};E(re(a.m)||!T(a.m),"listen() called for non-default but complete query");E(!this.$[f][e],"listen() called twice for same path/queryId.");a={G:d,hd:b,gg:a,tag:c};this.$[f][e]=a;this.ma&&oh(this,a)};
function oh(a,b){var c=b.gg,d=c.path.toString(),e=c.ja();a.f("Listen on "+d+" for "+e);var f={p:d};b.tag&&(f.q=nf(c.m),f.t=b.tag);f.h=b.hd();a.ua("q",f,function(f){var k=f.d,m=f.s;if(k&&"object"===typeof k&&fb(k,"w")){var l=B(k,"w");ea(l)&&0<=Ga(l,"no_index")&&M("Using an unspecified index. Consider adding "+('".indexOn": "'+c.m.g.toString()+'"')+" at "+c.path.toString()+" to your security rules for better performance")}(a.$[d]&&a.$[d][e])===b&&(a.f("listen response",f),"ok"!==m&&ph(a,d,e),b.G&&b.G(m,
k))})}h.hf=function(a){this.mb=a;this.f("Auth token refreshed");this.mb?qh(this):this.ma&&this.ua("unauth",{},function(){});if(a&&40===a.length||yc(a))this.f("Admin auth credential detected.  Reducing max reconnect time."),this.qd=3E4};function qh(a){if(a.ma&&a.mb){var b=a.mb,c=xc(b)?"auth":"gauth",d={cred:b};null===a.Rd?d.noauth=!0:"object"===typeof a.Rd&&(d.authvar=a.Rd);a.ua(c,d,function(c){var d=c.s;c=c.d||"error";a.mb===b&&("ok"===d?a.he=0:rh(a,d,c))})}}
h.tf=function(a,b){var c=a.path.toString(),d=a.ja();this.f("Unlisten called for "+c+" "+d);E(re(a.m)||!T(a.m),"unlisten() called for non-default but complete query");if(ph(this,c,d)&&this.ma){var e=nf(a.m);this.f("Unlisten on "+c+" for "+d);c={p:c};b&&(c.q=e,c.t=b);this.ua("n",c)}};h.pe=function(a,b,c){this.ma?sh(this,"o",a,b,c):this.Hc.push({ue:a,action:"o",data:b,G:c})};h.bf=function(a,b,c){this.ma?sh(this,"om",a,b,c):this.Hc.push({ue:a,action:"om",data:b,G:c})};
h.vd=function(a,b){this.ma?sh(this,"oc",a,null,b):this.Hc.push({ue:a,action:"oc",data:null,G:b})};function sh(a,b,c,d,e){c={p:c,d:d};a.f("onDisconnect "+b,c);a.ua(b,c,function(a){e&&setTimeout(function(){e(a.s,a.d)},Math.floor(0))})}h.put=function(a,b,c,d){th(this,"p",a,b,c,d)};h.Ye=function(a,b,c,d){th(this,"m",a,b,c,d)};function th(a,b,c,d,e,f){d={p:c,d:d};n(f)&&(d.h=f);a.pa.push({action:b,kf:d,G:e});a.Lc++;b=a.pa.length-1;a.ma?uh(a,b):a.f("Buffering put: "+c)}
function uh(a,b){var c=a.pa[b].action,d=a.pa[b].kf,e=a.pa[b].G;a.pa[b].hg=a.ma;a.ua(c,d,function(d){a.f(c+" response",d);delete a.pa[b];a.Lc--;0===a.Lc&&(a.pa=[]);e&&e(d.s,d.d)})}h.we=function(a){this.ma&&(a={c:a},this.f("reportStats",a),this.ua("s",a,function(a){"ok"!==a.s&&this.f("reportStats","Error sending stats: "+a.d)}))};
h.ud=function(a){if("r"in a){this.f("from server: "+A(a));var b=a.r,c=this.Ed[b];c&&(delete this.Ed[b],c(a.b))}else{if("error"in a)throw"A server-side error has occurred: "+a.error;"a"in a&&(b=a.a,a=a.b,this.f("handleServerMessage",b,a),"d"===b?this.Eb(a.p,a.d,!1,a.t):"m"===b?this.Eb(a.p,a.d,!0,a.t):"c"===b?vh(this,a.p,a.q):"ac"===b?rh(this,a.s,a.d):"sd"===b?this.xe?this.xe(a):"msg"in a&&"undefined"!==typeof console&&console.log("FIREBASE: "+a.msg.replace("\n","\nFIREBASE: ")):gc("Unrecognized action received from server: "+
A(b)+"\nAre you using the latest client?"))}};h.Ic=function(a,b){this.f("connection ready");this.ma=!0;this.xc=(new Date).getTime();this.se({serverTimeOffset:a-(new Date).getTime()});this.Ab=b;if(this.Oe){var c={};c["sdk.admin_node."+firebase.SDK_VERSION.replace(/\./g,"-")]=1;ih()?c["framework.cordova"]=1:"object"===typeof navigator&&"ReactNative"===navigator.product&&(c["framework.reactnative"]=1);this.we(c)}wh(this);this.Oe=!1;this.Gc(!0)};
function mh(a,b){E(!a.Ea,"Scheduling a connect when we're already connected/ing?");a.sb&&clearTimeout(a.sb);a.sb=setTimeout(function(){a.sb=null;xh(a)},Math.floor(b))}h.$f=function(a){a&&!this.Kb&&this.Ra===this.qd&&(this.f("Window became visible.  Reducing delay."),this.Ra=1E3,this.Ea||mh(this,0));this.Kb=a};h.Zf=function(a){a?(this.f("Browser went online."),this.Ra=1E3,this.Ea||mh(this,0)):(this.f("Browser went offline.  Killing connection."),this.Ea&&this.Ea.close())};
h.cf=function(){this.f("data client disconnected");this.ma=!1;this.Ea=null;for(var a=0;a<this.pa.length;a++){var b=this.pa[a];b&&"h"in b.kf&&b.hg&&(b.G&&b.G("disconnect"),delete this.pa[a],this.Lc--)}0===this.Lc&&(this.pa=[]);this.Ed={};yh(this)&&(this.Kb?this.xc&&(3E4<(new Date).getTime()-this.xc&&(this.Ra=1E3),this.xc=null):(this.f("Window isn't visible.  Delaying reconnect."),this.Ra=this.qd,this.je=(new Date).getTime()),a=Math.max(0,this.Ra-((new Date).getTime()-this.je)),a*=Math.random(),this.f("Trying to reconnect in "+
a+"ms"),mh(this,a),this.Ra=Math.min(this.qd,1.3*this.Ra));this.Gc(!1)};
function xh(a){if(yh(a)){a.f("Making a connection attempt");a.je=(new Date).getTime();a.xc=null;var b=q(a.ud,a),c=q(a.Ic,a),d=q(a.cf,a),e=a.id+":"+nh++,f=a.Ab,g=!1,k=null,m=function(){k?k.close():(g=!0,d())};a.Ea={close:m,ua:function(a){E(k,"sendRequest call when we're not connected not allowed.");k.ua(a)}};var l=a.ae;a.ae=!1;a.Xc.getToken(l).then(function(l){g?C("getToken() completed but was canceled"):(C("getToken() completed. Creating connection."),a.mb=l&&l.accessToken,k=new hg(e,a.L,b,c,d,function(b){M(b+
" ("+a.L.toString()+")");a.$a("server_kill")},f))}).then(null,function(b){a.f("Failed to get token: "+b);g||(M(b),m())})}}h.$a=function(a){C("Interrupting connection for reason: "+a);this.nd[a]=!0;this.Ea?this.Ea.close():(this.sb&&(clearTimeout(this.sb),this.sb=null),this.ma&&this.cf())};h.hc=function(a){C("Resuming connection for reason: "+a);delete this.nd[a];va(this.nd)&&(this.Ra=1E3,this.Ea||mh(this,0))};
function vh(a,b,c){c=c?Ja(c,function(a){return oc(a)}).join("$"):"default";(a=ph(a,b,c))&&a.G&&a.G("permission_denied")}function ph(a,b,c){b=(new G(b)).toString();var d;n(a.$[b])?(d=a.$[b][c],delete a.$[b][c],0===oa(a.$[b])&&delete a.$[b]):d=void 0;return d}
function rh(a,b,c){C("Auth token revoked: "+b+"/"+c);a.mb=null;a.ae=!0;a.Ea.close();if("invalid_token"===b||"permission_denied"===b)a.he++,3<=a.he&&(a.Ra=3E4,a=a.Xc,b='Provided authentication credentials for the app named "'+a.lc.name+'" are invalid. This usually indicates your app was not initialized correctly. ',b="credential"in a.lc.options?b+'Make sure the "credential" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.':"serviceAccount"in
a.lc.options?b+'Make sure the "serviceAccount" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.':b+'Make sure the "apiKey" and "databaseURL" properties provided to initializeApp() match the values provided for your app at https://console.firebase.google.com/.',M(b))}
function wh(a){qh(a);t(a.$,function(b){t(b,function(b){oh(a,b)})});for(var b=0;b<a.pa.length;b++)a.pa[b]&&uh(a,b);for(;a.Hc.length;)b=a.Hc.shift(),sh(a,b.action,b.ue,b.data,b.G)}function yh(a){var b;b=jh.Tb().ec;return va(a.nd)&&b};function dh(a,b,c){this.app=c;var d=new mb(c);this.L=a;this.Ua=Jf(a);this.Sc=null;this.ca=new he;this.td=1;this.Qa=null;if(b||0<=("object"===typeof window&&window.navigator&&window.navigator.userAgent||"").search(/googlebot|google webmaster tools|bingbot|yahoo! slurp|baiduspider|yandexbot|duckduckbot/i))this.va=new pe(this.L,q(this.Eb,this),d),setTimeout(q(this.Gc,this,!0),0);else{b=c.options.databaseAuthVariableOverride;if("undefined"!==da(b)&&null!==b){if("object"!==da(b))throw Error("Only objects are supported for option databaseAuthVariableOverride");
try{A(b)}catch(e){throw Error("Invalid authOverride provided: "+e);}}this.va=this.Qa=new kh(this.L,q(this.Eb,this),q(this.Gc,this),q(this.se,this),d,b)}var f=this;nb(d,function(a){f.va.hf(a)});this.qg=Kf(a,q(function(){return new Df(this.Ua,this.va)},this));this.jc=new Vc;this.fe=new Nb;this.md=new Dg({ye:function(a,b,c,d){b=[];c=f.fe.j(a.path);c.e()||(b=Fg(f.md,new Lb(Bd,a.path,c)),setTimeout(function(){d("ok")},0));return b},Ld:ba});zh(this,"connected",!1);this.ia=new Eb;this.Xa=new ch(this);this.cd=
0;this.ge=null;this.K=new Dg({ye:function(a,b,c,d){f.va.Xe(a,c,b,function(b,c){var e=d(b,c);me(f.ca,a.path,e)});return[]},Ld:function(a,b){f.va.tf(a,b)}})}h=dh.prototype;h.toString=function(){return(this.L.Pc?"https://":"http://")+this.L.host};h.name=function(){return this.L.ne};function Ah(a){a=a.fe.j(new G(".info/serverTimeOffset")).H()||0;return(new Date).getTime()+a}function Bh(a){a=a={timestamp:Ah(a)};a.timestamp=a.timestamp||(new Date).getTime();return a}
h.Eb=function(a,b,c,d){this.cd++;var e=new G(a);b=this.ge?this.ge(a,b):b;a=[];d?c?(b=ma(b,function(a){return H(a)}),a=Ng(this.K,e,b,d)):(b=H(b),a=Jg(this.K,e,b,d)):c?(d=ma(b,function(a){return H(a)}),a=Ig(this.K,e,d)):(d=H(b),a=Fg(this.K,new Lb(Bd,e,d)));d=e;0<a.length&&(d=Ch(this,e));me(this.ca,d,a)};h.Gc=function(a){zh(this,"connected",a);!1===a&&Dh(this)};h.se=function(a){var b=this;qc(a,function(a,d){zh(b,d,a)})};
function zh(a,b,c){b=new G("/.info/"+b);c=H(c);var d=a.fe;d.Hd=d.Hd.F(b,c);c=Fg(a.md,new Lb(Bd,b,c));me(a.ca,b,c)}h.Hb=function(a,b,c,d){this.f("set",{path:a.toString(),value:b,zg:c});var e=Bh(this);b=H(b,c);var e=Hb(b,e),f=this.td++,e=Eg(this.K,a,e,f,!0);ie(this.ca,e);var g=this;this.va.put(a.toString(),b.H(!0),function(b,c){var e="ok"===b;e||M("set at "+a+" failed: "+b);e=Hg(g.K,f,!e);me(g.ca,a,e);Eh(d,b,c)});e=Fh(this,a);Ch(this,e);me(this.ca,e,[])};
h.update=function(a,b,c){this.f("update",{path:a.toString(),value:b});var d=!0,e=Bh(this),f={};t(b,function(a,b){d=!1;var c=H(a);f[b]=Hb(c,e)});if(d)C("update() called with empty data.  Don't do anything."),Eh(c,"ok");else{var g=this.td++,k=Gg(this.K,a,f,g);ie(this.ca,k);var m=this;this.va.Ye(a.toString(),b,function(b,d){var e="ok"===b;e||M("update at "+a+" failed: "+b);var e=Hg(m.K,g,!e),f=a;0<e.length&&(f=Ch(m,a));me(m.ca,f,e);Eh(c,b,d)});t(b,function(b,c){var d=Fh(m,a.n(c));Ch(m,d)});me(this.ca,
a,[])}};function Dh(a){a.f("onDisconnectEvents");var b=Bh(a),c=[];Fb(Db(a.ia,b),J,function(b,e){c=c.concat(Fg(a.K,new Lb(Bd,b,e)));var f=Fh(a,b);Ch(a,f)});a.ia=new Eb;me(a.ca,J,c)}h.vd=function(a,b){var c=this;this.va.vd(a.toString(),function(d,e){"ok"===d&&Le(c.ia,a);Eh(b,d,e)})};function ug(a,b,c,d){var e=H(c);a.va.pe(b.toString(),e.H(!0),function(c,g){"ok"===c&&Gb(a.ia,b,e);Eh(d,c,g)})}
function vg(a,b,c,d,e){var f=H(c,d);a.va.pe(b.toString(),f.H(!0),function(c,d){"ok"===c&&Gb(a.ia,b,f);Eh(e,c,d)})}function wg(a,b,c,d){var e=!0,f;for(f in c)e=!1;e?(C("onDisconnect().update() called with empty data.  Don't do anything."),Eh(d,"ok")):a.va.bf(b.toString(),c,function(e,f){if("ok"===e)for(var m in c){var l=H(c[m]);Gb(a.ia,b.n(m),l)}Eh(d,e,f)})}function bh(a,b,c){c=".info"===O(b.path)?a.md.Lb(b,c):a.K.Lb(b,c);ke(a.ca,b.path,c)}h.$a=function(){this.Qa&&this.Qa.$a("repo_interrupt")};
h.hc=function(){this.Qa&&this.Qa.hc("repo_interrupt")};h.ze=function(a){if("undefined"!==typeof console){a?(this.Sc||(this.Sc=new Ef(this.Ua)),a=this.Sc.get()):a=this.Ua.get();var b=Ka(ra(a),function(a,b){return Math.max(b.length,a)},0),c;for(c in a){for(var d=a[c],e=c.length;e<b+2;e++)c+=" ";console.log(c+d)}}};h.Ae=function(a){Gf(this.Ua,a);this.qg.qf[a]=!0};h.f=function(a){var b="";this.Qa&&(b=this.Qa.id+":");C(b,arguments)};
function Eh(a,b,c){a&&tc(function(){if("ok"==b)a(null);else{var d=(b||"error").toUpperCase(),e=d;c&&(e+=": "+c);e=Error(e);e.code=d;a(e)}})};function Gh(a,b,c,d,e){function f(){}a.f("transaction on "+b);var g=new W(a,b);g.dc("value",f);c={path:b,update:c,G:d,status:null,df:Yb(),Fe:e,mf:0,Nd:function(){g.Fc("value",f)},Pd:null,Ba:null,$c:null,ad:null,bd:null};d=a.K.Aa(b,void 0)||L;c.$c=d;d=c.update(d.H());if(n(d)){kd("transaction failed: Data returned ",d,c.path);c.status=1;e=Wc(a.jc,b);var k=e.Ca()||[];k.push(c);Xc(e,k);"object"===typeof d&&null!==d&&fb(d,".priority")?(k=B(d,".priority"),E(id(k),"Invalid priority returned by transaction. Priority must be a valid string, finite number, server value, or null.")):
k=(a.K.Aa(b)||L).C().H();e=Bh(a);d=H(d,k);e=Hb(d,e);c.ad=d;c.bd=e;c.Ba=a.td++;c=Eg(a.K,b,e,c.Ba,c.Fe);me(a.ca,b,c);Hh(a)}else c.Nd(),c.ad=null,c.bd=null,c.G&&(a=new V(c.$c,new W(a,c.path),I),c.G(null,!1,a))}function Hh(a,b){var c=b||a.jc;b||Ih(a,c);if(null!==c.Ca()){var d=Jh(a,c);E(0<d.length,"Sending zero length transaction queue");La(d,function(a){return 1===a.status})&&Kh(a,c.path(),d)}else c.gd()&&c.O(function(b){Hh(a,b)})}
function Kh(a,b,c){for(var d=Ja(c,function(a){return a.Ba}),e=a.K.Aa(b,d)||L,d=e,e=e.hash(),f=0;f<c.length;f++){var g=c[f];E(1===g.status,"tryToSendTransactionQueue_: items in queue should all be run.");g.status=2;g.mf++;var k=N(b,g.path),d=d.F(k,g.ad)}d=d.H(!0);a.va.put(b.toString(),d,function(d){a.f("transaction put response",{path:b.toString(),status:d});var e=[];if("ok"===d){d=[];for(f=0;f<c.length;f++){c[f].status=3;e=e.concat(Hg(a.K,c[f].Ba));if(c[f].G){var g=c[f].bd,k=new W(a,c[f].path);d.push(q(c[f].G,
null,null,!0,new V(g,k,I)))}c[f].Nd()}Ih(a,Wc(a.jc,b));Hh(a);me(a.ca,b,e);for(f=0;f<d.length;f++)tc(d[f])}else{if("datastale"===d)for(f=0;f<c.length;f++)c[f].status=4===c[f].status?5:1;else for(M("transaction at "+b.toString()+" failed: "+d),f=0;f<c.length;f++)c[f].status=5,c[f].Pd=d;Ch(a,b)}},e)}function Ch(a,b){var c=Lh(a,b),d=c.path(),c=Jh(a,c);Mh(a,c,d);return d}
function Mh(a,b,c){if(0!==b.length){for(var d=[],e=[],f=Ia(b,function(a){return 1===a.status}),f=Ja(f,function(a){return a.Ba}),g=0;g<b.length;g++){var k=b[g],m=N(c,k.path),l=!1,r;E(null!==m,"rerunTransactionsUnderNode_: relativePath should not be null.");if(5===k.status)l=!0,r=k.Pd,e=e.concat(Hg(a.K,k.Ba,!0));else if(1===k.status)if(25<=k.mf)l=!0,r="maxretry",e=e.concat(Hg(a.K,k.Ba,!0));else{var y=a.K.Aa(k.path,f)||L;k.$c=y;var F=b[g].update(y.H());n(F)?(kd("transaction failed: Data returned ",F,
k.path),m=H(F),"object"===typeof F&&null!=F&&fb(F,".priority")||(m=m.fa(y.C())),y=k.Ba,F=Bh(a),F=Hb(m,F),k.ad=m,k.bd=F,k.Ba=a.td++,Oa(f,y),e=e.concat(Eg(a.K,k.path,F,k.Ba,k.Fe)),e=e.concat(Hg(a.K,y,!0))):(l=!0,r="nodata",e=e.concat(Hg(a.K,k.Ba,!0)))}me(a.ca,c,e);e=[];l&&(b[g].status=3,setTimeout(b[g].Nd,Math.floor(0)),b[g].G&&("nodata"===r?(k=new W(a,b[g].path),d.push(q(b[g].G,null,null,!1,new V(b[g].$c,k,I)))):d.push(q(b[g].G,null,Error(r),!1,null))))}Ih(a,a.jc);for(g=0;g<d.length;g++)tc(d[g]);Hh(a)}}
function Lh(a,b){for(var c,d=a.jc;null!==(c=O(b))&&null===d.Ca();)d=Wc(d,c),b=K(b);return d}function Jh(a,b){var c=[];Nh(a,b,c);c.sort(function(a,b){return a.df-b.df});return c}function Nh(a,b,c){var d=b.Ca();if(null!==d)for(var e=0;e<d.length;e++)c.push(d[e]);b.O(function(b){Nh(a,b,c)})}function Ih(a,b){var c=b.Ca();if(c){for(var d=0,e=0;e<c.length;e++)3!==c[e].status&&(c[d]=c[e],d++);c.length=d;Xc(b,0<c.length?c:null)}b.O(function(b){Ih(a,b)})}
function Fh(a,b){var c=Lh(a,b).path(),d=Wc(a.jc,b);$c(d,function(b){Oh(a,b)});Oh(a,d);Zc(d,function(b){Oh(a,b)});return c}
function Oh(a,b){var c=b.Ca();if(null!==c){for(var d=[],e=[],f=-1,g=0;g<c.length;g++)4!==c[g].status&&(2===c[g].status?(E(f===g-1,"All SENT items should be at beginning of queue."),f=g,c[g].status=4,c[g].Pd="set"):(E(1===c[g].status,"Unexpected transaction status in abort"),c[g].Nd(),e=e.concat(Hg(a.K,c[g].Ba,!0)),c[g].G&&d.push(q(c[g].G,null,Error("set"),!1,null))));-1===f?Xc(b,null):c.length=f+1;me(a.ca,b.path(),e);for(g=0;g<d.length;g++)tc(d[g])}};function hh(){this.jb={};this.uf=!1}hh.prototype.$a=function(){for(var a in this.jb)this.jb[a].$a()};hh.prototype.hc=function(){for(var a in this.jb)this.jb[a].hc()};hh.prototype.$d=function(a){this.uf=a};ca(hh);hh.prototype.interrupt=hh.prototype.$a;hh.prototype.resume=hh.prototype.hc;var Y={Of:function(){Vf=Qf=!0}};Y.forceLongPolling=Y.Of;Y.Pf=function(){Wf=!0};Y.forceWebSockets=Y.Pf;Y.Vf=function(){return Pf.isAvailable()};Y.isWebSocketsAvailable=Y.Vf;Y.ng=function(a,b){a.u.Qa.xe=b};Y.setSecurityDebugCallback=Y.ng;Y.ze=function(a,b){a.u.ze(b)};Y.stats=Y.ze;Y.Ae=function(a,b){a.u.Ae(b)};Y.statsIncrementCounter=Y.Ae;Y.cd=function(a){return a.u.cd};Y.dataUpdateCount=Y.cd;Y.Uf=function(a,b){a.u.ge=b};Y.interceptServerData=Y.Uf;var Z={};Z.kc=kh;Z.DataConnection=Z.kc;kh.prototype.pg=function(a,b){this.ua("q",{p:a},b)};Z.kc.prototype.simpleListen=Z.kc.prototype.pg;kh.prototype.If=function(a,b){this.ua("echo",{d:a},b)};Z.kc.prototype.echo=Z.kc.prototype.If;kh.prototype.interrupt=kh.prototype.$a;Z.yf=hg;Z.RealTimeConnection=Z.yf;hg.prototype.sendRequest=hg.prototype.ua;hg.prototype.close=hg.prototype.close;
Z.Tf=function(a){var b=kh.prototype.put;kh.prototype.put=function(c,d,e,f){n(f)&&(f=a());b.call(this,c,d,e,f)};return function(){kh.prototype.put=b}};Z.hijackHash=Z.Tf;Z.xf=Tb;Z.ConnectionTarget=Z.xf;Z.ja=function(a){return a.ja()};Z.queryIdentifier=Z.ja;Z.Wf=function(a){return a.u.Qa.$};Z.listens=Z.Wf;Z.$d=function(a){hh.Tb().$d(a)};Z.forceRestClient=Z.$d;Z.Context=hh;function W(a,b){if(!(a instanceof dh))throw Error("new Firebase() no longer supported - use app.database().");X.call(this,a,b,kf,!1);this.then=void 0;this["catch"]=void 0}la(W,X);h=W.prototype;h.getKey=function(){w("Firebase.key",0,0,arguments.length);return this.path.e()?null:Bc(this.path)};
h.n=function(a){w("Firebase.child",1,1,arguments.length);if(ga(a))a=String(a);else if(!(a instanceof G))if(null===O(this.path)){var b=a;b&&(b=b.replace(/^\/*\.info(\/|$)/,"/"));qd("Firebase.child",b)}else qd("Firebase.child",a);return new W(this.u,this.path.n(a))};h.getParent=function(){w("Firebase.parent",0,0,arguments.length);var a=this.path.parent();return null===a?null:new W(this.u,a)};
h.Qf=function(){w("Firebase.ref",0,0,arguments.length);for(var a=this;null!==a.getParent();)a=a.getParent();return a};h.Gf=function(){return this.u.Xa};h.set=function(a,b){w("Firebase.set",1,2,arguments.length);rd("Firebase.set",this.path);jd("Firebase.set",a,this.path,!1);z("Firebase.set",2,b,!0);var c=new ab;this.u.Hb(this.path,a,null,bb(c,b));return c.ra};
h.update=function(a,b){w("Firebase.update",1,2,arguments.length);rd("Firebase.update",this.path);if(ea(a)){for(var c={},d=0;d<a.length;++d)c[""+d]=a[d];a=c;M("Passing an Array to Firebase.update() is deprecated. Use set() if you want to overwrite the existing data, or an Object with integer keys if you really do want to only update some of the children.")}md("Firebase.update",a,this.path);z("Firebase.update",2,b,!0);c=new ab;this.u.update(this.path,a,bb(c,b));return c.ra};
h.Hb=function(a,b,c){w("Firebase.setWithPriority",2,3,arguments.length);rd("Firebase.setWithPriority",this.path);jd("Firebase.setWithPriority",a,this.path,!1);nd("Firebase.setWithPriority",2,b);z("Firebase.setWithPriority",3,c,!0);if(".length"===this.getKey()||".keys"===this.getKey())throw"Firebase.setWithPriority failed: "+this.getKey()+" is a read-only object.";var d=new ab;this.u.Hb(this.path,a,b,bb(d,c));return d.ra};
h.remove=function(a){w("Firebase.remove",0,1,arguments.length);rd("Firebase.remove",this.path);z("Firebase.remove",1,a,!0);return this.set(null,a)};
h.transaction=function(a,b,c){w("Firebase.transaction",1,3,arguments.length);rd("Firebase.transaction",this.path);z("Firebase.transaction",1,a,!1);z("Firebase.transaction",2,b,!0);if(n(c)&&"boolean"!=typeof c)throw Error(x("Firebase.transaction",3,!0)+"must be a boolean.");if(".length"===this.getKey()||".keys"===this.getKey())throw"Firebase.transaction failed: "+this.getKey()+" is a read-only object.";"undefined"===typeof c&&(c=!0);var d=new ab;ha(b)&&cb(d.ra);Gh(this.u,this.path,a,function(a,c,g){a?
d.reject(a):d.resolve(new tg(c,g));ha(b)&&b(a,c,g)},c);return d.ra};h.mg=function(a,b){w("Firebase.setPriority",1,2,arguments.length);rd("Firebase.setPriority",this.path);nd("Firebase.setPriority",1,a);z("Firebase.setPriority",2,b,!0);var c=new ab;this.u.Hb(this.path.n(".priority"),a,null,bb(c,b));return c.ra};
h.push=function(a,b){w("Firebase.push",0,2,arguments.length);rd("Firebase.push",this.path);jd("Firebase.push",a,this.path,!0);z("Firebase.push",2,b,!0);var c=Ah(this.u),d=ud(c),c=this.n(d),e=this.n(d),d=null!=a?c.set(a,b).then(function(){return e}):$a.resolve(e);c.then=q(d.then,d);c["catch"]=q(d.then,d,void 0);ha(b)&&cb(d);return c};h.gb=function(){rd("Firebase.onDisconnect",this.path);return new U(this.u,this.path)};W.prototype.child=W.prototype.n;W.prototype.set=W.prototype.set;
W.prototype.update=W.prototype.update;W.prototype.setWithPriority=W.prototype.Hb;W.prototype.remove=W.prototype.remove;W.prototype.transaction=W.prototype.transaction;W.prototype.setPriority=W.prototype.mg;W.prototype.push=W.prototype.push;W.prototype.onDisconnect=W.prototype.gb;uc(W.prototype,"database",W.prototype.Gf);uc(W.prototype,"key",W.prototype.getKey);uc(W.prototype,"parent",W.prototype.getParent);uc(W.prototype,"root",W.prototype.Qf);if("undefined"===typeof firebase)throw Error("Cannot install Firebase Database - be sure to load firebase-app.js first.");
try{var Ph=firebase.INTERNAL.registerService("database",function(a){var b=hh.Tb(),c=a.options.databaseURL;n(c)||hc("Can't determine Firebase Database URL.  Be sure to include databaseURL option when calling firebase.intializeApp().");var d=ic(c),c=d.gc;td("Invalid Firebase Database URL",d);d.path.e()||hc("Database URL must point to the root of a Firebase Database (not including a child path).");(d=B(b.jb,a.name))&&hc("FIREBASE INTERNAL ERROR: Database initialized multiple times.");d=new dh(c,b.uf,
a);b.jb[a.name]=d;return d.Xa},{Reference:W,Query:X,Database:ch,enableLogging:ec,INTERNAL:Y,TEST_ACCESS:Z,ServerValue:fh});module.exports=Ph}catch(Qh){hc("Failed to register the Firebase Database Service ("+Qh+")")};
})();

