@mercoa/react 0.0.7 → 0.0.8-rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -170,7 +170,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
170
170
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function _(nr,or){if(nr){if(typeof nr=="string")return g(nr,or);var ir=Object.prototype.toString.call(nr).slice(8,-1);return ir==="Object"&&nr.constructor&&(ir=nr.constructor.name),ir==="Map"||ir==="Set"?Array.from(nr):ir==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(ir)?g(nr,or):void 0}}function g(nr,or){(or==null||or>nr.length)&&(or=nr.length);for(var ir=0,ar=new Array(or);ir<or;ir++)ar[ir]=nr[ir];return ar}function v(nr,or){var ir=typeof Symbol<"u"&&nr[Symbol.iterator]||nr["@@iterator"];if(!ir){if(Array.isArray(nr)||(ir=_(nr))||or&&nr&&typeof nr.length=="number"){ir&&(nr=ir);var ar=0,sr=function(){};return{s:sr,n:function(){return ar>=nr.length?{done:!0}:{done:!1,value:nr[ar++]}},e:function(dr){throw dr},f:sr}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
171
171
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var lr,cr=!0,ur=!1;return{s:function(){ir=ir.call(nr)},n:function(){var dr=ir.next();return cr=dr.done,dr},e:function(dr){ur=!0,lr=dr},f:function(){try{cr||ir.return==null||ir.return()}finally{if(ur)throw lr}}}}var m={DEBUG:!1,LIB_VERSION:"1.103.1"},y=Array.isArray,b=Object.prototype,k=b.hasOwnProperty,w=b.toString,S=y||function(nr){return w.call(nr)==="[object Array]"},F=function(nr){return w.call(nr)==="[object Uint8Array]"},P=function(nr){return typeof nr=="function"},I=function(nr){return nr===Object(nr)&&!S(nr)},R=function(nr){return nr===void 0},x=function(nr){return w.call(nr)=="[object String]"},E=function(nr){return nr===null},C=function(nr){return w.call(nr)=="[object Number]"},O=function(nr){return w.call(nr)==="[object Boolean]"},$=Array.prototype,A=$.forEach,M=$.indexOf,T=typeof window<"u"?window:void 0,q=T==null?void 0:T.navigator,D=T==null?void 0:T.document,L=q==null?void 0:q.userAgent,B=T??{},N="[PostHog.js]",j={_log:function(nr){if(T&&(m.DEBUG||B.POSTHOG_DEBUG)&&!R(T.console)&&T.console){for(var or=("__rrweb_original__"in T.console[nr])?T.console[nr].__rrweb_original__:T.console[nr],ir=arguments.length,ar=new Array(ir>1?ir-1:0),sr=1;sr<ir;sr++)ar[sr-1]=arguments[sr];or.apply(void 0,[N].concat(ar))}},info:function(){for(var nr=arguments.length,or=new Array(nr),ir=0;ir<nr;ir++)or[ir]=arguments[ir];j._log.apply(j,["log"].concat(or))},warn:function(){for(var nr=arguments.length,or=new Array(nr),ir=0;ir<nr;ir++)or[ir]=arguments[ir];j._log.apply(j,["warn"].concat(or))},error:function(){for(var nr=arguments.length,or=new Array(nr),ir=0;ir<nr;ir++)or[ir]=arguments[ir];j._log.apply(j,["error"].concat(or))},critical:function(){for(var nr,or=arguments.length,ir=new Array(or),ar=0;ar<or;ar++)ir[ar]=arguments[ar];(nr=console).error.apply(nr,[N].concat(ir))},uninitializedWarning:function(nr){j.error("You must initialize PostHog before calling ".concat(nr))}},H={},W=function(nr){return nr.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")};function V(nr,or,ir){if(S(nr)){if(A&&nr.forEach===A)nr.forEach(or,ir);else if("length"in nr&&nr.length===+nr.length){for(var ar=0,sr=nr.length;ar<sr;ar++)if(ar in nr&&or.call(ir,nr[ar],ar)===H)return}}}function U(nr,or,ir){if(!E(nr)&&!R(nr)){if(S(nr))return V(nr,or,ir);for(var ar in nr)if(k.call(nr,ar)&&or.call(ir,nr[ar],ar)===H)return}}var G=function(nr){for(var or=arguments.length,ir=new Array(or>1?or-1:0),ar=1;ar<or;ar++)ir[ar-1]=arguments[ar];return V(ir,function(sr){for(var lr in sr)sr[lr]!==void 0&&(nr[lr]=sr[lr])}),nr};function z(nr,or){return nr.indexOf(or)!==-1}function Q(nr){for(var or=Object.keys(nr),ir=or.length,ar=new Array(ir);ir--;)ar[ir]=[or[ir],nr[or[ir]]];return ar}var Y=function(){return Date.now=Date.now||function(){return+new Date},Date.now()},J=function(nr){try{return nr()}catch{return}},X=function(nr){return function(){try{for(var or=arguments.length,ir=new Array(or),ar=0;ar<or;ar++)ir[ar]=arguments[ar];return nr.apply(this,ir)}catch(sr){j.critical("Implementation error. Please turn on debug mode and open a ticket on https://app.posthog.com/home#panel=support%3Asupport%3A."),j.critical(sr)}}},K=function(nr){var or={};return U(nr,function(ir,ar){x(ir)&&ir.length>0&&(or[ar]=ir)}),or},Z=["$performance_raw"];function ee(nr,or){return ir=nr,ar=function(lr,cr){return cr&&Z.indexOf(cr)>-1?lr:x(lr)&&!E(or)?lr.slice(0,or):lr},sr=new Set,function lr(cr,ur){return cr!==Object(cr)?ar?ar(cr,ur):cr:sr.has(cr)?void 0:(sr.add(cr),S(cr)?(dr=[],V(cr,function(fr){dr.push(lr(fr))})):(dr={},U(cr,function(fr,pr){sr.has(fr)||(dr[pr]=lr(fr,pr))})),dr);var dr}(ir);var ir,ar,sr}function te(nr){var or,ir,ar,sr,lr,cr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",ur=0,dr=0,fr="",pr=[];if(!nr)return nr;nr=ne(nr);do or=(lr=nr.charCodeAt(ur++)<<16|nr.charCodeAt(ur++)<<8|nr.charCodeAt(ur++))>>18&63,ir=lr>>12&63,ar=lr>>6&63,sr=63&lr,pr[dr++]=cr.charAt(or)+cr.charAt(ir)+cr.charAt(ar)+cr.charAt(sr);while(ur<nr.length);switch(fr=pr.join(""),nr.length%3){case 1:fr=fr.slice(0,-2)+"==";break;case 2:fr=fr.slice(0,-1)+"="}return fr}var ne=function(nr){var or,ir,ar,sr,lr="";for(or=ir=0,ar=(nr=(nr+"").replace(/\r\n/g,`
172
172
  `).replace(/\r/g,`
173
- `)).length,sr=0;sr<ar;sr++){var cr=nr.charCodeAt(sr),ur=null;cr<128?ir++:ur=cr>127&&cr<2048?String.fromCharCode(cr>>6|192,63&cr|128):String.fromCharCode(cr>>12|224,cr>>6&63|128,63&cr|128),E(ur)||(ir>or&&(lr+=nr.substring(or,ir)),lr+=ur,or=ir=sr+1)}return ir>or&&(lr+=nr.substring(or,nr.length)),lr},ie=function(){function nr(or){return or&&(or.preventDefault=nr.preventDefault,or.stopPropagation=nr.stopPropagation),or}return nr.preventDefault=function(){this.returnValue=!1},nr.stopPropagation=function(){this.cancelBubble=!0},function(or,ir,ar,sr,lr){if(or)if(or.addEventListener&&!sr)or.addEventListener(ir,ar,!!lr);else{var cr="on"+ir,ur=or[cr];or[cr]=function(dr,fr,pr){return function(hr){if(hr=hr||nr(T==null?void 0:T.event)){var gr,vr=!0;P(pr)&&(gr=pr(hr));var br=fr.call(dr,hr);return gr!==!1&&br!==!1||(vr=!1),vr}}}(or,ar,ur)}else j.error("No valid element provided to register_event")}}();function re(nr,or){var ir=function(){if(!D)return or("document not found");var ar=D.createElement("script");ar.type="text/javascript",ar.src=nr,ar.onload=function(cr){return or(void 0,cr)},ar.onerror=function(cr){return or(cr)};var sr,lr=D.querySelectorAll("body > script");lr.length>0?(sr=lr[0].parentNode)===null||sr===void 0||sr.insertBefore(ar,lr[0]):D.body.appendChild(ar)};D!=null&&D.body?ir():D==null||D.addEventListener("DOMContentLoaded",ir)}function oe(nr){return nr?W(nr).split(/\s+/):[]}function se(nr){var or="";switch(n(nr.className)){case"string":or=nr.className;break;case"object":or=("baseVal"in nr.className?nr.className.baseVal:null)||nr.getAttribute("class")||"";break;default:or=""}return oe(or)}function ae(nr){var or="";return fe(nr)&&!pe(nr)&&nr.childNodes&&nr.childNodes.length&&U(nr.childNodes,function(ir){ce(ir)&&ir.textContent&&(or+=W(ir.textContent).split(/(\s+)/).filter(_e).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255))}),W(or)}function ue(nr){return!!nr&&nr.nodeType===1}function le(nr,or){return!!nr&&!!nr.tagName&&nr.tagName.toLowerCase()===or.toLowerCase()}function ce(nr){return!!nr&&nr.nodeType===3}function de(nr){return!!nr&&nr.nodeType===11}var he=["a","button","form","input","select","textarea","label"];function fe(nr){for(var or=nr;or.parentNode&&!le(or,"body");or=or.parentNode){var ir=se(or);if(z(ir,"ph-sensitive")||z(ir,"ph-no-capture"))return!1}if(z(se(nr),"ph-include"))return!0;var ar=nr.type||"";if(x(ar))switch(ar.toLowerCase()){case"hidden":case"password":return!1}var sr=nr.name||nr.id||"";return!(x(sr)&&/^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(sr.replace(/[^a-zA-Z0-9]/g,"")))}function pe(nr){return!!(le(nr,"input")&&!["button","checkbox","submit","reset"].includes(nr.type)||le(nr,"select")||le(nr,"textarea")||nr.getAttribute("contenteditable")==="true")}function _e(nr){return!(E(nr)||R(nr)||x(nr)&&(nr=W(nr),/^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/.test((nr||"").replace(/[- ]/g,""))||/(^\d{3}-?\d{2}-?\d{4}$)/.test(nr)))}function ge(nr){var or=ae(nr);return _e(or="".concat(or," ").concat(ve(nr)).trim())?or:""}function ve(nr){var or="";return nr&&nr.childNodes&&nr.childNodes.length&&U(nr.childNodes,function(ir){var ar;if(ir&&((ar=ir.tagName)===null||ar===void 0?void 0:ar.toLowerCase())==="span")try{var sr=ae(ir);or="".concat(or," ").concat(sr).trim(),ir.childNodes&&ir.childNodes.length&&(or="".concat(or," ").concat(ve(ir)).trim())}catch(lr){j.error(lr)}}),or}function me(nr){return function(or){var ir=or.map(function(ar){var sr,lr,cr="";if(ar.tag_name&&(cr+=ar.tag_name),ar.attr_class){ar.attr_class.sort();var ur,dr=v(ar.attr_class);try{for(dr.s();!(ur=dr.n()).done;){var fr=ur.value;cr+=".".concat(fr.replace(/"/g,""))}}catch(gr){dr.e(gr)}finally{dr.f()}}var pr=t(t(t(t({},ar.text?{text:ar.text}:{}),{},{"nth-child":(sr=ar.nth_child)!==null&&sr!==void 0?sr:0,"nth-of-type":(lr=ar.nth_of_type)!==null&&lr!==void 0?lr:0},ar.href?{href:ar.href}:{}),ar.attr_id?{attr_id:ar.attr_id}:{}),ar.attributes),hr={};return Q(pr).sort(function(gr,vr){var br=f(gr,1)[0],mr=f(vr,1)[0];return br.localeCompare(mr)}).forEach(function(gr){var vr=f(gr,2),br=vr[0],mr=vr[1];return hr[ye(br.toString())]=ye(mr.toString())}),cr+=":",cr+=Q(pr).map(function(gr){var vr=f(gr,2),br=vr[0],mr=vr[1];return"".concat(br,'="').concat(mr,'"')}).join("")});return ir.join(";")}(function(or){return or.map(function(ir){var ar,sr,lr={text:(ar=ir.$el_text)===null||ar===void 0?void 0:ar.slice(0,400),tag_name:ir.tag_name,href:(sr=ir.attr__href)===null||sr===void 0?void 0:sr.slice(0,2048),attr_class:be(ir),attr_id:ir.attr__id,nth_child:ir.nth_child,nth_of_type:ir.nth_of_type,attributes:{}};return Q(ir).filter(function(cr){return f(cr,1)[0].indexOf("attr__")===0}).forEach(function(cr){var ur=f(cr,2),dr=ur[0],fr=ur[1];return lr.attributes[dr]=fr}),lr})}(nr))}function ye(nr){return nr.replace(/"|\\"/g,'\\"')}function be(nr){var or=nr.attr__class;return or?S(or)?or:oe(or):void 0}var ke=function(){function nr(or){i(this,nr),this.clicks=[],this.enabled=or}return o(nr,[{key:"isRageClick",value:function(or,ir,ar){if(!this.enabled)return!1;var sr=this.clicks[this.clicks.length-1];if(sr&&Math.abs(or-sr.x)+Math.abs(ir-sr.y)<30&&ar-sr.timestamp<1e3){if(this.clicks.push({x:or,y:ir,timestamp:ar}),this.clicks.length===3)return!0}else this.clicks=[{x:or,y:ir,timestamp:ar}];return!1}}]),nr}(),we="$people_distinct_id",Se="__alias",Fe="__timers",Pe="$autocapture_disabled_server_side",Ie="$session_recording_enabled_server_side",Re="$console_log_recording_enabled_server_side",xe="$session_recording_recorder_version_server_side",Ee="$session_recording_network_payload_capture",Ce="$sesid",Oe="$session_is_sampled",$e="$enabled_feature_flags",Ae="$early_access_features",Me="$stored_person_properties",Te="$stored_group_properties",qe="$surveys",De="$flag_call_reported",Le="$user_state",Be="$posthog_quota_limited",Ne="$client_session_props",je=[we,Se,"__cmpns",Fe,Ie,Ce,$e,Le,Be,Ae,Te,Me,qe,De,Ne];function He(nr,or){return or.length>nr?or.slice(0,nr)+"...":or}var We={_initializedTokens:[],_isDisabledServerSide:null,_isAutocaptureEnabled:!1,_setIsAutocaptureEnabled:function(nr){var or,ir=E(this._isDisabledServerSide)?!((or=nr.persistence)===null||or===void 0||!or.props[Pe]):this._isDisabledServerSide,ar=!!nr.config.autocapture;this._isAutocaptureEnabled=ar&&!ir},_previousElementSibling:function(nr){if(nr.previousElementSibling)return nr.previousElementSibling;var or=nr;do or=or.previousSibling;while(or&&!ue(or));return or},_getAugmentPropertiesFromElement:function(nr){if(!fe(nr))return{};var or={};return U(nr.attributes,function(ir){if(ir.name.indexOf("data-ph-capture-attribute")===0){var ar=ir.name.replace("data-ph-capture-attribute-",""),sr=ir.value;ar&&sr&&_e(sr)&&(or[ar]=sr)}}),or},_getPropertiesFromElement:function(nr,or,ir){var ar,sr=nr.tagName.toLowerCase(),lr={tag_name:sr};he.indexOf(sr)>-1&&!ir&&(sr.toLowerCase()==="a"||sr.toLowerCase()==="button"?lr.$el_text=He(1024,ge(nr)):lr.$el_text=He(1024,ae(nr)));var cr=se(nr);cr.length>0&&(lr.classes=cr.filter(function(hr){return hr!==""}));var ur=(ar=this.config)===null||ar===void 0?void 0:ar.element_attribute_ignorelist;U(nr.attributes,function(hr){var gr;if((!pe(nr)||["name","id","class"].indexOf(hr.name)!==-1)&&(ur==null||!ur.includes(hr.name))&&!or&&_e(hr.value)&&(gr=hr.name,!x(gr)||gr.substring(0,10)!=="_ngcontent"&&gr.substring(0,7)!=="_nghost")){var vr=hr.value;hr.name==="class"&&(vr=oe(vr).join(" ")),lr["attr__"+hr.name]=He(1024,vr)}});for(var dr=1,fr=1,pr=nr;pr=this._previousElementSibling(pr);)dr++,pr.tagName===nr.tagName&&fr++;return lr.nth_child=dr,lr.nth_of_type=fr,lr},_getDefaultProperties:function(nr){return{$event_type:nr,$ce_version:1}},_extractCustomPropertyValue:function(nr){var or=[];return U(D==null?void 0:D.querySelectorAll(nr.css_selector),function(ir){var ar;["input","select"].indexOf(ir.tagName.toLowerCase())>-1?ar=ir.value:ir.textContent&&(ar=ir.textContent),_e(ar)&&or.push(ar)}),or.join(", ")},_getCustomProperties:function(nr){var or=this,ir={};return U(this._customProperties,function(ar){U(ar.event_selectors,function(sr){U(D==null?void 0:D.querySelectorAll(sr),function(lr){z(nr,lr)&&fe(lr)&&(ir[ar.name]=or._extractCustomPropertyValue(ar))})})}),ir},_getEventTarget:function(nr){return R(nr.target)?nr.srcElement||null:(or=nr.target)!==null&&or!==void 0&&or.shadowRoot?nr.composedPath()[0]||null:nr.target||null;var or},_captureEvent:function(nr,or){var ir,ar=this,sr=arguments.length>2&&arguments[2]!==void 0?arguments[2]:"$autocapture",lr=this._getEventTarget(nr);if(ce(lr)&&(lr=lr.parentNode||null),sr==="$autocapture"&&nr.type==="click"&&nr instanceof MouseEvent&&(ir=this.rageclicks)!==null&&ir!==void 0&&ir.isRageClick(nr.clientX,nr.clientY,new Date().getTime())&&this._captureEvent(nr,or,"$rageclick"),lr&&function(mr,yr){var wr=arguments.length>2&&arguments[2]!==void 0?arguments[2]:void 0;if(!T||!mr||le(mr,"html")||!ue(mr))return!1;if(wr!=null&&wr.url_allowlist){var Tr=T.location.href,Pr=wr.url_allowlist;if(Pr&&!Pr.some(function(Vr){return Tr.match(Vr)}))return!1}if(wr!=null&&wr.dom_event_allowlist){var Rr=wr.dom_event_allowlist;if(Rr&&!Rr.some(function(Vr){return yr.type===Vr}))return!1}if(wr!=null&&wr.element_allowlist){var _r=wr.element_allowlist;if(_r&&!_r.some(function(Vr){return mr.tagName.toLowerCase()===Vr}))return!1}if(wr!=null&&wr.css_selector_allowlist){var jr=wr.css_selector_allowlist;if(jr&&!jr.some(function(Vr){return mr.matches(Vr)}))return!1}for(var Cr=!1,Sr=[mr],Mr=!0,Ur=mr;Ur.parentNode&&!le(Ur,"body");)if(de(Ur.parentNode))Sr.push(Ur.parentNode.host),Ur=Ur.parentNode.host;else{if(!(Mr=Ur.parentNode||!1))break;if(he.indexOf(Mr.tagName.toLowerCase())>-1)Cr=!0;else{var kr=T.getComputedStyle(Mr);kr&&kr.getPropertyValue("cursor")==="pointer"&&(Cr=!0)}Sr.push(Mr),Ur=Mr}var Ir=T.getComputedStyle(mr);if(Ir&&Ir.getPropertyValue("cursor")==="pointer"&&yr.type==="click")return!0;var qr=mr.tagName.toLowerCase();switch(qr){case"html":return!1;case"form":return yr.type==="submit";case"input":case"select":case"textarea":return yr.type==="change"||yr.type==="click";default:return Cr?yr.type==="click":yr.type==="click"&&(he.indexOf(qr)>-1||mr.getAttribute("contenteditable")==="true")}}(lr,nr,this.config)){for(var cr,ur,dr=[lr],fr=lr;fr.parentNode&&!le(fr,"body");)de(fr.parentNode)?(dr.push(fr.parentNode.host),fr=fr.parentNode.host):(dr.push(fr.parentNode),fr=fr.parentNode);var pr,hr=[],gr={},vr=!1;if(U(dr,function(mr){var yr=fe(mr);mr.tagName.toLowerCase()==="a"&&(pr=mr.getAttribute("href"),pr=yr&&_e(pr)&&pr),z(se(mr),"ph-no-capture")&&(vr=!0),hr.push(ar._getPropertiesFromElement(mr,or.config.mask_all_element_attributes,or.config.mask_all_text));var wr=ar._getAugmentPropertiesFromElement(mr);G(gr,wr)}),or.config.mask_all_text||(lr.tagName.toLowerCase()==="a"||lr.tagName.toLowerCase()==="button"?hr[0].$el_text=ge(lr):hr[0].$el_text=ae(lr)),pr&&(hr[0].attr__href=pr),vr)return!1;var br=G(this._getDefaultProperties(nr.type),or.elementsChainAsString?{$elements_chain:me(hr)}:{$elements:hr},(cr=hr[0])!==null&&cr!==void 0&&cr.$el_text?{$el_text:(ur=hr[0])===null||ur===void 0?void 0:ur.$el_text}:{},this._getCustomProperties(dr),gr);return or.capture(sr,br),!0}},_navigate:function(nr){T&&(T.location.href=nr)},_addDomEventHandlers:function(nr){var or=this;if(T&&D){var ir=function(ar){ar=ar||(T==null?void 0:T.event),or._captureEvent(ar,nr)};ie(D,"submit",ir,!1,!0),ie(D,"change",ir,!1,!0),ie(D,"click",ir,!1,!0)}},_customProperties:[],rageclicks:null,config:void 0,init:function(nr){var or;O(nr.__autocapture)||(this.config=nr.__autocapture),(or=this.config)!==null&&or!==void 0&&or.url_allowlist&&(this.config.url_allowlist=this.config.url_allowlist.map(function(ir){return new RegExp(ir)})),this.rageclicks=new ke(nr.config.rageclick)},afterDecideResponse:function(nr,or){var ir=or.config.token;this._initializedTokens.indexOf(ir)>-1?j.info('autocapture already initialized for token "'+ir+'"'):(or.persistence&&or.persistence.register(s({},Pe,!!nr.autocapture_opt_out)),this._isDisabledServerSide=!!nr.autocapture_opt_out,this._setIsAutocaptureEnabled(or),this._initializedTokens.push(ir),nr&&nr.config&&nr.config.enable_collect_everything&&this._isAutocaptureEnabled?(nr.custom_properties&&(this._customProperties=nr.custom_properties),this._addDomEventHandlers(or)):or.__autocapture=!1)},enabledForProject:function(nr,or,ir){if(!nr)return!0;or=R(or)?10:or,ir=R(ir)?10:ir;for(var ar=0,sr=0;sr<nr.length;sr++)ar+=nr.charCodeAt(sr);return ar%or<ir},isBrowserSupported:function(){return P(D==null?void 0:D.querySelectorAll)}};(function(nr){for(var or in nr)P(nr[or])&&(nr[or]=nr[or].bind(nr))})(We),function(nr){for(var or in nr)P(nr[or])&&(nr[or]=X(nr[or]))}(We);var Ve="$active_feature_flags",Ue="$override_feature_flags",Ge="$feature_flag_payloads",ze=function(nr){var or,ir={},ar=v(Q(nr||{}));try{for(ar.s();!(or=ar.n()).done;){var sr=f(or.value,2),lr=sr[0],cr=sr[1];cr&&(ir[lr]=cr)}}catch(ur){ar.e(ur)}finally{ar.f()}return ir},Qe=function(){function nr(or){i(this,nr),this.instance=or,this._override_warning=!1,this.featureFlagEventHandlers=[],this.reloadFeatureFlagsQueued=!1,this.reloadFeatureFlagsInAction=!1}return o(nr,[{key:"getFlags",value:function(){return Object.keys(this.getFlagVariants())}},{key:"getFlagVariants",value:function(){var or=this.instance.get_property($e),ir=this.instance.get_property(Ue);if(!ir)return or||{};for(var ar=G({},or),sr=Object.keys(ir),lr=0;lr<sr.length;lr++)ir[sr[lr]]===!1?delete ar[sr[lr]]:ar[sr[lr]]=ir[sr[lr]];return this._override_warning||(j.warn(" Overriding feature flags!",{enabledFlags:or,overriddenFlags:ir,finalFlags:ar}),this._override_warning=!0),ar}},{key:"getFlagPayloads",value:function(){return this.instance.get_property(Ge)||{}}},{key:"reloadFeatureFlags",value:function(){this.reloadFeatureFlagsQueued||(this.reloadFeatureFlagsQueued=!0,this._startReloadTimer())}},{key:"setAnonymousDistinctId",value:function(or){this.$anon_distinct_id=or}},{key:"setReloadingPaused",value:function(or){this.reloadFeatureFlagsInAction=or}},{key:"resetRequestQueue",value:function(){this.reloadFeatureFlagsQueued=!1}},{key:"_startReloadTimer",value:function(){var or=this;this.reloadFeatureFlagsQueued&&!this.reloadFeatureFlagsInAction&&setTimeout(function(){!or.reloadFeatureFlagsInAction&&or.reloadFeatureFlagsQueued&&(or.reloadFeatureFlagsQueued=!1,or._reloadFeatureFlagsRequest())},5)}},{key:"_reloadFeatureFlagsRequest",value:function(){var or=this;if(!this.instance.config.advanced_disable_feature_flags){this.setReloadingPaused(!0);var ir=this.instance.config.token,ar=this.instance.get_property(Me),sr=this.instance.get_property(Te),lr=te(JSON.stringify({token:ir,distinct_id:this.instance.get_distinct_id(),groups:this.instance.getGroups(),$anon_distinct_id:this.$anon_distinct_id,person_properties:ar,group_properties:sr,disable_flags:this.instance.config.advanced_disable_feature_flags||void 0}));this.instance._send_request(this.instance.config.api_host+"/decide/?v=3",{data:lr},{method:"POST"},this.instance._prepare_callback(function(cr){or.$anon_distinct_id=void 0,or.receivedFeatureFlags(cr),or.setReloadingPaused(!1),or._startReloadTimer()}))}}},{key:"getFeatureFlag",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(this.instance.decideEndpointWasHit||this.getFlags()&&this.getFlags().length>0){var ar,sr=this.getFlagVariants()[or],lr="".concat(sr),cr=this.instance.get_property(De)||{};return(ir.send_event||!("send_event"in ir))&&(!(or in cr)||!cr[or].includes(lr))&&(S(cr[or])?cr[or].push(lr):cr[or]=[lr],(ar=this.instance.persistence)===null||ar===void 0||ar.register(s({},De,cr)),this.instance.capture("$feature_flag_called",{$feature_flag:or,$feature_flag_response:sr})),sr}j.warn('getFeatureFlag for key "'+or+`" failed. Feature flags didn't load in time.`)}},{key:"getFeatureFlagPayload",value:function(or){return this.getFlagPayloads()[or]}},{key:"isFeatureEnabled",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(this.instance.decideEndpointWasHit||this.getFlags()&&this.getFlags().length>0)return!!this.getFeatureFlag(or,ir);j.warn('isFeatureEnabled for key "'+or+`" failed. Feature flags didn't load in time.`)}},{key:"addFeatureFlagsHandler",value:function(or){this.featureFlagEventHandlers.push(or)}},{key:"removeFeatureFlagsHandler",value:function(or){this.featureFlagEventHandlers=this.featureFlagEventHandlers.filter(function(ir){return ir!==or})}},{key:"receivedFeatureFlags",value:function(or){if(this.instance.persistence){this.instance.decideEndpointWasHit=!0;var ir=this.getFlagVariants(),ar=this.getFlagPayloads();(function(sr,lr){var cr=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ur=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{},dr=sr.featureFlags,fr=sr.featureFlagPayloads;if(dr)if(S(dr)){var pr,hr={};if(dr)for(var gr=0;gr<dr.length;gr++)hr[dr[gr]]=!0;lr&&lr.register((s(pr={},Ve,dr),s(pr,$e,hr),pr))}else{var vr,br=dr,mr=fr;sr.errorsWhileComputingFlags&&(br=t(t({},cr),br),mr=t(t({},ur),mr)),lr&&lr.register((s(vr={},Ve,Object.keys(ze(br))),s(vr,$e,br||{}),s(vr,Ge,mr||{}),vr))}})(or,this.instance.persistence,ir,ar),this._fireFeatureFlagsCallbacks()}}},{key:"override",value:function(or){if(!this.instance.__loaded||!this.instance.persistence)return j.uninitializedWarning("posthog.feature_flags.override");if(this._override_warning=!1,or===!1)this.instance.persistence.unregister(Ue);else if(S(or)){for(var ir={},ar=0;ar<or.length;ar++)ir[or[ar]]=!0;this.instance.persistence.register(s({},Ue,ir))}else this.instance.persistence.register(s({},Ue,or))}},{key:"onFeatureFlags",value:function(or){var ir=this;if(this.addFeatureFlagsHandler(or),this.instance.decideEndpointWasHit){var ar=this._prepareFeatureFlagsForCallbacks(),sr=ar.flags,lr=ar.flagVariants;or(sr,lr)}return function(){return ir.removeFeatureFlagsHandler(or)}}},{key:"updateEarlyAccessFeatureEnrollment",value:function(or,ir){var ar,sr,lr=s({},"$feature_enrollment/".concat(or),ir);this.instance.capture("$feature_enrollment_update",{$feature_flag:or,$feature_enrollment:ir,$set:lr}),this.setPersonPropertiesForFlags(lr,!1);var cr=t(t({},this.getFlagVariants()),{},s({},or,ir));(ar=this.instance.persistence)===null||ar===void 0||ar.register((s(sr={},Ve,Object.keys(ze(cr))),s(sr,$e,cr),sr)),this._fireFeatureFlagsCallbacks()}},{key:"getEarlyAccessFeatures",value:function(or){var ir=this,ar=arguments.length>1&&arguments[1]!==void 0&&arguments[1],sr=this.instance.get_property(Ae);if(sr&&!ar)return or(sr);this.instance._send_request("".concat(this.instance.config.api_host,"/api/early_access_features/?token=").concat(this.instance.config.token),{},{method:"GET"},function(lr){var cr,ur=lr.earlyAccessFeatures;return(cr=ir.instance.persistence)===null||cr===void 0||cr.register(s({},Ae,ur)),or(ur)})}},{key:"_prepareFeatureFlagsForCallbacks",value:function(){var or=this.getFlags(),ir=this.getFlagVariants();return{flags:or.filter(function(ar){return ir[ar]}),flagVariants:Object.keys(ir).filter(function(ar){return ir[ar]}).reduce(function(ar,sr){return ar[sr]=ir[sr],ar},{})}}},{key:"_fireFeatureFlagsCallbacks",value:function(){var or=this._prepareFeatureFlagsForCallbacks(),ir=or.flags,ar=or.flagVariants;this.featureFlagEventHandlers.forEach(function(sr){return sr(ir,ar)})}},{key:"setPersonPropertiesForFlags",value:function(or){var ir=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1],ar=this.instance.get_property(Me)||{};this.instance.register(s({},Me,t(t({},ar),or))),ir&&this.instance.reloadFeatureFlags()}},{key:"resetPersonPropertiesForFlags",value:function(){this.instance.unregister(Me)}},{key:"setGroupPropertiesForFlags",value:function(or){var ir=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1],ar=this.instance.get_property(Te)||{};Object.keys(ar).length!==0&&Object.keys(ar).forEach(function(sr){ar[sr]=t(t({},ar[sr]),or[sr]),delete or[sr]}),this.instance.register(s({},Te,t(t({},ar),or))),ir&&this.instance.reloadFeatureFlags()}},{key:"resetGroupPropertiesForFlags",value:function(or){if(or){var ir=this.instance.get_property(Te)||{};this.instance.register(s({},Te,t(t({},ir),{},s({},or,{}))))}else this.instance.unregister(Te)}}]),nr}();Math.trunc||(Math.trunc=function(nr){return nr<0?Math.ceil(nr):Math.floor(nr)}),Number.isInteger||(Number.isInteger=function(nr){return C(nr)&&isFinite(nr)&&Math.floor(nr)===nr});var Ye="0123456789abcdef",Je=function(){function nr(or){if(i(this,nr),this.bytes=or,or.length!==16)throw new TypeError("not 128-bit length")}return o(nr,[{key:"toString",value:function(){for(var or="",ir=0;ir<this.bytes.length;ir++)or=or+Ye.charAt(this.bytes[ir]>>>4)+Ye.charAt(15&this.bytes[ir]),ir!==3&&ir!==5&&ir!==7&&ir!==9||(or+="-");if(or.length!==36)throw new Error("Invalid UUIDv7 was generated");return or}},{key:"clone",value:function(){return new nr(this.bytes.slice(0))}},{key:"equals",value:function(or){return this.compareTo(or)===0}},{key:"compareTo",value:function(or){for(var ir=0;ir<16;ir++){var ar=this.bytes[ir]-or.bytes[ir];if(ar!==0)return Math.sign(ar)}return 0}}],[{key:"fromFieldsV7",value:function(or,ir,ar,sr){if(!Number.isInteger(or)||!Number.isInteger(ir)||!Number.isInteger(ar)||!Number.isInteger(sr)||or<0||ir<0||ar<0||sr<0||or>0xffffffffffff||ir>4095||ar>1073741823||sr>4294967295)throw new RangeError("invalid field value");var lr=new Uint8Array(16);return lr[0]=or/Math.pow(2,40),lr[1]=or/Math.pow(2,32),lr[2]=or/Math.pow(2,24),lr[3]=or/Math.pow(2,16),lr[4]=or/Math.pow(2,8),lr[5]=or,lr[6]=112|ir>>>8,lr[7]=ir,lr[8]=128|ar>>>24,lr[9]=ar>>>16,lr[10]=ar>>>8,lr[11]=ar,lr[12]=sr>>>24,lr[13]=sr>>>16,lr[14]=sr>>>8,lr[15]=sr,new nr(lr)}}]),nr}(),Xe=function(){function nr(){i(this,nr),s(this,"timestamp",0),s(this,"counter",0),s(this,"random",new et)}return o(nr,[{key:"generate",value:function(){var or=this.generateOrAbort();if(R(or)){this.timestamp=0;var ir=this.generateOrAbort();if(R(ir))throw new Error("Could not generate UUID after timestamp reset");return ir}return or}},{key:"generateOrAbort",value:function(){var or=Date.now();if(or>this.timestamp)this.timestamp=or,this.resetCounter();else{if(!(or+1e4>this.timestamp))return;this.counter++,this.counter>4398046511103&&(this.timestamp++,this.resetCounter())}return Je.fromFieldsV7(this.timestamp,Math.trunc(this.counter/Math.pow(2,30)),this.counter&Math.pow(2,30)-1,this.random.nextUint32())}},{key:"resetCounter",value:function(){this.counter=1024*this.random.nextUint32()+(1023&this.random.nextUint32())}}]),nr}(),Ke=function(nr){if(typeof UUIDV7_DENY_WEAK_RNG<"u"&&UUIDV7_DENY_WEAK_RNG)throw new Error("no cryptographically strong RNG available");for(var or=0;or<nr.length;or++)nr[or]=65536*Math.trunc(65536*Math.random())+Math.trunc(65536*Math.random());return nr};T&&!R(T.crypto)&&crypto.getRandomValues&&(Ke=function(nr){return crypto.getRandomValues(nr)});var Ze,et=function(){function nr(){i(this,nr),s(this,"buffer",new Uint32Array(8)),s(this,"cursor",1/0)}return o(nr,[{key:"nextUint32",value:function(){return this.cursor>=this.buffer.length&&(Ke(this.buffer),this.cursor=0),this.buffer[this.cursor++]}}]),nr}(),tt=function(){return nt().toString()},nt=function(){return(Ze||(Ze=new Xe)).generate()},it="Thu, 01 Jan 1970 00:00:00 GMT",rt="",ot=/[a-z0-9][a-z0-9-]+\.[a-z]{2,}$/i;function st(nr,or){if(or){var ir=function(sr){var lr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:D;if(rt)return rt;if(!lr||["localhost","127.0.0.1"].includes(sr))return"";for(var cr=sr.split("."),ur=Math.min(cr.length,8),dr="dmn_chk_"+tt(),fr=new RegExp("(^|;)\\s*"+dr+"=1");!rt&&ur--;){var pr=cr.slice(ur).join("."),hr=dr+"=1;domain=."+pr;lr.cookie=hr,fr.test(lr.cookie)&&(lr.cookie=hr+";expires="+it,rt=pr)}return rt}(nr);if(!ir){var ar=function(sr){var lr=sr.match(ot);return lr?lr[0]:""}(nr);ar!==ir&&j.info("Warning: cookie subdomain discovery mismatch",ar,ir),ir=ar}return ir?"; domain=."+ir:""}return""}var at={is_supported:function(){return!!D},error:function(nr){j.error("cookieStore error: "+nr)},get:function(nr){if(D){try{for(var or=nr+"=",ir=D.cookie.split(";").filter(function(lr){return lr.length}),ar=0;ar<ir.length;ar++){for(var sr=ir[ar];sr.charAt(0)==" ";)sr=sr.substring(1,sr.length);if(sr.indexOf(or)===0)return decodeURIComponent(sr.substring(or.length,sr.length))}}catch{}return null}},parse:function(nr){var or;try{or=JSON.parse(at.get(nr))||{}}catch{}return or},set:function(nr,or,ir,ar,sr){if(D)try{var lr="",cr="",ur=st(D.location.hostname,ar);if(ir){var dr=new Date;dr.setTime(dr.getTime()+24*ir*60*60*1e3),lr="; expires="+dr.toUTCString()}sr&&(cr="; secure");var fr=nr+"="+encodeURIComponent(JSON.stringify(or))+lr+"; SameSite=Lax; path=/"+ur+cr;return fr.length>3686.4&&j.warn("cookieStore warning: large cookie, len="+fr.length),D.cookie=fr,fr}catch{return}},remove:function(nr,or){try{at.set(nr,"",-1,or)}catch{return}}},ut=null,lt={is_supported:function(){if(!E(ut))return ut;var nr=!0;if(R(T))nr=!1;else try{var or="__mplssupport__";lt.set(or,"xyz"),lt.get(or)!=='"xyz"'&&(nr=!1),lt.remove(or)}catch{nr=!1}return nr||j.error("localStorage unsupported; falling back to cookie store"),ut=nr,nr},error:function(nr){j.error("localStorage error: "+nr)},get:function(nr){try{return T==null?void 0:T.localStorage.getItem(nr)}catch(or){lt.error(or)}return null},parse:function(nr){try{return JSON.parse(lt.get(nr))||{}}catch{}return null},set:function(nr,or){try{T==null||T.localStorage.setItem(nr,JSON.stringify(or))}catch(ir){lt.error(ir)}},remove:function(nr){try{T==null||T.localStorage.removeItem(nr)}catch(or){lt.error(or)}}},ct=["distinct_id",Ce,Oe],dt=t(t({},lt),{},{parse:function(nr){try{var or={};try{or=at.parse(nr)||{}}catch{}var ir=G(or,JSON.parse(lt.get(nr)||"{}"));return lt.set(nr,ir),ir}catch{}return null},set:function(nr,or,ir,ar,sr){try{lt.set(nr,or);var lr={};ct.forEach(function(cr){or[cr]&&(lr[cr]=or[cr])}),Object.keys(lr).length&&at.set(nr,lr,ir,ar,sr)}catch(cr){lt.error(cr)}},remove:function(nr,or){try{T==null||T.localStorage.removeItem(nr),at.remove(nr,or)}catch(ir){lt.error(ir)}}}),ht={},ft={is_supported:function(){return!0},error:function(nr){j.error("memoryStorage error: "+nr)},get:function(nr){return ht[nr]||null},parse:function(nr){return ht[nr]||null},set:function(nr,or){ht[nr]=or},remove:function(nr){delete ht[nr]}},pt=null,_t={is_supported:function(){if(!E(pt))return pt;if(pt=!0,R(T))pt=!1;else try{var nr="__support__";_t.set(nr,"xyz"),_t.get(nr)!=='"xyz"'&&(pt=!1),_t.remove(nr)}catch{pt=!1}return pt},error:function(nr){j.error("sessionStorage error: ",nr)},get:function(nr){try{return T==null?void 0:T.sessionStorage.getItem(nr)}catch(or){_t.error(or)}return null},parse:function(nr){try{return JSON.parse(_t.get(nr))||null}catch{}return null},set:function(nr,or){try{T==null||T.sessionStorage.setItem(nr,JSON.stringify(or))}catch(ir){_t.error(ir)}},remove:function(nr){try{T==null||T.sessionStorage.removeItem(nr)}catch(or){_t.error(or)}}},gt=["localhost","127.0.0.1"],vt=function(nr){var or=D==null?void 0:D.createElement("a");return R(or)?null:(or.href=nr,or)},mt=function(nr,or){return!!function(ir){try{new RegExp(ir)}catch{return!1}return!0}(or)&&new RegExp(or).test(nr)},yt=function(nr,or){for(var ir,ar=((nr.split("#")[0]||"").split("?")[1]||"").split("&"),sr=0;sr<ar.length;sr++){var lr=ar[sr].split("=");if(lr[0]===or){ir=lr;break}}if(!S(ir)||ir.length<2)return"";var cr=ir[1];try{cr=decodeURIComponent(cr)}catch{j.error("Skipping decoding for malformed query param: "+cr)}return cr.replace(/\+/g," ")},bt=function(nr,or){var ir=nr.match(new RegExp(or+"=([^&]*)"));return ir?ir[1]:null},kt={campaignParams:function(nr){var or=["utm_source","utm_medium","utm_campaign","utm_content","utm_term","gclid","gad_source","gbraid","wbraid","fbclid","msclkid"].concat(nr||[]),ir={};return U(or,function(ar){var sr=D?yt(D.URL,ar):"";sr.length&&(ir[ar]=sr)}),ir},searchEngine:function(){var nr=D==null?void 0:D.referrer;return nr?nr.search("https?://(.*)google.([^/?]*)")===0?"google":nr.search("https?://(.*)bing.com")===0?"bing":nr.search("https?://(.*)yahoo.com")===0?"yahoo":nr.search("https?://(.*)duckduckgo.com")===0?"duckduckgo":null:null},searchInfo:function(){var nr=kt.searchEngine(),or=nr!="yahoo"?"q":"p",ir={};if(!E(nr)){ir.$search_engine=nr;var ar=D?yt(D.referrer,or):"";ar.length&&(ir.ph_keyword=ar)}return ir},browser:function(nr,or,ir){return or=or||"",ir||z(nr," OPR/")?z(nr,"Mini")?"Opera Mini":"Opera":/(BlackBerry|PlayBook|BB10)/i.test(nr)?"BlackBerry":z(nr,"IEMobile")||z(nr,"WPDesktop")?"Internet Explorer Mobile":z(nr,"SamsungBrowser/")?"Samsung Internet":z(nr,"Edge")||z(nr,"Edg/")?"Microsoft Edge":z(nr,"FBIOS")?"Facebook Mobile":z(nr,"Chrome")?"Chrome":z(nr,"CriOS")?"Chrome iOS":z(nr,"UCWEB")||z(nr,"UCBrowser")?"UC Browser":z(nr,"FxiOS")?"Firefox iOS":z(or,"Apple")||function(ar){return z(ar,"Safari")&&!z(ar,"Chrome")&&!z(ar,"Android")}(nr)?z(nr,"Mobile")?"Mobile Safari":"Safari":z(nr,"Android")?"Android Mobile":z(nr,"Konqueror")||z(nr,"konqueror")?"Konqueror":z(nr,"Firefox")?"Firefox":z(nr,"MSIE")||z(nr,"Trident/")?"Internet Explorer":z(nr,"Gecko")?"Mozilla":""},browserVersion:function(nr,or,ir){var ar={"Internet Explorer Mobile":[/rv:(\d+(\.\d+)?)/],"Microsoft Edge":[/Edge?\/(\d+(\.\d+)?)/],Chrome:[/Chrome\/(\d+(\.\d+)?)/],"Chrome iOS":[/CriOS\/(\d+(\.\d+)?)/],"UC Browser":[/(UCBrowser|UCWEB)\/(\d+(\.\d+)?)/],Safari:[/Version\/(\d+(\.\d+)?)/],"Mobile Safari":[/Version\/(\d+(\.\d+)?)/],Opera:[/(Opera|OPR)\/(\d+(\.\d+)?)/],Firefox:[/Firefox\/(\d+(\.\d+)?)/],"Firefox iOS":[/FxiOS\/(\d+(\.\d+)?)/],Konqueror:[/Konqueror[:/]?(\d+(\.\d+)?)/i],BlackBerry:[/BlackBerry (\d+(\.\d+)?)/,/Version\/(\d+(\.\d+)?)/],"Android Mobile":[/android\s(\d+(\.\d+)?)/],"Samsung Internet":[/SamsungBrowser\/(\d+(\.\d+)?)/],"Internet Explorer":[/(rv:|MSIE )(\d+(\.\d+)?)/],Mozilla:[/rv:(\d+(\.\d+)?)/]}[kt.browser(nr,or,ir)];if(R(ar))return null;for(var sr=0;sr<ar.length;sr++){var lr=ar[sr],cr=nr.match(lr);if(cr)return parseFloat(cr[cr.length-2])}return null},browserLanguage:function(){return navigator.language||navigator.userLanguage},os:function(nr){if(/Windows/i.test(nr)){if(/Phone/.test(nr)||/WPDesktop/.test(nr))return{os_name:"Windows Phone",os_version:""};var or=/Windows NT ([0-9.]+)/i.exec(nr);return or&&or[1]?{os_name:"Windows",os_version:or[1]}:{os_name:"Windows",os_version:""}}if(/(iPhone|iPad|iPod)/.test(nr)){var ir=/OS (\d+)_(\d+)_?(\d+)?/i.exec(nr);return ir&&ir[1]?{os_name:"iOS",os_version:[ir[1],ir[2],ir[3]||"0"].join(".")}:{os_name:"iOS",os_version:""}}if(/Android/.test(nr)){var ar=/Android (\d+)\.(\d+)\.?(\d+)?/i.exec(nr);return ar&&ar[1]?{os_name:"Android",os_version:[ar[1],ar[2],ar[3]||"0"].join(".")}:{os_name:"Android",os_version:""}}if(/(BlackBerry|PlayBook|BB10)/i.test(nr))return{os_name:"BlackBerry",os_version:""};if(/Mac/i.test(nr)){var sr=/Mac OS X (\d+)[_.](\d+)[_.]?(\d+)?/i.exec(nr);return sr&&sr[1]?{os_name:"Mac OS X",os_version:[sr[1],sr[2],sr[3]||"0"].join(".")}:{os_name:"Mac OS X",os_version:""}}return/Linux/.test(nr)?{os_name:"Linux",os_version:""}:/CrOS/.test(nr)?{os_name:"Chrome OS",os_version:""}:{os_name:"",os_version:""}},device:function(nr){return/Windows Phone/i.test(nr)||/WPDesktop/.test(nr)?"Windows Phone":/iPad/.test(nr)?"iPad":/iPod/.test(nr)?"iPod Touch":/iPhone/.test(nr)?"iPhone":/(BlackBerry|PlayBook|BB10)/i.test(nr)?"BlackBerry":/Android/.test(nr)&&!/Mobile/.test(nr)?"Android Tablet":/Android/.test(nr)?"Android":""},deviceType:function(nr){var or=this.device(nr);return or==="iPad"||or==="Android Tablet"?"Tablet":or?"Mobile":"Desktop"},referrer:function(){return(D==null?void 0:D.referrer)||"$direct"},referringDomain:function(){var nr;return D!=null&&D.referrer&&((nr=vt(D.referrer))===null||nr===void 0?void 0:nr.host)||"$direct"},properties:function(){if(!L)return{};var nr=kt.os(L),or=nr.os_name,ir=nr.os_version;return G(K({$os:or,$os_version:ir,$browser:kt.browser(L,navigator.vendor,B.opera),$device:kt.device(L),$device_type:kt.deviceType(L)}),{$current_url:T==null?void 0:T.location.href,$host:T==null?void 0:T.location.host,$pathname:T==null?void 0:T.location.pathname,$raw_user_agent:L.length>1e3?L.substring(0,997)+"...":L,$browser_version:kt.browserVersion(L,navigator.vendor,B.opera),$browser_language:kt.browserLanguage(),$screen_height:T==null?void 0:T.screen.height,$screen_width:T==null?void 0:T.screen.width,$viewport_height:T==null?void 0:T.innerHeight,$viewport_width:T==null?void 0:T.innerWidth,$lib:"web",$lib_version:m.LIB_VERSION,$insert_id:Math.random().toString(36).substring(2,10)+Math.random().toString(36).substring(2,10),$time:Y()/1e3})},people_properties:function(){if(!L)return{};var nr=kt.os(L),or=nr.os_name,ir=nr.os_version;return G(K({$os:or,$os_version:ir,$browser:kt.browser(L,navigator.vendor,B.opera)}),{$browser_version:kt.browserVersion(L,navigator.vendor,B.opera)})}},wt=["cookie","localstorage","localstorage+cookie","sessionstorage","memory"],St=function(){function nr(or){i(this,nr);var ir="";or.token&&(ir=or.token.replace(/\+/g,"PL").replace(/\//g,"SL").replace(/=/g,"EQ")),this.props={},this.campaign_params_saved=!1,this.custom_campaign_params=or.custom_campaign_params||[],or.persistence_name?this.name="ph_"+or.persistence_name:this.name="ph_"+ir+"_posthog",wt.indexOf(or.persistence.toLowerCase())===-1&&(j.critical("Unknown persistence type "+or.persistence+"; falling back to localStorage+cookie"),or.persistence="localStorage+cookie");var ar=or.persistence.toLowerCase();ar==="localstorage"&&lt.is_supported()?this.storage=lt:ar==="localstorage+cookie"&&dt.is_supported()?this.storage=dt:ar==="sessionstorage"&&_t.is_supported()?this.storage=_t:ar==="memory"?this.storage=ft:ar==="cookie"?this.storage=at:dt.is_supported()?this.storage=dt:this.storage=at,this.load(),this.update_config(or),this.save()}return o(nr,[{key:"properties",value:function(){var or={};return U(this.props,function(ir,ar){if(ar===$e&&I(ir))for(var sr=Object.keys(ir),lr=0;lr<sr.length;lr++)or["$feature/".concat(sr[lr])]=ir[sr[lr]];else ur=ar,dr=!1,(E(cr=je)?dr:M&&cr.indexOf===M?cr.indexOf(ur)!=-1:(U(cr,function(fr){if(dr||(dr=fr===ur))return H}),dr))||(or[ar]=ir);var cr,ur,dr}),or}},{key:"load",value:function(){if(!this.disabled){var or=this.storage.parse(this.name);or&&(this.props=G({},or))}}},{key:"save",value:function(){this.disabled||this.storage.set(this.name,this.props,this.expire_days,this.cross_subdomain,this.secure)}},{key:"remove",value:function(){this.storage.remove(this.name,!1),this.storage.remove(this.name,!0)}},{key:"clear",value:function(){this.remove(),this.props={}}},{key:"register_once",value:function(or,ir,ar){var sr=this;if(I(or)){R(ir)&&(ir="None"),this.expire_days=R(ar)?this.default_expiry:ar;var lr=!1;if(U(or,function(cr,ur){sr.props.hasOwnProperty(ur)&&sr.props[ur]!==ir||(sr.props[ur]=cr,lr=!0)}),lr)return this.save(),!0}return!1}},{key:"register",value:function(or,ir){var ar=this;if(I(or)){this.expire_days=R(ir)?this.default_expiry:ir;var sr=!1;if(U(or,function(lr,cr){or.hasOwnProperty(cr)&&ar.props[cr]!==lr&&(ar.props[cr]=lr,sr=!0)}),sr)return this.save(),!0}return!1}},{key:"unregister",value:function(or){or in this.props&&(delete this.props[or],this.save())}},{key:"update_campaign_params",value:function(){this.campaign_params_saved||(this.register(kt.campaignParams(this.custom_campaign_params)),this.campaign_params_saved=!0)}},{key:"update_search_keyword",value:function(){this.register(kt.searchInfo())}},{key:"update_referrer_info",value:function(){this.register({$referrer:this.props.$referrer||kt.referrer(),$referring_domain:this.props.$referring_domain||kt.referringDomain()})}},{key:"get_referrer_info",value:function(){return K({$referrer:this.props.$referrer,$referring_domain:this.props.$referring_domain})}},{key:"safe_merge",value:function(or){return U(this.props,function(ir,ar){ar in or||(or[ar]=ir)}),or}},{key:"update_config",value:function(or){this.default_expiry=this.expire_days=or.cookie_expiration,this.set_disabled(or.disable_persistence),this.set_cross_subdomain(or.cross_subdomain_cookie),this.set_secure(or.secure_cookie)}},{key:"set_disabled",value:function(or){this.disabled=or,this.disabled?this.remove():this.save()}},{key:"set_cross_subdomain",value:function(or){or!==this.cross_subdomain&&(this.cross_subdomain=or,this.remove(),this.save())}},{key:"get_cross_subdomain",value:function(){return!!this.cross_subdomain}},{key:"set_secure",value:function(or){or!==this.secure&&(this.secure=or,this.remove(),this.save())}},{key:"set_event_timer",value:function(or,ir){var ar=this.props[Fe]||{};ar[or]=ir,this.props[Fe]=ar,this.save()}},{key:"remove_event_timer",value:function(or){var ir=(this.props[Fe]||{})[or];return R(ir)||(delete this.props[Fe][or],this.save()),ir}},{key:"get_user_state",value:function(){return this.props[Le]||"anonymous"}},{key:"set_user_state",value:function(or){this.props[Le]=or,this.save()}},{key:"get_quota_limits",value:function(){return this.props[Be]||{}}},{key:"set_quota_limits",value:function(or){this.props[Be]=or,this.save()}}]),nr}(),Ft=2,Pt=4,It=o(function nr(or){var ir,ar,sr=this,lr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};i(this,nr),s(this,"bucketSize",100),s(this,"refillRate",10),s(this,"mutationBuckets",{}),s(this,"loggedTracker",{}),s(this,"refillBuckets",function(){Object.keys(sr.mutationBuckets).forEach(function(cr){sr.mutationBuckets[cr]=sr.mutationBuckets[cr]+sr.refillRate,sr.mutationBuckets[cr]>=sr.bucketSize&&delete sr.mutationBuckets[cr]})}),s(this,"getNodeOrRelevantParent",function(cr){var ur=sr.rrweb.mirror.getNode(cr);if((ur==null?void 0:ur.nodeName)!=="svg"&&ur instanceof Element){var dr=ur.closest("svg");if(dr)return[sr.rrweb.mirror.getId(dr),dr]}return[cr,ur]}),s(this,"numberOfChanges",function(cr){var ur,dr,fr,pr,hr,gr,vr,br;return((ur=(dr=cr.removes)===null||dr===void 0?void 0:dr.length)!==null&&ur!==void 0?ur:0)+((fr=(pr=cr.attributes)===null||pr===void 0?void 0:pr.length)!==null&&fr!==void 0?fr:0)+((hr=(gr=cr.texts)===null||gr===void 0?void 0:gr.length)!==null&&hr!==void 0?hr:0)+((vr=(br=cr.adds)===null||br===void 0?void 0:br.length)!==null&&vr!==void 0?vr:0)}),s(this,"throttleMutations",function(cr){if(cr.type!==3||cr.data.source!==0)return cr;var ur=cr.data,dr=sr.numberOfChanges(ur);ur.attributes&&(ur.attributes=ur.attributes.filter(function(pr){var hr,gr,vr,br=f(sr.getNodeOrRelevantParent(pr.id),2),mr=br[0],yr=br[1];return sr.mutationBuckets[mr]===0?!1:(sr.mutationBuckets[mr]=(hr=sr.mutationBuckets[mr])!==null&&hr!==void 0?hr:sr.bucketSize,sr.mutationBuckets[mr]=Math.max(sr.mutationBuckets[mr]-1,0),sr.mutationBuckets[mr]===0&&(sr.loggedTracker[mr]||(sr.loggedTracker[mr]=!0,(gr=(vr=sr.options).onBlockedNode)===null||gr===void 0||gr.call(vr,mr,yr))),pr)}));var fr=sr.numberOfChanges(ur);return fr!==0||dr===fr?cr:void 0}),this.rrweb=or,this.options=lr,this.refillRate=(ir=this.options.refillRate)!==null&&ir!==void 0?ir:this.refillRate,this.bucketSize=(ar=this.options.bucketSize)!==null&&ar!==void 0?ar:this.bucketSize,setInterval(function(){sr.refillBuckets()},1e3)}),Rt=function(nr){return nr[nr.DomContentLoaded=0]="DomContentLoaded",nr[nr.Load=1]="Load",nr[nr.FullSnapshot=2]="FullSnapshot",nr[nr.IncrementalSnapshot=3]="IncrementalSnapshot",nr[nr.Meta=4]="Meta",nr[nr.Custom=5]="Custom",nr[nr.Plugin=6]="Plugin",nr}(Rt||{}),xt={initiatorTypes:["audio","beacon","body","css","early-hint","embed","fetch","frame","iframe","icon","image","img","input","link","navigation","object","ping","script","track","video","xmlhttprequest"],maskRequestFn:function(nr){return nr},recordHeaders:!1,recordBody:!1,recordInitialRequests:!1,recordPerformance:!1,performanceEntryTypeToObserve:["first-input","navigation","paint","resource"],payloadSizeLimitBytes:1e6},Et=["authorization","x-forwarded-for","authorization","cookie","set-cookie","x-api-key","x-real-ip","remote-addr","forwarded","proxy-authorization","x-csrf-token","x-csrftoken","x-xsrf-token"],Ct=["/s/","/e/","/i/vo/e/"];function Ot(nr,or,ir,ar){var sr=or==null?void 0:or["content-length"];return sr&&parseInt(sr)>ir?"".concat(ar," body too large to record"):nr}var $t=function(nr,or){var ir,ar,sr,lr=nr.session_recording,cr=lr.recordHeaders!==!1&&or.recordHeaders,ur=lr.recordBody!==!1&&or.recordBody,dr=lr.recordPerformance!==!1&&or.recordPerformance,fr=(ir=lr,sr=Math.min(1e6,(ar=ir.payloadSizeLimitBytes)!==null&&ar!==void 0?ar:1e6),function(gr){return gr!=null&&gr.requestBody&&(gr.requestBody=Ot(gr.requestBody,gr.requestHeaders,sr,"Request")),gr!=null&&gr.responseBody&&(gr.responseBody=Ot(gr.responseBody,gr.responseHeaders,sr,"Response")),gr}),pr=function(gr){return fr(function(mr){var yr=vt(mr.name);if(!(yr&&yr.pathname&&Ct.includes(yr.pathname)))return mr}((vr=gr,Object.keys((br=vr.requestHeaders)!==null&&br!==void 0?br:{}).forEach(function(mr){var yr;Et.includes(mr.toLowerCase())&&((yr=vr.requestHeaders)===null||yr===void 0||delete yr[mr])}),vr)));var vr,br},hr=P(nr.session_recording.maskNetworkRequestFn);return hr&&P(nr.session_recording.maskCapturedNetworkRequestFn)&&j.warn("Both `maskNetworkRequestFn` and `maskCapturedNetworkRequestFn` are defined. `maskNetworkRequestFn` will be ignored."),hr&&(nr.session_recording.maskCapturedNetworkRequestFn=function(gr){var vr=nr.session_recording.maskNetworkRequestFn({url:gr.name});return t(t({},gr),{},{name:vr==null?void 0:vr.url})}),lr.maskRequestFn=P(nr.session_recording.maskCapturedNetworkRequestFn)?function(gr){var vr,br,mr,yr=pr(gr);return yr&&(vr=(br=(mr=nr.session_recording).maskCapturedNetworkRequestFn)===null||br===void 0?void 0:br.call(mr,yr))!==null&&vr!==void 0?vr:void 0}:void 0,lr.maskRequestFn||(lr.maskRequestFn=pr),t(t(t({},xt),lr),{},{recordHeaders:cr,recordBody:ur,recordPerformance:dr,recordInitialRequests:dr})},At="__ph_opt_in_out_";function Mt(nr,or){Ht(!0,nr,or)}function Tt(nr,or){Ht(!1,nr,or)}function qt(nr,or){return jt(nr,or)==="1"}function Dt(nr,or){return!!function(ir){if(ir&&ir.respectDnt){var ar=ir&&ir.window||T,sr=ar==null?void 0:ar.navigator,lr=!1;return U([sr==null?void 0:sr.doNotTrack,sr.msDoNotTrack,ar.doNotTrack],function(cr){z([!0,1,"1","yes"],cr)&&(lr=!0)}),lr}return!1}(or)||jt(nr,or)==="0"}function Lt(nr,or){Bt(or=or||{}).remove(Nt(nr,or),!!or.crossSubdomainCookie)}function Bt(nr){return(nr=nr||{}).persistenceType==="localStorage"?lt:nr.persistenceType==="localStorage+cookie"?dt:at}function Nt(nr,or){return((or=or||{}).persistencePrefix||At)+nr}function jt(nr,or){return Bt(or).get(Nt(nr,or))}function Ht(nr,or,ir){x(or)&&or.length?(Bt(ir=ir||{}).set(Nt(or,ir),nr?1:0,C(ir.cookieExpiration)?ir.cookieExpiration:null,ir.crossSubdomainCookie,ir.secureCookie),ir.capture&&nr&&ir.capture(ir.captureEventName||"$opt_in",ir.captureProperties||{},{send_instantly:!0})):j.error("gdpr."+(nr?"optIn":"optOut")+" called with an invalid token")}function Wt(nr){var or=!1;try{var ir=nr.config.token,ar=nr.config.respect_dnt,sr=nr.config.opt_out_capturing_persistence_type,lr=nr.config.opt_out_capturing_cookie_prefix||void 0,cr=nr.config.window;ir&&(or=Dt(ir,{respectDnt:ar,persistenceType:sr,persistencePrefix:lr,window:cr}))}catch(ur){j.error("Unexpected error when checking capturing opt-out status: "+ur)}return or}var Vt,Ut=3e5,Gt=Ut;(function(nr){nr[nr.Mutation=0]="Mutation",nr[nr.MouseMove=1]="MouseMove",nr[nr.MouseInteraction=2]="MouseInteraction",nr[nr.Scroll=3]="Scroll",nr[nr.ViewportResize=4]="ViewportResize",nr[nr.Input=5]="Input",nr[nr.TouchMove=6]="TouchMove",nr[nr.MediaInteraction=7]="MediaInteraction",nr[nr.StyleSheetRule=8]="StyleSheetRule",nr[nr.CanvasMutation=9]="CanvasMutation",nr[nr.Font=10]="Font",nr[nr.Log=11]="Log",nr[nr.Drag=12]="Drag",nr[nr.StyleDeclaration=13]="StyleDeclaration",nr[nr.Selection=14]="Selection",nr[nr.AdoptedStyleSheet=15]="AdoptedStyleSheet"})(Vt||(Vt={}));var zt=[Vt.MouseMove,Vt.MouseInteraction,Vt.Scroll,Vt.ViewportResize,Vt.Input,Vt.TouchMove,Vt.MediaInteraction,Vt.Drag],Qt=function(nr){return{rrwebMethod:nr,enqueuedAt:Date.now(),attempt:1}},Yt=function(){function nr(or){var ir=this;if(i(this,nr),s(this,"queuedRRWebEvents",[]),s(this,"isIdle",!1),s(this,"_linkedFlagSeen",!1),s(this,"_lastActivityTimestamp",Date.now()),s(this,"windowId",null),s(this,"sessionId",null),s(this,"_linkedFlag",null),s(this,"_sampleRate",null),s(this,"_minimumDuration",null),s(this,"_recordCanvas",!1),s(this,"_canvasFps",null),s(this,"_canvasQuality",null),s(this,"_forceAllowLocalhostNetworkCapture",!1),this.instance=or,this._captureStarted=!1,this._endpoint="/s/",this.stopRrweb=void 0,this.receivedDecide=!1,T==null||T.addEventListener("beforeunload",function(){ir._flushBuffer()}),T==null||T.addEventListener("offline",function(){ir._tryAddCustomEvent("browser offline",{})}),T==null||T.addEventListener("online",function(){ir._tryAddCustomEvent("browser online",{})}),!this.instance.sessionManager)throw j.error("Session recording started without valid sessionManager"),new Error("Session recording started without valid sessionManager. This is a bug.");this.buffer=this.clearBuffer()}return o(nr,[{key:"started",get:function(){return this._captureStarted}},{key:"sessionManager",get:function(){if(!this.instance.sessionManager)throw j.error("Session recording started without valid sessionManager"),new Error("Session recording started without valid sessionManager. This is a bug.");return this.instance.sessionManager}},{key:"isSampled",get:function(){return C(this._sampleRate)?this.instance.get_property(Oe):null}},{key:"sessionDuration",get:function(){var or,ir,ar=(or=this.buffer)===null||or===void 0?void 0:or.data[((ir=this.buffer)===null||ir===void 0?void 0:ir.data.length)-1],sr=this.sessionManager.checkAndGetSessionAndWindowId(!0).sessionStartTimestamp;return ar?ar.timestamp-sr:null}},{key:"isRecordingEnabled",get:function(){var or=!!this.instance.get_property(Ie),ir=!this.instance.config.disable_session_recording;return T&&or&&ir}},{key:"isConsoleLogCaptureEnabled",get:function(){var or=!!this.instance.get_property(Re),ir=this.instance.config.enable_recording_console_log;return ir??or}},{key:"recordingVersion",get:function(){var or,ir=this.instance.get_property(xe);return((or=this.instance.config.session_recording)===null||or===void 0?void 0:or.recorderVersion)||ir||"v1"}},{key:"networkPayloadCapture",get:function(){var or,ir,ar=this.instance.get_property(Ee),sr={recordHeaders:(or=this.instance.config.session_recording)===null||or===void 0?void 0:or.recordHeaders,recordBody:(ir=this.instance.config.session_recording)===null||ir===void 0?void 0:ir.recordBody},lr=(sr==null?void 0:sr.recordHeaders)||(ar==null?void 0:ar.recordHeaders),cr=(sr==null?void 0:sr.recordBody)||(ar==null?void 0:ar.recordBody),ur=this.instance.config.capture_performance||(ar==null?void 0:ar.capturePerformance);return lr||cr||ur?{recordHeaders:lr,recordBody:cr,recordPerformance:ur}:void 0}},{key:"status",get:function(){return this.receivedDecide?this.isRecordingEnabled?x(this._linkedFlag)&&!this._linkedFlagSeen?"buffering":O(this.isSampled)?this.isSampled?"sampled":"disabled":"active":"disabled":"buffering"}},{key:"startRecordingIfEnabled",value:function(){this.isRecordingEnabled?(this.startCaptureAndTrySendingQueuedSnapshots(),j.info("[SessionRecording] started")):(this.stopRecording(),this.clearBuffer())}},{key:"stopRecording",value:function(){this._captureStarted&&this.stopRrweb&&(this.stopRrweb(),this.stopRrweb=void 0,this._captureStarted=!1,j.info("[SessionRecording] stopped"))}},{key:"makeSamplingDecision",value:function(or){var ir,ar=this.sessionId!==or;if(C(this._sampleRate)){var sr,lr=this.isSampled;ar||!O(lr)?sr=Math.random()<this._sampleRate:sr=lr,sr||j.warn("[SessionSampling] Sample rate (".concat(this._sampleRate,") has determined that this sessionId (").concat(or,") will not be sent to the server.")),(ir=this.instance.persistence)===null||ir===void 0||ir.register(s({},Oe,sr))}else{var cr;(cr=this.instance.persistence)===null||cr===void 0||cr.register(s({},Oe,null))}}},{key:"afterDecideResponse",value:function(or){var ir,ar,sr,lr,cr,ur,dr,fr,pr,hr,gr,vr=this;this.instance.persistence&&this.instance.persistence.register((s(gr={},Ie,!!or.sessionRecording),s(gr,Re,(fr=or.sessionRecording)===null||fr===void 0?void 0:fr.consoleLogRecordingEnabled),s(gr,xe,(pr=or.sessionRecording)===null||pr===void 0?void 0:pr.recorderVersion),s(gr,Ee,t({capturePerformance:or.capturePerformance},(hr=or.sessionRecording)===null||hr===void 0?void 0:hr.networkPayloadCapture)),gr));var br=(ir=or.sessionRecording)===null||ir===void 0?void 0:ir.sampleRate;this._sampleRate=R(br)||E(br)?null:parseFloat(br);var mr=(ar=or.sessionRecording)===null||ar===void 0?void 0:ar.minimumDurationMilliseconds;this._minimumDuration=R(mr)?null:mr;var yr=(sr=or.sessionRecording)===null||sr===void 0?void 0:sr.recordCanvas;this._recordCanvas=!R(yr)&&!E(yr)&&yr;var wr=(lr=or.sessionRecording)===null||lr===void 0?void 0:lr.canvasFps;this._canvasFps=R(wr)?null:wr;var Tr,Pr=(cr=or.sessionRecording)===null||cr===void 0?void 0:cr.canvasQuality;if(this._canvasQuality=R(Pr)||E(Pr)?null:parseFloat(Pr),this._linkedFlag=((ur=or.sessionRecording)===null||ur===void 0?void 0:ur.linkedFlag)||null,(dr=or.sessionRecording)!==null&&dr!==void 0&&dr.endpoint&&(this._endpoint=(Tr=or.sessionRecording)===null||Tr===void 0?void 0:Tr.endpoint),C(this._sampleRate)&&this.sessionManager.onSessionId(function(_r){vr.makeSamplingDecision(_r)}),x(this._linkedFlag)){var Rr=this._linkedFlag;this.instance.onFeatureFlags(function(_r){vr._linkedFlagSeen=_r.includes(Rr)})}this.receivedDecide=!0,this.startRecordingIfEnabled()}},{key:"log",value:function(or){var ir,ar=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"log";(ir=this.instance.sessionRecording)===null||ir===void 0||ir.onRRwebEmit({type:6,data:{plugin:"rrweb/console@1",payload:{level:ar,trace:[],payload:[JSON.stringify(or)]}},timestamp:Y()})}},{key:"startCaptureAndTrySendingQueuedSnapshots",value:function(){this._startCapture()}},{key:"_startCapture",value:function(){var or=this;if(!R(Object.assign)&&!(this._captureStarted||this.instance.config.disable_session_recording||Wt(this.instance))){this._captureStarted=!0,this.sessionManager.checkAndGetSessionAndWindowId();var ir=this.recordingVersion==="v2"?"recorder-v2.js":"recorder.js";this.instance.__loaded_recorder_version!==this.recordingVersion?re(this.instance.config.api_host+"/static/".concat(ir,"?v=").concat(m.LIB_VERSION),function(ar){if(ar)return j.error("Could not load ".concat(ir),ar);or._onScriptLoaded()}):this._onScriptLoaded()}}},{key:"_isInteractiveEvent",value:function(or){var ir;return or.type===3&&zt.indexOf((ir=or.data)===null||ir===void 0?void 0:ir.source)!==-1}},{key:"_updateWindowAndSessionIds",value:function(or){var ir=this._isInteractiveEvent(or);ir||this.isIdle||or.timestamp-this._lastActivityTimestamp>Gt&&(this.isIdle=!0,this._tryAddCustomEvent("sessionIdle",{reason:"user inactivity",timeSinceLastActive:or.timestamp-this._lastActivityTimestamp,threshold:Gt}));var ar=!1;if(ir&&(this._lastActivityTimestamp=or.timestamp,this.isIdle&&(this.isIdle=!1,this._tryAddCustomEvent("sessionNoLongerIdle",{reason:"user activity",type:or.type}),ar=!0)),!this.isIdle){var sr=this.sessionManager.checkAndGetSessionAndWindowId(!ir,or.timestamp),lr=sr.windowId,cr=sr.sessionId,ur=this.sessionId!==cr,dr=this.windowId!==lr;this.windowId=lr,this.sessionId=cr,(ar||[Ft,Pt].indexOf(or.type)===-1&&(dr||ur))&&this._tryTakeFullSnapshot()}}},{key:"_tryRRWebMethod",value:function(or){try{return or.rrwebMethod(),!0}catch(ir){return j.warn("[Session-Recording] could not emit queued rrweb event.",ir),this.queuedRRWebEvents.length<10&&this.queuedRRWebEvents.push({enqueuedAt:or.enqueuedAt||Date.now(),attempt:or.attempt++,rrwebMethod:or.rrwebMethod}),!1}}},{key:"_tryAddCustomEvent",value:function(or,ir){var ar=this;return this._tryRRWebMethod(Qt(function(){return ar.rrwebRecord.addCustomEvent(or,ir)}))}},{key:"_tryTakeFullSnapshot",value:function(){var or=this;return this._tryRRWebMethod(Qt(function(){return or.rrwebRecord.takeFullSnapshot()}))}},{key:"_onScriptLoaded",value:function(){var or,ir=this,ar={blockClass:"ph-no-capture",blockSelector:void 0,ignoreClass:"ph-ignore-input",maskTextClass:"ph-mask",maskTextSelector:void 0,maskTextFn:void 0,maskAllInputs:!0,maskInputOptions:{},maskInputFn:void 0,slimDOMOptions:{},collectFonts:!1,inlineStylesheet:!0,recordCrossOriginIframes:!1};this.rrwebRecord=T.rrweb?T.rrweb.record:T.rrwebRecord;for(var sr=this.instance.config.session_recording,lr=0,cr=Object.entries(sr||{});lr<cr.length;lr++){var ur=f(cr[lr],2),dr=ur[0],fr=ur[1];dr in ar&&(ar[dr]=fr)}if(!this._recordCanvas||E(this._canvasFps)||E(this._canvasQuality)||(ar.recordCanvas=!0,ar.sampling={canvas:this._canvasFps},ar.dataURLOptions={type:"image/webp",quality:this._canvasQuality}),this.rrwebRecord){this.mutationRateLimiter=(or=this.mutationRateLimiter)!==null&&or!==void 0?or:new It(this.rrwebRecord,{onBlockedNode:function(hr,gr){var vr="Too many mutations on node '".concat(hr,"'. Rate limiting. This could be due to SVG animations or something similar");j.info(vr,{node:gr}),ir.log("[PostHog Recorder] "+vr,"warn")}}),this._scheduleFullSnapshot();var pr=this._gatherRRWebPlugins();this.stopRrweb=this.rrwebRecord(t({emit:function(hr){ir.onRRwebEmit(hr)},plugins:pr},ar)),this.instance._addCaptureHook(function(hr){try{if(hr==="$pageview"){var gr=T?ir._maskUrl(T.location.href):"";if(!gr)return;ir._tryAddCustomEvent("$pageview",{href:gr})}}catch(vr){j.error("Could not add $pageview to rrweb session",vr)}}),this._lastActivityTimestamp=Date.now(),this.isIdle=!1,this._tryAddCustomEvent("$session_options",{sessionRecordingOptions:ar,activePlugins:pr.map(function(hr){return hr==null?void 0:hr.name})})}else j.error("onScriptLoaded was called but rrwebRecord is not available. This indicates something has gone wrong.")}},{key:"_scheduleFullSnapshot",value:function(){var or=this;this._fullSnapshotTimer&&clearInterval(this._fullSnapshotTimer),this._fullSnapshotTimer=setInterval(function(){or._tryTakeFullSnapshot()},Ut)}},{key:"_gatherRRWebPlugins",value:function(){var or=[];return B.rrwebConsoleRecord&&this.isConsoleLogCaptureEnabled&&or.push(B.rrwebConsoleRecord.getRecordConsolePlugin()),this.networkPayloadCapture&&P(B.getRecordNetworkPlugin)&&(!gt.includes(location.hostname)||this._forceAllowLocalhostNetworkCapture?or.push(B.getRecordNetworkPlugin($t(this.instance.config,this.networkPayloadCapture))):j.info("[SessionReplay-NetworkCapture] not started because we are on localhost.")),or}},{key:"onRRwebEmit",value:function(or){if(this._processQueuedEvents(),or&&I(or)){if(or.type===Rt.Meta){var ir=this._maskUrl(or.data.href);if(!ir)return;or.data.href=ir}or.type===Rt.FullSnapshot&&this._scheduleFullSnapshot();var ar=this.mutationRateLimiter?this.mutationRateLimiter.throttleMutations(or):or;if(ar){var sr=function(ur){var dr=ur;if(dr&&I(dr)&&dr.type===6&&I(dr.data)&&dr.data.plugin==="rrweb/console@1"){dr.data.payload.payload.length>10&&(dr.data.payload.payload=dr.data.payload.payload.slice(0,10),dr.data.payload.payload.push("...[truncated]"));for(var fr=[],pr=0;pr<dr.data.payload.payload.length;pr++)dr.data.payload.payload[pr]&&dr.data.payload.payload[pr].length>2e3?fr.push(dr.data.payload.payload[pr].slice(0,2e3)+"...[truncated]"):fr.push(dr.data.payload.payload[pr]);return dr.data.payload.payload=fr,ur}return ur}(ar),lr=JSON.stringify(sr).length;if(this._updateWindowAndSessionIds(sr),!this.isIdle){var cr={$snapshot_bytes:lr,$snapshot_data:sr,$session_id:this.sessionId,$window_id:this.windowId};this.status!=="disabled"?this._captureSnapshotBuffered(cr):this.clearBuffer()}}}}},{key:"_processQueuedEvents",value:function(){var or=this;if(this.queuedRRWebEvents.length){var ir=p(this.queuedRRWebEvents);this.queuedRRWebEvents=[],ir.forEach(function(ar){Date.now()-ar.enqueuedAt>2e3?or._tryAddCustomEvent("rrwebQueueTimeout",{enqueuedAt:ar.enqueuedAt,attempt:ar.attempt,queueLength:ir.length}):or._tryRRWebMethod(ar)&&or._tryAddCustomEvent("rrwebQueueSuccess",{enqueuedAt:ar.enqueuedAt,attempt:ar.attempt,queueLength:ir.length})})}}},{key:"_maskUrl",value:function(or){var ir=this.instance.config.session_recording;if(ir.maskNetworkRequestFn){var ar,sr={url:or};return(ar=sr=ir.maskNetworkRequestFn(sr))===null||ar===void 0?void 0:ar.url}return or}},{key:"clearBuffer",value:function(){return this.buffer=void 0,{size:0,data:[],sessionId:this.sessionId,windowId:this.windowId}}},{key:"_flushBuffer",value:function(){var or=this;this.flushBufferTimer&&(clearTimeout(this.flushBufferTimer),this.flushBufferTimer=void 0);var ir=this._minimumDuration,ar=this.sessionDuration,sr=C(ar)&&ar>=0,lr=C(ir)&&sr&&ar<ir;return this.status==="buffering"||lr?(this.flushBufferTimer=setTimeout(function(){or._flushBuffer()},2e3),this.buffer||this.clearBuffer()):this.buffer&&this.buffer.data.length!==0?(this._captureSnapshot({$snapshot_bytes:this.buffer.size,$snapshot_data:this.buffer.data,$session_id:this.buffer.sessionId,$window_id:this.buffer.windowId}),this.clearBuffer()):this.buffer||this.clearBuffer()}},{key:"_captureSnapshotBuffered",value:function(or){var ir,ar=this,sr=2+(((ir=this.buffer)===null||ir===void 0?void 0:ir.data.length)||0);(!this.buffer||this.buffer.size+or.$snapshot_bytes+sr>943718.4||this.buffer.sessionId&&this.buffer.sessionId!==this.sessionId)&&(this.buffer=this._flushBuffer()),E(this.buffer.sessionId)&&!E(this.sessionId)&&(this.buffer.sessionId=this.sessionId,this.buffer.windowId=this.windowId),this.buffer.size+=or.$snapshot_bytes,this.buffer.data.push(or.$snapshot_data),this.flushBufferTimer||(this.flushBufferTimer=setTimeout(function(){ar._flushBuffer()},2e3))}},{key:"_captureSnapshot",value:function(or){this.instance.capture("$snapshot",or,{transport:"XHR",method:"POST",endpoint:this._endpoint,_noTruncate:!0,_batchKey:"recordings",_metrics:{rrweb_full_snapshot:or.$snapshot_data.type===Ft}})}}]),nr}(),Jt=function(){function nr(or){i(this,nr),this.instance=or,this.instance.decideEndpointWasHit=this.instance._hasBootstrappedFeatureFlags()}return o(nr,[{key:"call",value:function(){var or=this,ir=te(JSON.stringify({token:this.instance.config.token,distinct_id:this.instance.get_distinct_id(),groups:this.instance.getGroups(),person_properties:this.instance.get_property(Me),group_properties:this.instance.get_property(Te),disable_flags:this.instance.config.advanced_disable_feature_flags||this.instance.config.advanced_disable_feature_flags_on_first_load||void 0}));this.instance._send_request("".concat(this.instance.config.api_host,"/decide/?v=3"),{data:ir,verbose:!0},{method:"POST"},function(ar){return or.parseDecideResponse(ar)})}},{key:"parseDecideResponse",value:function(or){var ir,ar=this;if(this.instance.featureFlags.setReloadingPaused(!1),this.instance.featureFlags._startReloadTimer(),(or==null?void 0:or.status)!==0){if(!D||!D.body)return j.info("document not ready yet, trying again in 500 milliseconds..."),void setTimeout(function(){ar.parseDecideResponse(or)},500);this.instance.toolbar.afterDecideResponse(or),(ir=this.instance.sessionRecording)===null||ir===void 0||ir.afterDecideResponse(or),We.afterDecideResponse(or,this.instance),this.instance._afterDecideResponse(or),this.instance.config.advanced_disable_feature_flags_on_first_load||this.instance.config.advanced_disable_feature_flags||this.instance.featureFlags.receivedFeatureFlags(or);var sr=T==null?void 0:T.extendPostHogWithSurveys;or.surveys&&!sr&&re(this.instance.config.api_host+"/static/surveys.js",function(pr){if(pr)return j.error("Could not load surveys script",pr);T.extendPostHogWithSurveys(ar.instance)});var lr=T==null?void 0:T.extendPostHogWithExceptionAutoCapture;if(or.autocaptureExceptions&&or.autocaptureExceptions&&R(lr)&&re(this.instance.config.api_host+"/static/exception-autocapture.js",function(pr){if(pr)return j.error("Could not load exception autocapture script",pr);T.extendPostHogWithExceptionAutocapture(ar.instance,or)}),or.siteApps)if(this.instance.config.opt_in_site_apps){var cr,ur=this.instance.config.api_host,dr=v(or.siteApps);try{var fr=function(){var pr=cr.value,hr=pr.id,gr=pr.url,vr=[ur,ur[ur.length-1]==="/"&&gr[0]==="/"?gr.substring(1):gr].join("");B["__$$ph_site_app_".concat(hr)]=ar.instance,re(vr,function(br){br&&j.error("Error while initializing PostHog app with config id ".concat(hr),br)})};for(dr.s();!(cr=dr.n()).done;)fr()}catch(pr){dr.e(pr)}finally{dr.f()}}else or.siteApps.length>0&&j.error('PostHog site apps are disabled. Enable the "opt_in_site_apps" config to proceed.')}else j.error("Failed to fetch feature flags from PostHog.")}}]),nr}(),Xt=["https://app.posthog.com","https://eu.posthog.com"],Kt=["source"],Zt=T!=null&&T.location?bt(T.location.hash,"__posthog")||bt(location.hash,"state"):null,en=function(){function nr(or){i(this,nr),this.instance=or}return o(nr,[{key:"afterDecideResponse",value:function(or){var ir=or.toolbarParams||or.editorParams||(or.toolbarVersion?{toolbarVersion:or.toolbarVersion}:{});or.isAuthenticated&&ir.toolbarVersion&&ir.toolbarVersion.indexOf("toolbar")===0&&this.loadToolbar(t({},ir))}},{key:"maybeLoadToolbar",value:function(){var or,ir,ar=arguments.length>0&&arguments[0]!==void 0?arguments[0]:void 0,sr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0,lr=arguments.length>2&&arguments[2]!==void 0?arguments[2]:void 0;if(!T||!D)return!1;ar=(or=ar)!==null&&or!==void 0?or:T.location,lr=(ir=lr)!==null&&ir!==void 0?ir:T.history;try{if(!sr){try{T.localStorage.setItem("test","test"),T.localStorage.removeItem("test")}catch{return!1}sr=T==null?void 0:T.localStorage}var cr,ur=Zt||bt(ar.hash,"__posthog")||bt(ar.hash,"state"),dr=ur?J(function(){return JSON.parse(atob(decodeURIComponent(ur)))})||J(function(){return JSON.parse(decodeURIComponent(ur))}):null;return dr&&dr.action==="ph_authorize"?((cr=dr).source="url",cr&&Object.keys(cr).length>0&&(dr.desiredHash?ar.hash=dr.desiredHash:lr?lr.replaceState("",D.title,ar.pathname+ar.search):ar.hash="")):((cr=JSON.parse(sr.getItem("_postHogToolbarParams")||"{}")).source="localstorage",delete cr.userIntent),!(!cr.token||this.instance.config.token!==cr.token)&&(this.loadToolbar(cr),!0)}catch{return!1}}},{key:"loadToolbar",value:function(or){var ir=this;if(!T||B._postHogToolbarLoaded)return!1;B._postHogToolbarLoaded=!0;var ar=this.instance.config.api_host,sr=3e5,lr=Math.floor(Date.now()/sr)*sr,cr="".concat(ar).concat(ar.endsWith("/")?"":"/","static/toolbar.js?t=").concat(lr),ur=!Xt.includes(this.instance.config.api_host)&&this.instance.config.advanced_disable_toolbar_metrics,dr=t(t({token:this.instance.config.token},or),{},{apiURL:ar},ur?{instrument:!1}:{});dr.source;var fr=c(dr,Kt);return T.localStorage.setItem("_postHogToolbarParams",JSON.stringify(fr)),re(cr,function(pr){pr?j.error("Failed to load toolbar",pr):(B.ph_load_toolbar||B.ph_load_editor)(dr,ir.instance)}),ie(T,"turbolinks:load",function(){B._postHogToolbarLoaded=!1,ir.loadToolbar(dr)}),!0}},{key:"_loadEditor",value:function(or){return this.loadToolbar(or)}},{key:"maybeLoadEditor",value:function(){var or=arguments.length>0&&arguments[0]!==void 0?arguments[0]:void 0,ir=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0,ar=arguments.length>2&&arguments[2]!==void 0?arguments[2]:void 0;return this.maybeLoadToolbar(or,ir,ar)}}]),nr}(),tn=function(){function nr(){var or=arguments.length>0&&arguments[0]!==void 0?arguments[0]:3e3;i(this,nr),this.isPolling=!0,this._event_queue=[],this._empty_queue_count=0,this._poller=void 0,this._pollInterval=or}return o(nr,[{key:"setPollInterval",value:function(or){this._pollInterval=or,this.isPolling&&this.poll()}},{key:"poll",value:function(){}},{key:"unload",value:function(){}},{key:"getTime",value:function(){return new Date().getTime()}}]),nr}(),nn=function(nr){a(ir,tn);var or=h(ir);function ir(ar){var sr,lr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:3e3;return i(this,ir),(sr=or.call(this,lr)).handlePollRequest=ar,sr}return o(ir,[{key:"enqueue",value:function(ar,sr,lr){this._event_queue.push({url:ar,data:sr,options:lr}),this.isPolling||(this.isPolling=!0,this.poll())}},{key:"poll",value:function(){var ar=this;clearTimeout(this._poller),this._poller=setTimeout(function(){if(ar._event_queue.length>0){var sr=ar.formatQueue(),lr=function(ur){var dr=sr[ur],fr=dr.url,pr=dr.data,hr=dr.options;U(pr,function(gr,vr){pr[vr].offset=Math.abs(pr[vr].timestamp-ar.getTime()),delete pr[vr].timestamp}),ar.handlePollRequest(fr,pr,hr)};for(var cr in sr)lr(cr);ar._event_queue.length=0,ar._empty_queue_count=0}else ar._empty_queue_count++;ar._empty_queue_count>4&&(ar.isPolling=!1,ar._empty_queue_count=0),ar.isPolling&&ar.poll()},this._pollInterval)}},{key:"unload",value:function(){var ar=this;clearTimeout(this._poller);var sr=this._event_queue.length>0?this.formatQueue():{};this._event_queue.length=0;var lr=Object.values(sr);[].concat(p(lr.filter(function(cr){return cr.url.indexOf("/e")===0})),p(lr.filter(function(cr){return cr.url.indexOf("/e")!==0}))).map(function(cr){var ur=cr.url,dr=cr.data,fr=cr.options;ar.handlePollRequest(ur,dr,t(t({},fr),{},{transport:"sendBeacon"}))})}},{key:"formatQueue",value:function(){var ar={};return U(this._event_queue,function(sr){var lr=sr.url,cr=sr.data,ur=sr.options,dr=(ur?ur._batchKey:null)||lr;R(ar[dr])&&(ar[dr]={data:[],url:lr,options:ur}),ur&&ar[dr].options&&ar[dr].options._metrics&&!ar[dr].options._metrics.rrweb_full_snapshot&&(ar[dr].options._metrics.rrweb_full_snapshot=ur._metrics.rrweb_full_snapshot),ar[dr].data.push(cr)}),ar}}]),ir}(),rn=Uint8Array,on=Uint16Array,sn=Uint32Array,an=new rn([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),un=new rn([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ln=new rn([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),cn=function(nr,or){for(var ir=new on(31),ar=0;ar<31;++ar)ir[ar]=or+=1<<nr[ar-1];var sr=new sn(ir[30]);for(ar=1;ar<30;++ar)for(var lr=ir[ar];lr<ir[ar+1];++lr)sr[lr]=lr-ir[ar]<<5|ar;return[ir,sr]},dn=cn(an,2),hn=dn[0],fn=dn[1];hn[28]=258,fn[258]=28;for(var pn=cn(un,0)[1],_n=new on(32768),gn=0;gn<32768;++gn){var vn=(43690&gn)>>>1|(21845&gn)<<1;vn=(61680&(vn=(52428&vn)>>>2|(13107&vn)<<2))>>>4|(3855&vn)<<4,_n[gn]=((65280&vn)>>>8|(255&vn)<<8)>>>1}var mn=function(nr,or,ir){for(var ar=nr.length,sr=0,lr=new on(or);sr<ar;++sr)++lr[nr[sr]-1];var cr,ur=new on(or);for(sr=0;sr<or;++sr)ur[sr]=ur[sr-1]+lr[sr-1]<<1;if(ir){cr=new on(1<<or);var dr=15-or;for(sr=0;sr<ar;++sr)if(nr[sr])for(var fr=sr<<4|nr[sr],pr=or-nr[sr],hr=ur[nr[sr]-1]++<<pr,gr=hr|(1<<pr)-1;hr<=gr;++hr)cr[_n[hr]>>>dr]=fr}else for(cr=new on(ar),sr=0;sr<ar;++sr)cr[sr]=_n[ur[nr[sr]-1]++]>>>15-nr[sr];return cr},yn=new rn(288);for(gn=0;gn<144;++gn)yn[gn]=8;for(gn=144;gn<256;++gn)yn[gn]=9;for(gn=256;gn<280;++gn)yn[gn]=7;for(gn=280;gn<288;++gn)yn[gn]=8;var bn=new rn(32);for(gn=0;gn<32;++gn)bn[gn]=5;var kn,wn=mn(yn,9,0),Sn=mn(bn,5,0),Fn=function(nr){return(nr/8>>0)+(7&nr&&1)},Pn=function(nr,or,ir){(or==null||or<0)&&(or=0),(ir==null||ir>nr.length)&&(ir=nr.length);var ar=new(nr instanceof on?on:nr instanceof sn?sn:rn)(ir-or);return ar.set(nr.subarray(or,ir)),ar},In=function(nr,or,ir){ir<<=7&or;var ar=or/8>>0;nr[ar]|=ir,nr[ar+1]|=ir>>>8},Rn=function(nr,or,ir){ir<<=7&or;var ar=or/8>>0;nr[ar]|=ir,nr[ar+1]|=ir>>>8,nr[ar+2]|=ir>>>16},xn=function(nr,or){for(var ir=[],ar=0;ar<nr.length;++ar)nr[ar]&&ir.push({s:ar,f:nr[ar]});var sr=ir.length,lr=ir.slice();if(!sr)return[new rn(0),0];if(sr==1){var cr=new rn(ir[0].s+1);return cr[ir[0].s]=1,[cr,1]}ir.sort(function(_r,jr){return _r.f-jr.f}),ir.push({s:-1,f:25001});var ur=ir[0],dr=ir[1],fr=0,pr=1,hr=2;for(ir[0]={s:-1,f:ur.f+dr.f,l:ur,r:dr};pr!=sr-1;)ur=ir[ir[fr].f<ir[hr].f?fr++:hr++],dr=ir[fr!=pr&&ir[fr].f<ir[hr].f?fr++:hr++],ir[pr++]={s:-1,f:ur.f+dr.f,l:ur,r:dr};var gr=lr[0].s;for(ar=1;ar<sr;++ar)lr[ar].s>gr&&(gr=lr[ar].s);var vr=new on(gr+1),br=En(ir[pr-1],vr,0);if(br>or){ar=0;var mr=0,yr=br-or,wr=1<<yr;for(lr.sort(function(_r,jr){return vr[jr.s]-vr[_r.s]||_r.f-jr.f});ar<sr;++ar){var Tr=lr[ar].s;if(!(vr[Tr]>or))break;mr+=wr-(1<<br-vr[Tr]),vr[Tr]=or}for(mr>>>=yr;mr>0;){var Pr=lr[ar].s;vr[Pr]<or?mr-=1<<or-vr[Pr]++-1:++ar}for(;ar>=0&&mr;--ar){var Rr=lr[ar].s;vr[Rr]==or&&(--vr[Rr],++mr)}br=or}return[new rn(vr),br]},En=function nr(or,ir,ar){return or.s==-1?Math.max(nr(or.l,ir,ar+1),nr(or.r,ir,ar+1)):ir[or.s]=ar},Cn=function(nr){for(var or=nr.length;or&&!nr[--or];);for(var ir=new on(++or),ar=0,sr=nr[0],lr=1,cr=function(dr){ir[ar++]=dr},ur=1;ur<=or;++ur)if(nr[ur]==sr&&ur!=or)++lr;else{if(!sr&&lr>2){for(;lr>138;lr-=138)cr(32754);lr>2&&(cr(lr>10?lr-11<<5|28690:lr-3<<5|12305),lr=0)}else if(lr>3){for(cr(sr),--lr;lr>6;lr-=6)cr(8304);lr>2&&(cr(lr-3<<5|8208),lr=0)}for(;lr--;)cr(sr);lr=1,sr=nr[ur]}return[ir.subarray(0,ar),or]},On=function(nr,or){for(var ir=0,ar=0;ar<or.length;++ar)ir+=nr[ar]*or[ar];return ir},$n=function(nr,or,ir){var ar=ir.length,sr=Fn(or+2);nr[sr]=255&ar,nr[sr+1]=ar>>>8,nr[sr+2]=255^nr[sr],nr[sr+3]=255^nr[sr+1];for(var lr=0;lr<ar;++lr)nr[sr+lr+4]=ir[lr];return 8*(sr+4+ar)},An=function(nr,or,ir,ar,sr,lr,cr,ur,dr,fr,pr){In(or,pr++,ir),++sr[256];for(var hr=xn(sr,15),gr=hr[0],vr=hr[1],br=xn(lr,15),mr=br[0],yr=br[1],wr=Cn(gr),Tr=wr[0],Pr=wr[1],Rr=Cn(mr),_r=Rr[0],jr=Rr[1],Cr=new on(19),Sr=0;Sr<Tr.length;++Sr)Cr[31&Tr[Sr]]++;for(Sr=0;Sr<_r.length;++Sr)Cr[31&_r[Sr]]++;for(var Mr=xn(Cr,7),Ur=Mr[0],kr=Mr[1],Ir=19;Ir>4&&!Ur[ln[Ir-1]];--Ir);var qr,Vr,fo,bo,go=fr+5<<3,mo=On(sr,yn)+On(lr,bn)+cr,Br=On(sr,gr)+On(lr,mr)+cr+14+3*Ir+On(Cr,Ur)+(2*Cr[16]+3*Cr[17]+7*Cr[18]);if(go<=mo&&go<=Br)return $n(or,pr,nr.subarray(dr,dr+fr));if(In(or,pr,1+(Br<mo)),pr+=2,Br<mo){qr=mn(gr,vr,0),Vr=gr,fo=mn(mr,yr,0),bo=mr;var Gr=mn(Ur,kr,0);for(In(or,pr,Pr-257),In(or,pr+5,jr-1),In(or,pr+10,Ir-4),pr+=14,Sr=0;Sr<Ir;++Sr)In(or,pr+3*Sr,Ur[ln[Sr]]);pr+=3*Ir;for(var Qr=[Tr,_r],Fr=0;Fr<2;++Fr){var Or=Qr[Fr];for(Sr=0;Sr<Or.length;++Sr){var xr=31&Or[Sr];In(or,pr,Gr[xr]),pr+=Ur[xr],xr>15&&(In(or,pr,Or[Sr]>>>5&127),pr+=Or[Sr]>>>12)}}}else qr=wn,Vr=yn,fo=Sn,bo=bn;for(Sr=0;Sr<ur;++Sr)if(ar[Sr]>255){xr=ar[Sr]>>>18&31,Rn(or,pr,qr[xr+257]),pr+=Vr[xr+257],xr>7&&(In(or,pr,ar[Sr]>>>23&31),pr+=an[xr]);var zr=31&ar[Sr];Rn(or,pr,fo[zr]),pr+=bo[zr],zr>3&&(Rn(or,pr,ar[Sr]>>>5&8191),pr+=un[zr])}else Rn(or,pr,qr[ar[Sr]]),pr+=Vr[ar[Sr]];return Rn(or,pr,qr[256]),pr+Vr[256]},Mn=new sn([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Tn=new rn(0),qn=function(){for(var nr=new sn(256),or=0;or<256;++or){for(var ir=or,ar=9;--ar;)ir=(1&ir&&3988292384)^ir>>>1;nr[or]=ir}return nr}(),Dn=function(){var nr=4294967295;return{p:function(or){for(var ir=nr,ar=0;ar<or.length;++ar)ir=qn[255&ir^or[ar]]^ir>>>8;nr=ir},d:function(){return 4294967295^nr}}},Ln=function(nr,or,ir,ar,sr){return function(lr,cr,ur,dr,fr,pr){var hr=lr.length,gr=new rn(dr+hr+5*(1+Math.floor(hr/7e3))+fr),vr=gr.subarray(dr,gr.length-fr),br=0;if(!cr||hr<8)for(var mr=0;mr<=hr;mr+=65535){var yr=mr+65535;yr<hr?br=$n(vr,br,lr.subarray(mr,yr)):(vr[mr]=pr,br=$n(vr,br,lr.subarray(mr,hr)))}else{for(var wr=Mn[cr-1],Tr=wr>>>13,Pr=8191&wr,Rr=(1<<ur)-1,_r=new on(32768),jr=new on(Rr+1),Cr=Math.ceil(ur/3),Sr=2*Cr,Mr=function(Do){return(lr[Do]^lr[Do+1]<<Cr^lr[Do+2]<<Sr)&Rr},Ur=new sn(25e3),kr=new on(288),Ir=new on(32),qr=0,Vr=0,fo=(mr=0,0),bo=0,go=0;mr<hr;++mr){var mo=Mr(mr),Br=32767&mr,Gr=jr[mo];if(_r[Br]=Gr,jr[mo]=Br,bo<=mr){var Qr=hr-mr;if((qr>7e3||fo>24576)&&Qr>423){br=An(lr,vr,0,Ur,kr,Ir,Vr,fo,go,mr-go,br),fo=qr=Vr=0,go=mr;for(var Fr=0;Fr<286;++Fr)kr[Fr]=0;for(Fr=0;Fr<30;++Fr)Ir[Fr]=0}var Or=2,xr=0,zr=Pr,Ar=Br-Gr&32767;if(Qr>2&&mo==Mr(mr-Ar))for(var $r=Math.min(Tr,Qr)-1,Er=Math.min(32767,mr),Dr=Math.min(258,Qr);Ar<=Er&&--zr&&Br!=Gr;){if(lr[mr+Or]==lr[mr+Or-Ar]){for(var Wr=0;Wr<Dr&&lr[mr+Wr]==lr[mr+Wr-Ar];++Wr);if(Wr>Or){if(Or=Wr,xr=Ar,Wr>$r)break;var Nr=Math.min(Ar,Wr-2),Hr=0;for(Fr=0;Fr<Nr;++Fr){var yo=mr-Ar+Fr+32768&32767,_o=yo-_r[yo]+32768&32767;_o>Hr&&(Hr=_o,Gr=yo)}}}Ar+=(Br=Gr)-(Gr=_r[Br])+32768&32767}if(xr){Ur[fo++]=268435456|fn[Or]<<18|pn[xr];var Ro=31&fn[Or],No=31&pn[xr];Vr+=an[Ro]+un[No],++kr[257+Ro],++Ir[No],bo=mr+Or,++qr}else Ur[fo++]=lr[mr],++kr[lr[mr]]}}br=An(lr,vr,pr,Ur,kr,Ir,Vr,fo,go,mr-go,br),pr||(br=$n(vr,br,Tn))}return Pn(gr,0,dr+Fn(br)+fr)}(nr,or.level==null?6:or.level,or.mem==null?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(nr.length)))):12+or.mem,ir,ar,!sr)},Bn=function(nr,or,ir){for(;ir;++or)nr[or]=ir,ir>>>=8},Nn=function(nr,or){var ir=or.filename;if(nr[0]=31,nr[1]=139,nr[2]=8,nr[8]=or.level<2?4:or.level==9?2:0,nr[9]=3,or.mtime!=0&&Bn(nr,4,Math.floor(new Date(or.mtime||Date.now())/1e3)),ir){nr[3]=8;for(var ar=0;ar<=ir.length;++ar)nr[ar+10]=ir.charCodeAt(ar)}},jn=function(nr){return 10+(nr.filename&&nr.filename.length+1||0)};function Hn(nr,or){or===void 0&&(or={});var ir=Dn(),ar=nr.length;ir.p(nr);var sr=Ln(nr,or,jn(or),8),lr=sr.length;return Nn(sr,or),Bn(sr,lr-8,ir.d()),Bn(sr,lr-4,ar),sr}function Wn(nr,or){var ir=nr.length;if(!or&&typeof TextEncoder<"u")return new TextEncoder().encode(nr);for(var ar=new rn(nr.length+(nr.length>>>1)),sr=0,lr=function(fr){ar[sr++]=fr},cr=0;cr<ir;++cr){if(sr+5>ar.length){var ur=new rn(sr+8+(ir-cr<<1));ur.set(ar),ar=ur}var dr=nr.charCodeAt(cr);dr<128||or?lr(dr):dr<2048?(lr(192|dr>>>6),lr(128|63&dr)):dr>55295&&dr<57344?(lr(240|(dr=65536+(1047552&dr)|1023&nr.charCodeAt(++cr))>>>18),lr(128|dr>>>12&63),lr(128|dr>>>6&63),lr(128|63&dr)):(lr(224|dr>>>12),lr(128|dr>>>6&63),lr(128|63&dr))}return Pn(ar,0,sr)}(function(nr){nr.GZipJS="gzip-js",nr.Base64="base64"})(kn||(kn={}));var Vn=function(nr,or,ir){var ar=or||{};ar.ip=ir.ip?1:0,ar._=new Date().getTime().toString(),ar.ver=m.LIB_VERSION;var sr=nr.split("?");if(sr.length>1){var lr,cr=v(sr[1].split("&"));try{for(cr.s();!(lr=cr.n()).done;){var ur=lr.value.split("=")[0];R(ar[ur])||delete ar[ur]}}catch(fr){cr.e(fr)}finally{cr.f()}}var dr=nr.indexOf("?")>-1?"&":"?";return nr+dr+function(fr){var pr,hr,gr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"&",vr=[];return U(fr,function(br,mr){R(br)||R(mr)||mr==="undefined"||(pr=encodeURIComponent(br.toString()),hr=encodeURIComponent(mr),vr[vr.length]=hr+"="+pr)}),vr.join(gr)}(ar)},Un=function nr(or,ir){if(ir.blob&&or.buffer)return new Blob([F(or)?or:or.buffer],{type:"text/plain"});if(ir.sendBeacon||ir.blob){var ar=nr(or,{method:"POST"});return new Blob([ar],{type:"application/x-www-form-urlencoded"})}return ir.method!=="POST"?null:(sr=S(or)||F(or)?"data="+encodeURIComponent(or):"data="+encodeURIComponent(or.data),"compression"in or&&or.compression&&(sr+="&compression="+or.compression),sr);var sr},Gn=function(nr){var or=nr.url,ir=nr.data,ar=nr.headers,sr=nr.options,lr=nr.callback,cr=nr.retriesPerformedSoFar,ur=nr.retryQueue,dr=nr.onXHRError,fr=nr.timeout,pr=fr===void 0?6e4:fr,hr=nr.onResponse;C(cr)&&cr>0&&(or=Vn(or,{retry_count:cr},{}));var gr=new XMLHttpRequest;gr.open(sr.method||"GET",or,!0);var vr=Un(ir,sr);U(ar,function(br,mr){gr.setRequestHeader(mr,br)}),sr.method!=="POST"||sr.blob||gr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),gr.timeout=pr,gr.withCredentials=!0,gr.onreadystatechange=function(){if(gr.readyState===4)if(hr==null||hr(gr),gr.status===200){if(lr){var br;try{br=JSON.parse(gr.responseText)}catch(mr){return void j.error(mr)}lr(br)}}else P(dr)&&dr(gr),(gr.status<400||gr.status>500)&&ur.enqueue({url:or,data:ir,options:sr,headers:ar,retriesPerformedSoFar:(cr||0)+1,callback:lr}),lr==null||lr({status:0})},gr.send(vr)},zn=function(nr){a(ir,tn);var or=h(ir);function ir(ar,sr){var lr;return i(this,ir),(lr=or.call(this)).isPolling=!1,lr.queue=[],lr.areWeOnline=!0,lr.onXHRError=ar,lr.rateLimiter=sr,!R(T)&&"onLine"in T.navigator&&(lr.areWeOnline=T.navigator.onLine,T.addEventListener("online",function(){lr._handleWeAreNowOnline()}),T.addEventListener("offline",function(){lr.areWeOnline=!1})),lr}return o(ir,[{key:"enqueue",value:function(ar){var sr=ar.retriesPerformedSoFar||0;if(!(sr>=10)){var lr=function(dr){var fr=3e3*Math.pow(2,dr),pr=fr/2,hr=Math.min(18e5,fr),gr=(Math.random()-.5)*(hr-pr);return Math.ceil(hr+gr)}(sr),cr=new Date(Date.now()+lr);this.queue.push({retryAt:cr,requestData:ar});var ur="Enqueued failed request for retry in ".concat(lr);navigator.onLine||(ur+=" (Browser is offline)"),j.warn(ur),this.isPolling||(this.isPolling=!0,this.poll())}}},{key:"poll",value:function(){var ar=this;this._poller&&clearTimeout(this._poller),this._poller=setTimeout(function(){ar.areWeOnline&&ar.queue.length>0&&ar.flush(),ar.poll()},this._pollInterval)}},{key:"flush",value:function(){var ar=new Date(Date.now()),sr=this.queue.filter(function(dr){return dr.retryAt<ar});if(sr.length>0){this.queue=this.queue.filter(function(dr){return dr.retryAt>=ar});var lr,cr=v(sr);try{for(cr.s();!(lr=cr.n()).done;){var ur=lr.value.requestData;this._executeXhrRequest(ur)}}catch(dr){cr.e(dr)}finally{cr.f()}}}},{key:"unload",value:function(){this._poller&&(clearTimeout(this._poller),this._poller=void 0);var ar,sr=v(this.queue);try{for(sr.s();!(ar=sr.n()).done;){var lr=ar.value.requestData,cr=lr.url,ur=lr.data,dr=lr.options;if(this.rateLimiter.isRateLimited(dr._batchKey))j.warn("[RetryQueue] is quota limited. Dropping request.");else try{T==null||T.navigator.sendBeacon(cr,Un(ur,t(t({},dr),{},{sendBeacon:!0})))}catch(fr){j.error(fr)}}}catch(fr){sr.e(fr)}finally{sr.f()}this.queue=[]}},{key:"_executeXhrRequest",value:function(ar){var sr=ar.url,lr=ar.data,cr=ar.options,ur=ar.headers,dr=ar.callback,fr=ar.retriesPerformedSoFar;this.rateLimiter.isRateLimited(cr._batchKey)||Gn({url:sr,data:lr||{},options:cr||{},headers:ur||{},retriesPerformedSoFar:fr||0,callback:dr,retryQueue:this,onXHRError:this.onXHRError,onResponse:this.rateLimiter.checkForLimiting})}},{key:"_handleWeAreNowOnline",value:function(){this.areWeOnline=!0,this.flush()}}]),ir}(),Qn=1800,Yn=function(){function nr(or,ir,ar,sr){i(this,nr),s(this,"_sessionIdChangedHandlers",[]),this.config=or,this.persistence=ir,this._windowId=void 0,this._sessionId=void 0,this._sessionStartTimestamp=null,this._sessionActivityTimestamp=null,this._sessionIdGenerator=ar||tt,this._windowIdGenerator=sr||tt;var lr=or.persistence_name||or.token,cr=or.session_idle_timeout_seconds||Qn;if(C(cr)?cr>Qn?j.warn("session_idle_timeout_seconds cannot be greater than 30 minutes. Using 30 minutes instead."):cr<60&&j.warn("session_idle_timeout_seconds cannot be less than 60 seconds. Using 60 seconds instead."):(j.warn("session_idle_timeout_seconds must be a number. Defaulting to 30 minutes."),cr=Qn),this._sessionTimeoutMs=1e3*Math.min(Math.max(cr,60),Qn),this._window_id_storage_key="ph_"+lr+"_window_id",this._primary_window_exists_storage_key="ph_"+lr+"_primary_window_exists",this._canUseSessionStorage()){var ur=_t.parse(this._window_id_storage_key),dr=_t.parse(this._primary_window_exists_storage_key);ur&&!dr?this._windowId=ur:_t.remove(this._window_id_storage_key),_t.set(this._primary_window_exists_storage_key,!0)}this._listenToReloadWindow()}return o(nr,[{key:"onSessionId",value:function(or){var ir=this;return R(this._sessionIdChangedHandlers)&&(this._sessionIdChangedHandlers=[]),this._sessionIdChangedHandlers.push(or),this._sessionId&&or(this._sessionId,this._windowId),function(){ir._sessionIdChangedHandlers=ir._sessionIdChangedHandlers.filter(function(ar){return ar!==or})}}},{key:"_canUseSessionStorage",value:function(){return this.config.persistence!=="memory"&&!this.persistence.disabled&&_t.is_supported()}},{key:"_setWindowId",value:function(or){or!==this._windowId&&(this._windowId=or,this._canUseSessionStorage()&&_t.set(this._window_id_storage_key,or))}},{key:"_getWindowId",value:function(){return this._windowId?this._windowId:this._canUseSessionStorage()?_t.parse(this._window_id_storage_key):null}},{key:"_setSessionId",value:function(or,ir,ar){or===this._sessionId&&ir===this._sessionActivityTimestamp&&ar===this._sessionStartTimestamp||(this._sessionStartTimestamp=ar,this._sessionActivityTimestamp=ir,this._sessionId=or,this.persistence.register(s({},Ce,[ir,or,ar])))}},{key:"_getSessionId",value:function(){if(this._sessionId&&this._sessionActivityTimestamp&&this._sessionStartTimestamp)return[this._sessionActivityTimestamp,this._sessionId,this._sessionStartTimestamp];var or=this.persistence.props[Ce];return S(or)&&or.length===2&&or.push(or[0]),or||[0,null,0]}},{key:"resetSessionId",value:function(){this._setSessionId(null,null,null)}},{key:"_listenToReloadWindow",value:function(){var or=this;T==null||T.addEventListener("beforeunload",function(){or._canUseSessionStorage()&&_t.remove(or._primary_window_exists_storage_key)})}},{key:"checkAndGetSessionAndWindowId",value:function(){var or=arguments.length>0&&arguments[0]!==void 0&&arguments[0],ir=(arguments.length>1&&arguments[1]!==void 0?arguments[1]:null)||new Date().getTime(),ar=f(this._getSessionId(),3),sr=ar[0],lr=ar[1],cr=ar[2],ur=this._getWindowId(),dr=cr&&cr>0&&Math.abs(ir-cr)>864e5,fr=!1,pr=!lr,hr=!or&&Math.abs(ir-sr)>this._sessionTimeoutMs;pr||hr||dr?(lr=this._sessionIdGenerator(),ur=this._windowIdGenerator(),j.info("[SessionId] new session ID generated",{sessionId:lr,windowId:ur,changeReason:{noSessionId:pr,activityTimeout:hr,sessionPastMaximumLength:dr}}),cr=ir,fr=!0):ur||(ur=this._windowIdGenerator(),fr=!0);var gr=sr===0||!or||dr?ir:sr,vr=cr===0?new Date().getTime():cr;return this._setWindowId(ur),this._setSessionId(lr,gr,vr),fr&&this._sessionIdChangedHandlers.forEach(function(br){return br(lr,ur)}),{sessionId:lr,windowId:ur,sessionStartTimestamp:vr}}}]),nr}(),Jn=o(function nr(or,ir,ar,sr){i(this,nr),this.name="posthog-js",this.setupOnce=function(lr){lr(function(cr){var ur,dr,fr,pr,hr;if(cr.level!=="error"||!or.__loaded)return cr;cr.tags||(cr.tags={});var gr=or.config.ui_host||or.config.api_host;cr.tags["PostHog Person URL"]=gr+"/person/"+or.get_distinct_id(),or.sessionRecordingStarted()&&(cr.tags["PostHog Recording URL"]=or.get_session_replay_url({withTimestamp:!0}));var vr=((ur=cr.exception)===null||ur===void 0?void 0:ur.values)||[],br={$exception_message:(dr=vr[0])===null||dr===void 0?void 0:dr.value,$exception_type:(fr=vr[0])===null||fr===void 0?void 0:fr.type,$exception_personURL:gr+"/person/"+or.get_distinct_id(),$sentry_event_id:cr.event_id,$sentry_exception:cr.exception,$sentry_exception_message:(pr=vr[0])===null||pr===void 0?void 0:pr.value,$sentry_exception_type:(hr=vr[0])===null||hr===void 0?void 0:hr.type,$sentry_tags:cr.tags};return ir&&ar&&(br.$sentry_url=(sr||"https://sentry.io/organizations/")+ir+"/issues/?project="+ar+"&query="+cr.event_id),or.capture("$exception",br),cr})}}),Xn=function(){function nr(or){var ir=this;i(this,nr),s(this,"_hasSeenPageView",!1),s(this,"_updateScrollData",function(){var ar,sr,lr,cr;ir._pageViewData||(ir._pageViewData=ir._createPageViewData());var ur=ir._pageViewData,dr=ir._scrollY(),fr=ir._scrollHeight(),pr=ir._contentY(),hr=ir._contentHeight();ur.lastScrollY=dr,ur.maxScrollY=Math.max(dr,(ar=ur.maxScrollY)!==null&&ar!==void 0?ar:0),ur.maxScrollHeight=Math.max(fr,(sr=ur.maxScrollHeight)!==null&&sr!==void 0?sr:0),ur.lastContentY=pr,ur.maxContentY=Math.max(pr,(lr=ur.maxContentY)!==null&&lr!==void 0?lr:0),ur.maxContentHeight=Math.max(hr,(cr=ur.maxContentHeight)!==null&&cr!==void 0?cr:0)}),this._instance=or}return o(nr,[{key:"_createPageViewData",value:function(){var or;return{pathname:(or=T==null?void 0:T.location.pathname)!==null&&or!==void 0?or:""}}},{key:"doPageView",value:function(){var or,ir;return this._hasSeenPageView?(ir=this._pageViewData,this._pageViewData=this._createPageViewData()):(this._hasSeenPageView=!0,ir=void 0,this._pageViewData||(this._pageViewData=this._createPageViewData())),setTimeout(this._updateScrollData,0),t({$prev_pageview_pathname:(or=ir)===null||or===void 0?void 0:or.pathname},this._calculatePrevPageScrollProperties(ir))}},{key:"doPageLeave",value:function(){var or=this._pageViewData;return t({$prev_pageview_pathname:or==null?void 0:or.pathname},this._calculatePrevPageScrollProperties(or))}},{key:"_calculatePrevPageScrollProperties",value:function(or){if(!or||or.maxScrollHeight==null||or.lastScrollY==null||or.maxScrollY==null||or.maxContentHeight==null||or.lastContentY==null||or.maxContentY==null)return{};var ir=or.maxScrollHeight,ar=or.lastScrollY,sr=or.maxScrollY,lr=or.maxContentHeight,cr=or.lastContentY,ur=or.maxContentY;return ir=Math.ceil(ir),ar=Math.ceil(ar),sr=Math.ceil(sr),lr=Math.ceil(lr),cr=Math.ceil(cr),ur=Math.ceil(ur),{$prev_pageview_last_scroll:ar,$prev_pageview_last_scroll_percentage:ir<=1?1:Kn(ar/ir,0,1),$prev_pageview_max_scroll:sr,$prev_pageview_max_scroll_percentage:ir<=1?1:Kn(sr/ir,0,1),$prev_pageview_last_content:cr,$prev_pageview_last_content_percentage:lr<=1?1:Kn(cr/lr,0,1),$prev_pageview_max_content:ur,$prev_pageview_max_content_percentage:lr<=1?1:Kn(ur/lr,0,1)}}},{key:"startMeasuringScrollPosition",value:function(){T==null||T.addEventListener("scroll",this._updateScrollData,!0),T==null||T.addEventListener("scrollend",this._updateScrollData,!0),T==null||T.addEventListener("resize",this._updateScrollData)}},{key:"stopMeasuringScrollPosition",value:function(){T==null||T.removeEventListener("scroll",this._updateScrollData),T==null||T.removeEventListener("scrollend",this._updateScrollData),T==null||T.removeEventListener("resize",this._updateScrollData)}},{key:"_scrollElement",value:function(){if(!this._instance.config.scroll_root_selector)return T==null?void 0:T.document.documentElement;var or,ir=v(S(this._instance.config.scroll_root_selector)?this._instance.config.scroll_root_selector:[this._instance.config.scroll_root_selector]);try{for(ir.s();!(or=ir.n()).done;){var ar=or.value,sr=T==null?void 0:T.document.querySelector(ar);if(sr)return sr}}catch(lr){ir.e(lr)}finally{ir.f()}}},{key:"_scrollHeight",value:function(){var or=this._scrollElement();return or?Math.max(0,or.scrollHeight-or.clientHeight):0}},{key:"_scrollY",value:function(){if(this._instance.config.scroll_root_selector){var or=this._scrollElement();return or&&or.scrollTop||0}return T&&(T.scrollY||T.pageYOffset||T.document.documentElement.scrollTop)||0}},{key:"_contentHeight",value:function(){var or=this._scrollElement();return(or==null?void 0:or.scrollHeight)||0}},{key:"_contentY",value:function(){var or=this._scrollElement(),ir=(or==null?void 0:or.clientHeight)||0;return this._scrollY()+ir}}]),nr}();function Kn(nr,or,ir){return Math.max(or,Math.min(nr,ir))}var Zn,ei,ti,ni={icontains:function(nr){return!!T&&T.location.href.toLowerCase().indexOf(nr.toLowerCase())>-1},regex:function(nr){return!!T&&mt(T.location.href,nr)},exact:function(nr){return(T==null?void 0:T.location.href)===nr}},ii=function(){function nr(or){i(this,nr),this.instance=or}return o(nr,[{key:"getSurveys",value:function(or){var ir=this,ar=arguments.length>1&&arguments[1]!==void 0&&arguments[1],sr=this.instance.get_property(qe);if(sr&&!ar)return or(sr);this.instance._send_request("".concat(this.instance.config.api_host,"/api/surveys/?token=").concat(this.instance.config.token),{},{method:"GET"},function(lr){var cr,ur=lr.surveys||[];return(cr=ir.instance.persistence)===null||cr===void 0||cr.register(s({},qe,ur)),or(ur)})}},{key:"getActiveMatchingSurveys",value:function(or){var ir=this,ar=arguments.length>1&&arguments[1]!==void 0&&arguments[1];this.getSurveys(function(sr){var lr=sr.filter(function(cr){return!(!cr.start_date||cr.end_date)}).filter(function(cr){var ur,dr,fr,pr;if(!cr.conditions)return!0;var hr=(ur=cr.conditions)===null||ur===void 0||!ur.url||ni[(dr=(fr=cr.conditions)===null||fr===void 0?void 0:fr.urlMatchType)!==null&&dr!==void 0?dr:"icontains"](cr.conditions.url),gr=(pr=cr.conditions)===null||pr===void 0||!pr.selector||(D==null?void 0:D.querySelector(cr.conditions.selector));return hr&&gr}).filter(function(cr){if(!cr.linked_flag_key&&!cr.targeting_flag_key)return!0;var ur=!cr.linked_flag_key||ir.instance.featureFlags.isFeatureEnabled(cr.linked_flag_key),dr=!cr.targeting_flag_key||ir.instance.featureFlags.isFeatureEnabled(cr.targeting_flag_key);return ur&&dr});return or(lr)},ar)}}]),nr}(),ri=function(){function nr(){var or=this;i(this,nr),s(this,"limits",{}),s(this,"checkForLimiting",function(ir){try{var ar=ir.responseText;if(!ar||!ar.length)return;(JSON.parse(ar).quota_limited||[]).forEach(function(sr){j.info("[RateLimiter] ".concat(sr||"events"," is quota limited.")),or.limits[sr]=new Date().getTime()+6e4})}catch(sr){return void j.error(sr)}})}return o(nr,[{key:"isRateLimited",value:function(or){var ir=this.limits[or||"events"]||!1;return ir!==!1&&new Date().getTime()<ir}}]),nr}(),oi=function(){return t({initialPathName:(T==null?void 0:T.location.pathname)||"",referringDomain:kt.referringDomain()},kt.campaignParams())},si=function(){function nr(or,ir,ar){var sr=this;i(this,nr),s(this,"_onSessionIdCallback",function(lr){var cr=sr._getStoredProps();if(!cr||cr.sessionId!==lr){var ur={sessionId:lr,props:sr._sessionSourceParamGenerator()};sr._persistence.register(s({},Ne,ur))}}),this._sessionIdManager=or,this._persistence=ir,this._sessionSourceParamGenerator=ar||oi,this._sessionIdManager.onSessionId(this._onSessionIdCallback)}return o(nr,[{key:"_getStoredProps",value:function(){return this._persistence.props[Ne]}},{key:"getSessionProps",value:function(){var or,ir=(or=this._getStoredProps())===null||or===void 0?void 0:or.props;return ir?{$client_session_initial_referring_host:ir.referringDomain,$client_session_initial_pathname:ir.initialPathName,$client_session_initial_utm_source:ir.utm_source,$client_session_initial_utm_campaign:ir.utm_campaign,$client_session_initial_utm_medium:ir.utm_medium,$client_session_initial_utm_content:ir.utm_content,$client_session_initial_utm_term:ir.utm_term}:{}}}]),nr}(),ai=["ahrefsbot","ahrefssiteaudit","applebot","baiduspider","bingbot","bingpreview","bot.htm","bot.php","crawler","duckduckbot","facebookexternal","facebookcatalog","gptbot","http://yandex.com/bots","hubspot","ia_archiver","linkedinbot","mj12bot","msnbot","nessus","petalbot","pinterest","prerender","rogerbot","screaming frog","semrushbot","sitebulb","slurp","turnitin","twitterbot","vercelbot","yahoo! slurp","yandexbot","adsbot-google","apis-google","duplexweb-google","feedfetcher-google","google favicon","google web preview","google-read-aloud","googlebot","googleweblight","mediapartners-google","storebot-google"],ui=function(nr,or){if(!nr)return!1;var ir=nr.toLowerCase();return ai.concat(or||[]).some(function(ar){var sr=ar.toLowerCase();return ir.includes?ir.includes(sr):ir.indexOf(sr)!==-1})};(function(nr){nr[nr.INIT_MODULE=0]="INIT_MODULE",nr[nr.INIT_SNIPPET=1]="INIT_SNIPPET"})(Zn||(Zn={}));var li=function(){},ci={},di="posthog",hi=(T==null?void 0:T.XMLHttpRequest)&&"withCredentials"in new XMLHttpRequest,fi=!hi&&(L==null?void 0:L.indexOf("MSIE"))===-1&&(L==null?void 0:L.indexOf("Mozilla"))===-1,pi=function(){var nr,or,ir;return{api_host:"https://app.posthog.com",api_method:"POST",api_transport:"XHR",ui_host:null,token:"",autocapture:!0,rageclick:!0,cross_subdomain_cookie:(or=D==null?void 0:D.location,ir=or==null?void 0:or.hostname,!!x(ir)&&ir.split(".").slice(-2).join(".")!=="herokuapp.com"),persistence:"localStorage+cookie",persistence_name:"",cookie_name:"",loaded:li,store_google:!0,custom_campaign_params:[],custom_blocked_useragents:[],save_referrer:!0,capture_pageview:!0,capture_pageleave:!0,debug:!1,verbose:!1,cookie_expiration:365,upgrade:!1,disable_session_recording:!1,disable_persistence:!1,disable_cookie:!1,enable_recording_console_log:void 0,secure_cookie:(T==null||(nr=T.location)===null||nr===void 0?void 0:nr.protocol)==="https:",ip:!0,opt_out_capturing_by_default:!1,opt_out_persistence_by_default:!1,opt_out_useragent_filter:!1,opt_out_capturing_persistence_type:"localStorage",opt_out_capturing_cookie_prefix:null,opt_in_site_apps:!1,property_blacklist:[],respect_dnt:!1,sanitize_properties:null,xhr_headers:{},inapp_protocol:"//",inapp_link_new_window:!1,request_batching:!0,properties_string_max_length:65535,session_recording:{},mask_all_element_attributes:!1,mask_all_text:!1,advanced_disable_decide:!1,advanced_disable_feature_flags:!1,advanced_disable_feature_flags_on_first_load:!1,advanced_disable_toolbar_metrics:!1,on_xhr_error:function(ar){var sr="Bad HTTP status: "+ar.status+" "+ar.statusText;j.error(sr)},get_device_id:function(ar){return ar},_onCapture:li,capture_performance:void 0,name:"posthog",callback_fn:"posthog._jsc",bootstrap:{},disable_compression:!1,session_idle_timeout_seconds:1800}},_i=function(nr,or,ir,ar){var sr,lr=ir!==di&&ti?ir?ti[ir]:void 0:ti,cr={initComplete:!1,syncCode:!1},ur=function(dr){return function(fr){cr[dr]||(cr[dr]=!0,cr.initComplete&&cr.syncCode&&(ar==null||ar(fr)))}};if(lr&&ei===Zn.INIT_MODULE)sr=lr;else{if(lr&&!S(lr))return void j.error("You have already initialized "+ir);sr=new vi}return sr._init(nr,or,ir,ur("initComplete")),sr.toolbar.maybeLoadToolbar(),sr.sessionRecording=new Yt(sr),sr.sessionRecording.startRecordingIfEnabled(),sr.config.disable_scroll_properties||sr.pageViewManager.startMeasuringScrollPosition(),sr.__autocapture=sr.config.autocapture,We._setIsAutocaptureEnabled(sr),We._isAutocaptureEnabled&&(sr.__autocapture=sr.config.autocapture,We.enabledForProject(sr.config.token,100,100)?We.isBrowserSupported()?We.init(sr):(sr.__autocapture=!1,j.info("Disabling Automatic Event Collection because this browser is not supported")):(sr.__autocapture=!1,j.info("Not in active bucket: disabling Automatic Event Collection."))),m.DEBUG=m.DEBUG||sr.config.debug,!R(lr)&&S(lr)&&(sr._execute_array.call(sr.people,lr.people),sr._execute_array(lr)),ur("syncCode")(sr),sr},gi=function(){function nr(){i(this,nr),s(this,"__forceAllowLocalhost",!1)}return o(nr,[{key:"_forceAllowLocalhost",get:function(){return this.__forceAllowLocalhost},set:function(or){j.error("WebPerformanceObserver is deprecated and has no impact on network capture. Use `_forceAllowLocalhostNetworkCapture` on `posthog.sessionRecording`"),this.__forceAllowLocalhost=or}}]),nr}(),vi=function(){function nr(){var or=this;i(this,nr),s(this,"webPerformance",new gi),this.config=pi(),this.compression={},this.decideEndpointWasHit=!1,this.SentryIntegration=Jn,this.segmentIntegration=function(){return function(ir){Promise&&Promise.resolve||j.warn("This browser does not have Promise support, and can not use the segment integration");var ar=function(sr,lr){sr.event.userId||sr.event.anonymousId===ir.get_distinct_id()||ir.reset(),sr.event.userId&&sr.event.userId!==ir.get_distinct_id()&&(ir.register({distinct_id:sr.event.userId}),ir.reloadFeatureFlags());var cr=ir._calculate_event_properties(lr,sr.event.properties);return sr.event.properties=Object.assign({},cr,sr.event.properties),sr};return{name:"PostHog JS",type:"enrichment",version:"1.0.0",isLoaded:function(){return!0},load:function(){return Promise.resolve()},track:function(sr){return ar(sr,sr.event.event)},page:function(sr){return ar(sr,"$pageview")},identify:function(sr){return ar(sr,"$identify")},screen:function(sr){return ar(sr,"$screen")}}}(or)},this.__captureHooks=[],this.__request_queue=[],this.__loaded=!1,this.__loaded_recorder_version=void 0,this.__autocapture=void 0,this._jsc=function(){},this.analyticsDefaultEndpoint="/e/",this.elementsChainAsString=!1,this.featureFlags=new Qe(this),this.toolbar=new en(this),this.pageViewManager=new Xn(this),this.surveys=new ii(this),this.rateLimiter=new ri,this.people={set:function(ir,ar,sr){var lr=x(ir)?s({},ir,ar):ir;or.setPersonProperties(lr),sr==null||sr({})},set_once:function(ir,ar,sr){var lr=x(ir)?s({},ir,ar):ir;or.setPersonProperties(void 0,lr),sr==null||sr({})}}}return o(nr,[{key:"init",value:function(or,ir,ar){if(R(ar))j.critical("You must name your new library: init(token, config, name)");else{if(ar!==di){var sr=_i(or,ir,ar,function(lr){ti[ar]=lr,lr._loaded()});return ti[ar]=sr,sr}j.critical("You must initialize the main posthog object right after you include the PostHog js snippet")}}},{key:"_init",value:function(or){var ir,ar,sr,lr=this,cr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ur=arguments.length>2?arguments[2]:void 0,dr=arguments.length>3?arguments[3]:void 0;this.__loaded=!0,this.config={},this._triggered_notifs=[];var fr,pr={segmentRegister:!1,syncCode:!1},hr=function(_r){return function(){pr[_r]||(pr[_r]=!0,pr.segmentRegister&&pr.syncCode&&(dr==null||dr(lr)))}};if(this.set_config(G({},pi(),cr,{name:ur,token:or,callback_fn:(ur===di?ur:di+"."+ur)+"._jsc"})),this._jsc=function(){},(T!=null&&(ir=T.rrweb)!==null&&ir!==void 0&&ir.record||T!=null&&T.rrwebRecord)&&(this.__loaded_recorder_version=T==null||(fr=T.rrweb)===null||fr===void 0?void 0:fr.version),this.persistence=new St(this.config),this._requestQueue=new nn(this._handle_queued_event.bind(this)),this._retryQueue=new zn(this.config.on_xhr_error,this.rateLimiter),this.__captureHooks=[],this.__request_queue=[],this.sessionManager=new Yn(this.config,this.persistence),this.sessionPropsManager=new si(this.sessionManager,this.persistence),this.sessionPersistence=this.config.persistence==="sessionStorage"?this.persistence:new St(t(t({},this.config),{},{persistence:"sessionStorage"})),this._gdpr_init(),cr.segment?(this.config.get_device_id=function(){return cr.segment.user().anonymousId()},cr.segment.user().id()&&(this.register({distinct_id:cr.segment.user().id()}),this.persistence.set_user_state("identified")),cr.segment.register(this.segmentIntegration()).then(hr("segmentRegister"))):hr("segmentRegister")(),((ar=cr.bootstrap)===null||ar===void 0?void 0:ar.distinctID)!==void 0){var gr,vr,br=this.config.get_device_id(tt()),mr=(gr=cr.bootstrap)!==null&&gr!==void 0&&gr.isIdentifiedID?br:cr.bootstrap.distinctID;this.persistence.set_user_state((vr=cr.bootstrap)!==null&&vr!==void 0&&vr.isIdentifiedID?"identified":"anonymous"),this.register({distinct_id:cr.bootstrap.distinctID,$device_id:mr})}if(this._hasBootstrappedFeatureFlags()){var yr,wr,Tr=Object.keys(((yr=cr.bootstrap)===null||yr===void 0?void 0:yr.featureFlags)||{}).filter(function(_r){var jr,Cr;return!((jr=cr.bootstrap)===null||jr===void 0||(Cr=jr.featureFlags)===null||Cr===void 0||!Cr[_r])}).reduce(function(_r,jr){var Cr,Sr;return _r[jr]=((Cr=cr.bootstrap)===null||Cr===void 0||(Sr=Cr.featureFlags)===null||Sr===void 0?void 0:Sr[jr])||!1,_r},{}),Pr=Object.keys(((wr=cr.bootstrap)===null||wr===void 0?void 0:wr.featureFlagPayloads)||{}).filter(function(_r){return Tr[_r]}).reduce(function(_r,jr){var Cr,Sr,Mr,Ur;return(Cr=cr.bootstrap)!==null&&Cr!==void 0&&(Sr=Cr.featureFlagPayloads)!==null&&Sr!==void 0&&Sr[jr]&&(_r[jr]=(Mr=cr.bootstrap)===null||Mr===void 0||(Ur=Mr.featureFlagPayloads)===null||Ur===void 0?void 0:Ur[jr]),_r},{});this.featureFlags.receivedFeatureFlags({featureFlags:Tr,featureFlagPayloads:Pr})}if(!this.get_distinct_id()){var Rr=this.config.get_device_id(tt());this.register_once({distinct_id:Rr,$device_id:Rr},""),this.persistence.set_user_state("anonymous")}T==null||(sr=T.addEventListener)===null||sr===void 0||sr.call(T,"onpagehide"in self?"pagehide":"unload",this._handle_unload.bind(this)),hr("syncCode")()}},{key:"_afterDecideResponse",value:function(or){var ir;if(this.compression={},or.supportedCompression&&!this.config.disable_compression){var ar,sr={},lr=v(or.supportedCompression);try{for(lr.s();!(ar=lr.n()).done;)sr[ar.value]=!0}catch(cr){lr.e(cr)}finally{lr.f()}this.compression=sr}(ir=or.analytics)!==null&&ir!==void 0&&ir.endpoint&&(this.analyticsDefaultEndpoint=or.analytics.endpoint),or.elementsChainAsString&&(this.elementsChainAsString=or.elementsChainAsString)}},{key:"_loaded",value:function(){var or=this.config.advanced_disable_decide;or||this.featureFlags.setReloadingPaused(!0);try{this.config.loaded(this)}catch(ir){j.critical("`loaded` function failed",ir)}this._start_queue_if_opted_in(),this.config.capture_pageview&&D&&this.capture("$pageview",{title:D.title},{send_instantly:!0}),or||(new Jt(this).call(),this.featureFlags.resetRequestQueue())}},{key:"_start_queue_if_opted_in",value:function(){var or;this.has_opted_out_capturing()||this.config.request_batching&&((or=this._requestQueue)===null||or===void 0||or.poll())}},{key:"_dom_loaded",value:function(){var or=this;this.has_opted_out_capturing()||V(this.__request_queue,function(ir){or._send_request.apply(or,p(ir))}),this.__request_queue=[],this._start_queue_if_opted_in()}},{key:"_prepare_callback",value:function(or,ir){if(R(or))return null;if(hi)return function(cr){or(cr,ir)};var ar=this._jsc,sr=""+Math.floor(1e8*Math.random()),lr=this.config.callback_fn+"["+sr+"]";return ar[sr]=function(cr){delete ar[sr],or(cr,ir)},lr}},{key:"_handle_unload",value:function(){var or,ir;this.config.request_batching?(this.config.capture_pageview&&this.config.capture_pageleave&&this.capture("$pageleave"),(or=this._requestQueue)===null||or===void 0||or.unload(),(ir=this._retryQueue)===null||ir===void 0||ir.unload()):this.config.capture_pageview&&this.config.capture_pageleave&&this.capture("$pageleave",null,{transport:"sendBeacon"})}},{key:"_handle_queued_event",value:function(or,ir,ar){var sr=JSON.stringify(ir);this.__compress_and_send_json_request(or,sr,ar||ci,li)}},{key:"__compress_and_send_json_request",value:function(or,ir,ar,sr){var lr=function(fr,pr,hr){return fr===kn.GZipJS?[Hn(Wn(pr),{mtime:0}),t(t({},hr),{},{blob:!0,urlQueryArgs:{compression:kn.GZipJS}})]:[{data:te(pr)},hr]}(this.compression[kn.GZipJS]?kn.GZipJS:kn.Base64,ir,ar),cr=f(lr,2),ur=cr[0],dr=cr[1];this._send_request(or,ur,dr,sr)}},{key:"_send_request",value:function(or,ir,ar,sr){if(this.__loaded&&this._retryQueue&&!this.rateLimiter.isRateLimited(ar._batchKey))if(fi)this.__request_queue.push([or,ir,ar,sr]);else{var lr={method:this.config.api_method,transport:this.config.api_transport,verbose:this.config.verbose};ar=G(lr,ar||{}),hi||(ar.method="GET");var cr=T&&"sendBeacon"in T.navigator&&ar.transport==="sendBeacon";if(or=Vn(or,ar.urlQueryArgs||{},{ip:this.config.ip}),cr)try{T==null||T.navigator.sendBeacon(or,Un(ir,t(t({},ar),{},{sendBeacon:!0})))}catch{}else if(hi||!D)try{Gn({url:or,data:ir,headers:this.config.xhr_headers,options:ar,callback:sr,retriesPerformedSoFar:0,retryQueue:this._retryQueue,onXHRError:this.config.on_xhr_error,onResponse:this.rateLimiter.checkForLimiting})}catch(pr){j.error(pr)}else{var ur,dr=D.createElement("script");dr.type="text/javascript",dr.async=!0,dr.defer=!0,dr.src=or;var fr=D.getElementsByTagName("script")[0];(ur=fr.parentNode)===null||ur===void 0||ur.insertBefore(dr,fr)}}}},{key:"_execute_array",value:function(or){var ir,ar=this,sr=[],lr=[],cr=[];V(or,function(dr){dr&&(ir=dr[0],S(ir)?cr.push(dr):P(dr)?dr.call(ar):S(dr)&&ir==="alias"?sr.push(dr):S(dr)&&ir.indexOf("capture")!==-1&&P(ar[ir])?cr.push(dr):lr.push(dr))});var ur=function(dr,fr){V(dr,function(pr){if(S(pr[0])){var hr=fr;U(pr,function(gr){hr=hr[gr[0]].apply(hr,gr.slice(1))})}else this[pr[0]].apply(this,pr.slice(1))},fr)};ur(sr,this),ur(lr,this),ur(cr,this)}},{key:"_hasBootstrappedFeatureFlags",value:function(){var or,ir;return((or=this.config.bootstrap)===null||or===void 0?void 0:or.featureFlags)&&Object.keys((ir=this.config.bootstrap)===null||ir===void 0?void 0:ir.featureFlags).length>0||!1}},{key:"push",value:function(or){this._execute_array([or])}},{key:"capture",value:function(or,ir){var ar=arguments.length>2&&arguments[2]!==void 0?arguments[2]:ci;if(!this.__loaded||!this.sessionPersistence||!this._requestQueue)return j.uninitializedWarning("posthog.capture");if(!Wt(this)){var sr=(ar=ar||ci).transport;if(sr&&(ar.transport=sr),!R(or)&&x(or)){if(!L||this.config.opt_out_useragent_filter||!ui(L,this.config.custom_blocked_useragents)){this.sessionPersistence.update_search_keyword(),this.config.store_google&&this.sessionPersistence.update_campaign_params(),this.config.save_referrer&&this.sessionPersistence.update_referrer_info();var lr={uuid:tt(),event:or,properties:this._calculate_event_properties(or,ir||{})};or==="$identify"&&(lr.$set=ar.$set,lr.$set_once=ar.$set_once),(lr=ee(lr,ar._noTruncate?null:this.config.properties_string_max_length)).timestamp=ar.timestamp||new Date;var cr=t(t({},lr.properties.$set),lr.$set);(function(pr){if(I(pr)){for(var hr in pr)if(k.call(pr,hr))return!1;return!0}return!1})(cr)||this.setPersonPropertiesForFlags(cr),j.info("send",lr);var ur=JSON.stringify(lr),dr=this.config.api_host+(ar.endpoint||this.analyticsDefaultEndpoint),fr=ar!==ci;return!this.config.request_batching||fr&&!ar._batchKey||ar.send_instantly?this.__compress_and_send_json_request(dr,ur,ar):this._requestQueue.enqueue(dr,lr,ar),this._invokeCaptureHooks(or,lr),lr}}else j.error("No event name provided to posthog.capture")}}},{key:"_addCaptureHook",value:function(or){this.__captureHooks.push(or)}},{key:"_invokeCaptureHooks",value:function(or,ir){this.config._onCapture(or,ir),U(this.__captureHooks,function(ar){return ar(or)})}},{key:"_calculate_event_properties",value:function(or,ir){if(!this.persistence||!this.sessionPersistence)return ir;var ar=this.persistence.remove_event_timer(or),sr=t({},ir);if(sr.token=this.config.token,or==="$snapshot"){var lr=t(t({},this.persistence.properties()),this.sessionPersistence.properties());return sr.distinct_id=lr.distinct_id,sr}var cr=kt.properties();if(this.sessionManager){var ur=this.sessionManager.checkAndGetSessionAndWindowId(),dr=ur.sessionId,fr=ur.windowId;sr.$session_id=dr,sr.$window_id=fr}if(this.sessionPropsManager&&this.config.__preview_send_client_session_params&&(or==="$pageview"||or==="$pageleave"||or==="$autocapture")){var pr=this.sessionPropsManager.getSessionProps();sr=G(sr,pr)}if(!this.config.disable_scroll_properties){var hr={};or==="$pageview"?hr=this.pageViewManager.doPageView():or==="$pageleave"&&(hr=this.pageViewManager.doPageLeave()),sr=G(sr,hr)}if(or==="$pageview"&&D&&(sr.title=D.title),or==="$performance_event"){var gr=this.persistence.properties();return sr.distinct_id=gr.distinct_id,sr.$current_url=cr.$current_url,sr}if(!R(ar)){var vr=new Date().getTime()-ar;sr.$duration=parseFloat((vr/1e3).toFixed(3))}L&&this.config.opt_out_useragent_filter&&(sr.$browser_type=ui(L,this.config.custom_blocked_useragents)?"bot":"browser"),sr=G({},kt.properties(),this.persistence.properties(),this.sessionPersistence.properties(),sr);var br=this.config.property_blacklist;S(br)?U(br,function(yr){delete sr[yr]}):j.error("Invalid value for property_blacklist config: "+br);var mr=this.config.sanitize_properties;return mr&&(sr=mr(sr,or)),sr}},{key:"register",value:function(or,ir){var ar;(ar=this.persistence)===null||ar===void 0||ar.register(or,ir)}},{key:"register_once",value:function(or,ir,ar){var sr;(sr=this.persistence)===null||sr===void 0||sr.register_once(or,ir,ar)}},{key:"register_for_session",value:function(or){var ir;(ir=this.sessionPersistence)===null||ir===void 0||ir.register(or)}},{key:"unregister",value:function(or){var ir;(ir=this.persistence)===null||ir===void 0||ir.unregister(or)}},{key:"unregister_for_session",value:function(or){var ir;(ir=this.sessionPersistence)===null||ir===void 0||ir.unregister(or)}},{key:"_register_single",value:function(or,ir){this.register(s({},or,ir))}},{key:"getFeatureFlag",value:function(or,ir){return this.featureFlags.getFeatureFlag(or,ir)}},{key:"getFeatureFlagPayload",value:function(or){var ir=this.featureFlags.getFeatureFlagPayload(or);try{return JSON.parse(ir)}catch{return ir}}},{key:"isFeatureEnabled",value:function(or,ir){return this.featureFlags.isFeatureEnabled(or,ir)}},{key:"reloadFeatureFlags",value:function(){this.featureFlags.reloadFeatureFlags()}},{key:"updateEarlyAccessFeatureEnrollment",value:function(or,ir){this.featureFlags.updateEarlyAccessFeatureEnrollment(or,ir)}},{key:"getEarlyAccessFeatures",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.featureFlags.getEarlyAccessFeatures(or,ir)}},{key:"onFeatureFlags",value:function(or){return this.featureFlags.onFeatureFlags(or)}},{key:"onSessionId",value:function(or){var ir,ar;return(ir=(ar=this.sessionManager)===null||ar===void 0?void 0:ar.onSessionId(or))!==null&&ir!==void 0?ir:function(){}}},{key:"getSurveys",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0&&arguments[1];this.surveys.getSurveys(or,ir)}},{key:"getActiveMatchingSurveys",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0&&arguments[1];this.surveys.getActiveMatchingSurveys(or,ir)}},{key:"identify",value:function(or,ir,ar){if(!this.__loaded||!this.persistence)return j.uninitializedWarning("posthog.identify");if(or)if(["distinct_id","distinctid"].includes(or.toLowerCase()))j.critical('The string "'.concat(or,'" was set in posthog.identify which indicates an error. This ID should be unique to the user and not a hardcoded string.'));else{var sr=this.get_distinct_id();if(this.register({$user_id:or}),!this.get_property("$device_id")){var lr=sr;this.register_once({$had_persisted_distinct_id:!0,$device_id:lr},"")}or!==sr&&or!==this.get_property(Se)&&(this.unregister(Se),this.register({distinct_id:or}));var cr=this.persistence.get_user_state()==="anonymous";or!==sr&&cr?(this.persistence.set_user_state("identified"),this.setPersonPropertiesForFlags(ir||{},!1),this.capture("$identify",{distinct_id:or,$anon_distinct_id:sr},{$set:ir||{},$set_once:ar||{}}),this.featureFlags.setAnonymousDistinctId(sr)):(ir||ar)&&this.setPersonProperties(ir,ar),or!==sr&&(this.reloadFeatureFlags(),this.unregister(De))}else j.error("Unique user id has not been set in posthog.identify")}},{key:"setPersonProperties",value:function(or,ir){(or||ir)&&(this.setPersonPropertiesForFlags(or||{}),this.capture("$set",{$set:or||{},$set_once:ir||{}}))}},{key:"group",value:function(or,ir,ar){if(or&&ir){var sr=this.getGroups();sr[or]!==ir&&this.resetGroupPropertiesForFlags(or),this.register({$groups:t(t({},sr),{},s({},or,ir))}),ar&&(this.capture("$groupidentify",{$group_type:or,$group_key:ir,$group_set:ar}),this.setGroupPropertiesForFlags(s({},or,ar))),sr[or]===ir||ar||this.reloadFeatureFlags()}else j.error("posthog.group requires a group type and group key")}},{key:"resetGroups",value:function(){this.register({$groups:{}}),this.resetGroupPropertiesForFlags(),this.reloadFeatureFlags()}},{key:"setPersonPropertiesForFlags",value:function(or){var ir=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];this.featureFlags.setPersonPropertiesForFlags(or,ir)}},{key:"resetPersonPropertiesForFlags",value:function(){this.featureFlags.resetPersonPropertiesForFlags()}},{key:"setGroupPropertiesForFlags",value:function(or){var ir=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];this.featureFlags.setGroupPropertiesForFlags(or,ir)}},{key:"resetGroupPropertiesForFlags",value:function(or){this.featureFlags.resetGroupPropertiesForFlags(or)}},{key:"reset",value:function(or){var ir,ar,sr,lr;if(!this.__loaded)return j.uninitializedWarning("posthog.reset");var cr=this.get_property("$device_id");(ir=this.persistence)===null||ir===void 0||ir.clear(),(ar=this.sessionPersistence)===null||ar===void 0||ar.clear(),(sr=this.persistence)===null||sr===void 0||sr.set_user_state("anonymous"),(lr=this.sessionManager)===null||lr===void 0||lr.resetSessionId();var ur=this.config.get_device_id(tt());this.register_once({distinct_id:ur,$device_id:or?ur:cr},"")}},{key:"get_distinct_id",value:function(){return this.get_property("distinct_id")}},{key:"getGroups",value:function(){return this.get_property("$groups")||{}}},{key:"get_session_id",value:function(){var or,ir;return(or=(ir=this.sessionManager)===null||ir===void 0?void 0:ir.checkAndGetSessionAndWindowId(!0).sessionId)!==null&&or!==void 0?or:""}},{key:"get_session_replay_url",value:function(or){if(!this.sessionManager)return"";var ir=this.config.ui_host||this.config.api_host,ar=this.sessionManager.checkAndGetSessionAndWindowId(!0),sr=ar.sessionId,lr=ar.sessionStartTimestamp,cr=ir+"/replay/"+sr;if(or!=null&&or.withTimestamp&&lr){var ur,dr=(ur=or.timestampLookBack)!==null&&ur!==void 0?ur:10;if(!lr)return cr;var fr=Math.max(Math.floor((new Date().getTime()-lr)/1e3)-dr,0);cr+="?t=".concat(fr)}return cr}},{key:"alias",value:function(or,ir){return or===this.get_property(we)?(j.critical("Attempting to create alias for existing People user - aborting."),-2):(R(ir)&&(ir=this.get_distinct_id()),or!==ir?(this._register_single(Se,or),this.capture("$create_alias",{alias:or,distinct_id:ir})):(j.warn("alias matches current distinct_id - skipping api call."),this.identify(or),-1))}},{key:"set_config",value:function(or){var ir,ar,sr=t({},this.config);if(I(or)&&(G(this.config,or),this.config.persistence_name||(this.config.persistence_name=this.config.cookie_name),this.config.disable_persistence||(this.config.disable_persistence=this.config.disable_cookie),this.config.api_host=this.config.api_host.replace(/\/$/,""),this.config.api_host==="https://us.posthog.com"&&(this.config.api_host="https://app.posthog.com"),(ir=this.persistence)===null||ir===void 0||ir.update_config(this.config),(ar=this.sessionPersistence)===null||ar===void 0||ar.update_config(this.config),lt.is_supported()&&lt.get("ph_debug")==="true"&&(this.config.debug=!0),this.config.debug&&(m.DEBUG=!0),this.sessionRecording&&!R(or.disable_session_recording))){var lr=sr.disable_session_recording!==or.disable_session_recording,cr=!Wt(this)&&!or.disable_session_recording&&!this.sessionRecording.started;(lr||cr)&&(or.disable_session_recording?this.sessionRecording.stopRecording():this.sessionRecording.startRecordingIfEnabled())}}},{key:"startSessionRecording",value:function(){this.set_config({disable_session_recording:!1})}},{key:"stopSessionRecording",value:function(){this.set_config({disable_session_recording:!0})}},{key:"sessionRecordingStarted",value:function(){var or;return!((or=this.sessionRecording)===null||or===void 0||!or.started)}},{key:"loadToolbar",value:function(or){return this.toolbar.loadToolbar(or)}},{key:"get_property",value:function(or){var ir;return(ir=this.persistence)===null||ir===void 0?void 0:ir.props[or]}},{key:"getSessionProperty",value:function(or){var ir;return(ir=this.sessionPersistence)===null||ir===void 0?void 0:ir.props[or]}},{key:"toString",value:function(){var or,ir=(or=this.config.name)!==null&&or!==void 0?or:di;return ir!==di&&(ir=di+"."+ir),ir}},{key:"_gdpr_init",value:function(){this.config.opt_out_capturing_persistence_type==="localStorage"&&lt.is_supported()&&(!this.has_opted_in_capturing()&&this.has_opted_in_capturing({persistence_type:"cookie"})&&this.opt_in_capturing({enable_persistence:!1}),!this.has_opted_out_capturing()&&this.has_opted_out_capturing({persistence_type:"cookie"})&&this.opt_out_capturing({clear_persistence:!1}),this.clear_opt_in_out_capturing({persistence_type:"cookie",enable_persistence:!1})),this.has_opted_out_capturing()?this._gdpr_update_persistence({clear_persistence:!0}):this.has_opted_in_capturing()||!this.config.opt_out_capturing_by_default&&!at.get("ph_optout")||(at.remove("ph_optout"),this.opt_out_capturing({clear_persistence:this.config.opt_out_persistence_by_default}))}},{key:"_gdpr_update_persistence",value:function(or){var ir,ar,sr,lr,cr;if(or&&or.clear_persistence)sr=!0;else{if(!or||!or.enable_persistence)return;sr=!1}this.config.disable_persistence||((ir=this.persistence)===null||ir===void 0?void 0:ir.disabled)===sr||(lr=this.persistence)===null||lr===void 0||lr.set_disabled(sr),this.config.disable_persistence||((ar=this.sessionPersistence)===null||ar===void 0?void 0:ar.disabled)===sr||(cr=this.sessionPersistence)===null||cr===void 0||cr.set_disabled(sr)}},{key:"_gdpr_call_func",value:function(or,ir){return ir=G({capture:this.capture.bind(this),persistence_type:this.config.opt_out_capturing_persistence_type,cookie_prefix:this.config.opt_out_capturing_cookie_prefix,cookie_expiration:this.config.cookie_expiration,cross_subdomain_cookie:this.config.cross_subdomain_cookie,secure_cookie:this.config.secure_cookie},ir||{}),lt.is_supported()||ir.persistence_type!=="localStorage"||(ir.persistence_type="cookie"),or(this.config.token,{capture:ir.capture,captureEventName:ir.capture_event_name,captureProperties:ir.capture_properties,persistenceType:ir.persistence_type,persistencePrefix:ir.cookie_prefix,cookieExpiration:ir.cookie_expiration,crossSubdomainCookie:ir.cross_subdomain_cookie,secureCookie:ir.secure_cookie})}},{key:"opt_in_capturing",value:function(or){or=G({enable_persistence:!0},or||{}),this._gdpr_call_func(Mt,or),this._gdpr_update_persistence(or)}},{key:"opt_out_capturing",value:function(or){var ir=G({clear_persistence:!0},or||{});this._gdpr_call_func(Tt,ir),this._gdpr_update_persistence(ir)}},{key:"has_opted_in_capturing",value:function(or){return this._gdpr_call_func(qt,or)}},{key:"has_opted_out_capturing",value:function(or){return this._gdpr_call_func(Dt,or)}},{key:"clear_opt_in_out_capturing",value:function(or){var ir=G({enable_persistence:!0},or??{});this._gdpr_call_func(Lt,ir),this._gdpr_update_persistence(ir)}},{key:"debug",value:function(or){or===!1?(T==null||T.console.log("You've disabled debug mode."),localStorage&&localStorage.removeItem("ph_debug"),this.set_config({debug:!1})):(T==null||T.console.log("You're now in debug mode. All calls to PostHog will be logged in your console.\nYou can disable this with `posthog.debug(false)`."),localStorage&&localStorage.setItem("ph_debug","true"),this.set_config({debug:!0}))}}]),nr}();(function(nr,or){for(var ir=0;ir<or.length;ir++)nr.prototype[or[ir]]=X(nr.prototype[or[ir]])})(vi,["identify"]);var mi,yi,bi={},ki=function(){ti.init=function(nr,or,ir){if(ir)return ti[ir]||(ti[ir]=bi[ir]=_i(nr||"",or||{},ir,function(sr){ti[ir]=bi[ir]=sr,sr._loaded()})),ti[ir];var ar=ti;return bi[di]?ar=bi[di]:nr&&(ar=_i(nr,or||{},di,function(sr){bi[di]=sr,sr._loaded()}),bi[di]=ar),ti=ar,ei===Zn.INIT_SNIPPET&&(B[di]=ti),U(bi,function(sr,lr){lr!==di&&(ti[lr]=sr)}),ar}};(function(nr){nr.Popover="popover",nr.API="api",nr.Widget="widget"})(mi||(mi={})),function(nr){nr.Open="open",nr.MultipleChoice="multiple_choice",nr.SingleChoice="single_choice",nr.Rating="rating",nr.Link="link"}(yi||(yi={}));var wi=(ei=Zn.INIT_MODULE,ti=new vi,ki(),ti.init(),function(){function nr(){nr.done||(nr.done=!0,fi=!1,U(bi,function(or){or._dom_loaded()}))}D!=null&&D.addEventListener&&(D.readyState==="complete"?nr():D.addEventListener("DOMContentLoaded",nr,!1)),T&&ie(T,"load",nr,!0)}(),ti);const sessionContext=React$1.createContext({token:"",entityId:"",entity:void 0,user:void 0,users:[],selectedInvoice:void 0,setSelectedInvoice:()=>{},client:void 0,refresh:()=>{},refreshId:0,organization:void 0,moov:void 0,moovToken:void 0,moovAccountId:void 0,iframeOptions:void 0,setIframeOptions:()=>{},getNewToken:nr=>{},googleMapsApiKey:void 0});function MercoaSession({children:nr,entityId:or,entityUserId:ir,token:ar,endpoint:sr,isAdmin:lr,googleMapsApiKey:cr}){return jsx(sessionContext.Provider,{value:useProvideSession({token:ar,entityId:or,entityUserId:ir,endpoint:sr,isAdmin:lr,googleMapsApiKey:cr}),children:nr||jsx(EntityPortal,{token:ar})})}const useMercoaSession=()=>React$1.useContext(sessionContext);function useProvideSession({token:nr,entityId:or,entityUserId:ir,endpoint:ar,isAdmin:sr,googleMapsApiKey:lr}){var fo;const[cr,ur]=React$1.useState(),[dr,fr]=React$1.useState(),[pr,hr]=React$1.useState([]),[gr,vr]=React$1.useState(),[br,mr]=React$1.useState(),[yr,wr]=React$1.useState(0),[Tr,Pr]=React$1.useState(),[Rr,_r]=React$1.useState(),[jr,Cr]=React$1.useState(),[Sr,Mr]=React$1.useState(nr),[Ur,kr]=React$1.useState(),Ir=React$1.useMemo(()=>new javascript.MercoaClient({environment:ar??"https://api.mercoa.com",token:Sr}),[Sr]);async function qr(){if(!nr)return;let bo=or;if(!bo)try{const{entityId:go}=jwtDecode(String(nr));bo=go}catch(go){console.error(go)}if(bo!=="undefined"&&(Ir.organization.get({paymentMethods:!0,emailProvider:!0,colorScheme:!0,payeeOnboardingOptions:!0,payorOnboardingOptions:!0,metadataSchema:!0}).then(go=>{mr(go)}),bo!=="all"&&bo)){Ir.entity.get(bo).then(mo=>{ur(mo),wr(Math.random())});let go=ir;if(!go)try{const{userId:mo}=jwtDecode(String(nr));go=mo}catch(mo){console.error(mo)}go&&Ir.entity.user.get(bo,go).then(mo=>{fr(mo)}),Ir.entity.user.getAll(bo).then(mo=>{hr(mo)}),!Tr&&!sr&&Ir.entity.getToken(bo,{}).then(async mo=>{Mr(mo);const{moov:Br}=jwtDecode(String(mo));if(_r(Br.accountId),Cr(Br.token),!(!Br||!Br.token||Br.token==="sandbox"))try{const Gr=await loadMoov(Br.token);Gr&&Pr(Gr)}catch(Gr){console.error(Gr)}})}}async function Vr(bo){const go=Ur||{options:{expiresIn:bo??"12hr"}};if(go.options||(go.options={}),go.options.expiresIn=bo??"12hr",!(cr!=null&&cr.id))return;let mo="";dr!=null&&dr.id?mo=await Ir.entity.user.getToken(cr.id,dr.id,{...go.options}):mo=await Ir.entity.getToken(cr.id,{...go.options}),Mr(mo)}return React$1.useEffect(()=>{var Fr,Or,xr,zr,Ar;const bo=($r,Er)=>{$r=$r.replace(/^#/,""),$r.length===3&&($r=$r[0]+$r[0]+$r[1]+$r[1]+$r[2]+$r[2]);let[Dr,Wr,Nr]=$r.match(/.{2}/g);[Dr,Wr,Nr]=[parseInt(Dr,16)+Er,parseInt(Wr,16)+Er,parseInt(Nr,16)+Er],Dr=Math.max(Math.min(255,Dr),0).toString(16),Wr=Math.max(Math.min(255,Wr),0).toString(16),Nr=Math.max(Math.min(255,Nr),0).toString(16);const Hr=(Dr.length<2?"0":"")+Dr,yo=(Wr.length<2?"0":"")+Wr,_o=(Nr.length<2?"0":"")+Nr;return`#${Hr}${yo}${_o}`},go=((Fr=br==null?void 0:br.colorScheme)==null?void 0:Fr.primaryColor)||"#4f46e5",mo=(Or=br==null?void 0:br.colorScheme)!=null&&Or.primaryColor?bo((xr=br==null?void 0:br.colorScheme)==null?void 0:xr.primaryColor,40):"#6366f1",Br=(zr=br==null?void 0:br.colorScheme)!=null&&zr.primaryColor?bo((Ar=br==null?void 0:br.colorScheme)==null?void 0:Ar.primaryColor,-40):"#4338ca";let Gr=go,Qr="#ffffff";go==="#f8fafc"&&(Gr="#111827",Qr="#111827"),document.documentElement.style.setProperty("--mercoa-primary",go),document.documentElement.style.setProperty("--mercoa-primary-light",mo),document.documentElement.style.setProperty("--mercoa-primary-dark",Br),document.documentElement.style.setProperty("--mercoa-primary-text",Gr),document.documentElement.style.setProperty("--mercoa-primary-text-invert",Qr)},[(fo=br==null?void 0:br.colorScheme)==null?void 0:fo.primaryColor]),React$1.useEffect(()=>{qr()},[nr,or]),React$1.useEffect(()=>{dr!=null&&dr.id?wi.identify(cr==null?void 0:cr.id,{email:dr==null?void 0:dr.email}):wi.identify(cr==null?void 0:cr.id,{email:cr==null?void 0:cr.email})},[dr]),{refresh:qr,refreshId:yr,token:nr,entityId:or??(cr==null?void 0:cr.id),entity:cr,user:dr,users:pr,selectedInvoice:gr,setSelectedInvoice:vr,client:Ir,organization:br,moov:Tr,moovAccountId:Rr,moovToken:jr,iframeOptions:Ur,setIframeOptions:kr,getNewToken:Vr,googleMapsApiKey:lr}}dayjs$1.extend(relativeTime);function InvoiceComments({invoice:nr}){var gr;const or=useMercoaSession(),[ir,ar]=React$1.useState((nr==null?void 0:nr.comments)??[]),{register:sr,handleSubmit:lr,setValue:cr}=useForm({defaultValues:{type:"comment",text:""}});function ur({type:vr,text:br}){var mr,yr,wr;if(!((mr=or.user)!=null&&mr.id)){Q$2.error("Please login as a user to comment");return}!or.token||!(nr!=null&&nr.id)||br&&vr==="comment"&&((wr=or.client)==null||wr.invoice.comment.create(nr.id,{text:br,userId:(yr=or.user)==null?void 0:yr.id}).then(Tr=>{Tr&&(console.log(Tr),ar([...ir,Tr]),cr("text",""))}))}function dr(vr){let br=jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-gray-100 ring-1 ring-gray-300"});return vr.action==="APPROVE"?br=jsx(CheckCircleIcon$1,{className:"h-6 w-6 text-green-600","aria-hidden":"true"}):vr.action==="REJECT"&&(br=jsx(XCircleIcon$1,{className:"h-6 w-6 text-red-600","aria-hidden":"true"})),br}const fr={APPROVE:"approved",REJECT:"rejected",NONE:"created"},pr=ir.filter(vr=>vr.text||vr.associatedApprovalAction),hr={id:(nr==null?void 0:nr.id)??"",createdAt:(nr==null?void 0:nr.createdAt)??"",user:(nr==null?void 0:nr.creatorUser)??{id:"",name:"Email"},text:"",associatedApprovalAction:{action:javascript.Mercoa.ApproverAction.None,userId:((gr=nr==null?void 0:nr.creatorUser)==null?void 0:gr.id)??""}};return jsxs(Fragment,{children:[jsx("ul",{role:"list",className:"space-y-6 ml-1",children:[hr,...pr].map((vr,br)=>{var mr,yr;return jsxs("li",{className:"relative flex gap-x-4",children:[jsx("div",{className:`${br===pr.length?"h-6":"-bottom-6"} absolute left-0 top-0 flex w-6 justify-center`,children:jsx("div",{className:"w-px bg-gray-200"})}),vr.text&&jsxs(Fragment,{children:[jsx(UserIcon$1,{className:"h-8 w-8 text-gray-300 mt-3 text-gray-300 bg-gray-100 rounded-full p-1 -ml-1"}),jsxs("div",{className:"flex-auto rounded-md p-3 ring-1 ring-inset ring-gray-200",children:[jsxs("div",{className:"flex justify-between gap-x-4",children:[jsxs("div",{className:"py-0.5 text-xs leading-5 text-gray-500",children:[jsx("span",{className:"font-medium text-gray-900",children:(mr=vr.user)==null?void 0:mr.name})," commented"]}),jsx("time",{dateTime:dayjs$1(vr.createdAt).toISOString(),className:"flex-none py-0.5 text-xs leading-5 text-gray-500",children:dayjs$1(vr.createdAt).fromNow()})]}),jsx("p",{className:"text-sm leading-6 text-gray-500",children:vr.text})]})]}),vr.associatedApprovalAction&&jsxs(Fragment,{children:[jsx("div",{className:"relative flex h-6 w-6 flex-none items-center justify-center bg-white",children:dr(vr.associatedApprovalAction)}),jsxs("p",{className:"flex-auto py-0.5 text-xs leading-5 text-gray-500",children:[jsx("span",{className:"font-medium text-gray-900",children:(yr=vr.user)==null?void 0:yr.name})," ",fr[vr.associatedApprovalAction.action]," the invoice."]}),jsx("time",{dateTime:dayjs$1(vr.createdAt).toISOString(),className:"flex-none py-0.5 text-xs leading-5 text-gray-500",children:dayjs$1(vr.createdAt).fromNow()})]})]},vr.id)})}),jsx("div",{className:"mt-6 flex gap-x-3",children:jsxs("form",{onSubmit:lr(ur),className:"relative flex-auto",children:[jsxs("div",{className:"overflow-hidden rounded-lg pb-12 shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-indigo-600",children:[jsx("label",{htmlFor:"comment",className:"sr-only",children:"Add your comment"}),jsx("textarea",{rows:2,...sr("text"),className:"block w-full resize-none border-0 bg-transparent py-1.5 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6",placeholder:"Add your comment..."})]}),jsxs("div",{className:"absolute inset-x-0 bottom-0 flex justify-between py-2 pl-3 pr-2",children:[jsx("div",{}),jsx("button",{type:"submit",className:"rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50",children:"Comment"})]})]})})]})}const dJSON=require("dirty-json");dayjs$1.extend(minMax);function classNames(...nr){return nr.filter(Boolean).join(" ")}function InvoiceDetails({invoiceId:nr,invoice:or,onRedirect:ir,addPaymentMethodRedirect:ar,children:sr}){var kr;const lr=useMercoaSession(),[cr,ur]=React$1.useState(),[dr,fr]=React$1.useState(),[pr,hr]=React$1.useState(),[gr,vr]=React$1.useState(!1),[br,mr]=React$1.useState(or),[yr,wr]=React$1.useState(),[Tr,Pr]=React$1.useState(typeof window<"u"?window.innerHeight-70:0),[Rr,_r]=React$1.useState(!1);async function jr(Ir){var Vr,fo;if(!lr.token||!((Vr=lr.entity)!=null&&Vr.id))return;const qr=await((fo=lr.client)==null?void 0:fo.invoice.get(Ir));qr&&mr(qr)}async function Cr(Ir){var Vr,fo;if(!lr.token||!((Vr=lr.entity)!=null&&Vr.id))return;const qr=await((fo=lr.client)==null?void 0:fo.ocr.getAsyncOcr(Ir));qr&&qr.status===javascript.Mercoa.OcrJobStatus.Success?(fr(qr.data),vr(!1)):qr&&qr.status===javascript.Mercoa.OcrJobStatus.Failed?(Q$2.error("OCR failed"),vr(!1)):setTimeout(()=>Cr(Ir),5e3)}async function Sr(Ir,qr){var Vr;ur({fileReaderObj:Ir,mimeType:qr.type}),hr(Ir),vr(!0);try{const fo=await((Vr=lr.client)==null?void 0:Vr.ocr.runAsyncOcr({entityId:lr.entityId,image:Ir,mimeType:qr.type}));fo?Cr(fo==null?void 0:fo.jobId):(Q$2.error("OCR failed"),vr(!1))}catch(fo){console.log(fo),Q$2.error("OCR failed"),vr(!1)}}React$1.useEffect(()=>{var Ir;!lr.token||!((Ir=lr.entity)!=null&&Ir.id)||!or&&nr&&jr(nr)},[or,nr,lr.token,(kr=lr.entity)==null?void 0:kr.id]);function Mr(){Pr(window.innerHeight-70)}React$1.useEffect(()=>(Mr(),window.addEventListener("resize",Mr,!1),()=>{window.removeEventListener("resize",Mr)}),[]),React$1.useEffect(()=>{var Ir;br&&br.hasDocuments&&((Ir=lr.client)==null||Ir.invoice.document.getAll(br.id).then(qr=>{var Vr,fo;qr&&qr.length>0&&(wr(qr),ur({fileReaderObj:(Vr=qr==null?void 0:qr[0])==null?void 0:Vr.uri,mimeType:(fo=qr==null?void 0:qr[0])==null?void 0:fo.mimeType}))}))},[br]);const Ur=jsx("div",{className:"min-w-[300px] mr-5",children:cr?jsxs(Fragment,{children:[jsxs("div",{className:`text-center ${gr?"block mb-5":"hidden"}`,children:[jsx("span",{className:"text-gray-800 w-full",children:" Extracting Invoice Details "}),jsx(ProgressBar,{})]}),jsx(InvoiceDocuments,{documents:new Array(cr),height:Tr})]}):jsx(InvoiceDocumentsUpload,{onFileUpload:Sr})});return sr?jsx(Fragment,{children:sr({invoice:br,documents:yr})}):br?jsxs(X$3,{children:[jsx(_$3,{minSize:0,children:Ur}),jsx(ne$1,{size:5,className:"bg-gray-200 cursor-ew-resize invisible min-[450px]:visible",children:jsx("div",{className:"w-3 h-10 bg-gray-500 absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"})}),jsxs(_$3,{className:"pl-5 relative",minSize:400,children:[jsx("div",{className:"flex w-full flex-row-reverse visible min-[450px]:invisible absolute top-2",children:jsxs(MercoaButton,{isEmphasized:!0,size:"sm",type:"button",onClick:()=>{_r(!Rr)},className:"mr-7 z-20",children:["View ",Rr?"Form":"Invoice"]})}),Rr?jsx("div",{className:"mt-20",children:Ur}):jsx(EditInvoiceForm,{invoice:br,ocrResponse:dr,uploadedImage:pr,setUploadedImage:hr,onRedirect:ir,refreshInvoice:jr,addPaymentMethodRedirect:ar,height:Tr})]})]}):jsx(LoadingSpinner,{})}function InvoiceDocumentsUpload({onFileUpload:nr}){const or=ir=>new Promise((ar,sr)=>{const lr=new FileReader;lr.onload=()=>ar(String(lr.result)),lr.onerror=sr,lr.readAsDataURL(ir)});return jsx(Dropzone$1,{onDropAccepted:ir=>{or(ir[0]).then(ar=>{nr(ar,ir[0])})},onDropRejected:()=>{Q$2.error("Invalid file type")},minSize:0,maxSize:1e7,accept:{"application/pdf":[".pdf"],"image/png":[".png"],"image/gif":[".gif"],"image/tiff":[".tif",".tiff"],"image/jpeg":[".jpeg",".jpg"],"image/bmp":[".bmp"],"image/webp":[".webp"]},children:({getRootProps:ir,getInputProps:ar,isDragActive:sr})=>jsx("div",{className:`mt-2 flex justify-center rounded-lg border border-dashed border-gray-900/25 ${sr?"border-mercoa-primary":"border-gray-300"} px-6 py-10`,...ir(),children:jsxs("div",{className:"text-center",children:[jsx(PhotoIcon$1,{className:"mx-auto h-12 w-12 text-gray-300","aria-hidden":"true"}),jsxs("div",{className:"mt-4 flex text-sm text-gray-600",children:[jsxs("label",{htmlFor:"file-upload",className:"relative cursor-pointer rounded-md bg-white font-semibold text-mercoa-primary focus-within:outline-none focus-within:ring-2 focus-within:ring-mercoa-primary focus-within:ring-offset-2 hover:text-indigo-500",children:[jsx("span",{children:"Upload an invoice"}),jsx("input",{...ar(),id:"file-upload",name:"file-upload",type:"file",className:"sr-only"})]}),jsx("p",{className:"pl-1",children:"or drag and drop"})]}),jsx("p",{className:"text-xs leading-5 text-gray-600",children:"PNG, JPG, PDF up to 10MB"})]})})})}function InvoiceDocuments({documents:nr,height:or}){const[ir,ar]=React$1.useState(),[sr,lr]=React$1.useState(1),[cr,ur]=useDebounce(0,20),dr=React$1.useRef(null);React$1.useLayoutEffect(()=>{dr.current!==null&&ur(dr.current.getBoundingClientRect().width)},[dr]),useResizeObserver(dr,hr=>{cr&&Math.abs(cr-hr.contentRect.width)<20||ur(hr.contentRect.width)});const fr=jsx("div",{className:"flex justify-center ",children:jsxs("nav",{className:"isolate inline-flex -space-x-px rounded-md shadow-sm","aria-label":"Pagination",children:[jsxs("button",{type:"button",onClick:()=>lr(Math.max(sr-1,1)),className:"relative inline-flex items-center rounded-l-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0",children:[jsx("span",{className:"sr-only",children:"Previous"}),jsx(ChevronLeftIcon$1,{className:"h-5 w-5","aria-hidden":"true"})]}),Array.from(new Array(ir),(hr,gr)=>jsx("button",{type:"button",onClick:()=>lr(gr+1),"aria-current":sr!=gr+1?"false":"page",className:sr!=gr+1?"relative inline-flex items-center px-4 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0":"relative z-10 inline-flex items-center bg-mercoa-primary px-4 py-2 text-sm font-semibold text-white focus:z-20 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-mercoa-primary",children:gr+1},gr)),jsxs("button",{type:"button",onClick:()=>lr(Math.min(sr+1,ir??1)),className:"relative inline-flex items-center rounded-r-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0",children:[jsx("span",{className:"sr-only",children:"Next"}),jsx(ChevronRightIcon$1,{className:"h-5 w-5","aria-hidden":"true"})]})]})}),pr=jsx("div",{children:nr&&nr.length>0&&jsx("div",{ref:dr,children:nr.map((hr,gr)=>jsxs("div",{children:[jsx("div",{className:"rounded-md border shadow-lg",style:{width:`${cr}px`},children:hr.mimeType==="application/pdf"?jsx(Document$1,{loading:jsx("div",{className:"mt-2 flex w-full items-center justify-center",style:{height:"700px"},children:jsx(LoadingSpinnerIcon,{})}),file:hr.fileReaderObj,onLoadSuccess:({numPages:vr})=>ar(vr),children:jsx(Page$1,{pageNumber:sr,className:"m-0 w-full p-0 mt-2",renderTextLayer:!1,renderAnnotationLayer:!1,width:cr-5})},hr.fileReaderObj):jsx("img",{src:hr.fileReaderObj,onLoad:()=>ar(1),className:"mt-2"},hr.fileReaderObj)}),jsx("a",{href:hr.fileReaderObj,target:"_blank",rel:"noreferrer",className:"mt-2",download:!0,children:jsxs(MercoaButton,{type:"button",isEmphasized:!1,className:"mt-2",children:[jsxs("span",{className:"hidden xl:inline",children:[jsx(ArrowDownTrayIcon$1,{className:"-ml-1 mr-2 inline-flex h-5 w-5"})," Download Invoice"]}),jsx("span",{className:"inline xl:hidden",children:"Download"})]})})]},gr))})});return jsxs("div",{className:"overflow-auto",style:{height:`${or}px`},children:[fr,pr]})}function EditInvoiceForm({invoice:nr,ocrResponse:or,uploadedImage:ir,setUploadedImage:ar,onRedirect:sr,refreshInvoice:lr,addPaymentMethodRedirect:cr,height:ur}){var To,Ao,Kr,po,wo,so,Lr,Yr,jo,Jr,Po,Co,Yo,Oo,Mo,Zr,Go,Zo,Xr,Qo,Eo,vo,Fo,ko,Mi,Si,xi,ji,Di,Ti,zo,ho,xo,Bo,Ko,$o,Lo;const dr=useMercoaSession(),[fr,pr]=React$1.useState([]),[hr,gr]=React$1.useState([]),[vr,br]=React$1.useState([]),[mr,yr]=React$1.useState([]),[wr,Tr]=React$1.useState(nr==null?void 0:nr.vendor),[Pr,Rr]=React$1.useState(),[_r,jr]=React$1.useState([]),[Cr,Sr]=React$1.useState(!1),Mr=Io=>{const[Jo,Oi]=React$1.useState(0);return React$1.useLayoutEffect(()=>{Oi(Io.current.getBoundingClientRect().width)},[Io]),useResizeObserver(Io,Ri=>Oi(Ri.contentRect.width)),Jo},Ur=React$1.useRef(null),kr=Mr(Ur);let Ir="grid-cols-1";kr&&kr>300&&(Ir="grid-cols-2"),kr&&kr>500&&(Ir="grid-cols-3"),kr&&kr>700&&(Ir="grid-cols-4"),kr&&kr>900&&(Ir="grid-cols-5"),kr&&kr>1100&&(Ir="grid-cols-6");const qr=create$3({amount:create$5().positive().required().typeError("Please enter a valid number"),invoiceNumber:create$6(),description:create$6(),dueDate:create$4().required("Please select a due date").typeError("Please select a due date"),deductionDate:create$4().typeError("Please select a deduction date"),invoiceDate:create$4().required("Please select an invoice date").typeError("Please select an invoice date"),approvers:create$8(),lineItems:create$2().of(create$3({id:create$6(),description:create$6().required(),amount:create$5().moreThan(-1).required().typeError("Please enter a valid number"),quantity:create$5().moreThan(-1).required().typeError("Please enter a valid number"),unitPrice:create$5().moreThan(-1).required().typeError("Please enter a valid number"),metadata:create$8().nullable(),glAccountId:create$6()})),currency:create$6().required(),vendorId:create$6(),vendorName:create$6(),paymentDestinationId:create$6(),paymentMethodDestinationType:create$6(),paymentSourceId:create$6(),paymentMethodSourceType:create$6(),saveAsDraft:create$7(),metadata:create$8().nullable()}).required(),{register:Vr,handleSubmit:fo,setValue:bo,setError:go,clearErrors:mo,watch:Br,control:Gr,formState:{errors:Qr}}=useForm({resolver:o$1(qr),defaultValues:{invoiceNumber:nr==null?void 0:nr.invoiceNumber,amount:nr==null?void 0:nr.amount,currency:(nr==null?void 0:nr.currency)??"USD",vendorId:(To=nr==null?void 0:nr.vendor)==null?void 0:To.id,vendorName:(Ao=nr==null?void 0:nr.vendor)==null?void 0:Ao.name,invoiceDate:nr!=null&&nr.invoiceDate?dayjs$1(nr==null?void 0:nr.invoiceDate).toDate():void 0,dueDate:nr!=null&&nr.dueDate?dayjs$1(nr==null?void 0:nr.dueDate).toDate():void 0,deductionDate:nr!=null&&nr.deductionDate?dayjs$1(nr==null?void 0:nr.deductionDate).toDate():void 0,lineItems:(nr==null?void 0:nr.lineItems)??[],paymentDestinationId:(Kr=nr==null?void 0:nr.paymentDestination)==null?void 0:Kr.id,paymentMethodDestinationType:"",paymentSourceId:(po=nr==null?void 0:nr.paymentSource)==null?void 0:po.id,paymentMethodSourceType:"",description:(nr==null?void 0:nr.noteToSelf)??"",saveAsDraft:!1,metadata:JSON.stringify((nr==null?void 0:nr.metadata)??{}),approvers:nr!=null&&nr.approvers?nr.approvers.map(Io=>({approvalSlotId:Io.approvalSlotId,assignedUserId:Io.assignedUserId})):[]}}),Fr=Br("amount"),Or=Br("dueDate"),xr=Br("currency"),zr=Br("vendorId"),Ar=Br("vendorName"),$r=Br("paymentDestinationId"),Er=Br("paymentSourceId"),Dr=Br("approvers"),Wr=Br("metadata"),{fields:Nr,append:Hr,remove:yo}=useFieldArray({control:Gr,name:"lineItems"});React$1.useEffect(()=>{Rr(nr==null?void 0:nr.approvers.map(Io=>({assignedUserId:Io.assignedUserId??"",approvalSlotId:Io.approvalSlotId})))},[nr]),React$1.useEffect(()=>{var Io,Jo,Oi,Ri;!dr.token||!((Io=dr.entity)!=null&&Io.id)||!dr.client||((Oi=dr.client)==null||Oi.entity.paymentMethod.getAll((Jo=dr.entity)==null?void 0:Jo.id).then(Ei=>{Ei&&pr(Ei)}),(Ri=dr.client)==null||Ri.customPaymentMethodSchema.getAll().then(Ei=>{var Pi,Ai;if(Ei){gr(Ei);let Ci=[];((Ai=(Pi=dr.organization)==null?void 0:Pi.paymentMethods)==null?void 0:Ai.payerPayments.some(Ii=>Ii.active&&(Ii.type==="bankAccount"||Ii.type==="card")))&&Ci.push("USD"),Ei.forEach(Ii=>{Ii.supportedCurrencies&&(Ci=[...new Set([...Ci,...Ii.supportedCurrencies])])}),yr(Ci)}}))},[dr.client,(wo=dr.entity)==null?void 0:wo.id,dr.token]),React$1.useEffect(()=>{var Io,Jo;!dr.token||!((Io=dr.entity)!=null&&Io.id)||(Jo=dr.client)==null||Jo.entity.metadata.getAll(dr.entity.id).then(Oi=>{Oi&&jr(Oi)})},[(so=dr.entity)==null?void 0:so.id,dr.refreshId,dr.token]),React$1.useEffect(()=>{mr.length>0&&bo("currency",(nr==null?void 0:nr.currency)??mr[0])},[mr]),React$1.useEffect(()=>{var Io;!dr.token||!zr||(Io=dr.client)==null||Io.entity.paymentMethod.getAll(zr).then(Jo=>{Jo&&br(Jo)})},[dr.client,zr,dr.token]),React$1.useEffect(()=>{var Io,Jo,Oi,Ri,Ei,Pi;or&&(or.invoice.amount&&bo("amount",or.invoice.amount),bo("invoiceNumber",or.invoice.invoiceNumber),or.invoice.invoiceDate&&bo("invoiceDate",or.invoice.invoiceDate),or.invoice.dueDate&&bo("dueDate",or.invoice.dueDate),bo("deductionDate",or.invoice.deductionDate),or.invoice.currency&&bo("currency",or.invoice.currency),or.invoice.metadata&&bo("metadata",JSON.stringify(or.invoice.metadata)),or.invoice.lineItems&&!((Oi=(Jo=(Io=dr.iframeOptions)==null?void 0:Io.options)==null?void 0:Jo.invoice)!=null&&Oi.disableLineItems)&&bo("lineItems",or.invoice.lineItems.map(Ai=>({description:Ai.description??"",amount:Ai.amount??0,quantity:Ai.quantity??0,unitPrice:Ai.unitPrice??0,name:Ai.name??"",metadata:Ai.metadata??{},glAccountId:Ai.glAccountId??"",id:Ai.id??"",createdAt:Ai.createdAt??new Date,updatedAt:Ai.updatedAt??new Date}))),wr||(or.vendor.id==="new"&&((Pi=(Ei=(Ri=dr.iframeOptions)==null?void 0:Ri.options)==null?void 0:Ei.vendors)!=null&&Pi.disableCreation)?console.log("new vendor creation disabled"):or.vendor.id&&(console.log("setting selected vendor",or.vendor),Tr(or.vendor))))},[or,wr]);let _o=!1;nr!=null&&nr.approvers?_o=!!(Dr!=null&&Dr.every(Io=>!!Io)):_o=!!(nr!=null&&nr.approvers.every(Io=>Io.assignedUserId));let Ro=!!Fr&&!!Or&&!!xr&&!!zr&&zr!=="new"&&!!Er&&!!Ar;(jo=(Yr=(Lr=dr.iframeOptions)==null?void 0:Lr.options)==null?void 0:Yr.vendors)!=null&&jo.disableCreation||(Ro=Ro&&!!(wr!=null&&wr.email)&&!!(wr.accountType==="individual"||wr.accountType==="business"&&((Jr=wr.profile.business)!=null&&Jr.website||(Po=wr.profile.business)!=null&&Po.description)));const No=(nr==null?void 0:nr.status)===javascript.Mercoa.InvoiceStatus.Approved&&Ro&&(!$r||$r==="new"),Do=Ro&&(nr==null?void 0:nr.status)===javascript.Mercoa.InvoiceStatus.Approved&&$r;let Wo=javascript.Mercoa.InvoiceStatus.Draft;Do?Wo=javascript.Mercoa.InvoiceStatus.Scheduled:No||(nr==null?void 0:nr.status)===javascript.Mercoa.InvoiceStatus.New?Wo=javascript.Mercoa.InvoiceStatus.Approved:Ro&&_o&&(Wo=javascript.Mercoa.InvoiceStatus.New);const Vo=async Io=>{var Oi,Ri,Ei,Pi,Ai,Ci,zi,Ii,Bi,Ui;if(!dr.token||!((Oi=dr.entity)!=null&&Oi.id))return;const Jo={status:Io.saveAsDraft?javascript.Mercoa.InvoiceStatus.Draft:Wo,amount:Number(Io.amount),currency:Io.currency,invoiceDate:Io.invoiceDate,deductionDate:Io.deductionDate,dueDate:Io.dueDate,invoiceNumber:Io.invoiceNumber,noteToSelf:Io.description,payerId:(Ri=dr.entity)==null?void 0:Ri.id,paymentSourceId:Io.paymentSourceId,approvers:Io.approvers.filter(Ni=>Ni.assignedUserId),...Io.vendorId!=="new"&&{vendorId:Io.vendorId},paymentDestinationId:Io.paymentDestinationId,lineItems:Io.lineItems.map(Ni=>({...Ni.id&&{id:Ni.id},description:Ni.description,amount:Number(Ni.amount),quantity:Number(Ni.quantity),unitPrice:Number(Ni.unitPrice),metadata:Ni.metadata,currency:Io.currency??"USD",glAccountId:Ni.glAccountId})),metadata:JSON.parse(Io.metadata),uploadedImage:ir,creatorEntityId:(Ei=dr.entity)==null?void 0:Ei.id};if(console.log({data:Io,invoiceData:Jo}),Io.paymentMethodDestinationType&&(!Io.paymentDestinationId||Io.paymentDestinationId==="new")){const Ni=Io.paymentMethodDestinationType,Li=Io.paymentMethodDestinationType.startsWith("cpms_")?"custom":Io.paymentMethodDestinationType;let Gi;if(Li==="bankAccount")Gi={type:Li,accountNumber:Io.accountNumber,routingNumber:Io.routingNumber,accountType:Io.accountType,bankName:Io.bankName};else if(Li==="check")Gi={type:Li,...Io};else if(Li==="custom"){const Vi={};Object.entries(Io).forEach(([nl,ol])=>{nl.startsWith("~cpm~~")&&ol.forEach(wa=>{Vi[wa.name]=`${Vi[wa.name]??wa.value}`})}),Gi={type:Li,foreignId:Math.random().toString(36).substring(7),schemaId:Ni,data:Vi}}if(Gi){const Vi=await((Pi=dr.client)==null?void 0:Pi.entity.paymentMethod.create(Io.vendorId,Gi));Vi&&(Jo.paymentDestinationId=Vi.id)}}if(Jo.status!==javascript.Mercoa.InvoiceStatus.Draft&&((Ai=Jo.approvers)==null?void 0:Ai.length)!==(nr==null?void 0:nr.approvers.length)){Q$2.error("Please assign all approvers for this invoice."),Sr(!1);return}console.log("invoiceData before API call: ",{invoiceData:Jo}),nr?(Ii=dr.client)==null||Ii.invoice.update(nr.id,{...Jo,creatorUserId:((Ci=nr.creatorUser)==null?void 0:Ci.id)??((zi=dr.user)==null?void 0:zi.id)}).then(Ni=>{Ni&&(console.log("invoice/update API response: ",Ni),ar(void 0),Q$2.success("Invoice updated"),lr(Ni.id),Sr(!1))}).catch(Ni=>{console.log(Ni.statusCode),console.log(Ni.body),Q$2.error(`There was an error updating the invoice.
173
+ `)).length,sr=0;sr<ar;sr++){var cr=nr.charCodeAt(sr),ur=null;cr<128?ir++:ur=cr>127&&cr<2048?String.fromCharCode(cr>>6|192,63&cr|128):String.fromCharCode(cr>>12|224,cr>>6&63|128,63&cr|128),E(ur)||(ir>or&&(lr+=nr.substring(or,ir)),lr+=ur,or=ir=sr+1)}return ir>or&&(lr+=nr.substring(or,nr.length)),lr},ie=function(){function nr(or){return or&&(or.preventDefault=nr.preventDefault,or.stopPropagation=nr.stopPropagation),or}return nr.preventDefault=function(){this.returnValue=!1},nr.stopPropagation=function(){this.cancelBubble=!0},function(or,ir,ar,sr,lr){if(or)if(or.addEventListener&&!sr)or.addEventListener(ir,ar,!!lr);else{var cr="on"+ir,ur=or[cr];or[cr]=function(dr,fr,pr){return function(hr){if(hr=hr||nr(T==null?void 0:T.event)){var gr,vr=!0;P(pr)&&(gr=pr(hr));var br=fr.call(dr,hr);return gr!==!1&&br!==!1||(vr=!1),vr}}}(or,ar,ur)}else j.error("No valid element provided to register_event")}}();function re(nr,or){var ir=function(){if(!D)return or("document not found");var ar=D.createElement("script");ar.type="text/javascript",ar.src=nr,ar.onload=function(cr){return or(void 0,cr)},ar.onerror=function(cr){return or(cr)};var sr,lr=D.querySelectorAll("body > script");lr.length>0?(sr=lr[0].parentNode)===null||sr===void 0||sr.insertBefore(ar,lr[0]):D.body.appendChild(ar)};D!=null&&D.body?ir():D==null||D.addEventListener("DOMContentLoaded",ir)}function oe(nr){return nr?W(nr).split(/\s+/):[]}function se(nr){var or="";switch(n(nr.className)){case"string":or=nr.className;break;case"object":or=("baseVal"in nr.className?nr.className.baseVal:null)||nr.getAttribute("class")||"";break;default:or=""}return oe(or)}function ae(nr){var or="";return fe(nr)&&!pe(nr)&&nr.childNodes&&nr.childNodes.length&&U(nr.childNodes,function(ir){ce(ir)&&ir.textContent&&(or+=W(ir.textContent).split(/(\s+)/).filter(_e).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255))}),W(or)}function ue(nr){return!!nr&&nr.nodeType===1}function le(nr,or){return!!nr&&!!nr.tagName&&nr.tagName.toLowerCase()===or.toLowerCase()}function ce(nr){return!!nr&&nr.nodeType===3}function de(nr){return!!nr&&nr.nodeType===11}var he=["a","button","form","input","select","textarea","label"];function fe(nr){for(var or=nr;or.parentNode&&!le(or,"body");or=or.parentNode){var ir=se(or);if(z(ir,"ph-sensitive")||z(ir,"ph-no-capture"))return!1}if(z(se(nr),"ph-include"))return!0;var ar=nr.type||"";if(x(ar))switch(ar.toLowerCase()){case"hidden":case"password":return!1}var sr=nr.name||nr.id||"";return!(x(sr)&&/^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(sr.replace(/[^a-zA-Z0-9]/g,"")))}function pe(nr){return!!(le(nr,"input")&&!["button","checkbox","submit","reset"].includes(nr.type)||le(nr,"select")||le(nr,"textarea")||nr.getAttribute("contenteditable")==="true")}function _e(nr){return!(E(nr)||R(nr)||x(nr)&&(nr=W(nr),/^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/.test((nr||"").replace(/[- ]/g,""))||/(^\d{3}-?\d{2}-?\d{4}$)/.test(nr)))}function ge(nr){var or=ae(nr);return _e(or="".concat(or," ").concat(ve(nr)).trim())?or:""}function ve(nr){var or="";return nr&&nr.childNodes&&nr.childNodes.length&&U(nr.childNodes,function(ir){var ar;if(ir&&((ar=ir.tagName)===null||ar===void 0?void 0:ar.toLowerCase())==="span")try{var sr=ae(ir);or="".concat(or," ").concat(sr).trim(),ir.childNodes&&ir.childNodes.length&&(or="".concat(or," ").concat(ve(ir)).trim())}catch(lr){j.error(lr)}}),or}function me(nr){return function(or){var ir=or.map(function(ar){var sr,lr,cr="";if(ar.tag_name&&(cr+=ar.tag_name),ar.attr_class){ar.attr_class.sort();var ur,dr=v(ar.attr_class);try{for(dr.s();!(ur=dr.n()).done;){var fr=ur.value;cr+=".".concat(fr.replace(/"/g,""))}}catch(gr){dr.e(gr)}finally{dr.f()}}var pr=t(t(t(t({},ar.text?{text:ar.text}:{}),{},{"nth-child":(sr=ar.nth_child)!==null&&sr!==void 0?sr:0,"nth-of-type":(lr=ar.nth_of_type)!==null&&lr!==void 0?lr:0},ar.href?{href:ar.href}:{}),ar.attr_id?{attr_id:ar.attr_id}:{}),ar.attributes),hr={};return Q(pr).sort(function(gr,vr){var br=f(gr,1)[0],mr=f(vr,1)[0];return br.localeCompare(mr)}).forEach(function(gr){var vr=f(gr,2),br=vr[0],mr=vr[1];return hr[ye(br.toString())]=ye(mr.toString())}),cr+=":",cr+=Q(pr).map(function(gr){var vr=f(gr,2),br=vr[0],mr=vr[1];return"".concat(br,'="').concat(mr,'"')}).join("")});return ir.join(";")}(function(or){return or.map(function(ir){var ar,sr,lr={text:(ar=ir.$el_text)===null||ar===void 0?void 0:ar.slice(0,400),tag_name:ir.tag_name,href:(sr=ir.attr__href)===null||sr===void 0?void 0:sr.slice(0,2048),attr_class:be(ir),attr_id:ir.attr__id,nth_child:ir.nth_child,nth_of_type:ir.nth_of_type,attributes:{}};return Q(ir).filter(function(cr){return f(cr,1)[0].indexOf("attr__")===0}).forEach(function(cr){var ur=f(cr,2),dr=ur[0],fr=ur[1];return lr.attributes[dr]=fr}),lr})}(nr))}function ye(nr){return nr.replace(/"|\\"/g,'\\"')}function be(nr){var or=nr.attr__class;return or?S(or)?or:oe(or):void 0}var ke=function(){function nr(or){i(this,nr),this.clicks=[],this.enabled=or}return o(nr,[{key:"isRageClick",value:function(or,ir,ar){if(!this.enabled)return!1;var sr=this.clicks[this.clicks.length-1];if(sr&&Math.abs(or-sr.x)+Math.abs(ir-sr.y)<30&&ar-sr.timestamp<1e3){if(this.clicks.push({x:or,y:ir,timestamp:ar}),this.clicks.length===3)return!0}else this.clicks=[{x:or,y:ir,timestamp:ar}];return!1}}]),nr}(),we="$people_distinct_id",Se="__alias",Fe="__timers",Pe="$autocapture_disabled_server_side",Ie="$session_recording_enabled_server_side",Re="$console_log_recording_enabled_server_side",xe="$session_recording_recorder_version_server_side",Ee="$session_recording_network_payload_capture",Ce="$sesid",Oe="$session_is_sampled",$e="$enabled_feature_flags",Ae="$early_access_features",Me="$stored_person_properties",Te="$stored_group_properties",qe="$surveys",De="$flag_call_reported",Le="$user_state",Be="$posthog_quota_limited",Ne="$client_session_props",je=[we,Se,"__cmpns",Fe,Ie,Ce,$e,Le,Be,Ae,Te,Me,qe,De,Ne];function He(nr,or){return or.length>nr?or.slice(0,nr)+"...":or}var We={_initializedTokens:[],_isDisabledServerSide:null,_isAutocaptureEnabled:!1,_setIsAutocaptureEnabled:function(nr){var or,ir=E(this._isDisabledServerSide)?!((or=nr.persistence)===null||or===void 0||!or.props[Pe]):this._isDisabledServerSide,ar=!!nr.config.autocapture;this._isAutocaptureEnabled=ar&&!ir},_previousElementSibling:function(nr){if(nr.previousElementSibling)return nr.previousElementSibling;var or=nr;do or=or.previousSibling;while(or&&!ue(or));return or},_getAugmentPropertiesFromElement:function(nr){if(!fe(nr))return{};var or={};return U(nr.attributes,function(ir){if(ir.name.indexOf("data-ph-capture-attribute")===0){var ar=ir.name.replace("data-ph-capture-attribute-",""),sr=ir.value;ar&&sr&&_e(sr)&&(or[ar]=sr)}}),or},_getPropertiesFromElement:function(nr,or,ir){var ar,sr=nr.tagName.toLowerCase(),lr={tag_name:sr};he.indexOf(sr)>-1&&!ir&&(sr.toLowerCase()==="a"||sr.toLowerCase()==="button"?lr.$el_text=He(1024,ge(nr)):lr.$el_text=He(1024,ae(nr)));var cr=se(nr);cr.length>0&&(lr.classes=cr.filter(function(hr){return hr!==""}));var ur=(ar=this.config)===null||ar===void 0?void 0:ar.element_attribute_ignorelist;U(nr.attributes,function(hr){var gr;if((!pe(nr)||["name","id","class"].indexOf(hr.name)!==-1)&&(ur==null||!ur.includes(hr.name))&&!or&&_e(hr.value)&&(gr=hr.name,!x(gr)||gr.substring(0,10)!=="_ngcontent"&&gr.substring(0,7)!=="_nghost")){var vr=hr.value;hr.name==="class"&&(vr=oe(vr).join(" ")),lr["attr__"+hr.name]=He(1024,vr)}});for(var dr=1,fr=1,pr=nr;pr=this._previousElementSibling(pr);)dr++,pr.tagName===nr.tagName&&fr++;return lr.nth_child=dr,lr.nth_of_type=fr,lr},_getDefaultProperties:function(nr){return{$event_type:nr,$ce_version:1}},_extractCustomPropertyValue:function(nr){var or=[];return U(D==null?void 0:D.querySelectorAll(nr.css_selector),function(ir){var ar;["input","select"].indexOf(ir.tagName.toLowerCase())>-1?ar=ir.value:ir.textContent&&(ar=ir.textContent),_e(ar)&&or.push(ar)}),or.join(", ")},_getCustomProperties:function(nr){var or=this,ir={};return U(this._customProperties,function(ar){U(ar.event_selectors,function(sr){U(D==null?void 0:D.querySelectorAll(sr),function(lr){z(nr,lr)&&fe(lr)&&(ir[ar.name]=or._extractCustomPropertyValue(ar))})})}),ir},_getEventTarget:function(nr){return R(nr.target)?nr.srcElement||null:(or=nr.target)!==null&&or!==void 0&&or.shadowRoot?nr.composedPath()[0]||null:nr.target||null;var or},_captureEvent:function(nr,or){var ir,ar=this,sr=arguments.length>2&&arguments[2]!==void 0?arguments[2]:"$autocapture",lr=this._getEventTarget(nr);if(ce(lr)&&(lr=lr.parentNode||null),sr==="$autocapture"&&nr.type==="click"&&nr instanceof MouseEvent&&(ir=this.rageclicks)!==null&&ir!==void 0&&ir.isRageClick(nr.clientX,nr.clientY,new Date().getTime())&&this._captureEvent(nr,or,"$rageclick"),lr&&function(mr,yr){var wr=arguments.length>2&&arguments[2]!==void 0?arguments[2]:void 0;if(!T||!mr||le(mr,"html")||!ue(mr))return!1;if(wr!=null&&wr.url_allowlist){var Tr=T.location.href,Pr=wr.url_allowlist;if(Pr&&!Pr.some(function(Vr){return Tr.match(Vr)}))return!1}if(wr!=null&&wr.dom_event_allowlist){var Rr=wr.dom_event_allowlist;if(Rr&&!Rr.some(function(Vr){return yr.type===Vr}))return!1}if(wr!=null&&wr.element_allowlist){var _r=wr.element_allowlist;if(_r&&!_r.some(function(Vr){return mr.tagName.toLowerCase()===Vr}))return!1}if(wr!=null&&wr.css_selector_allowlist){var jr=wr.css_selector_allowlist;if(jr&&!jr.some(function(Vr){return mr.matches(Vr)}))return!1}for(var Cr=!1,Sr=[mr],Mr=!0,Ur=mr;Ur.parentNode&&!le(Ur,"body");)if(de(Ur.parentNode))Sr.push(Ur.parentNode.host),Ur=Ur.parentNode.host;else{if(!(Mr=Ur.parentNode||!1))break;if(he.indexOf(Mr.tagName.toLowerCase())>-1)Cr=!0;else{var kr=T.getComputedStyle(Mr);kr&&kr.getPropertyValue("cursor")==="pointer"&&(Cr=!0)}Sr.push(Mr),Ur=Mr}var Ir=T.getComputedStyle(mr);if(Ir&&Ir.getPropertyValue("cursor")==="pointer"&&yr.type==="click")return!0;var qr=mr.tagName.toLowerCase();switch(qr){case"html":return!1;case"form":return yr.type==="submit";case"input":case"select":case"textarea":return yr.type==="change"||yr.type==="click";default:return Cr?yr.type==="click":yr.type==="click"&&(he.indexOf(qr)>-1||mr.getAttribute("contenteditable")==="true")}}(lr,nr,this.config)){for(var cr,ur,dr=[lr],fr=lr;fr.parentNode&&!le(fr,"body");)de(fr.parentNode)?(dr.push(fr.parentNode.host),fr=fr.parentNode.host):(dr.push(fr.parentNode),fr=fr.parentNode);var pr,hr=[],gr={},vr=!1;if(U(dr,function(mr){var yr=fe(mr);mr.tagName.toLowerCase()==="a"&&(pr=mr.getAttribute("href"),pr=yr&&_e(pr)&&pr),z(se(mr),"ph-no-capture")&&(vr=!0),hr.push(ar._getPropertiesFromElement(mr,or.config.mask_all_element_attributes,or.config.mask_all_text));var wr=ar._getAugmentPropertiesFromElement(mr);G(gr,wr)}),or.config.mask_all_text||(lr.tagName.toLowerCase()==="a"||lr.tagName.toLowerCase()==="button"?hr[0].$el_text=ge(lr):hr[0].$el_text=ae(lr)),pr&&(hr[0].attr__href=pr),vr)return!1;var br=G(this._getDefaultProperties(nr.type),or.elementsChainAsString?{$elements_chain:me(hr)}:{$elements:hr},(cr=hr[0])!==null&&cr!==void 0&&cr.$el_text?{$el_text:(ur=hr[0])===null||ur===void 0?void 0:ur.$el_text}:{},this._getCustomProperties(dr),gr);return or.capture(sr,br),!0}},_navigate:function(nr){T&&(T.location.href=nr)},_addDomEventHandlers:function(nr){var or=this;if(T&&D){var ir=function(ar){ar=ar||(T==null?void 0:T.event),or._captureEvent(ar,nr)};ie(D,"submit",ir,!1,!0),ie(D,"change",ir,!1,!0),ie(D,"click",ir,!1,!0)}},_customProperties:[],rageclicks:null,config:void 0,init:function(nr){var or;O(nr.__autocapture)||(this.config=nr.__autocapture),(or=this.config)!==null&&or!==void 0&&or.url_allowlist&&(this.config.url_allowlist=this.config.url_allowlist.map(function(ir){return new RegExp(ir)})),this.rageclicks=new ke(nr.config.rageclick)},afterDecideResponse:function(nr,or){var ir=or.config.token;this._initializedTokens.indexOf(ir)>-1?j.info('autocapture already initialized for token "'+ir+'"'):(or.persistence&&or.persistence.register(s({},Pe,!!nr.autocapture_opt_out)),this._isDisabledServerSide=!!nr.autocapture_opt_out,this._setIsAutocaptureEnabled(or),this._initializedTokens.push(ir),nr&&nr.config&&nr.config.enable_collect_everything&&this._isAutocaptureEnabled?(nr.custom_properties&&(this._customProperties=nr.custom_properties),this._addDomEventHandlers(or)):or.__autocapture=!1)},enabledForProject:function(nr,or,ir){if(!nr)return!0;or=R(or)?10:or,ir=R(ir)?10:ir;for(var ar=0,sr=0;sr<nr.length;sr++)ar+=nr.charCodeAt(sr);return ar%or<ir},isBrowserSupported:function(){return P(D==null?void 0:D.querySelectorAll)}};(function(nr){for(var or in nr)P(nr[or])&&(nr[or]=nr[or].bind(nr))})(We),function(nr){for(var or in nr)P(nr[or])&&(nr[or]=X(nr[or]))}(We);var Ve="$active_feature_flags",Ue="$override_feature_flags",Ge="$feature_flag_payloads",ze=function(nr){var or,ir={},ar=v(Q(nr||{}));try{for(ar.s();!(or=ar.n()).done;){var sr=f(or.value,2),lr=sr[0],cr=sr[1];cr&&(ir[lr]=cr)}}catch(ur){ar.e(ur)}finally{ar.f()}return ir},Qe=function(){function nr(or){i(this,nr),this.instance=or,this._override_warning=!1,this.featureFlagEventHandlers=[],this.reloadFeatureFlagsQueued=!1,this.reloadFeatureFlagsInAction=!1}return o(nr,[{key:"getFlags",value:function(){return Object.keys(this.getFlagVariants())}},{key:"getFlagVariants",value:function(){var or=this.instance.get_property($e),ir=this.instance.get_property(Ue);if(!ir)return or||{};for(var ar=G({},or),sr=Object.keys(ir),lr=0;lr<sr.length;lr++)ir[sr[lr]]===!1?delete ar[sr[lr]]:ar[sr[lr]]=ir[sr[lr]];return this._override_warning||(j.warn(" Overriding feature flags!",{enabledFlags:or,overriddenFlags:ir,finalFlags:ar}),this._override_warning=!0),ar}},{key:"getFlagPayloads",value:function(){return this.instance.get_property(Ge)||{}}},{key:"reloadFeatureFlags",value:function(){this.reloadFeatureFlagsQueued||(this.reloadFeatureFlagsQueued=!0,this._startReloadTimer())}},{key:"setAnonymousDistinctId",value:function(or){this.$anon_distinct_id=or}},{key:"setReloadingPaused",value:function(or){this.reloadFeatureFlagsInAction=or}},{key:"resetRequestQueue",value:function(){this.reloadFeatureFlagsQueued=!1}},{key:"_startReloadTimer",value:function(){var or=this;this.reloadFeatureFlagsQueued&&!this.reloadFeatureFlagsInAction&&setTimeout(function(){!or.reloadFeatureFlagsInAction&&or.reloadFeatureFlagsQueued&&(or.reloadFeatureFlagsQueued=!1,or._reloadFeatureFlagsRequest())},5)}},{key:"_reloadFeatureFlagsRequest",value:function(){var or=this;if(!this.instance.config.advanced_disable_feature_flags){this.setReloadingPaused(!0);var ir=this.instance.config.token,ar=this.instance.get_property(Me),sr=this.instance.get_property(Te),lr=te(JSON.stringify({token:ir,distinct_id:this.instance.get_distinct_id(),groups:this.instance.getGroups(),$anon_distinct_id:this.$anon_distinct_id,person_properties:ar,group_properties:sr,disable_flags:this.instance.config.advanced_disable_feature_flags||void 0}));this.instance._send_request(this.instance.config.api_host+"/decide/?v=3",{data:lr},{method:"POST"},this.instance._prepare_callback(function(cr){or.$anon_distinct_id=void 0,or.receivedFeatureFlags(cr),or.setReloadingPaused(!1),or._startReloadTimer()}))}}},{key:"getFeatureFlag",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(this.instance.decideEndpointWasHit||this.getFlags()&&this.getFlags().length>0){var ar,sr=this.getFlagVariants()[or],lr="".concat(sr),cr=this.instance.get_property(De)||{};return(ir.send_event||!("send_event"in ir))&&(!(or in cr)||!cr[or].includes(lr))&&(S(cr[or])?cr[or].push(lr):cr[or]=[lr],(ar=this.instance.persistence)===null||ar===void 0||ar.register(s({},De,cr)),this.instance.capture("$feature_flag_called",{$feature_flag:or,$feature_flag_response:sr})),sr}j.warn('getFeatureFlag for key "'+or+`" failed. Feature flags didn't load in time.`)}},{key:"getFeatureFlagPayload",value:function(or){return this.getFlagPayloads()[or]}},{key:"isFeatureEnabled",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(this.instance.decideEndpointWasHit||this.getFlags()&&this.getFlags().length>0)return!!this.getFeatureFlag(or,ir);j.warn('isFeatureEnabled for key "'+or+`" failed. Feature flags didn't load in time.`)}},{key:"addFeatureFlagsHandler",value:function(or){this.featureFlagEventHandlers.push(or)}},{key:"removeFeatureFlagsHandler",value:function(or){this.featureFlagEventHandlers=this.featureFlagEventHandlers.filter(function(ir){return ir!==or})}},{key:"receivedFeatureFlags",value:function(or){if(this.instance.persistence){this.instance.decideEndpointWasHit=!0;var ir=this.getFlagVariants(),ar=this.getFlagPayloads();(function(sr,lr){var cr=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ur=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{},dr=sr.featureFlags,fr=sr.featureFlagPayloads;if(dr)if(S(dr)){var pr,hr={};if(dr)for(var gr=0;gr<dr.length;gr++)hr[dr[gr]]=!0;lr&&lr.register((s(pr={},Ve,dr),s(pr,$e,hr),pr))}else{var vr,br=dr,mr=fr;sr.errorsWhileComputingFlags&&(br=t(t({},cr),br),mr=t(t({},ur),mr)),lr&&lr.register((s(vr={},Ve,Object.keys(ze(br))),s(vr,$e,br||{}),s(vr,Ge,mr||{}),vr))}})(or,this.instance.persistence,ir,ar),this._fireFeatureFlagsCallbacks()}}},{key:"override",value:function(or){if(!this.instance.__loaded||!this.instance.persistence)return j.uninitializedWarning("posthog.feature_flags.override");if(this._override_warning=!1,or===!1)this.instance.persistence.unregister(Ue);else if(S(or)){for(var ir={},ar=0;ar<or.length;ar++)ir[or[ar]]=!0;this.instance.persistence.register(s({},Ue,ir))}else this.instance.persistence.register(s({},Ue,or))}},{key:"onFeatureFlags",value:function(or){var ir=this;if(this.addFeatureFlagsHandler(or),this.instance.decideEndpointWasHit){var ar=this._prepareFeatureFlagsForCallbacks(),sr=ar.flags,lr=ar.flagVariants;or(sr,lr)}return function(){return ir.removeFeatureFlagsHandler(or)}}},{key:"updateEarlyAccessFeatureEnrollment",value:function(or,ir){var ar,sr,lr=s({},"$feature_enrollment/".concat(or),ir);this.instance.capture("$feature_enrollment_update",{$feature_flag:or,$feature_enrollment:ir,$set:lr}),this.setPersonPropertiesForFlags(lr,!1);var cr=t(t({},this.getFlagVariants()),{},s({},or,ir));(ar=this.instance.persistence)===null||ar===void 0||ar.register((s(sr={},Ve,Object.keys(ze(cr))),s(sr,$e,cr),sr)),this._fireFeatureFlagsCallbacks()}},{key:"getEarlyAccessFeatures",value:function(or){var ir=this,ar=arguments.length>1&&arguments[1]!==void 0&&arguments[1],sr=this.instance.get_property(Ae);if(sr&&!ar)return or(sr);this.instance._send_request("".concat(this.instance.config.api_host,"/api/early_access_features/?token=").concat(this.instance.config.token),{},{method:"GET"},function(lr){var cr,ur=lr.earlyAccessFeatures;return(cr=ir.instance.persistence)===null||cr===void 0||cr.register(s({},Ae,ur)),or(ur)})}},{key:"_prepareFeatureFlagsForCallbacks",value:function(){var or=this.getFlags(),ir=this.getFlagVariants();return{flags:or.filter(function(ar){return ir[ar]}),flagVariants:Object.keys(ir).filter(function(ar){return ir[ar]}).reduce(function(ar,sr){return ar[sr]=ir[sr],ar},{})}}},{key:"_fireFeatureFlagsCallbacks",value:function(){var or=this._prepareFeatureFlagsForCallbacks(),ir=or.flags,ar=or.flagVariants;this.featureFlagEventHandlers.forEach(function(sr){return sr(ir,ar)})}},{key:"setPersonPropertiesForFlags",value:function(or){var ir=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1],ar=this.instance.get_property(Me)||{};this.instance.register(s({},Me,t(t({},ar),or))),ir&&this.instance.reloadFeatureFlags()}},{key:"resetPersonPropertiesForFlags",value:function(){this.instance.unregister(Me)}},{key:"setGroupPropertiesForFlags",value:function(or){var ir=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1],ar=this.instance.get_property(Te)||{};Object.keys(ar).length!==0&&Object.keys(ar).forEach(function(sr){ar[sr]=t(t({},ar[sr]),or[sr]),delete or[sr]}),this.instance.register(s({},Te,t(t({},ar),or))),ir&&this.instance.reloadFeatureFlags()}},{key:"resetGroupPropertiesForFlags",value:function(or){if(or){var ir=this.instance.get_property(Te)||{};this.instance.register(s({},Te,t(t({},ir),{},s({},or,{}))))}else this.instance.unregister(Te)}}]),nr}();Math.trunc||(Math.trunc=function(nr){return nr<0?Math.ceil(nr):Math.floor(nr)}),Number.isInteger||(Number.isInteger=function(nr){return C(nr)&&isFinite(nr)&&Math.floor(nr)===nr});var Ye="0123456789abcdef",Je=function(){function nr(or){if(i(this,nr),this.bytes=or,or.length!==16)throw new TypeError("not 128-bit length")}return o(nr,[{key:"toString",value:function(){for(var or="",ir=0;ir<this.bytes.length;ir++)or=or+Ye.charAt(this.bytes[ir]>>>4)+Ye.charAt(15&this.bytes[ir]),ir!==3&&ir!==5&&ir!==7&&ir!==9||(or+="-");if(or.length!==36)throw new Error("Invalid UUIDv7 was generated");return or}},{key:"clone",value:function(){return new nr(this.bytes.slice(0))}},{key:"equals",value:function(or){return this.compareTo(or)===0}},{key:"compareTo",value:function(or){for(var ir=0;ir<16;ir++){var ar=this.bytes[ir]-or.bytes[ir];if(ar!==0)return Math.sign(ar)}return 0}}],[{key:"fromFieldsV7",value:function(or,ir,ar,sr){if(!Number.isInteger(or)||!Number.isInteger(ir)||!Number.isInteger(ar)||!Number.isInteger(sr)||or<0||ir<0||ar<0||sr<0||or>0xffffffffffff||ir>4095||ar>1073741823||sr>4294967295)throw new RangeError("invalid field value");var lr=new Uint8Array(16);return lr[0]=or/Math.pow(2,40),lr[1]=or/Math.pow(2,32),lr[2]=or/Math.pow(2,24),lr[3]=or/Math.pow(2,16),lr[4]=or/Math.pow(2,8),lr[5]=or,lr[6]=112|ir>>>8,lr[7]=ir,lr[8]=128|ar>>>24,lr[9]=ar>>>16,lr[10]=ar>>>8,lr[11]=ar,lr[12]=sr>>>24,lr[13]=sr>>>16,lr[14]=sr>>>8,lr[15]=sr,new nr(lr)}}]),nr}(),Xe=function(){function nr(){i(this,nr),s(this,"timestamp",0),s(this,"counter",0),s(this,"random",new et)}return o(nr,[{key:"generate",value:function(){var or=this.generateOrAbort();if(R(or)){this.timestamp=0;var ir=this.generateOrAbort();if(R(ir))throw new Error("Could not generate UUID after timestamp reset");return ir}return or}},{key:"generateOrAbort",value:function(){var or=Date.now();if(or>this.timestamp)this.timestamp=or,this.resetCounter();else{if(!(or+1e4>this.timestamp))return;this.counter++,this.counter>4398046511103&&(this.timestamp++,this.resetCounter())}return Je.fromFieldsV7(this.timestamp,Math.trunc(this.counter/Math.pow(2,30)),this.counter&Math.pow(2,30)-1,this.random.nextUint32())}},{key:"resetCounter",value:function(){this.counter=1024*this.random.nextUint32()+(1023&this.random.nextUint32())}}]),nr}(),Ke=function(nr){if(typeof UUIDV7_DENY_WEAK_RNG<"u"&&UUIDV7_DENY_WEAK_RNG)throw new Error("no cryptographically strong RNG available");for(var or=0;or<nr.length;or++)nr[or]=65536*Math.trunc(65536*Math.random())+Math.trunc(65536*Math.random());return nr};T&&!R(T.crypto)&&crypto.getRandomValues&&(Ke=function(nr){return crypto.getRandomValues(nr)});var Ze,et=function(){function nr(){i(this,nr),s(this,"buffer",new Uint32Array(8)),s(this,"cursor",1/0)}return o(nr,[{key:"nextUint32",value:function(){return this.cursor>=this.buffer.length&&(Ke(this.buffer),this.cursor=0),this.buffer[this.cursor++]}}]),nr}(),tt=function(){return nt().toString()},nt=function(){return(Ze||(Ze=new Xe)).generate()},it="Thu, 01 Jan 1970 00:00:00 GMT",rt="",ot=/[a-z0-9][a-z0-9-]+\.[a-z]{2,}$/i;function st(nr,or){if(or){var ir=function(sr){var lr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:D;if(rt)return rt;if(!lr||["localhost","127.0.0.1"].includes(sr))return"";for(var cr=sr.split("."),ur=Math.min(cr.length,8),dr="dmn_chk_"+tt(),fr=new RegExp("(^|;)\\s*"+dr+"=1");!rt&&ur--;){var pr=cr.slice(ur).join("."),hr=dr+"=1;domain=."+pr;lr.cookie=hr,fr.test(lr.cookie)&&(lr.cookie=hr+";expires="+it,rt=pr)}return rt}(nr);if(!ir){var ar=function(sr){var lr=sr.match(ot);return lr?lr[0]:""}(nr);ar!==ir&&j.info("Warning: cookie subdomain discovery mismatch",ar,ir),ir=ar}return ir?"; domain=."+ir:""}return""}var at={is_supported:function(){return!!D},error:function(nr){j.error("cookieStore error: "+nr)},get:function(nr){if(D){try{for(var or=nr+"=",ir=D.cookie.split(";").filter(function(lr){return lr.length}),ar=0;ar<ir.length;ar++){for(var sr=ir[ar];sr.charAt(0)==" ";)sr=sr.substring(1,sr.length);if(sr.indexOf(or)===0)return decodeURIComponent(sr.substring(or.length,sr.length))}}catch{}return null}},parse:function(nr){var or;try{or=JSON.parse(at.get(nr))||{}}catch{}return or},set:function(nr,or,ir,ar,sr){if(D)try{var lr="",cr="",ur=st(D.location.hostname,ar);if(ir){var dr=new Date;dr.setTime(dr.getTime()+24*ir*60*60*1e3),lr="; expires="+dr.toUTCString()}sr&&(cr="; secure");var fr=nr+"="+encodeURIComponent(JSON.stringify(or))+lr+"; SameSite=Lax; path=/"+ur+cr;return fr.length>3686.4&&j.warn("cookieStore warning: large cookie, len="+fr.length),D.cookie=fr,fr}catch{return}},remove:function(nr,or){try{at.set(nr,"",-1,or)}catch{return}}},ut=null,lt={is_supported:function(){if(!E(ut))return ut;var nr=!0;if(R(T))nr=!1;else try{var or="__mplssupport__";lt.set(or,"xyz"),lt.get(or)!=='"xyz"'&&(nr=!1),lt.remove(or)}catch{nr=!1}return nr||j.error("localStorage unsupported; falling back to cookie store"),ut=nr,nr},error:function(nr){j.error("localStorage error: "+nr)},get:function(nr){try{return T==null?void 0:T.localStorage.getItem(nr)}catch(or){lt.error(or)}return null},parse:function(nr){try{return JSON.parse(lt.get(nr))||{}}catch{}return null},set:function(nr,or){try{T==null||T.localStorage.setItem(nr,JSON.stringify(or))}catch(ir){lt.error(ir)}},remove:function(nr){try{T==null||T.localStorage.removeItem(nr)}catch(or){lt.error(or)}}},ct=["distinct_id",Ce,Oe],dt=t(t({},lt),{},{parse:function(nr){try{var or={};try{or=at.parse(nr)||{}}catch{}var ir=G(or,JSON.parse(lt.get(nr)||"{}"));return lt.set(nr,ir),ir}catch{}return null},set:function(nr,or,ir,ar,sr){try{lt.set(nr,or);var lr={};ct.forEach(function(cr){or[cr]&&(lr[cr]=or[cr])}),Object.keys(lr).length&&at.set(nr,lr,ir,ar,sr)}catch(cr){lt.error(cr)}},remove:function(nr,or){try{T==null||T.localStorage.removeItem(nr),at.remove(nr,or)}catch(ir){lt.error(ir)}}}),ht={},ft={is_supported:function(){return!0},error:function(nr){j.error("memoryStorage error: "+nr)},get:function(nr){return ht[nr]||null},parse:function(nr){return ht[nr]||null},set:function(nr,or){ht[nr]=or},remove:function(nr){delete ht[nr]}},pt=null,_t={is_supported:function(){if(!E(pt))return pt;if(pt=!0,R(T))pt=!1;else try{var nr="__support__";_t.set(nr,"xyz"),_t.get(nr)!=='"xyz"'&&(pt=!1),_t.remove(nr)}catch{pt=!1}return pt},error:function(nr){j.error("sessionStorage error: ",nr)},get:function(nr){try{return T==null?void 0:T.sessionStorage.getItem(nr)}catch(or){_t.error(or)}return null},parse:function(nr){try{return JSON.parse(_t.get(nr))||null}catch{}return null},set:function(nr,or){try{T==null||T.sessionStorage.setItem(nr,JSON.stringify(or))}catch(ir){_t.error(ir)}},remove:function(nr){try{T==null||T.sessionStorage.removeItem(nr)}catch(or){_t.error(or)}}},gt=["localhost","127.0.0.1"],vt=function(nr){var or=D==null?void 0:D.createElement("a");return R(or)?null:(or.href=nr,or)},mt=function(nr,or){return!!function(ir){try{new RegExp(ir)}catch{return!1}return!0}(or)&&new RegExp(or).test(nr)},yt=function(nr,or){for(var ir,ar=((nr.split("#")[0]||"").split("?")[1]||"").split("&"),sr=0;sr<ar.length;sr++){var lr=ar[sr].split("=");if(lr[0]===or){ir=lr;break}}if(!S(ir)||ir.length<2)return"";var cr=ir[1];try{cr=decodeURIComponent(cr)}catch{j.error("Skipping decoding for malformed query param: "+cr)}return cr.replace(/\+/g," ")},bt=function(nr,or){var ir=nr.match(new RegExp(or+"=([^&]*)"));return ir?ir[1]:null},kt={campaignParams:function(nr){var or=["utm_source","utm_medium","utm_campaign","utm_content","utm_term","gclid","gad_source","gbraid","wbraid","fbclid","msclkid"].concat(nr||[]),ir={};return U(or,function(ar){var sr=D?yt(D.URL,ar):"";sr.length&&(ir[ar]=sr)}),ir},searchEngine:function(){var nr=D==null?void 0:D.referrer;return nr?nr.search("https?://(.*)google.([^/?]*)")===0?"google":nr.search("https?://(.*)bing.com")===0?"bing":nr.search("https?://(.*)yahoo.com")===0?"yahoo":nr.search("https?://(.*)duckduckgo.com")===0?"duckduckgo":null:null},searchInfo:function(){var nr=kt.searchEngine(),or=nr!="yahoo"?"q":"p",ir={};if(!E(nr)){ir.$search_engine=nr;var ar=D?yt(D.referrer,or):"";ar.length&&(ir.ph_keyword=ar)}return ir},browser:function(nr,or,ir){return or=or||"",ir||z(nr," OPR/")?z(nr,"Mini")?"Opera Mini":"Opera":/(BlackBerry|PlayBook|BB10)/i.test(nr)?"BlackBerry":z(nr,"IEMobile")||z(nr,"WPDesktop")?"Internet Explorer Mobile":z(nr,"SamsungBrowser/")?"Samsung Internet":z(nr,"Edge")||z(nr,"Edg/")?"Microsoft Edge":z(nr,"FBIOS")?"Facebook Mobile":z(nr,"Chrome")?"Chrome":z(nr,"CriOS")?"Chrome iOS":z(nr,"UCWEB")||z(nr,"UCBrowser")?"UC Browser":z(nr,"FxiOS")?"Firefox iOS":z(or,"Apple")||function(ar){return z(ar,"Safari")&&!z(ar,"Chrome")&&!z(ar,"Android")}(nr)?z(nr,"Mobile")?"Mobile Safari":"Safari":z(nr,"Android")?"Android Mobile":z(nr,"Konqueror")||z(nr,"konqueror")?"Konqueror":z(nr,"Firefox")?"Firefox":z(nr,"MSIE")||z(nr,"Trident/")?"Internet Explorer":z(nr,"Gecko")?"Mozilla":""},browserVersion:function(nr,or,ir){var ar={"Internet Explorer Mobile":[/rv:(\d+(\.\d+)?)/],"Microsoft Edge":[/Edge?\/(\d+(\.\d+)?)/],Chrome:[/Chrome\/(\d+(\.\d+)?)/],"Chrome iOS":[/CriOS\/(\d+(\.\d+)?)/],"UC Browser":[/(UCBrowser|UCWEB)\/(\d+(\.\d+)?)/],Safari:[/Version\/(\d+(\.\d+)?)/],"Mobile Safari":[/Version\/(\d+(\.\d+)?)/],Opera:[/(Opera|OPR)\/(\d+(\.\d+)?)/],Firefox:[/Firefox\/(\d+(\.\d+)?)/],"Firefox iOS":[/FxiOS\/(\d+(\.\d+)?)/],Konqueror:[/Konqueror[:/]?(\d+(\.\d+)?)/i],BlackBerry:[/BlackBerry (\d+(\.\d+)?)/,/Version\/(\d+(\.\d+)?)/],"Android Mobile":[/android\s(\d+(\.\d+)?)/],"Samsung Internet":[/SamsungBrowser\/(\d+(\.\d+)?)/],"Internet Explorer":[/(rv:|MSIE )(\d+(\.\d+)?)/],Mozilla:[/rv:(\d+(\.\d+)?)/]}[kt.browser(nr,or,ir)];if(R(ar))return null;for(var sr=0;sr<ar.length;sr++){var lr=ar[sr],cr=nr.match(lr);if(cr)return parseFloat(cr[cr.length-2])}return null},browserLanguage:function(){return navigator.language||navigator.userLanguage},os:function(nr){if(/Windows/i.test(nr)){if(/Phone/.test(nr)||/WPDesktop/.test(nr))return{os_name:"Windows Phone",os_version:""};var or=/Windows NT ([0-9.]+)/i.exec(nr);return or&&or[1]?{os_name:"Windows",os_version:or[1]}:{os_name:"Windows",os_version:""}}if(/(iPhone|iPad|iPod)/.test(nr)){var ir=/OS (\d+)_(\d+)_?(\d+)?/i.exec(nr);return ir&&ir[1]?{os_name:"iOS",os_version:[ir[1],ir[2],ir[3]||"0"].join(".")}:{os_name:"iOS",os_version:""}}if(/Android/.test(nr)){var ar=/Android (\d+)\.(\d+)\.?(\d+)?/i.exec(nr);return ar&&ar[1]?{os_name:"Android",os_version:[ar[1],ar[2],ar[3]||"0"].join(".")}:{os_name:"Android",os_version:""}}if(/(BlackBerry|PlayBook|BB10)/i.test(nr))return{os_name:"BlackBerry",os_version:""};if(/Mac/i.test(nr)){var sr=/Mac OS X (\d+)[_.](\d+)[_.]?(\d+)?/i.exec(nr);return sr&&sr[1]?{os_name:"Mac OS X",os_version:[sr[1],sr[2],sr[3]||"0"].join(".")}:{os_name:"Mac OS X",os_version:""}}return/Linux/.test(nr)?{os_name:"Linux",os_version:""}:/CrOS/.test(nr)?{os_name:"Chrome OS",os_version:""}:{os_name:"",os_version:""}},device:function(nr){return/Windows Phone/i.test(nr)||/WPDesktop/.test(nr)?"Windows Phone":/iPad/.test(nr)?"iPad":/iPod/.test(nr)?"iPod Touch":/iPhone/.test(nr)?"iPhone":/(BlackBerry|PlayBook|BB10)/i.test(nr)?"BlackBerry":/Android/.test(nr)&&!/Mobile/.test(nr)?"Android Tablet":/Android/.test(nr)?"Android":""},deviceType:function(nr){var or=this.device(nr);return or==="iPad"||or==="Android Tablet"?"Tablet":or?"Mobile":"Desktop"},referrer:function(){return(D==null?void 0:D.referrer)||"$direct"},referringDomain:function(){var nr;return D!=null&&D.referrer&&((nr=vt(D.referrer))===null||nr===void 0?void 0:nr.host)||"$direct"},properties:function(){if(!L)return{};var nr=kt.os(L),or=nr.os_name,ir=nr.os_version;return G(K({$os:or,$os_version:ir,$browser:kt.browser(L,navigator.vendor,B.opera),$device:kt.device(L),$device_type:kt.deviceType(L)}),{$current_url:T==null?void 0:T.location.href,$host:T==null?void 0:T.location.host,$pathname:T==null?void 0:T.location.pathname,$raw_user_agent:L.length>1e3?L.substring(0,997)+"...":L,$browser_version:kt.browserVersion(L,navigator.vendor,B.opera),$browser_language:kt.browserLanguage(),$screen_height:T==null?void 0:T.screen.height,$screen_width:T==null?void 0:T.screen.width,$viewport_height:T==null?void 0:T.innerHeight,$viewport_width:T==null?void 0:T.innerWidth,$lib:"web",$lib_version:m.LIB_VERSION,$insert_id:Math.random().toString(36).substring(2,10)+Math.random().toString(36).substring(2,10),$time:Y()/1e3})},people_properties:function(){if(!L)return{};var nr=kt.os(L),or=nr.os_name,ir=nr.os_version;return G(K({$os:or,$os_version:ir,$browser:kt.browser(L,navigator.vendor,B.opera)}),{$browser_version:kt.browserVersion(L,navigator.vendor,B.opera)})}},wt=["cookie","localstorage","localstorage+cookie","sessionstorage","memory"],St=function(){function nr(or){i(this,nr);var ir="";or.token&&(ir=or.token.replace(/\+/g,"PL").replace(/\//g,"SL").replace(/=/g,"EQ")),this.props={},this.campaign_params_saved=!1,this.custom_campaign_params=or.custom_campaign_params||[],or.persistence_name?this.name="ph_"+or.persistence_name:this.name="ph_"+ir+"_posthog",wt.indexOf(or.persistence.toLowerCase())===-1&&(j.critical("Unknown persistence type "+or.persistence+"; falling back to localStorage+cookie"),or.persistence="localStorage+cookie");var ar=or.persistence.toLowerCase();ar==="localstorage"&&lt.is_supported()?this.storage=lt:ar==="localstorage+cookie"&&dt.is_supported()?this.storage=dt:ar==="sessionstorage"&&_t.is_supported()?this.storage=_t:ar==="memory"?this.storage=ft:ar==="cookie"?this.storage=at:dt.is_supported()?this.storage=dt:this.storage=at,this.load(),this.update_config(or),this.save()}return o(nr,[{key:"properties",value:function(){var or={};return U(this.props,function(ir,ar){if(ar===$e&&I(ir))for(var sr=Object.keys(ir),lr=0;lr<sr.length;lr++)or["$feature/".concat(sr[lr])]=ir[sr[lr]];else ur=ar,dr=!1,(E(cr=je)?dr:M&&cr.indexOf===M?cr.indexOf(ur)!=-1:(U(cr,function(fr){if(dr||(dr=fr===ur))return H}),dr))||(or[ar]=ir);var cr,ur,dr}),or}},{key:"load",value:function(){if(!this.disabled){var or=this.storage.parse(this.name);or&&(this.props=G({},or))}}},{key:"save",value:function(){this.disabled||this.storage.set(this.name,this.props,this.expire_days,this.cross_subdomain,this.secure)}},{key:"remove",value:function(){this.storage.remove(this.name,!1),this.storage.remove(this.name,!0)}},{key:"clear",value:function(){this.remove(),this.props={}}},{key:"register_once",value:function(or,ir,ar){var sr=this;if(I(or)){R(ir)&&(ir="None"),this.expire_days=R(ar)?this.default_expiry:ar;var lr=!1;if(U(or,function(cr,ur){sr.props.hasOwnProperty(ur)&&sr.props[ur]!==ir||(sr.props[ur]=cr,lr=!0)}),lr)return this.save(),!0}return!1}},{key:"register",value:function(or,ir){var ar=this;if(I(or)){this.expire_days=R(ir)?this.default_expiry:ir;var sr=!1;if(U(or,function(lr,cr){or.hasOwnProperty(cr)&&ar.props[cr]!==lr&&(ar.props[cr]=lr,sr=!0)}),sr)return this.save(),!0}return!1}},{key:"unregister",value:function(or){or in this.props&&(delete this.props[or],this.save())}},{key:"update_campaign_params",value:function(){this.campaign_params_saved||(this.register(kt.campaignParams(this.custom_campaign_params)),this.campaign_params_saved=!0)}},{key:"update_search_keyword",value:function(){this.register(kt.searchInfo())}},{key:"update_referrer_info",value:function(){this.register({$referrer:this.props.$referrer||kt.referrer(),$referring_domain:this.props.$referring_domain||kt.referringDomain()})}},{key:"get_referrer_info",value:function(){return K({$referrer:this.props.$referrer,$referring_domain:this.props.$referring_domain})}},{key:"safe_merge",value:function(or){return U(this.props,function(ir,ar){ar in or||(or[ar]=ir)}),or}},{key:"update_config",value:function(or){this.default_expiry=this.expire_days=or.cookie_expiration,this.set_disabled(or.disable_persistence),this.set_cross_subdomain(or.cross_subdomain_cookie),this.set_secure(or.secure_cookie)}},{key:"set_disabled",value:function(or){this.disabled=or,this.disabled?this.remove():this.save()}},{key:"set_cross_subdomain",value:function(or){or!==this.cross_subdomain&&(this.cross_subdomain=or,this.remove(),this.save())}},{key:"get_cross_subdomain",value:function(){return!!this.cross_subdomain}},{key:"set_secure",value:function(or){or!==this.secure&&(this.secure=or,this.remove(),this.save())}},{key:"set_event_timer",value:function(or,ir){var ar=this.props[Fe]||{};ar[or]=ir,this.props[Fe]=ar,this.save()}},{key:"remove_event_timer",value:function(or){var ir=(this.props[Fe]||{})[or];return R(ir)||(delete this.props[Fe][or],this.save()),ir}},{key:"get_user_state",value:function(){return this.props[Le]||"anonymous"}},{key:"set_user_state",value:function(or){this.props[Le]=or,this.save()}},{key:"get_quota_limits",value:function(){return this.props[Be]||{}}},{key:"set_quota_limits",value:function(or){this.props[Be]=or,this.save()}}]),nr}(),Ft=2,Pt=4,It=o(function nr(or){var ir,ar,sr=this,lr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};i(this,nr),s(this,"bucketSize",100),s(this,"refillRate",10),s(this,"mutationBuckets",{}),s(this,"loggedTracker",{}),s(this,"refillBuckets",function(){Object.keys(sr.mutationBuckets).forEach(function(cr){sr.mutationBuckets[cr]=sr.mutationBuckets[cr]+sr.refillRate,sr.mutationBuckets[cr]>=sr.bucketSize&&delete sr.mutationBuckets[cr]})}),s(this,"getNodeOrRelevantParent",function(cr){var ur=sr.rrweb.mirror.getNode(cr);if((ur==null?void 0:ur.nodeName)!=="svg"&&ur instanceof Element){var dr=ur.closest("svg");if(dr)return[sr.rrweb.mirror.getId(dr),dr]}return[cr,ur]}),s(this,"numberOfChanges",function(cr){var ur,dr,fr,pr,hr,gr,vr,br;return((ur=(dr=cr.removes)===null||dr===void 0?void 0:dr.length)!==null&&ur!==void 0?ur:0)+((fr=(pr=cr.attributes)===null||pr===void 0?void 0:pr.length)!==null&&fr!==void 0?fr:0)+((hr=(gr=cr.texts)===null||gr===void 0?void 0:gr.length)!==null&&hr!==void 0?hr:0)+((vr=(br=cr.adds)===null||br===void 0?void 0:br.length)!==null&&vr!==void 0?vr:0)}),s(this,"throttleMutations",function(cr){if(cr.type!==3||cr.data.source!==0)return cr;var ur=cr.data,dr=sr.numberOfChanges(ur);ur.attributes&&(ur.attributes=ur.attributes.filter(function(pr){var hr,gr,vr,br=f(sr.getNodeOrRelevantParent(pr.id),2),mr=br[0],yr=br[1];return sr.mutationBuckets[mr]===0?!1:(sr.mutationBuckets[mr]=(hr=sr.mutationBuckets[mr])!==null&&hr!==void 0?hr:sr.bucketSize,sr.mutationBuckets[mr]=Math.max(sr.mutationBuckets[mr]-1,0),sr.mutationBuckets[mr]===0&&(sr.loggedTracker[mr]||(sr.loggedTracker[mr]=!0,(gr=(vr=sr.options).onBlockedNode)===null||gr===void 0||gr.call(vr,mr,yr))),pr)}));var fr=sr.numberOfChanges(ur);return fr!==0||dr===fr?cr:void 0}),this.rrweb=or,this.options=lr,this.refillRate=(ir=this.options.refillRate)!==null&&ir!==void 0?ir:this.refillRate,this.bucketSize=(ar=this.options.bucketSize)!==null&&ar!==void 0?ar:this.bucketSize,setInterval(function(){sr.refillBuckets()},1e3)}),Rt=function(nr){return nr[nr.DomContentLoaded=0]="DomContentLoaded",nr[nr.Load=1]="Load",nr[nr.FullSnapshot=2]="FullSnapshot",nr[nr.IncrementalSnapshot=3]="IncrementalSnapshot",nr[nr.Meta=4]="Meta",nr[nr.Custom=5]="Custom",nr[nr.Plugin=6]="Plugin",nr}(Rt||{}),xt={initiatorTypes:["audio","beacon","body","css","early-hint","embed","fetch","frame","iframe","icon","image","img","input","link","navigation","object","ping","script","track","video","xmlhttprequest"],maskRequestFn:function(nr){return nr},recordHeaders:!1,recordBody:!1,recordInitialRequests:!1,recordPerformance:!1,performanceEntryTypeToObserve:["first-input","navigation","paint","resource"],payloadSizeLimitBytes:1e6},Et=["authorization","x-forwarded-for","authorization","cookie","set-cookie","x-api-key","x-real-ip","remote-addr","forwarded","proxy-authorization","x-csrf-token","x-csrftoken","x-xsrf-token"],Ct=["/s/","/e/","/i/vo/e/"];function Ot(nr,or,ir,ar){var sr=or==null?void 0:or["content-length"];return sr&&parseInt(sr)>ir?"".concat(ar," body too large to record"):nr}var $t=function(nr,or){var ir,ar,sr,lr=nr.session_recording,cr=lr.recordHeaders!==!1&&or.recordHeaders,ur=lr.recordBody!==!1&&or.recordBody,dr=lr.recordPerformance!==!1&&or.recordPerformance,fr=(ir=lr,sr=Math.min(1e6,(ar=ir.payloadSizeLimitBytes)!==null&&ar!==void 0?ar:1e6),function(gr){return gr!=null&&gr.requestBody&&(gr.requestBody=Ot(gr.requestBody,gr.requestHeaders,sr,"Request")),gr!=null&&gr.responseBody&&(gr.responseBody=Ot(gr.responseBody,gr.responseHeaders,sr,"Response")),gr}),pr=function(gr){return fr(function(mr){var yr=vt(mr.name);if(!(yr&&yr.pathname&&Ct.includes(yr.pathname)))return mr}((vr=gr,Object.keys((br=vr.requestHeaders)!==null&&br!==void 0?br:{}).forEach(function(mr){var yr;Et.includes(mr.toLowerCase())&&((yr=vr.requestHeaders)===null||yr===void 0||delete yr[mr])}),vr)));var vr,br},hr=P(nr.session_recording.maskNetworkRequestFn);return hr&&P(nr.session_recording.maskCapturedNetworkRequestFn)&&j.warn("Both `maskNetworkRequestFn` and `maskCapturedNetworkRequestFn` are defined. `maskNetworkRequestFn` will be ignored."),hr&&(nr.session_recording.maskCapturedNetworkRequestFn=function(gr){var vr=nr.session_recording.maskNetworkRequestFn({url:gr.name});return t(t({},gr),{},{name:vr==null?void 0:vr.url})}),lr.maskRequestFn=P(nr.session_recording.maskCapturedNetworkRequestFn)?function(gr){var vr,br,mr,yr=pr(gr);return yr&&(vr=(br=(mr=nr.session_recording).maskCapturedNetworkRequestFn)===null||br===void 0?void 0:br.call(mr,yr))!==null&&vr!==void 0?vr:void 0}:void 0,lr.maskRequestFn||(lr.maskRequestFn=pr),t(t(t({},xt),lr),{},{recordHeaders:cr,recordBody:ur,recordPerformance:dr,recordInitialRequests:dr})},At="__ph_opt_in_out_";function Mt(nr,or){Ht(!0,nr,or)}function Tt(nr,or){Ht(!1,nr,or)}function qt(nr,or){return jt(nr,or)==="1"}function Dt(nr,or){return!!function(ir){if(ir&&ir.respectDnt){var ar=ir&&ir.window||T,sr=ar==null?void 0:ar.navigator,lr=!1;return U([sr==null?void 0:sr.doNotTrack,sr.msDoNotTrack,ar.doNotTrack],function(cr){z([!0,1,"1","yes"],cr)&&(lr=!0)}),lr}return!1}(or)||jt(nr,or)==="0"}function Lt(nr,or){Bt(or=or||{}).remove(Nt(nr,or),!!or.crossSubdomainCookie)}function Bt(nr){return(nr=nr||{}).persistenceType==="localStorage"?lt:nr.persistenceType==="localStorage+cookie"?dt:at}function Nt(nr,or){return((or=or||{}).persistencePrefix||At)+nr}function jt(nr,or){return Bt(or).get(Nt(nr,or))}function Ht(nr,or,ir){x(or)&&or.length?(Bt(ir=ir||{}).set(Nt(or,ir),nr?1:0,C(ir.cookieExpiration)?ir.cookieExpiration:null,ir.crossSubdomainCookie,ir.secureCookie),ir.capture&&nr&&ir.capture(ir.captureEventName||"$opt_in",ir.captureProperties||{},{send_instantly:!0})):j.error("gdpr."+(nr?"optIn":"optOut")+" called with an invalid token")}function Wt(nr){var or=!1;try{var ir=nr.config.token,ar=nr.config.respect_dnt,sr=nr.config.opt_out_capturing_persistence_type,lr=nr.config.opt_out_capturing_cookie_prefix||void 0,cr=nr.config.window;ir&&(or=Dt(ir,{respectDnt:ar,persistenceType:sr,persistencePrefix:lr,window:cr}))}catch(ur){j.error("Unexpected error when checking capturing opt-out status: "+ur)}return or}var Vt,Ut=3e5,Gt=Ut;(function(nr){nr[nr.Mutation=0]="Mutation",nr[nr.MouseMove=1]="MouseMove",nr[nr.MouseInteraction=2]="MouseInteraction",nr[nr.Scroll=3]="Scroll",nr[nr.ViewportResize=4]="ViewportResize",nr[nr.Input=5]="Input",nr[nr.TouchMove=6]="TouchMove",nr[nr.MediaInteraction=7]="MediaInteraction",nr[nr.StyleSheetRule=8]="StyleSheetRule",nr[nr.CanvasMutation=9]="CanvasMutation",nr[nr.Font=10]="Font",nr[nr.Log=11]="Log",nr[nr.Drag=12]="Drag",nr[nr.StyleDeclaration=13]="StyleDeclaration",nr[nr.Selection=14]="Selection",nr[nr.AdoptedStyleSheet=15]="AdoptedStyleSheet"})(Vt||(Vt={}));var zt=[Vt.MouseMove,Vt.MouseInteraction,Vt.Scroll,Vt.ViewportResize,Vt.Input,Vt.TouchMove,Vt.MediaInteraction,Vt.Drag],Qt=function(nr){return{rrwebMethod:nr,enqueuedAt:Date.now(),attempt:1}},Yt=function(){function nr(or){var ir=this;if(i(this,nr),s(this,"queuedRRWebEvents",[]),s(this,"isIdle",!1),s(this,"_linkedFlagSeen",!1),s(this,"_lastActivityTimestamp",Date.now()),s(this,"windowId",null),s(this,"sessionId",null),s(this,"_linkedFlag",null),s(this,"_sampleRate",null),s(this,"_minimumDuration",null),s(this,"_recordCanvas",!1),s(this,"_canvasFps",null),s(this,"_canvasQuality",null),s(this,"_forceAllowLocalhostNetworkCapture",!1),this.instance=or,this._captureStarted=!1,this._endpoint="/s/",this.stopRrweb=void 0,this.receivedDecide=!1,T==null||T.addEventListener("beforeunload",function(){ir._flushBuffer()}),T==null||T.addEventListener("offline",function(){ir._tryAddCustomEvent("browser offline",{})}),T==null||T.addEventListener("online",function(){ir._tryAddCustomEvent("browser online",{})}),!this.instance.sessionManager)throw j.error("Session recording started without valid sessionManager"),new Error("Session recording started without valid sessionManager. This is a bug.");this.buffer=this.clearBuffer()}return o(nr,[{key:"started",get:function(){return this._captureStarted}},{key:"sessionManager",get:function(){if(!this.instance.sessionManager)throw j.error("Session recording started without valid sessionManager"),new Error("Session recording started without valid sessionManager. This is a bug.");return this.instance.sessionManager}},{key:"isSampled",get:function(){return C(this._sampleRate)?this.instance.get_property(Oe):null}},{key:"sessionDuration",get:function(){var or,ir,ar=(or=this.buffer)===null||or===void 0?void 0:or.data[((ir=this.buffer)===null||ir===void 0?void 0:ir.data.length)-1],sr=this.sessionManager.checkAndGetSessionAndWindowId(!0).sessionStartTimestamp;return ar?ar.timestamp-sr:null}},{key:"isRecordingEnabled",get:function(){var or=!!this.instance.get_property(Ie),ir=!this.instance.config.disable_session_recording;return T&&or&&ir}},{key:"isConsoleLogCaptureEnabled",get:function(){var or=!!this.instance.get_property(Re),ir=this.instance.config.enable_recording_console_log;return ir??or}},{key:"recordingVersion",get:function(){var or,ir=this.instance.get_property(xe);return((or=this.instance.config.session_recording)===null||or===void 0?void 0:or.recorderVersion)||ir||"v1"}},{key:"networkPayloadCapture",get:function(){var or,ir,ar=this.instance.get_property(Ee),sr={recordHeaders:(or=this.instance.config.session_recording)===null||or===void 0?void 0:or.recordHeaders,recordBody:(ir=this.instance.config.session_recording)===null||ir===void 0?void 0:ir.recordBody},lr=(sr==null?void 0:sr.recordHeaders)||(ar==null?void 0:ar.recordHeaders),cr=(sr==null?void 0:sr.recordBody)||(ar==null?void 0:ar.recordBody),ur=this.instance.config.capture_performance||(ar==null?void 0:ar.capturePerformance);return lr||cr||ur?{recordHeaders:lr,recordBody:cr,recordPerformance:ur}:void 0}},{key:"status",get:function(){return this.receivedDecide?this.isRecordingEnabled?x(this._linkedFlag)&&!this._linkedFlagSeen?"buffering":O(this.isSampled)?this.isSampled?"sampled":"disabled":"active":"disabled":"buffering"}},{key:"startRecordingIfEnabled",value:function(){this.isRecordingEnabled?(this.startCaptureAndTrySendingQueuedSnapshots(),j.info("[SessionRecording] started")):(this.stopRecording(),this.clearBuffer())}},{key:"stopRecording",value:function(){this._captureStarted&&this.stopRrweb&&(this.stopRrweb(),this.stopRrweb=void 0,this._captureStarted=!1,j.info("[SessionRecording] stopped"))}},{key:"makeSamplingDecision",value:function(or){var ir,ar=this.sessionId!==or;if(C(this._sampleRate)){var sr,lr=this.isSampled;ar||!O(lr)?sr=Math.random()<this._sampleRate:sr=lr,sr||j.warn("[SessionSampling] Sample rate (".concat(this._sampleRate,") has determined that this sessionId (").concat(or,") will not be sent to the server.")),(ir=this.instance.persistence)===null||ir===void 0||ir.register(s({},Oe,sr))}else{var cr;(cr=this.instance.persistence)===null||cr===void 0||cr.register(s({},Oe,null))}}},{key:"afterDecideResponse",value:function(or){var ir,ar,sr,lr,cr,ur,dr,fr,pr,hr,gr,vr=this;this.instance.persistence&&this.instance.persistence.register((s(gr={},Ie,!!or.sessionRecording),s(gr,Re,(fr=or.sessionRecording)===null||fr===void 0?void 0:fr.consoleLogRecordingEnabled),s(gr,xe,(pr=or.sessionRecording)===null||pr===void 0?void 0:pr.recorderVersion),s(gr,Ee,t({capturePerformance:or.capturePerformance},(hr=or.sessionRecording)===null||hr===void 0?void 0:hr.networkPayloadCapture)),gr));var br=(ir=or.sessionRecording)===null||ir===void 0?void 0:ir.sampleRate;this._sampleRate=R(br)||E(br)?null:parseFloat(br);var mr=(ar=or.sessionRecording)===null||ar===void 0?void 0:ar.minimumDurationMilliseconds;this._minimumDuration=R(mr)?null:mr;var yr=(sr=or.sessionRecording)===null||sr===void 0?void 0:sr.recordCanvas;this._recordCanvas=!R(yr)&&!E(yr)&&yr;var wr=(lr=or.sessionRecording)===null||lr===void 0?void 0:lr.canvasFps;this._canvasFps=R(wr)?null:wr;var Tr,Pr=(cr=or.sessionRecording)===null||cr===void 0?void 0:cr.canvasQuality;if(this._canvasQuality=R(Pr)||E(Pr)?null:parseFloat(Pr),this._linkedFlag=((ur=or.sessionRecording)===null||ur===void 0?void 0:ur.linkedFlag)||null,(dr=or.sessionRecording)!==null&&dr!==void 0&&dr.endpoint&&(this._endpoint=(Tr=or.sessionRecording)===null||Tr===void 0?void 0:Tr.endpoint),C(this._sampleRate)&&this.sessionManager.onSessionId(function(_r){vr.makeSamplingDecision(_r)}),x(this._linkedFlag)){var Rr=this._linkedFlag;this.instance.onFeatureFlags(function(_r){vr._linkedFlagSeen=_r.includes(Rr)})}this.receivedDecide=!0,this.startRecordingIfEnabled()}},{key:"log",value:function(or){var ir,ar=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"log";(ir=this.instance.sessionRecording)===null||ir===void 0||ir.onRRwebEmit({type:6,data:{plugin:"rrweb/console@1",payload:{level:ar,trace:[],payload:[JSON.stringify(or)]}},timestamp:Y()})}},{key:"startCaptureAndTrySendingQueuedSnapshots",value:function(){this._startCapture()}},{key:"_startCapture",value:function(){var or=this;if(!R(Object.assign)&&!(this._captureStarted||this.instance.config.disable_session_recording||Wt(this.instance))){this._captureStarted=!0,this.sessionManager.checkAndGetSessionAndWindowId();var ir=this.recordingVersion==="v2"?"recorder-v2.js":"recorder.js";this.instance.__loaded_recorder_version!==this.recordingVersion?re(this.instance.config.api_host+"/static/".concat(ir,"?v=").concat(m.LIB_VERSION),function(ar){if(ar)return j.error("Could not load ".concat(ir),ar);or._onScriptLoaded()}):this._onScriptLoaded()}}},{key:"_isInteractiveEvent",value:function(or){var ir;return or.type===3&&zt.indexOf((ir=or.data)===null||ir===void 0?void 0:ir.source)!==-1}},{key:"_updateWindowAndSessionIds",value:function(or){var ir=this._isInteractiveEvent(or);ir||this.isIdle||or.timestamp-this._lastActivityTimestamp>Gt&&(this.isIdle=!0,this._tryAddCustomEvent("sessionIdle",{reason:"user inactivity",timeSinceLastActive:or.timestamp-this._lastActivityTimestamp,threshold:Gt}));var ar=!1;if(ir&&(this._lastActivityTimestamp=or.timestamp,this.isIdle&&(this.isIdle=!1,this._tryAddCustomEvent("sessionNoLongerIdle",{reason:"user activity",type:or.type}),ar=!0)),!this.isIdle){var sr=this.sessionManager.checkAndGetSessionAndWindowId(!ir,or.timestamp),lr=sr.windowId,cr=sr.sessionId,ur=this.sessionId!==cr,dr=this.windowId!==lr;this.windowId=lr,this.sessionId=cr,(ar||[Ft,Pt].indexOf(or.type)===-1&&(dr||ur))&&this._tryTakeFullSnapshot()}}},{key:"_tryRRWebMethod",value:function(or){try{return or.rrwebMethod(),!0}catch(ir){return j.warn("[Session-Recording] could not emit queued rrweb event.",ir),this.queuedRRWebEvents.length<10&&this.queuedRRWebEvents.push({enqueuedAt:or.enqueuedAt||Date.now(),attempt:or.attempt++,rrwebMethod:or.rrwebMethod}),!1}}},{key:"_tryAddCustomEvent",value:function(or,ir){var ar=this;return this._tryRRWebMethod(Qt(function(){return ar.rrwebRecord.addCustomEvent(or,ir)}))}},{key:"_tryTakeFullSnapshot",value:function(){var or=this;return this._tryRRWebMethod(Qt(function(){return or.rrwebRecord.takeFullSnapshot()}))}},{key:"_onScriptLoaded",value:function(){var or,ir=this,ar={blockClass:"ph-no-capture",blockSelector:void 0,ignoreClass:"ph-ignore-input",maskTextClass:"ph-mask",maskTextSelector:void 0,maskTextFn:void 0,maskAllInputs:!0,maskInputOptions:{},maskInputFn:void 0,slimDOMOptions:{},collectFonts:!1,inlineStylesheet:!0,recordCrossOriginIframes:!1};this.rrwebRecord=T.rrweb?T.rrweb.record:T.rrwebRecord;for(var sr=this.instance.config.session_recording,lr=0,cr=Object.entries(sr||{});lr<cr.length;lr++){var ur=f(cr[lr],2),dr=ur[0],fr=ur[1];dr in ar&&(ar[dr]=fr)}if(!this._recordCanvas||E(this._canvasFps)||E(this._canvasQuality)||(ar.recordCanvas=!0,ar.sampling={canvas:this._canvasFps},ar.dataURLOptions={type:"image/webp",quality:this._canvasQuality}),this.rrwebRecord){this.mutationRateLimiter=(or=this.mutationRateLimiter)!==null&&or!==void 0?or:new It(this.rrwebRecord,{onBlockedNode:function(hr,gr){var vr="Too many mutations on node '".concat(hr,"'. Rate limiting. This could be due to SVG animations or something similar");j.info(vr,{node:gr}),ir.log("[PostHog Recorder] "+vr,"warn")}}),this._scheduleFullSnapshot();var pr=this._gatherRRWebPlugins();this.stopRrweb=this.rrwebRecord(t({emit:function(hr){ir.onRRwebEmit(hr)},plugins:pr},ar)),this.instance._addCaptureHook(function(hr){try{if(hr==="$pageview"){var gr=T?ir._maskUrl(T.location.href):"";if(!gr)return;ir._tryAddCustomEvent("$pageview",{href:gr})}}catch(vr){j.error("Could not add $pageview to rrweb session",vr)}}),this._lastActivityTimestamp=Date.now(),this.isIdle=!1,this._tryAddCustomEvent("$session_options",{sessionRecordingOptions:ar,activePlugins:pr.map(function(hr){return hr==null?void 0:hr.name})})}else j.error("onScriptLoaded was called but rrwebRecord is not available. This indicates something has gone wrong.")}},{key:"_scheduleFullSnapshot",value:function(){var or=this;this._fullSnapshotTimer&&clearInterval(this._fullSnapshotTimer),this._fullSnapshotTimer=setInterval(function(){or._tryTakeFullSnapshot()},Ut)}},{key:"_gatherRRWebPlugins",value:function(){var or=[];return B.rrwebConsoleRecord&&this.isConsoleLogCaptureEnabled&&or.push(B.rrwebConsoleRecord.getRecordConsolePlugin()),this.networkPayloadCapture&&P(B.getRecordNetworkPlugin)&&(!gt.includes(location.hostname)||this._forceAllowLocalhostNetworkCapture?or.push(B.getRecordNetworkPlugin($t(this.instance.config,this.networkPayloadCapture))):j.info("[SessionReplay-NetworkCapture] not started because we are on localhost.")),or}},{key:"onRRwebEmit",value:function(or){if(this._processQueuedEvents(),or&&I(or)){if(or.type===Rt.Meta){var ir=this._maskUrl(or.data.href);if(!ir)return;or.data.href=ir}or.type===Rt.FullSnapshot&&this._scheduleFullSnapshot();var ar=this.mutationRateLimiter?this.mutationRateLimiter.throttleMutations(or):or;if(ar){var sr=function(ur){var dr=ur;if(dr&&I(dr)&&dr.type===6&&I(dr.data)&&dr.data.plugin==="rrweb/console@1"){dr.data.payload.payload.length>10&&(dr.data.payload.payload=dr.data.payload.payload.slice(0,10),dr.data.payload.payload.push("...[truncated]"));for(var fr=[],pr=0;pr<dr.data.payload.payload.length;pr++)dr.data.payload.payload[pr]&&dr.data.payload.payload[pr].length>2e3?fr.push(dr.data.payload.payload[pr].slice(0,2e3)+"...[truncated]"):fr.push(dr.data.payload.payload[pr]);return dr.data.payload.payload=fr,ur}return ur}(ar),lr=JSON.stringify(sr).length;if(this._updateWindowAndSessionIds(sr),!this.isIdle){var cr={$snapshot_bytes:lr,$snapshot_data:sr,$session_id:this.sessionId,$window_id:this.windowId};this.status!=="disabled"?this._captureSnapshotBuffered(cr):this.clearBuffer()}}}}},{key:"_processQueuedEvents",value:function(){var or=this;if(this.queuedRRWebEvents.length){var ir=p(this.queuedRRWebEvents);this.queuedRRWebEvents=[],ir.forEach(function(ar){Date.now()-ar.enqueuedAt>2e3?or._tryAddCustomEvent("rrwebQueueTimeout",{enqueuedAt:ar.enqueuedAt,attempt:ar.attempt,queueLength:ir.length}):or._tryRRWebMethod(ar)&&or._tryAddCustomEvent("rrwebQueueSuccess",{enqueuedAt:ar.enqueuedAt,attempt:ar.attempt,queueLength:ir.length})})}}},{key:"_maskUrl",value:function(or){var ir=this.instance.config.session_recording;if(ir.maskNetworkRequestFn){var ar,sr={url:or};return(ar=sr=ir.maskNetworkRequestFn(sr))===null||ar===void 0?void 0:ar.url}return or}},{key:"clearBuffer",value:function(){return this.buffer=void 0,{size:0,data:[],sessionId:this.sessionId,windowId:this.windowId}}},{key:"_flushBuffer",value:function(){var or=this;this.flushBufferTimer&&(clearTimeout(this.flushBufferTimer),this.flushBufferTimer=void 0);var ir=this._minimumDuration,ar=this.sessionDuration,sr=C(ar)&&ar>=0,lr=C(ir)&&sr&&ar<ir;return this.status==="buffering"||lr?(this.flushBufferTimer=setTimeout(function(){or._flushBuffer()},2e3),this.buffer||this.clearBuffer()):this.buffer&&this.buffer.data.length!==0?(this._captureSnapshot({$snapshot_bytes:this.buffer.size,$snapshot_data:this.buffer.data,$session_id:this.buffer.sessionId,$window_id:this.buffer.windowId}),this.clearBuffer()):this.buffer||this.clearBuffer()}},{key:"_captureSnapshotBuffered",value:function(or){var ir,ar=this,sr=2+(((ir=this.buffer)===null||ir===void 0?void 0:ir.data.length)||0);(!this.buffer||this.buffer.size+or.$snapshot_bytes+sr>943718.4||this.buffer.sessionId&&this.buffer.sessionId!==this.sessionId)&&(this.buffer=this._flushBuffer()),E(this.buffer.sessionId)&&!E(this.sessionId)&&(this.buffer.sessionId=this.sessionId,this.buffer.windowId=this.windowId),this.buffer.size+=or.$snapshot_bytes,this.buffer.data.push(or.$snapshot_data),this.flushBufferTimer||(this.flushBufferTimer=setTimeout(function(){ar._flushBuffer()},2e3))}},{key:"_captureSnapshot",value:function(or){this.instance.capture("$snapshot",or,{transport:"XHR",method:"POST",endpoint:this._endpoint,_noTruncate:!0,_batchKey:"recordings",_metrics:{rrweb_full_snapshot:or.$snapshot_data.type===Ft}})}}]),nr}(),Jt=function(){function nr(or){i(this,nr),this.instance=or,this.instance.decideEndpointWasHit=this.instance._hasBootstrappedFeatureFlags()}return o(nr,[{key:"call",value:function(){var or=this,ir=te(JSON.stringify({token:this.instance.config.token,distinct_id:this.instance.get_distinct_id(),groups:this.instance.getGroups(),person_properties:this.instance.get_property(Me),group_properties:this.instance.get_property(Te),disable_flags:this.instance.config.advanced_disable_feature_flags||this.instance.config.advanced_disable_feature_flags_on_first_load||void 0}));this.instance._send_request("".concat(this.instance.config.api_host,"/decide/?v=3"),{data:ir,verbose:!0},{method:"POST"},function(ar){return or.parseDecideResponse(ar)})}},{key:"parseDecideResponse",value:function(or){var ir,ar=this;if(this.instance.featureFlags.setReloadingPaused(!1),this.instance.featureFlags._startReloadTimer(),(or==null?void 0:or.status)!==0){if(!D||!D.body)return j.info("document not ready yet, trying again in 500 milliseconds..."),void setTimeout(function(){ar.parseDecideResponse(or)},500);this.instance.toolbar.afterDecideResponse(or),(ir=this.instance.sessionRecording)===null||ir===void 0||ir.afterDecideResponse(or),We.afterDecideResponse(or,this.instance),this.instance._afterDecideResponse(or),this.instance.config.advanced_disable_feature_flags_on_first_load||this.instance.config.advanced_disable_feature_flags||this.instance.featureFlags.receivedFeatureFlags(or);var sr=T==null?void 0:T.extendPostHogWithSurveys;or.surveys&&!sr&&re(this.instance.config.api_host+"/static/surveys.js",function(pr){if(pr)return j.error("Could not load surveys script",pr);T.extendPostHogWithSurveys(ar.instance)});var lr=T==null?void 0:T.extendPostHogWithExceptionAutoCapture;if(or.autocaptureExceptions&&or.autocaptureExceptions&&R(lr)&&re(this.instance.config.api_host+"/static/exception-autocapture.js",function(pr){if(pr)return j.error("Could not load exception autocapture script",pr);T.extendPostHogWithExceptionAutocapture(ar.instance,or)}),or.siteApps)if(this.instance.config.opt_in_site_apps){var cr,ur=this.instance.config.api_host,dr=v(or.siteApps);try{var fr=function(){var pr=cr.value,hr=pr.id,gr=pr.url,vr=[ur,ur[ur.length-1]==="/"&&gr[0]==="/"?gr.substring(1):gr].join("");B["__$$ph_site_app_".concat(hr)]=ar.instance,re(vr,function(br){br&&j.error("Error while initializing PostHog app with config id ".concat(hr),br)})};for(dr.s();!(cr=dr.n()).done;)fr()}catch(pr){dr.e(pr)}finally{dr.f()}}else or.siteApps.length>0&&j.error('PostHog site apps are disabled. Enable the "opt_in_site_apps" config to proceed.')}else j.error("Failed to fetch feature flags from PostHog.")}}]),nr}(),Xt=["https://app.posthog.com","https://eu.posthog.com"],Kt=["source"],Zt=T!=null&&T.location?bt(T.location.hash,"__posthog")||bt(location.hash,"state"):null,en=function(){function nr(or){i(this,nr),this.instance=or}return o(nr,[{key:"afterDecideResponse",value:function(or){var ir=or.toolbarParams||or.editorParams||(or.toolbarVersion?{toolbarVersion:or.toolbarVersion}:{});or.isAuthenticated&&ir.toolbarVersion&&ir.toolbarVersion.indexOf("toolbar")===0&&this.loadToolbar(t({},ir))}},{key:"maybeLoadToolbar",value:function(){var or,ir,ar=arguments.length>0&&arguments[0]!==void 0?arguments[0]:void 0,sr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0,lr=arguments.length>2&&arguments[2]!==void 0?arguments[2]:void 0;if(!T||!D)return!1;ar=(or=ar)!==null&&or!==void 0?or:T.location,lr=(ir=lr)!==null&&ir!==void 0?ir:T.history;try{if(!sr){try{T.localStorage.setItem("test","test"),T.localStorage.removeItem("test")}catch{return!1}sr=T==null?void 0:T.localStorage}var cr,ur=Zt||bt(ar.hash,"__posthog")||bt(ar.hash,"state"),dr=ur?J(function(){return JSON.parse(atob(decodeURIComponent(ur)))})||J(function(){return JSON.parse(decodeURIComponent(ur))}):null;return dr&&dr.action==="ph_authorize"?((cr=dr).source="url",cr&&Object.keys(cr).length>0&&(dr.desiredHash?ar.hash=dr.desiredHash:lr?lr.replaceState("",D.title,ar.pathname+ar.search):ar.hash="")):((cr=JSON.parse(sr.getItem("_postHogToolbarParams")||"{}")).source="localstorage",delete cr.userIntent),!(!cr.token||this.instance.config.token!==cr.token)&&(this.loadToolbar(cr),!0)}catch{return!1}}},{key:"loadToolbar",value:function(or){var ir=this;if(!T||B._postHogToolbarLoaded)return!1;B._postHogToolbarLoaded=!0;var ar=this.instance.config.api_host,sr=3e5,lr=Math.floor(Date.now()/sr)*sr,cr="".concat(ar).concat(ar.endsWith("/")?"":"/","static/toolbar.js?t=").concat(lr),ur=!Xt.includes(this.instance.config.api_host)&&this.instance.config.advanced_disable_toolbar_metrics,dr=t(t({token:this.instance.config.token},or),{},{apiURL:ar},ur?{instrument:!1}:{});dr.source;var fr=c(dr,Kt);return T.localStorage.setItem("_postHogToolbarParams",JSON.stringify(fr)),re(cr,function(pr){pr?j.error("Failed to load toolbar",pr):(B.ph_load_toolbar||B.ph_load_editor)(dr,ir.instance)}),ie(T,"turbolinks:load",function(){B._postHogToolbarLoaded=!1,ir.loadToolbar(dr)}),!0}},{key:"_loadEditor",value:function(or){return this.loadToolbar(or)}},{key:"maybeLoadEditor",value:function(){var or=arguments.length>0&&arguments[0]!==void 0?arguments[0]:void 0,ir=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0,ar=arguments.length>2&&arguments[2]!==void 0?arguments[2]:void 0;return this.maybeLoadToolbar(or,ir,ar)}}]),nr}(),tn=function(){function nr(){var or=arguments.length>0&&arguments[0]!==void 0?arguments[0]:3e3;i(this,nr),this.isPolling=!0,this._event_queue=[],this._empty_queue_count=0,this._poller=void 0,this._pollInterval=or}return o(nr,[{key:"setPollInterval",value:function(or){this._pollInterval=or,this.isPolling&&this.poll()}},{key:"poll",value:function(){}},{key:"unload",value:function(){}},{key:"getTime",value:function(){return new Date().getTime()}}]),nr}(),nn=function(nr){a(ir,tn);var or=h(ir);function ir(ar){var sr,lr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:3e3;return i(this,ir),(sr=or.call(this,lr)).handlePollRequest=ar,sr}return o(ir,[{key:"enqueue",value:function(ar,sr,lr){this._event_queue.push({url:ar,data:sr,options:lr}),this.isPolling||(this.isPolling=!0,this.poll())}},{key:"poll",value:function(){var ar=this;clearTimeout(this._poller),this._poller=setTimeout(function(){if(ar._event_queue.length>0){var sr=ar.formatQueue(),lr=function(ur){var dr=sr[ur],fr=dr.url,pr=dr.data,hr=dr.options;U(pr,function(gr,vr){pr[vr].offset=Math.abs(pr[vr].timestamp-ar.getTime()),delete pr[vr].timestamp}),ar.handlePollRequest(fr,pr,hr)};for(var cr in sr)lr(cr);ar._event_queue.length=0,ar._empty_queue_count=0}else ar._empty_queue_count++;ar._empty_queue_count>4&&(ar.isPolling=!1,ar._empty_queue_count=0),ar.isPolling&&ar.poll()},this._pollInterval)}},{key:"unload",value:function(){var ar=this;clearTimeout(this._poller);var sr=this._event_queue.length>0?this.formatQueue():{};this._event_queue.length=0;var lr=Object.values(sr);[].concat(p(lr.filter(function(cr){return cr.url.indexOf("/e")===0})),p(lr.filter(function(cr){return cr.url.indexOf("/e")!==0}))).map(function(cr){var ur=cr.url,dr=cr.data,fr=cr.options;ar.handlePollRequest(ur,dr,t(t({},fr),{},{transport:"sendBeacon"}))})}},{key:"formatQueue",value:function(){var ar={};return U(this._event_queue,function(sr){var lr=sr.url,cr=sr.data,ur=sr.options,dr=(ur?ur._batchKey:null)||lr;R(ar[dr])&&(ar[dr]={data:[],url:lr,options:ur}),ur&&ar[dr].options&&ar[dr].options._metrics&&!ar[dr].options._metrics.rrweb_full_snapshot&&(ar[dr].options._metrics.rrweb_full_snapshot=ur._metrics.rrweb_full_snapshot),ar[dr].data.push(cr)}),ar}}]),ir}(),rn=Uint8Array,on=Uint16Array,sn=Uint32Array,an=new rn([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),un=new rn([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ln=new rn([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),cn=function(nr,or){for(var ir=new on(31),ar=0;ar<31;++ar)ir[ar]=or+=1<<nr[ar-1];var sr=new sn(ir[30]);for(ar=1;ar<30;++ar)for(var lr=ir[ar];lr<ir[ar+1];++lr)sr[lr]=lr-ir[ar]<<5|ar;return[ir,sr]},dn=cn(an,2),hn=dn[0],fn=dn[1];hn[28]=258,fn[258]=28;for(var pn=cn(un,0)[1],_n=new on(32768),gn=0;gn<32768;++gn){var vn=(43690&gn)>>>1|(21845&gn)<<1;vn=(61680&(vn=(52428&vn)>>>2|(13107&vn)<<2))>>>4|(3855&vn)<<4,_n[gn]=((65280&vn)>>>8|(255&vn)<<8)>>>1}var mn=function(nr,or,ir){for(var ar=nr.length,sr=0,lr=new on(or);sr<ar;++sr)++lr[nr[sr]-1];var cr,ur=new on(or);for(sr=0;sr<or;++sr)ur[sr]=ur[sr-1]+lr[sr-1]<<1;if(ir){cr=new on(1<<or);var dr=15-or;for(sr=0;sr<ar;++sr)if(nr[sr])for(var fr=sr<<4|nr[sr],pr=or-nr[sr],hr=ur[nr[sr]-1]++<<pr,gr=hr|(1<<pr)-1;hr<=gr;++hr)cr[_n[hr]>>>dr]=fr}else for(cr=new on(ar),sr=0;sr<ar;++sr)cr[sr]=_n[ur[nr[sr]-1]++]>>>15-nr[sr];return cr},yn=new rn(288);for(gn=0;gn<144;++gn)yn[gn]=8;for(gn=144;gn<256;++gn)yn[gn]=9;for(gn=256;gn<280;++gn)yn[gn]=7;for(gn=280;gn<288;++gn)yn[gn]=8;var bn=new rn(32);for(gn=0;gn<32;++gn)bn[gn]=5;var kn,wn=mn(yn,9,0),Sn=mn(bn,5,0),Fn=function(nr){return(nr/8>>0)+(7&nr&&1)},Pn=function(nr,or,ir){(or==null||or<0)&&(or=0),(ir==null||ir>nr.length)&&(ir=nr.length);var ar=new(nr instanceof on?on:nr instanceof sn?sn:rn)(ir-or);return ar.set(nr.subarray(or,ir)),ar},In=function(nr,or,ir){ir<<=7&or;var ar=or/8>>0;nr[ar]|=ir,nr[ar+1]|=ir>>>8},Rn=function(nr,or,ir){ir<<=7&or;var ar=or/8>>0;nr[ar]|=ir,nr[ar+1]|=ir>>>8,nr[ar+2]|=ir>>>16},xn=function(nr,or){for(var ir=[],ar=0;ar<nr.length;++ar)nr[ar]&&ir.push({s:ar,f:nr[ar]});var sr=ir.length,lr=ir.slice();if(!sr)return[new rn(0),0];if(sr==1){var cr=new rn(ir[0].s+1);return cr[ir[0].s]=1,[cr,1]}ir.sort(function(_r,jr){return _r.f-jr.f}),ir.push({s:-1,f:25001});var ur=ir[0],dr=ir[1],fr=0,pr=1,hr=2;for(ir[0]={s:-1,f:ur.f+dr.f,l:ur,r:dr};pr!=sr-1;)ur=ir[ir[fr].f<ir[hr].f?fr++:hr++],dr=ir[fr!=pr&&ir[fr].f<ir[hr].f?fr++:hr++],ir[pr++]={s:-1,f:ur.f+dr.f,l:ur,r:dr};var gr=lr[0].s;for(ar=1;ar<sr;++ar)lr[ar].s>gr&&(gr=lr[ar].s);var vr=new on(gr+1),br=En(ir[pr-1],vr,0);if(br>or){ar=0;var mr=0,yr=br-or,wr=1<<yr;for(lr.sort(function(_r,jr){return vr[jr.s]-vr[_r.s]||_r.f-jr.f});ar<sr;++ar){var Tr=lr[ar].s;if(!(vr[Tr]>or))break;mr+=wr-(1<<br-vr[Tr]),vr[Tr]=or}for(mr>>>=yr;mr>0;){var Pr=lr[ar].s;vr[Pr]<or?mr-=1<<or-vr[Pr]++-1:++ar}for(;ar>=0&&mr;--ar){var Rr=lr[ar].s;vr[Rr]==or&&(--vr[Rr],++mr)}br=or}return[new rn(vr),br]},En=function nr(or,ir,ar){return or.s==-1?Math.max(nr(or.l,ir,ar+1),nr(or.r,ir,ar+1)):ir[or.s]=ar},Cn=function(nr){for(var or=nr.length;or&&!nr[--or];);for(var ir=new on(++or),ar=0,sr=nr[0],lr=1,cr=function(dr){ir[ar++]=dr},ur=1;ur<=or;++ur)if(nr[ur]==sr&&ur!=or)++lr;else{if(!sr&&lr>2){for(;lr>138;lr-=138)cr(32754);lr>2&&(cr(lr>10?lr-11<<5|28690:lr-3<<5|12305),lr=0)}else if(lr>3){for(cr(sr),--lr;lr>6;lr-=6)cr(8304);lr>2&&(cr(lr-3<<5|8208),lr=0)}for(;lr--;)cr(sr);lr=1,sr=nr[ur]}return[ir.subarray(0,ar),or]},On=function(nr,or){for(var ir=0,ar=0;ar<or.length;++ar)ir+=nr[ar]*or[ar];return ir},$n=function(nr,or,ir){var ar=ir.length,sr=Fn(or+2);nr[sr]=255&ar,nr[sr+1]=ar>>>8,nr[sr+2]=255^nr[sr],nr[sr+3]=255^nr[sr+1];for(var lr=0;lr<ar;++lr)nr[sr+lr+4]=ir[lr];return 8*(sr+4+ar)},An=function(nr,or,ir,ar,sr,lr,cr,ur,dr,fr,pr){In(or,pr++,ir),++sr[256];for(var hr=xn(sr,15),gr=hr[0],vr=hr[1],br=xn(lr,15),mr=br[0],yr=br[1],wr=Cn(gr),Tr=wr[0],Pr=wr[1],Rr=Cn(mr),_r=Rr[0],jr=Rr[1],Cr=new on(19),Sr=0;Sr<Tr.length;++Sr)Cr[31&Tr[Sr]]++;for(Sr=0;Sr<_r.length;++Sr)Cr[31&_r[Sr]]++;for(var Mr=xn(Cr,7),Ur=Mr[0],kr=Mr[1],Ir=19;Ir>4&&!Ur[ln[Ir-1]];--Ir);var qr,Vr,fo,bo,go=fr+5<<3,mo=On(sr,yn)+On(lr,bn)+cr,Br=On(sr,gr)+On(lr,mr)+cr+14+3*Ir+On(Cr,Ur)+(2*Cr[16]+3*Cr[17]+7*Cr[18]);if(go<=mo&&go<=Br)return $n(or,pr,nr.subarray(dr,dr+fr));if(In(or,pr,1+(Br<mo)),pr+=2,Br<mo){qr=mn(gr,vr,0),Vr=gr,fo=mn(mr,yr,0),bo=mr;var Gr=mn(Ur,kr,0);for(In(or,pr,Pr-257),In(or,pr+5,jr-1),In(or,pr+10,Ir-4),pr+=14,Sr=0;Sr<Ir;++Sr)In(or,pr+3*Sr,Ur[ln[Sr]]);pr+=3*Ir;for(var Qr=[Tr,_r],Fr=0;Fr<2;++Fr){var Or=Qr[Fr];for(Sr=0;Sr<Or.length;++Sr){var xr=31&Or[Sr];In(or,pr,Gr[xr]),pr+=Ur[xr],xr>15&&(In(or,pr,Or[Sr]>>>5&127),pr+=Or[Sr]>>>12)}}}else qr=wn,Vr=yn,fo=Sn,bo=bn;for(Sr=0;Sr<ur;++Sr)if(ar[Sr]>255){xr=ar[Sr]>>>18&31,Rn(or,pr,qr[xr+257]),pr+=Vr[xr+257],xr>7&&(In(or,pr,ar[Sr]>>>23&31),pr+=an[xr]);var zr=31&ar[Sr];Rn(or,pr,fo[zr]),pr+=bo[zr],zr>3&&(Rn(or,pr,ar[Sr]>>>5&8191),pr+=un[zr])}else Rn(or,pr,qr[ar[Sr]]),pr+=Vr[ar[Sr]];return Rn(or,pr,qr[256]),pr+Vr[256]},Mn=new sn([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Tn=new rn(0),qn=function(){for(var nr=new sn(256),or=0;or<256;++or){for(var ir=or,ar=9;--ar;)ir=(1&ir&&3988292384)^ir>>>1;nr[or]=ir}return nr}(),Dn=function(){var nr=4294967295;return{p:function(or){for(var ir=nr,ar=0;ar<or.length;++ar)ir=qn[255&ir^or[ar]]^ir>>>8;nr=ir},d:function(){return 4294967295^nr}}},Ln=function(nr,or,ir,ar,sr){return function(lr,cr,ur,dr,fr,pr){var hr=lr.length,gr=new rn(dr+hr+5*(1+Math.floor(hr/7e3))+fr),vr=gr.subarray(dr,gr.length-fr),br=0;if(!cr||hr<8)for(var mr=0;mr<=hr;mr+=65535){var yr=mr+65535;yr<hr?br=$n(vr,br,lr.subarray(mr,yr)):(vr[mr]=pr,br=$n(vr,br,lr.subarray(mr,hr)))}else{for(var wr=Mn[cr-1],Tr=wr>>>13,Pr=8191&wr,Rr=(1<<ur)-1,_r=new on(32768),jr=new on(Rr+1),Cr=Math.ceil(ur/3),Sr=2*Cr,Mr=function(Do){return(lr[Do]^lr[Do+1]<<Cr^lr[Do+2]<<Sr)&Rr},Ur=new sn(25e3),kr=new on(288),Ir=new on(32),qr=0,Vr=0,fo=(mr=0,0),bo=0,go=0;mr<hr;++mr){var mo=Mr(mr),Br=32767&mr,Gr=jr[mo];if(_r[Br]=Gr,jr[mo]=Br,bo<=mr){var Qr=hr-mr;if((qr>7e3||fo>24576)&&Qr>423){br=An(lr,vr,0,Ur,kr,Ir,Vr,fo,go,mr-go,br),fo=qr=Vr=0,go=mr;for(var Fr=0;Fr<286;++Fr)kr[Fr]=0;for(Fr=0;Fr<30;++Fr)Ir[Fr]=0}var Or=2,xr=0,zr=Pr,Ar=Br-Gr&32767;if(Qr>2&&mo==Mr(mr-Ar))for(var $r=Math.min(Tr,Qr)-1,Er=Math.min(32767,mr),Dr=Math.min(258,Qr);Ar<=Er&&--zr&&Br!=Gr;){if(lr[mr+Or]==lr[mr+Or-Ar]){for(var Wr=0;Wr<Dr&&lr[mr+Wr]==lr[mr+Wr-Ar];++Wr);if(Wr>Or){if(Or=Wr,xr=Ar,Wr>$r)break;var Nr=Math.min(Ar,Wr-2),Hr=0;for(Fr=0;Fr<Nr;++Fr){var yo=mr-Ar+Fr+32768&32767,_o=yo-_r[yo]+32768&32767;_o>Hr&&(Hr=_o,Gr=yo)}}}Ar+=(Br=Gr)-(Gr=_r[Br])+32768&32767}if(xr){Ur[fo++]=268435456|fn[Or]<<18|pn[xr];var Ro=31&fn[Or],No=31&pn[xr];Vr+=an[Ro]+un[No],++kr[257+Ro],++Ir[No],bo=mr+Or,++qr}else Ur[fo++]=lr[mr],++kr[lr[mr]]}}br=An(lr,vr,pr,Ur,kr,Ir,Vr,fo,go,mr-go,br),pr||(br=$n(vr,br,Tn))}return Pn(gr,0,dr+Fn(br)+fr)}(nr,or.level==null?6:or.level,or.mem==null?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(nr.length)))):12+or.mem,ir,ar,!sr)},Bn=function(nr,or,ir){for(;ir;++or)nr[or]=ir,ir>>>=8},Nn=function(nr,or){var ir=or.filename;if(nr[0]=31,nr[1]=139,nr[2]=8,nr[8]=or.level<2?4:or.level==9?2:0,nr[9]=3,or.mtime!=0&&Bn(nr,4,Math.floor(new Date(or.mtime||Date.now())/1e3)),ir){nr[3]=8;for(var ar=0;ar<=ir.length;++ar)nr[ar+10]=ir.charCodeAt(ar)}},jn=function(nr){return 10+(nr.filename&&nr.filename.length+1||0)};function Hn(nr,or){or===void 0&&(or={});var ir=Dn(),ar=nr.length;ir.p(nr);var sr=Ln(nr,or,jn(or),8),lr=sr.length;return Nn(sr,or),Bn(sr,lr-8,ir.d()),Bn(sr,lr-4,ar),sr}function Wn(nr,or){var ir=nr.length;if(!or&&typeof TextEncoder<"u")return new TextEncoder().encode(nr);for(var ar=new rn(nr.length+(nr.length>>>1)),sr=0,lr=function(fr){ar[sr++]=fr},cr=0;cr<ir;++cr){if(sr+5>ar.length){var ur=new rn(sr+8+(ir-cr<<1));ur.set(ar),ar=ur}var dr=nr.charCodeAt(cr);dr<128||or?lr(dr):dr<2048?(lr(192|dr>>>6),lr(128|63&dr)):dr>55295&&dr<57344?(lr(240|(dr=65536+(1047552&dr)|1023&nr.charCodeAt(++cr))>>>18),lr(128|dr>>>12&63),lr(128|dr>>>6&63),lr(128|63&dr)):(lr(224|dr>>>12),lr(128|dr>>>6&63),lr(128|63&dr))}return Pn(ar,0,sr)}(function(nr){nr.GZipJS="gzip-js",nr.Base64="base64"})(kn||(kn={}));var Vn=function(nr,or,ir){var ar=or||{};ar.ip=ir.ip?1:0,ar._=new Date().getTime().toString(),ar.ver=m.LIB_VERSION;var sr=nr.split("?");if(sr.length>1){var lr,cr=v(sr[1].split("&"));try{for(cr.s();!(lr=cr.n()).done;){var ur=lr.value.split("=")[0];R(ar[ur])||delete ar[ur]}}catch(fr){cr.e(fr)}finally{cr.f()}}var dr=nr.indexOf("?")>-1?"&":"?";return nr+dr+function(fr){var pr,hr,gr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"&",vr=[];return U(fr,function(br,mr){R(br)||R(mr)||mr==="undefined"||(pr=encodeURIComponent(br.toString()),hr=encodeURIComponent(mr),vr[vr.length]=hr+"="+pr)}),vr.join(gr)}(ar)},Un=function nr(or,ir){if(ir.blob&&or.buffer)return new Blob([F(or)?or:or.buffer],{type:"text/plain"});if(ir.sendBeacon||ir.blob){var ar=nr(or,{method:"POST"});return new Blob([ar],{type:"application/x-www-form-urlencoded"})}return ir.method!=="POST"?null:(sr=S(or)||F(or)?"data="+encodeURIComponent(or):"data="+encodeURIComponent(or.data),"compression"in or&&or.compression&&(sr+="&compression="+or.compression),sr);var sr},Gn=function(nr){var or=nr.url,ir=nr.data,ar=nr.headers,sr=nr.options,lr=nr.callback,cr=nr.retriesPerformedSoFar,ur=nr.retryQueue,dr=nr.onXHRError,fr=nr.timeout,pr=fr===void 0?6e4:fr,hr=nr.onResponse;C(cr)&&cr>0&&(or=Vn(or,{retry_count:cr},{}));var gr=new XMLHttpRequest;gr.open(sr.method||"GET",or,!0);var vr=Un(ir,sr);U(ar,function(br,mr){gr.setRequestHeader(mr,br)}),sr.method!=="POST"||sr.blob||gr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),gr.timeout=pr,gr.withCredentials=!0,gr.onreadystatechange=function(){if(gr.readyState===4)if(hr==null||hr(gr),gr.status===200){if(lr){var br;try{br=JSON.parse(gr.responseText)}catch(mr){return void j.error(mr)}lr(br)}}else P(dr)&&dr(gr),(gr.status<400||gr.status>500)&&ur.enqueue({url:or,data:ir,options:sr,headers:ar,retriesPerformedSoFar:(cr||0)+1,callback:lr}),lr==null||lr({status:0})},gr.send(vr)},zn=function(nr){a(ir,tn);var or=h(ir);function ir(ar,sr){var lr;return i(this,ir),(lr=or.call(this)).isPolling=!1,lr.queue=[],lr.areWeOnline=!0,lr.onXHRError=ar,lr.rateLimiter=sr,!R(T)&&"onLine"in T.navigator&&(lr.areWeOnline=T.navigator.onLine,T.addEventListener("online",function(){lr._handleWeAreNowOnline()}),T.addEventListener("offline",function(){lr.areWeOnline=!1})),lr}return o(ir,[{key:"enqueue",value:function(ar){var sr=ar.retriesPerformedSoFar||0;if(!(sr>=10)){var lr=function(dr){var fr=3e3*Math.pow(2,dr),pr=fr/2,hr=Math.min(18e5,fr),gr=(Math.random()-.5)*(hr-pr);return Math.ceil(hr+gr)}(sr),cr=new Date(Date.now()+lr);this.queue.push({retryAt:cr,requestData:ar});var ur="Enqueued failed request for retry in ".concat(lr);navigator.onLine||(ur+=" (Browser is offline)"),j.warn(ur),this.isPolling||(this.isPolling=!0,this.poll())}}},{key:"poll",value:function(){var ar=this;this._poller&&clearTimeout(this._poller),this._poller=setTimeout(function(){ar.areWeOnline&&ar.queue.length>0&&ar.flush(),ar.poll()},this._pollInterval)}},{key:"flush",value:function(){var ar=new Date(Date.now()),sr=this.queue.filter(function(dr){return dr.retryAt<ar});if(sr.length>0){this.queue=this.queue.filter(function(dr){return dr.retryAt>=ar});var lr,cr=v(sr);try{for(cr.s();!(lr=cr.n()).done;){var ur=lr.value.requestData;this._executeXhrRequest(ur)}}catch(dr){cr.e(dr)}finally{cr.f()}}}},{key:"unload",value:function(){this._poller&&(clearTimeout(this._poller),this._poller=void 0);var ar,sr=v(this.queue);try{for(sr.s();!(ar=sr.n()).done;){var lr=ar.value.requestData,cr=lr.url,ur=lr.data,dr=lr.options;if(this.rateLimiter.isRateLimited(dr._batchKey))j.warn("[RetryQueue] is quota limited. Dropping request.");else try{T==null||T.navigator.sendBeacon(cr,Un(ur,t(t({},dr),{},{sendBeacon:!0})))}catch(fr){j.error(fr)}}}catch(fr){sr.e(fr)}finally{sr.f()}this.queue=[]}},{key:"_executeXhrRequest",value:function(ar){var sr=ar.url,lr=ar.data,cr=ar.options,ur=ar.headers,dr=ar.callback,fr=ar.retriesPerformedSoFar;this.rateLimiter.isRateLimited(cr._batchKey)||Gn({url:sr,data:lr||{},options:cr||{},headers:ur||{},retriesPerformedSoFar:fr||0,callback:dr,retryQueue:this,onXHRError:this.onXHRError,onResponse:this.rateLimiter.checkForLimiting})}},{key:"_handleWeAreNowOnline",value:function(){this.areWeOnline=!0,this.flush()}}]),ir}(),Qn=1800,Yn=function(){function nr(or,ir,ar,sr){i(this,nr),s(this,"_sessionIdChangedHandlers",[]),this.config=or,this.persistence=ir,this._windowId=void 0,this._sessionId=void 0,this._sessionStartTimestamp=null,this._sessionActivityTimestamp=null,this._sessionIdGenerator=ar||tt,this._windowIdGenerator=sr||tt;var lr=or.persistence_name||or.token,cr=or.session_idle_timeout_seconds||Qn;if(C(cr)?cr>Qn?j.warn("session_idle_timeout_seconds cannot be greater than 30 minutes. Using 30 minutes instead."):cr<60&&j.warn("session_idle_timeout_seconds cannot be less than 60 seconds. Using 60 seconds instead."):(j.warn("session_idle_timeout_seconds must be a number. Defaulting to 30 minutes."),cr=Qn),this._sessionTimeoutMs=1e3*Math.min(Math.max(cr,60),Qn),this._window_id_storage_key="ph_"+lr+"_window_id",this._primary_window_exists_storage_key="ph_"+lr+"_primary_window_exists",this._canUseSessionStorage()){var ur=_t.parse(this._window_id_storage_key),dr=_t.parse(this._primary_window_exists_storage_key);ur&&!dr?this._windowId=ur:_t.remove(this._window_id_storage_key),_t.set(this._primary_window_exists_storage_key,!0)}this._listenToReloadWindow()}return o(nr,[{key:"onSessionId",value:function(or){var ir=this;return R(this._sessionIdChangedHandlers)&&(this._sessionIdChangedHandlers=[]),this._sessionIdChangedHandlers.push(or),this._sessionId&&or(this._sessionId,this._windowId),function(){ir._sessionIdChangedHandlers=ir._sessionIdChangedHandlers.filter(function(ar){return ar!==or})}}},{key:"_canUseSessionStorage",value:function(){return this.config.persistence!=="memory"&&!this.persistence.disabled&&_t.is_supported()}},{key:"_setWindowId",value:function(or){or!==this._windowId&&(this._windowId=or,this._canUseSessionStorage()&&_t.set(this._window_id_storage_key,or))}},{key:"_getWindowId",value:function(){return this._windowId?this._windowId:this._canUseSessionStorage()?_t.parse(this._window_id_storage_key):null}},{key:"_setSessionId",value:function(or,ir,ar){or===this._sessionId&&ir===this._sessionActivityTimestamp&&ar===this._sessionStartTimestamp||(this._sessionStartTimestamp=ar,this._sessionActivityTimestamp=ir,this._sessionId=or,this.persistence.register(s({},Ce,[ir,or,ar])))}},{key:"_getSessionId",value:function(){if(this._sessionId&&this._sessionActivityTimestamp&&this._sessionStartTimestamp)return[this._sessionActivityTimestamp,this._sessionId,this._sessionStartTimestamp];var or=this.persistence.props[Ce];return S(or)&&or.length===2&&or.push(or[0]),or||[0,null,0]}},{key:"resetSessionId",value:function(){this._setSessionId(null,null,null)}},{key:"_listenToReloadWindow",value:function(){var or=this;T==null||T.addEventListener("beforeunload",function(){or._canUseSessionStorage()&&_t.remove(or._primary_window_exists_storage_key)})}},{key:"checkAndGetSessionAndWindowId",value:function(){var or=arguments.length>0&&arguments[0]!==void 0&&arguments[0],ir=(arguments.length>1&&arguments[1]!==void 0?arguments[1]:null)||new Date().getTime(),ar=f(this._getSessionId(),3),sr=ar[0],lr=ar[1],cr=ar[2],ur=this._getWindowId(),dr=cr&&cr>0&&Math.abs(ir-cr)>864e5,fr=!1,pr=!lr,hr=!or&&Math.abs(ir-sr)>this._sessionTimeoutMs;pr||hr||dr?(lr=this._sessionIdGenerator(),ur=this._windowIdGenerator(),j.info("[SessionId] new session ID generated",{sessionId:lr,windowId:ur,changeReason:{noSessionId:pr,activityTimeout:hr,sessionPastMaximumLength:dr}}),cr=ir,fr=!0):ur||(ur=this._windowIdGenerator(),fr=!0);var gr=sr===0||!or||dr?ir:sr,vr=cr===0?new Date().getTime():cr;return this._setWindowId(ur),this._setSessionId(lr,gr,vr),fr&&this._sessionIdChangedHandlers.forEach(function(br){return br(lr,ur)}),{sessionId:lr,windowId:ur,sessionStartTimestamp:vr}}}]),nr}(),Jn=o(function nr(or,ir,ar,sr){i(this,nr),this.name="posthog-js",this.setupOnce=function(lr){lr(function(cr){var ur,dr,fr,pr,hr;if(cr.level!=="error"||!or.__loaded)return cr;cr.tags||(cr.tags={});var gr=or.config.ui_host||or.config.api_host;cr.tags["PostHog Person URL"]=gr+"/person/"+or.get_distinct_id(),or.sessionRecordingStarted()&&(cr.tags["PostHog Recording URL"]=or.get_session_replay_url({withTimestamp:!0}));var vr=((ur=cr.exception)===null||ur===void 0?void 0:ur.values)||[],br={$exception_message:(dr=vr[0])===null||dr===void 0?void 0:dr.value,$exception_type:(fr=vr[0])===null||fr===void 0?void 0:fr.type,$exception_personURL:gr+"/person/"+or.get_distinct_id(),$sentry_event_id:cr.event_id,$sentry_exception:cr.exception,$sentry_exception_message:(pr=vr[0])===null||pr===void 0?void 0:pr.value,$sentry_exception_type:(hr=vr[0])===null||hr===void 0?void 0:hr.type,$sentry_tags:cr.tags};return ir&&ar&&(br.$sentry_url=(sr||"https://sentry.io/organizations/")+ir+"/issues/?project="+ar+"&query="+cr.event_id),or.capture("$exception",br),cr})}}),Xn=function(){function nr(or){var ir=this;i(this,nr),s(this,"_hasSeenPageView",!1),s(this,"_updateScrollData",function(){var ar,sr,lr,cr;ir._pageViewData||(ir._pageViewData=ir._createPageViewData());var ur=ir._pageViewData,dr=ir._scrollY(),fr=ir._scrollHeight(),pr=ir._contentY(),hr=ir._contentHeight();ur.lastScrollY=dr,ur.maxScrollY=Math.max(dr,(ar=ur.maxScrollY)!==null&&ar!==void 0?ar:0),ur.maxScrollHeight=Math.max(fr,(sr=ur.maxScrollHeight)!==null&&sr!==void 0?sr:0),ur.lastContentY=pr,ur.maxContentY=Math.max(pr,(lr=ur.maxContentY)!==null&&lr!==void 0?lr:0),ur.maxContentHeight=Math.max(hr,(cr=ur.maxContentHeight)!==null&&cr!==void 0?cr:0)}),this._instance=or}return o(nr,[{key:"_createPageViewData",value:function(){var or;return{pathname:(or=T==null?void 0:T.location.pathname)!==null&&or!==void 0?or:""}}},{key:"doPageView",value:function(){var or,ir;return this._hasSeenPageView?(ir=this._pageViewData,this._pageViewData=this._createPageViewData()):(this._hasSeenPageView=!0,ir=void 0,this._pageViewData||(this._pageViewData=this._createPageViewData())),setTimeout(this._updateScrollData,0),t({$prev_pageview_pathname:(or=ir)===null||or===void 0?void 0:or.pathname},this._calculatePrevPageScrollProperties(ir))}},{key:"doPageLeave",value:function(){var or=this._pageViewData;return t({$prev_pageview_pathname:or==null?void 0:or.pathname},this._calculatePrevPageScrollProperties(or))}},{key:"_calculatePrevPageScrollProperties",value:function(or){if(!or||or.maxScrollHeight==null||or.lastScrollY==null||or.maxScrollY==null||or.maxContentHeight==null||or.lastContentY==null||or.maxContentY==null)return{};var ir=or.maxScrollHeight,ar=or.lastScrollY,sr=or.maxScrollY,lr=or.maxContentHeight,cr=or.lastContentY,ur=or.maxContentY;return ir=Math.ceil(ir),ar=Math.ceil(ar),sr=Math.ceil(sr),lr=Math.ceil(lr),cr=Math.ceil(cr),ur=Math.ceil(ur),{$prev_pageview_last_scroll:ar,$prev_pageview_last_scroll_percentage:ir<=1?1:Kn(ar/ir,0,1),$prev_pageview_max_scroll:sr,$prev_pageview_max_scroll_percentage:ir<=1?1:Kn(sr/ir,0,1),$prev_pageview_last_content:cr,$prev_pageview_last_content_percentage:lr<=1?1:Kn(cr/lr,0,1),$prev_pageview_max_content:ur,$prev_pageview_max_content_percentage:lr<=1?1:Kn(ur/lr,0,1)}}},{key:"startMeasuringScrollPosition",value:function(){T==null||T.addEventListener("scroll",this._updateScrollData,!0),T==null||T.addEventListener("scrollend",this._updateScrollData,!0),T==null||T.addEventListener("resize",this._updateScrollData)}},{key:"stopMeasuringScrollPosition",value:function(){T==null||T.removeEventListener("scroll",this._updateScrollData),T==null||T.removeEventListener("scrollend",this._updateScrollData),T==null||T.removeEventListener("resize",this._updateScrollData)}},{key:"_scrollElement",value:function(){if(!this._instance.config.scroll_root_selector)return T==null?void 0:T.document.documentElement;var or,ir=v(S(this._instance.config.scroll_root_selector)?this._instance.config.scroll_root_selector:[this._instance.config.scroll_root_selector]);try{for(ir.s();!(or=ir.n()).done;){var ar=or.value,sr=T==null?void 0:T.document.querySelector(ar);if(sr)return sr}}catch(lr){ir.e(lr)}finally{ir.f()}}},{key:"_scrollHeight",value:function(){var or=this._scrollElement();return or?Math.max(0,or.scrollHeight-or.clientHeight):0}},{key:"_scrollY",value:function(){if(this._instance.config.scroll_root_selector){var or=this._scrollElement();return or&&or.scrollTop||0}return T&&(T.scrollY||T.pageYOffset||T.document.documentElement.scrollTop)||0}},{key:"_contentHeight",value:function(){var or=this._scrollElement();return(or==null?void 0:or.scrollHeight)||0}},{key:"_contentY",value:function(){var or=this._scrollElement(),ir=(or==null?void 0:or.clientHeight)||0;return this._scrollY()+ir}}]),nr}();function Kn(nr,or,ir){return Math.max(or,Math.min(nr,ir))}var Zn,ei,ti,ni={icontains:function(nr){return!!T&&T.location.href.toLowerCase().indexOf(nr.toLowerCase())>-1},regex:function(nr){return!!T&&mt(T.location.href,nr)},exact:function(nr){return(T==null?void 0:T.location.href)===nr}},ii=function(){function nr(or){i(this,nr),this.instance=or}return o(nr,[{key:"getSurveys",value:function(or){var ir=this,ar=arguments.length>1&&arguments[1]!==void 0&&arguments[1],sr=this.instance.get_property(qe);if(sr&&!ar)return or(sr);this.instance._send_request("".concat(this.instance.config.api_host,"/api/surveys/?token=").concat(this.instance.config.token),{},{method:"GET"},function(lr){var cr,ur=lr.surveys||[];return(cr=ir.instance.persistence)===null||cr===void 0||cr.register(s({},qe,ur)),or(ur)})}},{key:"getActiveMatchingSurveys",value:function(or){var ir=this,ar=arguments.length>1&&arguments[1]!==void 0&&arguments[1];this.getSurveys(function(sr){var lr=sr.filter(function(cr){return!(!cr.start_date||cr.end_date)}).filter(function(cr){var ur,dr,fr,pr;if(!cr.conditions)return!0;var hr=(ur=cr.conditions)===null||ur===void 0||!ur.url||ni[(dr=(fr=cr.conditions)===null||fr===void 0?void 0:fr.urlMatchType)!==null&&dr!==void 0?dr:"icontains"](cr.conditions.url),gr=(pr=cr.conditions)===null||pr===void 0||!pr.selector||(D==null?void 0:D.querySelector(cr.conditions.selector));return hr&&gr}).filter(function(cr){if(!cr.linked_flag_key&&!cr.targeting_flag_key)return!0;var ur=!cr.linked_flag_key||ir.instance.featureFlags.isFeatureEnabled(cr.linked_flag_key),dr=!cr.targeting_flag_key||ir.instance.featureFlags.isFeatureEnabled(cr.targeting_flag_key);return ur&&dr});return or(lr)},ar)}}]),nr}(),ri=function(){function nr(){var or=this;i(this,nr),s(this,"limits",{}),s(this,"checkForLimiting",function(ir){try{var ar=ir.responseText;if(!ar||!ar.length)return;(JSON.parse(ar).quota_limited||[]).forEach(function(sr){j.info("[RateLimiter] ".concat(sr||"events"," is quota limited.")),or.limits[sr]=new Date().getTime()+6e4})}catch(sr){return void j.error(sr)}})}return o(nr,[{key:"isRateLimited",value:function(or){var ir=this.limits[or||"events"]||!1;return ir!==!1&&new Date().getTime()<ir}}]),nr}(),oi=function(){return t({initialPathName:(T==null?void 0:T.location.pathname)||"",referringDomain:kt.referringDomain()},kt.campaignParams())},si=function(){function nr(or,ir,ar){var sr=this;i(this,nr),s(this,"_onSessionIdCallback",function(lr){var cr=sr._getStoredProps();if(!cr||cr.sessionId!==lr){var ur={sessionId:lr,props:sr._sessionSourceParamGenerator()};sr._persistence.register(s({},Ne,ur))}}),this._sessionIdManager=or,this._persistence=ir,this._sessionSourceParamGenerator=ar||oi,this._sessionIdManager.onSessionId(this._onSessionIdCallback)}return o(nr,[{key:"_getStoredProps",value:function(){return this._persistence.props[Ne]}},{key:"getSessionProps",value:function(){var or,ir=(or=this._getStoredProps())===null||or===void 0?void 0:or.props;return ir?{$client_session_initial_referring_host:ir.referringDomain,$client_session_initial_pathname:ir.initialPathName,$client_session_initial_utm_source:ir.utm_source,$client_session_initial_utm_campaign:ir.utm_campaign,$client_session_initial_utm_medium:ir.utm_medium,$client_session_initial_utm_content:ir.utm_content,$client_session_initial_utm_term:ir.utm_term}:{}}}]),nr}(),ai=["ahrefsbot","ahrefssiteaudit","applebot","baiduspider","bingbot","bingpreview","bot.htm","bot.php","crawler","duckduckbot","facebookexternal","facebookcatalog","gptbot","http://yandex.com/bots","hubspot","ia_archiver","linkedinbot","mj12bot","msnbot","nessus","petalbot","pinterest","prerender","rogerbot","screaming frog","semrushbot","sitebulb","slurp","turnitin","twitterbot","vercelbot","yahoo! slurp","yandexbot","adsbot-google","apis-google","duplexweb-google","feedfetcher-google","google favicon","google web preview","google-read-aloud","googlebot","googleweblight","mediapartners-google","storebot-google"],ui=function(nr,or){if(!nr)return!1;var ir=nr.toLowerCase();return ai.concat(or||[]).some(function(ar){var sr=ar.toLowerCase();return ir.includes?ir.includes(sr):ir.indexOf(sr)!==-1})};(function(nr){nr[nr.INIT_MODULE=0]="INIT_MODULE",nr[nr.INIT_SNIPPET=1]="INIT_SNIPPET"})(Zn||(Zn={}));var li=function(){},ci={},di="posthog",hi=(T==null?void 0:T.XMLHttpRequest)&&"withCredentials"in new XMLHttpRequest,fi=!hi&&(L==null?void 0:L.indexOf("MSIE"))===-1&&(L==null?void 0:L.indexOf("Mozilla"))===-1,pi=function(){var nr,or,ir;return{api_host:"https://app.posthog.com",api_method:"POST",api_transport:"XHR",ui_host:null,token:"",autocapture:!0,rageclick:!0,cross_subdomain_cookie:(or=D==null?void 0:D.location,ir=or==null?void 0:or.hostname,!!x(ir)&&ir.split(".").slice(-2).join(".")!=="herokuapp.com"),persistence:"localStorage+cookie",persistence_name:"",cookie_name:"",loaded:li,store_google:!0,custom_campaign_params:[],custom_blocked_useragents:[],save_referrer:!0,capture_pageview:!0,capture_pageleave:!0,debug:!1,verbose:!1,cookie_expiration:365,upgrade:!1,disable_session_recording:!1,disable_persistence:!1,disable_cookie:!1,enable_recording_console_log:void 0,secure_cookie:(T==null||(nr=T.location)===null||nr===void 0?void 0:nr.protocol)==="https:",ip:!0,opt_out_capturing_by_default:!1,opt_out_persistence_by_default:!1,opt_out_useragent_filter:!1,opt_out_capturing_persistence_type:"localStorage",opt_out_capturing_cookie_prefix:null,opt_in_site_apps:!1,property_blacklist:[],respect_dnt:!1,sanitize_properties:null,xhr_headers:{},inapp_protocol:"//",inapp_link_new_window:!1,request_batching:!0,properties_string_max_length:65535,session_recording:{},mask_all_element_attributes:!1,mask_all_text:!1,advanced_disable_decide:!1,advanced_disable_feature_flags:!1,advanced_disable_feature_flags_on_first_load:!1,advanced_disable_toolbar_metrics:!1,on_xhr_error:function(ar){var sr="Bad HTTP status: "+ar.status+" "+ar.statusText;j.error(sr)},get_device_id:function(ar){return ar},_onCapture:li,capture_performance:void 0,name:"posthog",callback_fn:"posthog._jsc",bootstrap:{},disable_compression:!1,session_idle_timeout_seconds:1800}},_i=function(nr,or,ir,ar){var sr,lr=ir!==di&&ti?ir?ti[ir]:void 0:ti,cr={initComplete:!1,syncCode:!1},ur=function(dr){return function(fr){cr[dr]||(cr[dr]=!0,cr.initComplete&&cr.syncCode&&(ar==null||ar(fr)))}};if(lr&&ei===Zn.INIT_MODULE)sr=lr;else{if(lr&&!S(lr))return void j.error("You have already initialized "+ir);sr=new vi}return sr._init(nr,or,ir,ur("initComplete")),sr.toolbar.maybeLoadToolbar(),sr.sessionRecording=new Yt(sr),sr.sessionRecording.startRecordingIfEnabled(),sr.config.disable_scroll_properties||sr.pageViewManager.startMeasuringScrollPosition(),sr.__autocapture=sr.config.autocapture,We._setIsAutocaptureEnabled(sr),We._isAutocaptureEnabled&&(sr.__autocapture=sr.config.autocapture,We.enabledForProject(sr.config.token,100,100)?We.isBrowserSupported()?We.init(sr):(sr.__autocapture=!1,j.info("Disabling Automatic Event Collection because this browser is not supported")):(sr.__autocapture=!1,j.info("Not in active bucket: disabling Automatic Event Collection."))),m.DEBUG=m.DEBUG||sr.config.debug,!R(lr)&&S(lr)&&(sr._execute_array.call(sr.people,lr.people),sr._execute_array(lr)),ur("syncCode")(sr),sr},gi=function(){function nr(){i(this,nr),s(this,"__forceAllowLocalhost",!1)}return o(nr,[{key:"_forceAllowLocalhost",get:function(){return this.__forceAllowLocalhost},set:function(or){j.error("WebPerformanceObserver is deprecated and has no impact on network capture. Use `_forceAllowLocalhostNetworkCapture` on `posthog.sessionRecording`"),this.__forceAllowLocalhost=or}}]),nr}(),vi=function(){function nr(){var or=this;i(this,nr),s(this,"webPerformance",new gi),this.config=pi(),this.compression={},this.decideEndpointWasHit=!1,this.SentryIntegration=Jn,this.segmentIntegration=function(){return function(ir){Promise&&Promise.resolve||j.warn("This browser does not have Promise support, and can not use the segment integration");var ar=function(sr,lr){sr.event.userId||sr.event.anonymousId===ir.get_distinct_id()||ir.reset(),sr.event.userId&&sr.event.userId!==ir.get_distinct_id()&&(ir.register({distinct_id:sr.event.userId}),ir.reloadFeatureFlags());var cr=ir._calculate_event_properties(lr,sr.event.properties);return sr.event.properties=Object.assign({},cr,sr.event.properties),sr};return{name:"PostHog JS",type:"enrichment",version:"1.0.0",isLoaded:function(){return!0},load:function(){return Promise.resolve()},track:function(sr){return ar(sr,sr.event.event)},page:function(sr){return ar(sr,"$pageview")},identify:function(sr){return ar(sr,"$identify")},screen:function(sr){return ar(sr,"$screen")}}}(or)},this.__captureHooks=[],this.__request_queue=[],this.__loaded=!1,this.__loaded_recorder_version=void 0,this.__autocapture=void 0,this._jsc=function(){},this.analyticsDefaultEndpoint="/e/",this.elementsChainAsString=!1,this.featureFlags=new Qe(this),this.toolbar=new en(this),this.pageViewManager=new Xn(this),this.surveys=new ii(this),this.rateLimiter=new ri,this.people={set:function(ir,ar,sr){var lr=x(ir)?s({},ir,ar):ir;or.setPersonProperties(lr),sr==null||sr({})},set_once:function(ir,ar,sr){var lr=x(ir)?s({},ir,ar):ir;or.setPersonProperties(void 0,lr),sr==null||sr({})}}}return o(nr,[{key:"init",value:function(or,ir,ar){if(R(ar))j.critical("You must name your new library: init(token, config, name)");else{if(ar!==di){var sr=_i(or,ir,ar,function(lr){ti[ar]=lr,lr._loaded()});return ti[ar]=sr,sr}j.critical("You must initialize the main posthog object right after you include the PostHog js snippet")}}},{key:"_init",value:function(or){var ir,ar,sr,lr=this,cr=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ur=arguments.length>2?arguments[2]:void 0,dr=arguments.length>3?arguments[3]:void 0;this.__loaded=!0,this.config={},this._triggered_notifs=[];var fr,pr={segmentRegister:!1,syncCode:!1},hr=function(_r){return function(){pr[_r]||(pr[_r]=!0,pr.segmentRegister&&pr.syncCode&&(dr==null||dr(lr)))}};if(this.set_config(G({},pi(),cr,{name:ur,token:or,callback_fn:(ur===di?ur:di+"."+ur)+"._jsc"})),this._jsc=function(){},(T!=null&&(ir=T.rrweb)!==null&&ir!==void 0&&ir.record||T!=null&&T.rrwebRecord)&&(this.__loaded_recorder_version=T==null||(fr=T.rrweb)===null||fr===void 0?void 0:fr.version),this.persistence=new St(this.config),this._requestQueue=new nn(this._handle_queued_event.bind(this)),this._retryQueue=new zn(this.config.on_xhr_error,this.rateLimiter),this.__captureHooks=[],this.__request_queue=[],this.sessionManager=new Yn(this.config,this.persistence),this.sessionPropsManager=new si(this.sessionManager,this.persistence),this.sessionPersistence=this.config.persistence==="sessionStorage"?this.persistence:new St(t(t({},this.config),{},{persistence:"sessionStorage"})),this._gdpr_init(),cr.segment?(this.config.get_device_id=function(){return cr.segment.user().anonymousId()},cr.segment.user().id()&&(this.register({distinct_id:cr.segment.user().id()}),this.persistence.set_user_state("identified")),cr.segment.register(this.segmentIntegration()).then(hr("segmentRegister"))):hr("segmentRegister")(),((ar=cr.bootstrap)===null||ar===void 0?void 0:ar.distinctID)!==void 0){var gr,vr,br=this.config.get_device_id(tt()),mr=(gr=cr.bootstrap)!==null&&gr!==void 0&&gr.isIdentifiedID?br:cr.bootstrap.distinctID;this.persistence.set_user_state((vr=cr.bootstrap)!==null&&vr!==void 0&&vr.isIdentifiedID?"identified":"anonymous"),this.register({distinct_id:cr.bootstrap.distinctID,$device_id:mr})}if(this._hasBootstrappedFeatureFlags()){var yr,wr,Tr=Object.keys(((yr=cr.bootstrap)===null||yr===void 0?void 0:yr.featureFlags)||{}).filter(function(_r){var jr,Cr;return!((jr=cr.bootstrap)===null||jr===void 0||(Cr=jr.featureFlags)===null||Cr===void 0||!Cr[_r])}).reduce(function(_r,jr){var Cr,Sr;return _r[jr]=((Cr=cr.bootstrap)===null||Cr===void 0||(Sr=Cr.featureFlags)===null||Sr===void 0?void 0:Sr[jr])||!1,_r},{}),Pr=Object.keys(((wr=cr.bootstrap)===null||wr===void 0?void 0:wr.featureFlagPayloads)||{}).filter(function(_r){return Tr[_r]}).reduce(function(_r,jr){var Cr,Sr,Mr,Ur;return(Cr=cr.bootstrap)!==null&&Cr!==void 0&&(Sr=Cr.featureFlagPayloads)!==null&&Sr!==void 0&&Sr[jr]&&(_r[jr]=(Mr=cr.bootstrap)===null||Mr===void 0||(Ur=Mr.featureFlagPayloads)===null||Ur===void 0?void 0:Ur[jr]),_r},{});this.featureFlags.receivedFeatureFlags({featureFlags:Tr,featureFlagPayloads:Pr})}if(!this.get_distinct_id()){var Rr=this.config.get_device_id(tt());this.register_once({distinct_id:Rr,$device_id:Rr},""),this.persistence.set_user_state("anonymous")}T==null||(sr=T.addEventListener)===null||sr===void 0||sr.call(T,"onpagehide"in self?"pagehide":"unload",this._handle_unload.bind(this)),hr("syncCode")()}},{key:"_afterDecideResponse",value:function(or){var ir;if(this.compression={},or.supportedCompression&&!this.config.disable_compression){var ar,sr={},lr=v(or.supportedCompression);try{for(lr.s();!(ar=lr.n()).done;)sr[ar.value]=!0}catch(cr){lr.e(cr)}finally{lr.f()}this.compression=sr}(ir=or.analytics)!==null&&ir!==void 0&&ir.endpoint&&(this.analyticsDefaultEndpoint=or.analytics.endpoint),or.elementsChainAsString&&(this.elementsChainAsString=or.elementsChainAsString)}},{key:"_loaded",value:function(){var or=this.config.advanced_disable_decide;or||this.featureFlags.setReloadingPaused(!0);try{this.config.loaded(this)}catch(ir){j.critical("`loaded` function failed",ir)}this._start_queue_if_opted_in(),this.config.capture_pageview&&D&&this.capture("$pageview",{title:D.title},{send_instantly:!0}),or||(new Jt(this).call(),this.featureFlags.resetRequestQueue())}},{key:"_start_queue_if_opted_in",value:function(){var or;this.has_opted_out_capturing()||this.config.request_batching&&((or=this._requestQueue)===null||or===void 0||or.poll())}},{key:"_dom_loaded",value:function(){var or=this;this.has_opted_out_capturing()||V(this.__request_queue,function(ir){or._send_request.apply(or,p(ir))}),this.__request_queue=[],this._start_queue_if_opted_in()}},{key:"_prepare_callback",value:function(or,ir){if(R(or))return null;if(hi)return function(cr){or(cr,ir)};var ar=this._jsc,sr=""+Math.floor(1e8*Math.random()),lr=this.config.callback_fn+"["+sr+"]";return ar[sr]=function(cr){delete ar[sr],or(cr,ir)},lr}},{key:"_handle_unload",value:function(){var or,ir;this.config.request_batching?(this.config.capture_pageview&&this.config.capture_pageleave&&this.capture("$pageleave"),(or=this._requestQueue)===null||or===void 0||or.unload(),(ir=this._retryQueue)===null||ir===void 0||ir.unload()):this.config.capture_pageview&&this.config.capture_pageleave&&this.capture("$pageleave",null,{transport:"sendBeacon"})}},{key:"_handle_queued_event",value:function(or,ir,ar){var sr=JSON.stringify(ir);this.__compress_and_send_json_request(or,sr,ar||ci,li)}},{key:"__compress_and_send_json_request",value:function(or,ir,ar,sr){var lr=function(fr,pr,hr){return fr===kn.GZipJS?[Hn(Wn(pr),{mtime:0}),t(t({},hr),{},{blob:!0,urlQueryArgs:{compression:kn.GZipJS}})]:[{data:te(pr)},hr]}(this.compression[kn.GZipJS]?kn.GZipJS:kn.Base64,ir,ar),cr=f(lr,2),ur=cr[0],dr=cr[1];this._send_request(or,ur,dr,sr)}},{key:"_send_request",value:function(or,ir,ar,sr){if(this.__loaded&&this._retryQueue&&!this.rateLimiter.isRateLimited(ar._batchKey))if(fi)this.__request_queue.push([or,ir,ar,sr]);else{var lr={method:this.config.api_method,transport:this.config.api_transport,verbose:this.config.verbose};ar=G(lr,ar||{}),hi||(ar.method="GET");var cr=T&&"sendBeacon"in T.navigator&&ar.transport==="sendBeacon";if(or=Vn(or,ar.urlQueryArgs||{},{ip:this.config.ip}),cr)try{T==null||T.navigator.sendBeacon(or,Un(ir,t(t({},ar),{},{sendBeacon:!0})))}catch{}else if(hi||!D)try{Gn({url:or,data:ir,headers:this.config.xhr_headers,options:ar,callback:sr,retriesPerformedSoFar:0,retryQueue:this._retryQueue,onXHRError:this.config.on_xhr_error,onResponse:this.rateLimiter.checkForLimiting})}catch(pr){j.error(pr)}else{var ur,dr=D.createElement("script");dr.type="text/javascript",dr.async=!0,dr.defer=!0,dr.src=or;var fr=D.getElementsByTagName("script")[0];(ur=fr.parentNode)===null||ur===void 0||ur.insertBefore(dr,fr)}}}},{key:"_execute_array",value:function(or){var ir,ar=this,sr=[],lr=[],cr=[];V(or,function(dr){dr&&(ir=dr[0],S(ir)?cr.push(dr):P(dr)?dr.call(ar):S(dr)&&ir==="alias"?sr.push(dr):S(dr)&&ir.indexOf("capture")!==-1&&P(ar[ir])?cr.push(dr):lr.push(dr))});var ur=function(dr,fr){V(dr,function(pr){if(S(pr[0])){var hr=fr;U(pr,function(gr){hr=hr[gr[0]].apply(hr,gr.slice(1))})}else this[pr[0]].apply(this,pr.slice(1))},fr)};ur(sr,this),ur(lr,this),ur(cr,this)}},{key:"_hasBootstrappedFeatureFlags",value:function(){var or,ir;return((or=this.config.bootstrap)===null||or===void 0?void 0:or.featureFlags)&&Object.keys((ir=this.config.bootstrap)===null||ir===void 0?void 0:ir.featureFlags).length>0||!1}},{key:"push",value:function(or){this._execute_array([or])}},{key:"capture",value:function(or,ir){var ar=arguments.length>2&&arguments[2]!==void 0?arguments[2]:ci;if(!this.__loaded||!this.sessionPersistence||!this._requestQueue)return j.uninitializedWarning("posthog.capture");if(!Wt(this)){var sr=(ar=ar||ci).transport;if(sr&&(ar.transport=sr),!R(or)&&x(or)){if(!L||this.config.opt_out_useragent_filter||!ui(L,this.config.custom_blocked_useragents)){this.sessionPersistence.update_search_keyword(),this.config.store_google&&this.sessionPersistence.update_campaign_params(),this.config.save_referrer&&this.sessionPersistence.update_referrer_info();var lr={uuid:tt(),event:or,properties:this._calculate_event_properties(or,ir||{})};or==="$identify"&&(lr.$set=ar.$set,lr.$set_once=ar.$set_once),(lr=ee(lr,ar._noTruncate?null:this.config.properties_string_max_length)).timestamp=ar.timestamp||new Date;var cr=t(t({},lr.properties.$set),lr.$set);(function(pr){if(I(pr)){for(var hr in pr)if(k.call(pr,hr))return!1;return!0}return!1})(cr)||this.setPersonPropertiesForFlags(cr),j.info("send",lr);var ur=JSON.stringify(lr),dr=this.config.api_host+(ar.endpoint||this.analyticsDefaultEndpoint),fr=ar!==ci;return!this.config.request_batching||fr&&!ar._batchKey||ar.send_instantly?this.__compress_and_send_json_request(dr,ur,ar):this._requestQueue.enqueue(dr,lr,ar),this._invokeCaptureHooks(or,lr),lr}}else j.error("No event name provided to posthog.capture")}}},{key:"_addCaptureHook",value:function(or){this.__captureHooks.push(or)}},{key:"_invokeCaptureHooks",value:function(or,ir){this.config._onCapture(or,ir),U(this.__captureHooks,function(ar){return ar(or)})}},{key:"_calculate_event_properties",value:function(or,ir){if(!this.persistence||!this.sessionPersistence)return ir;var ar=this.persistence.remove_event_timer(or),sr=t({},ir);if(sr.token=this.config.token,or==="$snapshot"){var lr=t(t({},this.persistence.properties()),this.sessionPersistence.properties());return sr.distinct_id=lr.distinct_id,sr}var cr=kt.properties();if(this.sessionManager){var ur=this.sessionManager.checkAndGetSessionAndWindowId(),dr=ur.sessionId,fr=ur.windowId;sr.$session_id=dr,sr.$window_id=fr}if(this.sessionPropsManager&&this.config.__preview_send_client_session_params&&(or==="$pageview"||or==="$pageleave"||or==="$autocapture")){var pr=this.sessionPropsManager.getSessionProps();sr=G(sr,pr)}if(!this.config.disable_scroll_properties){var hr={};or==="$pageview"?hr=this.pageViewManager.doPageView():or==="$pageleave"&&(hr=this.pageViewManager.doPageLeave()),sr=G(sr,hr)}if(or==="$pageview"&&D&&(sr.title=D.title),or==="$performance_event"){var gr=this.persistence.properties();return sr.distinct_id=gr.distinct_id,sr.$current_url=cr.$current_url,sr}if(!R(ar)){var vr=new Date().getTime()-ar;sr.$duration=parseFloat((vr/1e3).toFixed(3))}L&&this.config.opt_out_useragent_filter&&(sr.$browser_type=ui(L,this.config.custom_blocked_useragents)?"bot":"browser"),sr=G({},kt.properties(),this.persistence.properties(),this.sessionPersistence.properties(),sr);var br=this.config.property_blacklist;S(br)?U(br,function(yr){delete sr[yr]}):j.error("Invalid value for property_blacklist config: "+br);var mr=this.config.sanitize_properties;return mr&&(sr=mr(sr,or)),sr}},{key:"register",value:function(or,ir){var ar;(ar=this.persistence)===null||ar===void 0||ar.register(or,ir)}},{key:"register_once",value:function(or,ir,ar){var sr;(sr=this.persistence)===null||sr===void 0||sr.register_once(or,ir,ar)}},{key:"register_for_session",value:function(or){var ir;(ir=this.sessionPersistence)===null||ir===void 0||ir.register(or)}},{key:"unregister",value:function(or){var ir;(ir=this.persistence)===null||ir===void 0||ir.unregister(or)}},{key:"unregister_for_session",value:function(or){var ir;(ir=this.sessionPersistence)===null||ir===void 0||ir.unregister(or)}},{key:"_register_single",value:function(or,ir){this.register(s({},or,ir))}},{key:"getFeatureFlag",value:function(or,ir){return this.featureFlags.getFeatureFlag(or,ir)}},{key:"getFeatureFlagPayload",value:function(or){var ir=this.featureFlags.getFeatureFlagPayload(or);try{return JSON.parse(ir)}catch{return ir}}},{key:"isFeatureEnabled",value:function(or,ir){return this.featureFlags.isFeatureEnabled(or,ir)}},{key:"reloadFeatureFlags",value:function(){this.featureFlags.reloadFeatureFlags()}},{key:"updateEarlyAccessFeatureEnrollment",value:function(or,ir){this.featureFlags.updateEarlyAccessFeatureEnrollment(or,ir)}},{key:"getEarlyAccessFeatures",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.featureFlags.getEarlyAccessFeatures(or,ir)}},{key:"onFeatureFlags",value:function(or){return this.featureFlags.onFeatureFlags(or)}},{key:"onSessionId",value:function(or){var ir,ar;return(ir=(ar=this.sessionManager)===null||ar===void 0?void 0:ar.onSessionId(or))!==null&&ir!==void 0?ir:function(){}}},{key:"getSurveys",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0&&arguments[1];this.surveys.getSurveys(or,ir)}},{key:"getActiveMatchingSurveys",value:function(or){var ir=arguments.length>1&&arguments[1]!==void 0&&arguments[1];this.surveys.getActiveMatchingSurveys(or,ir)}},{key:"identify",value:function(or,ir,ar){if(!this.__loaded||!this.persistence)return j.uninitializedWarning("posthog.identify");if(or)if(["distinct_id","distinctid"].includes(or.toLowerCase()))j.critical('The string "'.concat(or,'" was set in posthog.identify which indicates an error. This ID should be unique to the user and not a hardcoded string.'));else{var sr=this.get_distinct_id();if(this.register({$user_id:or}),!this.get_property("$device_id")){var lr=sr;this.register_once({$had_persisted_distinct_id:!0,$device_id:lr},"")}or!==sr&&or!==this.get_property(Se)&&(this.unregister(Se),this.register({distinct_id:or}));var cr=this.persistence.get_user_state()==="anonymous";or!==sr&&cr?(this.persistence.set_user_state("identified"),this.setPersonPropertiesForFlags(ir||{},!1),this.capture("$identify",{distinct_id:or,$anon_distinct_id:sr},{$set:ir||{},$set_once:ar||{}}),this.featureFlags.setAnonymousDistinctId(sr)):(ir||ar)&&this.setPersonProperties(ir,ar),or!==sr&&(this.reloadFeatureFlags(),this.unregister(De))}else j.error("Unique user id has not been set in posthog.identify")}},{key:"setPersonProperties",value:function(or,ir){(or||ir)&&(this.setPersonPropertiesForFlags(or||{}),this.capture("$set",{$set:or||{},$set_once:ir||{}}))}},{key:"group",value:function(or,ir,ar){if(or&&ir){var sr=this.getGroups();sr[or]!==ir&&this.resetGroupPropertiesForFlags(or),this.register({$groups:t(t({},sr),{},s({},or,ir))}),ar&&(this.capture("$groupidentify",{$group_type:or,$group_key:ir,$group_set:ar}),this.setGroupPropertiesForFlags(s({},or,ar))),sr[or]===ir||ar||this.reloadFeatureFlags()}else j.error("posthog.group requires a group type and group key")}},{key:"resetGroups",value:function(){this.register({$groups:{}}),this.resetGroupPropertiesForFlags(),this.reloadFeatureFlags()}},{key:"setPersonPropertiesForFlags",value:function(or){var ir=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];this.featureFlags.setPersonPropertiesForFlags(or,ir)}},{key:"resetPersonPropertiesForFlags",value:function(){this.featureFlags.resetPersonPropertiesForFlags()}},{key:"setGroupPropertiesForFlags",value:function(or){var ir=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];this.featureFlags.setGroupPropertiesForFlags(or,ir)}},{key:"resetGroupPropertiesForFlags",value:function(or){this.featureFlags.resetGroupPropertiesForFlags(or)}},{key:"reset",value:function(or){var ir,ar,sr,lr;if(!this.__loaded)return j.uninitializedWarning("posthog.reset");var cr=this.get_property("$device_id");(ir=this.persistence)===null||ir===void 0||ir.clear(),(ar=this.sessionPersistence)===null||ar===void 0||ar.clear(),(sr=this.persistence)===null||sr===void 0||sr.set_user_state("anonymous"),(lr=this.sessionManager)===null||lr===void 0||lr.resetSessionId();var ur=this.config.get_device_id(tt());this.register_once({distinct_id:ur,$device_id:or?ur:cr},"")}},{key:"get_distinct_id",value:function(){return this.get_property("distinct_id")}},{key:"getGroups",value:function(){return this.get_property("$groups")||{}}},{key:"get_session_id",value:function(){var or,ir;return(or=(ir=this.sessionManager)===null||ir===void 0?void 0:ir.checkAndGetSessionAndWindowId(!0).sessionId)!==null&&or!==void 0?or:""}},{key:"get_session_replay_url",value:function(or){if(!this.sessionManager)return"";var ir=this.config.ui_host||this.config.api_host,ar=this.sessionManager.checkAndGetSessionAndWindowId(!0),sr=ar.sessionId,lr=ar.sessionStartTimestamp,cr=ir+"/replay/"+sr;if(or!=null&&or.withTimestamp&&lr){var ur,dr=(ur=or.timestampLookBack)!==null&&ur!==void 0?ur:10;if(!lr)return cr;var fr=Math.max(Math.floor((new Date().getTime()-lr)/1e3)-dr,0);cr+="?t=".concat(fr)}return cr}},{key:"alias",value:function(or,ir){return or===this.get_property(we)?(j.critical("Attempting to create alias for existing People user - aborting."),-2):(R(ir)&&(ir=this.get_distinct_id()),or!==ir?(this._register_single(Se,or),this.capture("$create_alias",{alias:or,distinct_id:ir})):(j.warn("alias matches current distinct_id - skipping api call."),this.identify(or),-1))}},{key:"set_config",value:function(or){var ir,ar,sr=t({},this.config);if(I(or)&&(G(this.config,or),this.config.persistence_name||(this.config.persistence_name=this.config.cookie_name),this.config.disable_persistence||(this.config.disable_persistence=this.config.disable_cookie),this.config.api_host=this.config.api_host.replace(/\/$/,""),this.config.api_host==="https://us.posthog.com"&&(this.config.api_host="https://app.posthog.com"),(ir=this.persistence)===null||ir===void 0||ir.update_config(this.config),(ar=this.sessionPersistence)===null||ar===void 0||ar.update_config(this.config),lt.is_supported()&&lt.get("ph_debug")==="true"&&(this.config.debug=!0),this.config.debug&&(m.DEBUG=!0),this.sessionRecording&&!R(or.disable_session_recording))){var lr=sr.disable_session_recording!==or.disable_session_recording,cr=!Wt(this)&&!or.disable_session_recording&&!this.sessionRecording.started;(lr||cr)&&(or.disable_session_recording?this.sessionRecording.stopRecording():this.sessionRecording.startRecordingIfEnabled())}}},{key:"startSessionRecording",value:function(){this.set_config({disable_session_recording:!1})}},{key:"stopSessionRecording",value:function(){this.set_config({disable_session_recording:!0})}},{key:"sessionRecordingStarted",value:function(){var or;return!((or=this.sessionRecording)===null||or===void 0||!or.started)}},{key:"loadToolbar",value:function(or){return this.toolbar.loadToolbar(or)}},{key:"get_property",value:function(or){var ir;return(ir=this.persistence)===null||ir===void 0?void 0:ir.props[or]}},{key:"getSessionProperty",value:function(or){var ir;return(ir=this.sessionPersistence)===null||ir===void 0?void 0:ir.props[or]}},{key:"toString",value:function(){var or,ir=(or=this.config.name)!==null&&or!==void 0?or:di;return ir!==di&&(ir=di+"."+ir),ir}},{key:"_gdpr_init",value:function(){this.config.opt_out_capturing_persistence_type==="localStorage"&&lt.is_supported()&&(!this.has_opted_in_capturing()&&this.has_opted_in_capturing({persistence_type:"cookie"})&&this.opt_in_capturing({enable_persistence:!1}),!this.has_opted_out_capturing()&&this.has_opted_out_capturing({persistence_type:"cookie"})&&this.opt_out_capturing({clear_persistence:!1}),this.clear_opt_in_out_capturing({persistence_type:"cookie",enable_persistence:!1})),this.has_opted_out_capturing()?this._gdpr_update_persistence({clear_persistence:!0}):this.has_opted_in_capturing()||!this.config.opt_out_capturing_by_default&&!at.get("ph_optout")||(at.remove("ph_optout"),this.opt_out_capturing({clear_persistence:this.config.opt_out_persistence_by_default}))}},{key:"_gdpr_update_persistence",value:function(or){var ir,ar,sr,lr,cr;if(or&&or.clear_persistence)sr=!0;else{if(!or||!or.enable_persistence)return;sr=!1}this.config.disable_persistence||((ir=this.persistence)===null||ir===void 0?void 0:ir.disabled)===sr||(lr=this.persistence)===null||lr===void 0||lr.set_disabled(sr),this.config.disable_persistence||((ar=this.sessionPersistence)===null||ar===void 0?void 0:ar.disabled)===sr||(cr=this.sessionPersistence)===null||cr===void 0||cr.set_disabled(sr)}},{key:"_gdpr_call_func",value:function(or,ir){return ir=G({capture:this.capture.bind(this),persistence_type:this.config.opt_out_capturing_persistence_type,cookie_prefix:this.config.opt_out_capturing_cookie_prefix,cookie_expiration:this.config.cookie_expiration,cross_subdomain_cookie:this.config.cross_subdomain_cookie,secure_cookie:this.config.secure_cookie},ir||{}),lt.is_supported()||ir.persistence_type!=="localStorage"||(ir.persistence_type="cookie"),or(this.config.token,{capture:ir.capture,captureEventName:ir.capture_event_name,captureProperties:ir.capture_properties,persistenceType:ir.persistence_type,persistencePrefix:ir.cookie_prefix,cookieExpiration:ir.cookie_expiration,crossSubdomainCookie:ir.cross_subdomain_cookie,secureCookie:ir.secure_cookie})}},{key:"opt_in_capturing",value:function(or){or=G({enable_persistence:!0},or||{}),this._gdpr_call_func(Mt,or),this._gdpr_update_persistence(or)}},{key:"opt_out_capturing",value:function(or){var ir=G({clear_persistence:!0},or||{});this._gdpr_call_func(Tt,ir),this._gdpr_update_persistence(ir)}},{key:"has_opted_in_capturing",value:function(or){return this._gdpr_call_func(qt,or)}},{key:"has_opted_out_capturing",value:function(or){return this._gdpr_call_func(Dt,or)}},{key:"clear_opt_in_out_capturing",value:function(or){var ir=G({enable_persistence:!0},or??{});this._gdpr_call_func(Lt,ir),this._gdpr_update_persistence(ir)}},{key:"debug",value:function(or){or===!1?(T==null||T.console.log("You've disabled debug mode."),localStorage&&localStorage.removeItem("ph_debug"),this.set_config({debug:!1})):(T==null||T.console.log("You're now in debug mode. All calls to PostHog will be logged in your console.\nYou can disable this with `posthog.debug(false)`."),localStorage&&localStorage.setItem("ph_debug","true"),this.set_config({debug:!0}))}}]),nr}();(function(nr,or){for(var ir=0;ir<or.length;ir++)nr.prototype[or[ir]]=X(nr.prototype[or[ir]])})(vi,["identify"]);var mi,yi,bi={},ki=function(){ti.init=function(nr,or,ir){if(ir)return ti[ir]||(ti[ir]=bi[ir]=_i(nr||"",or||{},ir,function(sr){ti[ir]=bi[ir]=sr,sr._loaded()})),ti[ir];var ar=ti;return bi[di]?ar=bi[di]:nr&&(ar=_i(nr,or||{},di,function(sr){bi[di]=sr,sr._loaded()}),bi[di]=ar),ti=ar,ei===Zn.INIT_SNIPPET&&(B[di]=ti),U(bi,function(sr,lr){lr!==di&&(ti[lr]=sr)}),ar}};(function(nr){nr.Popover="popover",nr.API="api",nr.Widget="widget"})(mi||(mi={})),function(nr){nr.Open="open",nr.MultipleChoice="multiple_choice",nr.SingleChoice="single_choice",nr.Rating="rating",nr.Link="link"}(yi||(yi={}));var wi=(ei=Zn.INIT_MODULE,ti=new vi,ki(),ti.init(),function(){function nr(){nr.done||(nr.done=!0,fi=!1,U(bi,function(or){or._dom_loaded()}))}D!=null&&D.addEventListener&&(D.readyState==="complete"?nr():D.addEventListener("DOMContentLoaded",nr,!1)),T&&ie(T,"load",nr,!0)}(),ti);const sessionContext=React$1.createContext({token:"",entityId:"",entity:void 0,user:void 0,users:[],selectedInvoice:void 0,setSelectedInvoice:()=>{},client:void 0,refresh:()=>{},refreshId:0,organization:void 0,moov:void 0,moovToken:void 0,moovAccountId:void 0,iframeOptions:void 0,setIframeOptions:()=>{},getNewToken:nr=>{},googleMapsApiKey:void 0});function MercoaSession({children:nr,entityId:or,entityUserId:ir,token:ar,endpoint:sr,isAdmin:lr,googleMapsApiKey:cr}){return jsx(sessionContext.Provider,{value:useProvideSession({token:ar,entityId:or,entityUserId:ir,endpoint:sr,isAdmin:lr,googleMapsApiKey:cr}),children:nr||jsx(EntityPortal,{token:ar})})}const useMercoaSession=()=>React$1.useContext(sessionContext);function useProvideSession({token:nr,entityId:or,entityUserId:ir,endpoint:ar,isAdmin:sr,googleMapsApiKey:lr}){var fo;const[cr,ur]=React$1.useState(),[dr,fr]=React$1.useState(),[pr,hr]=React$1.useState([]),[gr,vr]=React$1.useState(),[br,mr]=React$1.useState(),[yr,wr]=React$1.useState(0),[Tr,Pr]=React$1.useState(),[Rr,_r]=React$1.useState(),[jr,Cr]=React$1.useState(),[Sr,Mr]=React$1.useState(nr),[Ur,kr]=React$1.useState(),Ir=React$1.useMemo(()=>new javascript.MercoaClient({environment:ar??"https://api.mercoa.com",token:Sr}),[Sr]);async function qr(){if(!nr)return;let bo=or;if(!bo)try{const{entityId:go}=jwtDecode(String(nr));bo=go}catch(go){console.error(go)}if(bo!=="undefined"&&(Ir.organization.get({paymentMethods:!0,emailProvider:!0,colorScheme:!0,payeeOnboardingOptions:!0,payorOnboardingOptions:!0,metadataSchema:!0}).then(go=>{mr(go)}),bo!=="all"&&bo)){Ir.entity.get(bo).then(mo=>{ur(mo),wr(Math.random())});let go=ir;if(!go)try{const{userId:mo}=jwtDecode(String(nr));go=mo}catch(mo){console.error(mo)}go&&Ir.entity.user.get(bo,go).then(mo=>{fr(mo)}),Ir.entity.user.getAll(bo).then(mo=>{hr(mo)}),!Tr&&!sr&&Ir.entity.getToken(bo,{}).then(async mo=>{Mr(mo);const{moov:Br}=jwtDecode(String(mo));if(_r(Br.accountId),Cr(Br.token),!(!Br||!Br.token||Br.token==="sandbox"))try{const Gr=await loadMoov(Br.token);Gr&&Pr(Gr)}catch(Gr){console.error(Gr)}})}}async function Vr(bo){const go=Ur||{options:{expiresIn:bo??"12hr"}};if(go.options||(go.options={}),go.options.expiresIn=bo??"12hr",!(cr!=null&&cr.id))return;let mo="";dr!=null&&dr.id?mo=await Ir.entity.user.getToken(cr.id,dr.id,{...go.options}):mo=await Ir.entity.getToken(cr.id,{...go.options}),Mr(mo)}return React$1.useEffect(()=>{var Fr,Or,xr,zr,Ar;const bo=($r,Er)=>{$r=$r.replace(/^#/,""),$r.length===3&&($r=$r[0]+$r[0]+$r[1]+$r[1]+$r[2]+$r[2]);let[Dr,Wr,Nr]=$r.match(/.{2}/g);[Dr,Wr,Nr]=[parseInt(Dr,16)+Er,parseInt(Wr,16)+Er,parseInt(Nr,16)+Er],Dr=Math.max(Math.min(255,Dr),0).toString(16),Wr=Math.max(Math.min(255,Wr),0).toString(16),Nr=Math.max(Math.min(255,Nr),0).toString(16);const Hr=(Dr.length<2?"0":"")+Dr,yo=(Wr.length<2?"0":"")+Wr,_o=(Nr.length<2?"0":"")+Nr;return`#${Hr}${yo}${_o}`},go=((Fr=br==null?void 0:br.colorScheme)==null?void 0:Fr.primaryColor)||"#4f46e5",mo=(Or=br==null?void 0:br.colorScheme)!=null&&Or.primaryColor?bo((xr=br==null?void 0:br.colorScheme)==null?void 0:xr.primaryColor,40):"#6366f1",Br=(zr=br==null?void 0:br.colorScheme)!=null&&zr.primaryColor?bo((Ar=br==null?void 0:br.colorScheme)==null?void 0:Ar.primaryColor,-40):"#4338ca";let Gr=go,Qr="#ffffff";go==="#f8fafc"&&(Gr="#111827",Qr="#111827"),document.documentElement.style.setProperty("--mercoa-primary",go),document.documentElement.style.setProperty("--mercoa-primary-light",mo),document.documentElement.style.setProperty("--mercoa-primary-dark",Br),document.documentElement.style.setProperty("--mercoa-primary-text",Gr),document.documentElement.style.setProperty("--mercoa-primary-text-invert",Qr)},[(fo=br==null?void 0:br.colorScheme)==null?void 0:fo.primaryColor]),React$1.useEffect(()=>{qr()},[nr,or]),React$1.useEffect(()=>{dr!=null&&dr.id?wi.identify(cr==null?void 0:cr.id,{email:dr==null?void 0:dr.email}):wi.identify(cr==null?void 0:cr.id,{email:cr==null?void 0:cr.email})},[dr]),{refresh:qr,refreshId:yr,token:nr,entityId:or??(cr==null?void 0:cr.id),entity:cr,user:dr,users:pr,selectedInvoice:gr,setSelectedInvoice:vr,client:Ir,organization:br,moov:Tr,moovAccountId:Rr,moovToken:jr,iframeOptions:Ur,setIframeOptions:kr,getNewToken:Vr,googleMapsApiKey:lr}}dayjs$1.extend(relativeTime);function InvoiceComments({invoice:nr}){var gr;const or=useMercoaSession(),[ir,ar]=React$1.useState((nr==null?void 0:nr.comments)??[]),{register:sr,handleSubmit:lr,setValue:cr}=useForm({defaultValues:{type:"comment",text:""}});function ur({type:vr,text:br}){var mr,yr,wr;if(!((mr=or.user)!=null&&mr.id)){Q$2.error("Please login as a user to comment");return}!or.token||!(nr!=null&&nr.id)||br&&vr==="comment"&&((wr=or.client)==null||wr.invoice.comment.create(nr.id,{text:br,userId:(yr=or.user)==null?void 0:yr.id}).then(Tr=>{Tr&&(console.log(Tr),ar([...ir,Tr]),cr("text",""))}))}function dr(vr){let br=jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-gray-100 ring-1 ring-gray-300"});return vr.action==="APPROVE"?br=jsx(CheckCircleIcon$1,{className:"h-6 w-6 text-green-600","aria-hidden":"true"}):vr.action==="REJECT"&&(br=jsx(XCircleIcon$1,{className:"h-6 w-6 text-red-600","aria-hidden":"true"})),br}const fr={APPROVE:"approved",REJECT:"rejected",NONE:"created"},pr=ir.filter(vr=>vr.text||vr.associatedApprovalAction),hr={id:(nr==null?void 0:nr.id)??"",createdAt:(nr==null?void 0:nr.createdAt)??"",user:(nr==null?void 0:nr.creatorUser)??{id:"",name:"Email"},text:"",associatedApprovalAction:{action:javascript.Mercoa.ApproverAction.None,userId:((gr=nr==null?void 0:nr.creatorUser)==null?void 0:gr.id)??""}};return jsxs(Fragment,{children:[jsx("ul",{role:"list",className:"space-y-6 ml-1",children:[hr,...pr].map((vr,br)=>{var mr,yr;return jsxs("li",{className:"relative flex gap-x-4",children:[jsx("div",{className:`${br===pr.length?"h-6":"-bottom-6"} absolute left-0 top-0 flex w-6 justify-center`,children:jsx("div",{className:"w-px bg-gray-200"})}),vr.text&&jsxs(Fragment,{children:[jsx(UserIcon$1,{className:"h-8 w-8 text-gray-300 mt-3 text-gray-300 bg-gray-100 rounded-full p-1 -ml-1"}),jsxs("div",{className:"flex-auto rounded-md p-3 ring-1 ring-inset ring-gray-200",children:[jsxs("div",{className:"flex justify-between gap-x-4",children:[jsxs("div",{className:"py-0.5 text-xs leading-5 text-gray-500",children:[jsx("span",{className:"font-medium text-gray-900",children:(mr=vr.user)==null?void 0:mr.name})," commented"]}),jsx("time",{dateTime:dayjs$1(vr.createdAt).toISOString(),className:"flex-none py-0.5 text-xs leading-5 text-gray-500",children:dayjs$1(vr.createdAt).fromNow()})]}),jsx("p",{className:"text-sm leading-6 text-gray-500",children:vr.text})]})]}),vr.associatedApprovalAction&&jsxs(Fragment,{children:[jsx("div",{className:"relative flex h-6 w-6 flex-none items-center justify-center bg-white",children:dr(vr.associatedApprovalAction)}),jsxs("p",{className:"flex-auto py-0.5 text-xs leading-5 text-gray-500",children:[jsx("span",{className:"font-medium text-gray-900",children:(yr=vr.user)==null?void 0:yr.name})," ",fr[vr.associatedApprovalAction.action]," the invoice."]}),jsx("time",{dateTime:dayjs$1(vr.createdAt).toISOString(),className:"flex-none py-0.5 text-xs leading-5 text-gray-500",children:dayjs$1(vr.createdAt).fromNow()})]})]},vr.id)})}),jsx("div",{className:"mt-6 flex gap-x-3",children:jsxs("form",{onSubmit:lr(ur),className:"relative flex-auto",children:[jsxs("div",{className:"overflow-hidden rounded-lg pb-12 shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-indigo-600",children:[jsx("label",{htmlFor:"comment",className:"sr-only",children:"Add your comment"}),jsx("textarea",{rows:2,...sr("text"),className:"block w-full resize-none border-0 bg-transparent py-1.5 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6",placeholder:"Add your comment..."})]}),jsxs("div",{className:"absolute inset-x-0 bottom-0 flex justify-between py-2 pl-3 pr-2",children:[jsx("div",{}),jsx("button",{type:"submit",className:"rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50",children:"Comment"})]})]})})]})}const dJSON=require("dirty-json");dayjs$1.extend(minMax);function classNames(...nr){return nr.filter(Boolean).join(" ")}function InvoiceDetails({invoiceId:nr,invoice:or,onRedirect:ir,addPaymentMethodRedirect:ar,children:sr}){var kr;const lr=useMercoaSession(),[cr,ur]=React$1.useState(),[dr,fr]=React$1.useState(),[pr,hr]=React$1.useState(),[gr,vr]=React$1.useState(!1),[br,mr]=React$1.useState(or),[yr,wr]=React$1.useState(),[Tr,Pr]=React$1.useState(typeof window<"u"?window.innerHeight-70:0),[Rr,_r]=React$1.useState(!1);async function jr(Ir){var Vr,fo;if(!lr.token||!((Vr=lr.entity)!=null&&Vr.id))return;const qr=await((fo=lr.client)==null?void 0:fo.invoice.get(Ir));qr&&mr(qr)}async function Cr(Ir){var Vr,fo;if(!lr.token||!((Vr=lr.entity)!=null&&Vr.id))return;const qr=await((fo=lr.client)==null?void 0:fo.ocr.getAsyncOcr(Ir));qr&&qr.status===javascript.Mercoa.OcrJobStatus.Success?(fr(qr.data),vr(!1)):qr&&qr.status===javascript.Mercoa.OcrJobStatus.Failed?(Q$2.error("OCR failed"),vr(!1)):setTimeout(()=>Cr(Ir),5e3)}async function Sr(Ir,qr){var Vr;ur({fileReaderObj:Ir,mimeType:qr.type}),hr(Ir),vr(!0);try{const fo=await((Vr=lr.client)==null?void 0:Vr.ocr.runAsyncOcr({entityId:lr.entityId,image:Ir,mimeType:qr.type}));fo?Cr(fo==null?void 0:fo.jobId):(Q$2.error("OCR failed"),vr(!1))}catch(fo){console.log(fo),Q$2.error("OCR failed"),vr(!1)}}React$1.useEffect(()=>{var Ir;!lr.token||!((Ir=lr.entity)!=null&&Ir.id)||!or&&nr&&jr(nr)},[or,nr,lr.token,(kr=lr.entity)==null?void 0:kr.id]);function Mr(){Pr(window.innerHeight-70)}React$1.useEffect(()=>(Mr(),window.addEventListener("resize",Mr,!1),()=>{window.removeEventListener("resize",Mr)}),[]),React$1.useEffect(()=>{var Ir;br&&br.hasDocuments&&((Ir=lr.client)==null||Ir.invoice.document.getAll(br.id).then(qr=>{var Vr,fo;qr&&qr.length>0&&(wr(qr),ur({fileReaderObj:(Vr=qr==null?void 0:qr[0])==null?void 0:Vr.uri,mimeType:(fo=qr==null?void 0:qr[0])==null?void 0:fo.mimeType}))}))},[br]);const Ur=jsx("div",{className:"min-w-[300px] mr-5",children:cr?jsxs(Fragment,{children:[jsxs("div",{className:`text-center ${gr?"block mb-5":"hidden"}`,children:[jsx("span",{className:"text-gray-800 w-full",children:" Extracting Invoice Details "}),jsx(ProgressBar,{})]}),jsx(InvoiceDocuments,{documents:new Array(cr),height:Tr})]}):jsx(InvoiceDocumentsUpload,{onFileUpload:Sr})});return sr?jsx(Fragment,{children:sr({invoice:br,documents:yr})}):!br&&nr?jsx(LoadingSpinner,{}):jsxs(X$3,{children:[jsx(_$3,{minSize:0,children:Ur}),jsx(ne$1,{size:5,className:"bg-gray-200 cursor-ew-resize invisible min-[450px]:visible",children:jsx("div",{className:"w-3 h-10 bg-gray-500 absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"})}),jsxs(_$3,{className:"pl-5 relative",minSize:400,children:[jsx("div",{className:"flex w-full flex-row-reverse visible min-[450px]:invisible absolute top-2",children:jsxs(MercoaButton,{isEmphasized:!0,size:"sm",type:"button",onClick:()=>{_r(!Rr)},className:"mr-7 z-20",children:["View ",Rr?"Form":"Invoice"]})}),Rr?jsx("div",{className:"mt-20",children:Ur}):jsx(EditInvoiceForm,{invoice:br,ocrResponse:dr,uploadedImage:pr,setUploadedImage:hr,onRedirect:ir,refreshInvoice:jr,addPaymentMethodRedirect:ar,height:Tr})]})]})}function InvoiceDocumentsUpload({onFileUpload:nr}){const or=ir=>new Promise((ar,sr)=>{const lr=new FileReader;lr.onload=()=>ar(String(lr.result)),lr.onerror=sr,lr.readAsDataURL(ir)});return jsx(Dropzone$1,{onDropAccepted:ir=>{or(ir[0]).then(ar=>{nr(ar,ir[0])})},onDropRejected:()=>{Q$2.error("Invalid file type")},minSize:0,maxSize:1e7,accept:{"application/pdf":[".pdf"],"image/png":[".png"],"image/gif":[".gif"],"image/tiff":[".tif",".tiff"],"image/jpeg":[".jpeg",".jpg"],"image/bmp":[".bmp"],"image/webp":[".webp"]},children:({getRootProps:ir,getInputProps:ar,isDragActive:sr})=>jsx("div",{className:`mt-2 flex justify-center rounded-lg border border-dashed border-gray-900/25 ${sr?"border-mercoa-primary":"border-gray-300"} px-6 py-10`,...ir(),children:jsxs("div",{className:"text-center",children:[jsx(PhotoIcon$1,{className:"mx-auto h-12 w-12 text-gray-300","aria-hidden":"true"}),jsxs("div",{className:"mt-4 flex text-sm text-gray-600",children:[jsxs("label",{htmlFor:"file-upload",className:"relative cursor-pointer rounded-md bg-white font-semibold text-mercoa-primary focus-within:outline-none focus-within:ring-2 focus-within:ring-mercoa-primary focus-within:ring-offset-2 hover:text-indigo-500",children:[jsx("span",{children:"Upload an invoice"}),jsx("input",{...ar(),id:"file-upload",name:"file-upload",type:"file",className:"sr-only"})]}),jsx("p",{className:"pl-1",children:"or drag and drop"})]}),jsx("p",{className:"text-xs leading-5 text-gray-600",children:"PNG, JPG, PDF up to 10MB"})]})})})}function InvoiceDocuments({documents:nr,height:or}){const[ir,ar]=React$1.useState(),[sr,lr]=React$1.useState(1),[cr,ur]=useDebounce(0,20),dr=React$1.useRef(null);React$1.useLayoutEffect(()=>{dr.current!==null&&ur(dr.current.getBoundingClientRect().width)},[dr]),useResizeObserver(dr,hr=>{cr&&Math.abs(cr-hr.contentRect.width)<20||ur(hr.contentRect.width)});const fr=jsx("div",{className:"flex justify-center ",children:jsxs("nav",{className:"isolate inline-flex -space-x-px rounded-md shadow-sm","aria-label":"Pagination",children:[jsxs("button",{type:"button",onClick:()=>lr(Math.max(sr-1,1)),className:"relative inline-flex items-center rounded-l-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0",children:[jsx("span",{className:"sr-only",children:"Previous"}),jsx(ChevronLeftIcon$1,{className:"h-5 w-5","aria-hidden":"true"})]}),Array.from(new Array(ir),(hr,gr)=>jsx("button",{type:"button",onClick:()=>lr(gr+1),"aria-current":sr!=gr+1?"false":"page",className:sr!=gr+1?"relative inline-flex items-center px-4 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0":"relative z-10 inline-flex items-center bg-mercoa-primary px-4 py-2 text-sm font-semibold text-white focus:z-20 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-mercoa-primary",children:gr+1},gr)),jsxs("button",{type:"button",onClick:()=>lr(Math.min(sr+1,ir??1)),className:"relative inline-flex items-center rounded-r-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0",children:[jsx("span",{className:"sr-only",children:"Next"}),jsx(ChevronRightIcon$1,{className:"h-5 w-5","aria-hidden":"true"})]})]})}),pr=jsx("div",{children:nr&&nr.length>0&&jsx("div",{ref:dr,children:nr.map((hr,gr)=>jsxs("div",{children:[jsx("div",{className:"rounded-md border shadow-lg",style:{width:`${cr}px`},children:hr.mimeType==="application/pdf"?jsx(Document$1,{loading:jsx("div",{className:"mt-2 flex w-full items-center justify-center",style:{height:"700px"},children:jsx(LoadingSpinnerIcon,{})}),file:hr.fileReaderObj,onLoadSuccess:({numPages:vr})=>ar(vr),children:jsx(Page$1,{pageNumber:sr,className:"m-0 w-full p-0 mt-2",renderTextLayer:!1,renderAnnotationLayer:!1,width:cr-5})},hr.fileReaderObj):jsx("img",{src:hr.fileReaderObj,onLoad:()=>ar(1),className:"mt-2"},hr.fileReaderObj)}),jsx("a",{href:hr.fileReaderObj,target:"_blank",rel:"noreferrer",className:"mt-2",download:!0,children:jsxs(MercoaButton,{type:"button",isEmphasized:!1,className:"mt-2",children:[jsxs("span",{className:"hidden xl:inline",children:[jsx(ArrowDownTrayIcon$1,{className:"-ml-1 mr-2 inline-flex h-5 w-5"})," Download Invoice"]}),jsx("span",{className:"inline xl:hidden",children:"Download"})]})})]},gr))})});return jsxs("div",{className:"overflow-auto",style:{height:`${or}px`},children:[fr,pr]})}function EditInvoiceForm({invoice:nr,ocrResponse:or,uploadedImage:ir,setUploadedImage:ar,onRedirect:sr,refreshInvoice:lr,addPaymentMethodRedirect:cr,height:ur}){var To,Ao,Kr,po,wo,so,Lr,Yr,jo,Jr,Po,Co,Yo,Oo,Mo,Zr,Go,Zo,Xr,Qo,Eo,vo,Fo,ko,Mi,Si,xi,ji,Di,Ti,zo,ho,xo,Bo,Ko,$o,Lo;const dr=useMercoaSession(),[fr,pr]=React$1.useState([]),[hr,gr]=React$1.useState([]),[vr,br]=React$1.useState([]),[mr,yr]=React$1.useState([]),[wr,Tr]=React$1.useState(nr==null?void 0:nr.vendor),[Pr,Rr]=React$1.useState(),[_r,jr]=React$1.useState([]),[Cr,Sr]=React$1.useState(!1),Mr=Io=>{const[Jo,Oi]=React$1.useState(0);return React$1.useLayoutEffect(()=>{Oi(Io.current.getBoundingClientRect().width)},[Io]),useResizeObserver(Io,Ri=>Oi(Ri.contentRect.width)),Jo},Ur=React$1.useRef(null),kr=Mr(Ur);let Ir="grid-cols-1";kr&&kr>300&&(Ir="grid-cols-2"),kr&&kr>500&&(Ir="grid-cols-3"),kr&&kr>700&&(Ir="grid-cols-4"),kr&&kr>900&&(Ir="grid-cols-5"),kr&&kr>1100&&(Ir="grid-cols-6");const qr=create$3({amount:create$5().positive().required().typeError("Please enter a valid number"),invoiceNumber:create$6(),description:create$6(),dueDate:create$4().required("Please select a due date").typeError("Please select a due date"),deductionDate:create$4().typeError("Please select a deduction date"),invoiceDate:create$4().required("Please select an invoice date").typeError("Please select an invoice date"),approvers:create$8(),lineItems:create$2().of(create$3({id:create$6(),description:create$6().required(),amount:create$5().moreThan(-1).required().typeError("Please enter a valid number"),quantity:create$5().moreThan(-1).required().typeError("Please enter a valid number"),unitPrice:create$5().moreThan(-1).required().typeError("Please enter a valid number"),metadata:create$8().nullable(),glAccountId:create$6()})),currency:create$6().required(),vendorId:create$6(),vendorName:create$6(),paymentDestinationId:create$6(),paymentMethodDestinationType:create$6(),paymentSourceId:create$6(),paymentMethodSourceType:create$6(),saveAsDraft:create$7(),metadata:create$8().nullable()}).required(),{register:Vr,handleSubmit:fo,setValue:bo,setError:go,clearErrors:mo,watch:Br,control:Gr,formState:{errors:Qr}}=useForm({resolver:o$1(qr),defaultValues:{invoiceNumber:nr==null?void 0:nr.invoiceNumber,amount:nr==null?void 0:nr.amount,currency:(nr==null?void 0:nr.currency)??"USD",vendorId:(To=nr==null?void 0:nr.vendor)==null?void 0:To.id,vendorName:(Ao=nr==null?void 0:nr.vendor)==null?void 0:Ao.name,invoiceDate:nr!=null&&nr.invoiceDate?dayjs$1(nr==null?void 0:nr.invoiceDate).toDate():void 0,dueDate:nr!=null&&nr.dueDate?dayjs$1(nr==null?void 0:nr.dueDate).toDate():void 0,deductionDate:nr!=null&&nr.deductionDate?dayjs$1(nr==null?void 0:nr.deductionDate).toDate():void 0,lineItems:(nr==null?void 0:nr.lineItems)??[],paymentDestinationId:(Kr=nr==null?void 0:nr.paymentDestination)==null?void 0:Kr.id,paymentMethodDestinationType:"",paymentSourceId:(po=nr==null?void 0:nr.paymentSource)==null?void 0:po.id,paymentMethodSourceType:"",description:(nr==null?void 0:nr.noteToSelf)??"",saveAsDraft:!1,metadata:JSON.stringify((nr==null?void 0:nr.metadata)??{}),approvers:nr!=null&&nr.approvers?nr.approvers.map(Io=>({approvalSlotId:Io.approvalSlotId,assignedUserId:Io.assignedUserId})):[]}}),Fr=Br("amount"),Or=Br("dueDate"),xr=Br("currency"),zr=Br("vendorId"),Ar=Br("vendorName"),$r=Br("paymentDestinationId"),Er=Br("paymentSourceId"),Dr=Br("approvers"),Wr=Br("metadata"),{fields:Nr,append:Hr,remove:yo}=useFieldArray({control:Gr,name:"lineItems"});React$1.useEffect(()=>{Rr(nr==null?void 0:nr.approvers.map(Io=>({assignedUserId:Io.assignedUserId??"",approvalSlotId:Io.approvalSlotId})))},[nr]),React$1.useEffect(()=>{var Io,Jo,Oi,Ri;!dr.token||!((Io=dr.entity)!=null&&Io.id)||!dr.client||((Oi=dr.client)==null||Oi.entity.paymentMethod.getAll((Jo=dr.entity)==null?void 0:Jo.id).then(Ei=>{Ei&&pr(Ei)}),(Ri=dr.client)==null||Ri.customPaymentMethodSchema.getAll().then(Ei=>{var Pi,Ai;if(Ei){gr(Ei);let Ci=[];((Ai=(Pi=dr.organization)==null?void 0:Pi.paymentMethods)==null?void 0:Ai.payerPayments.some(Ii=>Ii.active&&(Ii.type==="bankAccount"||Ii.type==="card")))&&Ci.push("USD"),Ei.forEach(Ii=>{Ii.supportedCurrencies&&(Ci=[...new Set([...Ci,...Ii.supportedCurrencies])])}),yr(Ci)}}))},[dr.client,(wo=dr.entity)==null?void 0:wo.id,dr.token]),React$1.useEffect(()=>{var Io,Jo;!dr.token||!((Io=dr.entity)!=null&&Io.id)||(Jo=dr.client)==null||Jo.entity.metadata.getAll(dr.entity.id).then(Oi=>{Oi&&jr(Oi)})},[(so=dr.entity)==null?void 0:so.id,dr.refreshId,dr.token]),React$1.useEffect(()=>{mr.length>0&&bo("currency",(nr==null?void 0:nr.currency)??mr[0])},[mr]),React$1.useEffect(()=>{var Io;!dr.token||!zr||(Io=dr.client)==null||Io.entity.paymentMethod.getAll(zr).then(Jo=>{Jo&&br(Jo)})},[dr.client,zr,dr.token]),React$1.useEffect(()=>{var Io,Jo,Oi,Ri,Ei,Pi;or&&(or.invoice.amount&&bo("amount",or.invoice.amount),bo("invoiceNumber",or.invoice.invoiceNumber),or.invoice.invoiceDate&&bo("invoiceDate",or.invoice.invoiceDate),or.invoice.dueDate&&bo("dueDate",or.invoice.dueDate),bo("deductionDate",or.invoice.deductionDate),or.invoice.currency&&bo("currency",or.invoice.currency),or.invoice.metadata&&bo("metadata",JSON.stringify(or.invoice.metadata)),or.invoice.lineItems&&!((Oi=(Jo=(Io=dr.iframeOptions)==null?void 0:Io.options)==null?void 0:Jo.invoice)!=null&&Oi.disableLineItems)&&bo("lineItems",or.invoice.lineItems.map(Ai=>({description:Ai.description??"",amount:Ai.amount??0,quantity:Ai.quantity??0,unitPrice:Ai.unitPrice??0,name:Ai.name??"",metadata:Ai.metadata??{},glAccountId:Ai.glAccountId??"",id:Ai.id??"",createdAt:Ai.createdAt??new Date,updatedAt:Ai.updatedAt??new Date}))),wr||(or.vendor.id==="new"&&((Pi=(Ei=(Ri=dr.iframeOptions)==null?void 0:Ri.options)==null?void 0:Ei.vendors)!=null&&Pi.disableCreation)?console.log("new vendor creation disabled"):or.vendor.id&&(console.log("setting selected vendor",or.vendor),Tr(or.vendor))))},[or,wr]);let _o=!1;nr!=null&&nr.approvers?_o=!!(Dr!=null&&Dr.every(Io=>!!Io)):_o=!!(nr!=null&&nr.approvers.every(Io=>Io.assignedUserId));let Ro=!!Fr&&!!Or&&!!xr&&!!zr&&zr!=="new"&&!!Er&&!!Ar;(jo=(Yr=(Lr=dr.iframeOptions)==null?void 0:Lr.options)==null?void 0:Yr.vendors)!=null&&jo.disableCreation||(Ro=Ro&&!!(wr!=null&&wr.email)&&!!(wr.accountType==="individual"||wr.accountType==="business"&&((Jr=wr.profile.business)!=null&&Jr.website||(Po=wr.profile.business)!=null&&Po.description)));const No=(nr==null?void 0:nr.status)===javascript.Mercoa.InvoiceStatus.Approved&&Ro&&(!$r||$r==="new"),Do=Ro&&(nr==null?void 0:nr.status)===javascript.Mercoa.InvoiceStatus.Approved&&$r;let Wo=javascript.Mercoa.InvoiceStatus.Draft;Do?Wo=javascript.Mercoa.InvoiceStatus.Scheduled:No||(nr==null?void 0:nr.status)===javascript.Mercoa.InvoiceStatus.New?Wo=javascript.Mercoa.InvoiceStatus.Approved:Ro&&_o&&(Wo=javascript.Mercoa.InvoiceStatus.New);const Vo=async Io=>{var Oi,Ri,Ei,Pi,Ai,Ci,zi,Ii,Bi,Ui;if(!dr.token||!((Oi=dr.entity)!=null&&Oi.id))return;const Jo={status:Io.saveAsDraft?javascript.Mercoa.InvoiceStatus.Draft:Wo,amount:Number(Io.amount),currency:Io.currency,invoiceDate:Io.invoiceDate,deductionDate:Io.deductionDate,dueDate:Io.dueDate,invoiceNumber:Io.invoiceNumber,noteToSelf:Io.description,payerId:(Ri=dr.entity)==null?void 0:Ri.id,paymentSourceId:Io.paymentSourceId,approvers:Io.approvers.filter(Ni=>Ni.assignedUserId),...Io.vendorId!=="new"&&{vendorId:Io.vendorId},paymentDestinationId:Io.paymentDestinationId,lineItems:Io.lineItems.map(Ni=>({...Ni.id&&{id:Ni.id},description:Ni.description,amount:Number(Ni.amount),quantity:Number(Ni.quantity),unitPrice:Number(Ni.unitPrice),metadata:Ni.metadata,currency:Io.currency??"USD",glAccountId:Ni.glAccountId})),metadata:JSON.parse(Io.metadata),uploadedImage:ir,creatorEntityId:(Ei=dr.entity)==null?void 0:Ei.id};if(console.log({data:Io,invoiceData:Jo}),Io.paymentMethodDestinationType&&(!Io.paymentDestinationId||Io.paymentDestinationId==="new")){const Ni=Io.paymentMethodDestinationType,Li=Io.paymentMethodDestinationType.startsWith("cpms_")?"custom":Io.paymentMethodDestinationType;let Gi;if(Li==="bankAccount")Gi={type:Li,accountNumber:Io.accountNumber,routingNumber:Io.routingNumber,accountType:Io.accountType,bankName:Io.bankName};else if(Li==="check")Gi={type:Li,...Io};else if(Li==="custom"){const Vi={};Object.entries(Io).forEach(([nl,ol])=>{nl.startsWith("~cpm~~")&&ol.forEach(wa=>{Vi[wa.name]=`${Vi[wa.name]??wa.value}`})}),Gi={type:Li,foreignId:Math.random().toString(36).substring(7),schemaId:Ni,data:Vi}}if(Gi){const Vi=await((Pi=dr.client)==null?void 0:Pi.entity.paymentMethod.create(Io.vendorId,Gi));Vi&&(Jo.paymentDestinationId=Vi.id)}}if(Jo.status!==javascript.Mercoa.InvoiceStatus.Draft&&((Ai=Jo.approvers)==null?void 0:Ai.length)!==(nr==null?void 0:nr.approvers.length)){Q$2.error("Please assign all approvers for this invoice."),Sr(!1);return}console.log("invoiceData before API call: ",{invoiceData:Jo}),nr?(Ii=dr.client)==null||Ii.invoice.update(nr.id,{...Jo,creatorUserId:((Ci=nr.creatorUser)==null?void 0:Ci.id)??((zi=dr.user)==null?void 0:zi.id)}).then(Ni=>{Ni&&(console.log("invoice/update API response: ",Ni),ar(void 0),Q$2.success("Invoice updated"),lr(Ni.id),Sr(!1))}).catch(Ni=>{console.log(Ni.statusCode),console.log(Ni.body),Q$2.error(`There was an error updating the invoice.
174
174
  Error: ${Ni.body}`),Sr(!1)}):(Ui=dr.client)==null||Ui.invoice.create({...Jo,creatorUserId:(Bi=dr.user)==null?void 0:Bi.id}).then(Ni=>{Ni&&(console.log("invoice/create API response: ",Ni),Q$2.success("Invoice created"),ar(void 0),lr(Ni.id),sr(Ni),Sr(!1))}).catch(Ni=>{console.log(Ni.statusCode),console.log(Ni.body),Q$2.error(`'There was an error creating the invoice.
175
175
  Error: ${Ni.body}`),Q$2.error("There was an error creating the invoice. Make sure the invoice number is unique for this vendor and try again."),Sr(!1)})},So=(Io,Jo,Oi)=>{const Ri=Pr==null?void 0:Pr.map((Ei,Pi)=>Pi===Io?Jo:Ei);Rr(Ri),Oi(Ri)};async function Uo(){var Jo;if(!(nr!=null&&nr.id))return;const Io=await((Jo=dr.client)==null?void 0:Jo.invoice.getVendorLink(nr.id));Io?navigator.clipboard.writeText(Io).then(function(){Q$2.info("Link Copied")},function(Oi){Q$2.error("There was an issue generating the vendor link. Please refresh and try again.")}):Q$2.error("There was an issue generating the vendor link. Please refresh and try again.")}return jsxs("div",{style:{height:`${ur}px`},className:"overflow-auto pr-2 pb-10",ref:Ur,children:[jsxs("h2",{className:"text-base font-semibold leading-7 text-gray-900",children:["Edit Invoice ",nr&&jsx(InvoiceStatusPill,{invoice:nr})]}),jsx("p",{className:"mb-3 text-xs leading-6 text-gray-400 select-all",children:nr==null?void 0:nr.id}),jsx("div",{className:"border-b border-gray-900/10 mb-4"}),jsxs("div",{className:"sm:col-span-3",children:[jsx("label",{htmlFor:"vendor-name",className:"block text-lg font-medium leading-6 text-gray-700",children:"Vendor"}),jsx("div",{className:"mt-2 flex items-center justify-left",children:jsx(CounterpartySearch,{type:"payee",onSelect:Io=>{console.log({vendor:Io}),Tr(Io),bo("vendorId",(Io==null?void 0:Io.id)??void 0,{shouldTouch:!0,shouldDirty:!0}),bo("vendorName",(Io==null?void 0:Io.name)??void 0,{shouldTouch:!0,shouldDirty:!0})},counterparty:wr})})]}),jsx("div",{className:"border-b border-gray-900/10 pb-6"}),jsxs("form",{onSubmit:fo(Vo),className:`${zr==="new"&&!((Oo=(Yo=(Co=dr.iframeOptions)==null?void 0:Co.options)==null?void 0:Yo.vendors)!=null&&Oo.disableCreation)?"opacity-25 pointer-events-none":""}
176
176
  ${Ir}