import{n as e}from"./rolldown-runtime-BG2f4sTM.js";import{$ft as t,Jft as n,Qft as r,Xft as i,Yft as a,qft as o}from"./app-initial-BHB6SClA.js";import{h as s,t as c}from"./esm-Dg7vifPm.js";import{f as l,p as u}from"./load-script-Cltl04TI.js";import{c as d,s as f}from"./middleware-D4PmVk-p.js";function p(){return u()?window.navigator.onLine:!0}function m(){return!p()}var h=e((()=>{l()})),g=e((()=>{c()}));function _(e){var t=C.getItem(e);return(t?JSON.parse(t):[]).map(function(e){return new f(e.event,e.id)})}function v(e,t){var n=_(e),i=r(r([],t,!0),n,!0).reduce(function(e,t){var n;return o(o({},e),(n={},n[t.id]=t,n))},{});C.setItem(e,JSON.stringify(Object.values(i)))}function y(e){var t=C.getItem(e);return t?JSON.parse(t):{}}function b(e,t){var n=y(e);C.setItem(e,JSON.stringify(o(o({},n),t)))}function x(e){C.removeItem(e)}function S(e,t,n){n===void 0&&(n=0);var r=50,i=`persisted-queue:v1:${e}:lock`,a=function(e){return new Date().getTime()>e},o=C.getItem(i),s=o?JSON.parse(o):null,c=s===null||a(s);if(c){C.setItem(i,JSON.stringify(w()+r)),t(),C.removeItem(i);return}!c&&n<3?setTimeout(function(){S(e,t,n+1)},r):console.error(`Unable to retrieve lock`)}var C,w,T,E=e((()=>{t(),g(),d(),l(),C={getItem:function(){},setItem:function(){},removeItem:function(){}};try{C=u()&&window.localStorage?window.localStorage:C}catch(e){console.warn(`Unable to access localStorage`,e)}w=function(){return new Date().getTime()},T=function(e){a(t,e);function t(t,n){var i=e.call(this,t,[])||this,a=`persisted-queue:v1:${n}:items`,s=`persisted-queue:v1:${n}:seen`,c=[],l={};return S(n,function(){try{c=_(a),l=y(s),x(a),x(s),i.queue=r(r([],c,!0),i.queue,!0),i.seen=o(o({},l),i.seen)}catch(e){console.error(e)}}),window.addEventListener(`pagehide`,function(){if(i.todo>0){var e=r(r([],i.queue,!0),i.future,!0);try{S(n,function(){v(a,e),b(s,i.seen)})}catch(e){console.error(e)}}}),i}return t}(s)})),D,O=e((()=>{t(),D=function(e,t){return n(void 0,void 0,void 0,function(){var r;return i(this,function(a){return r=function(a){return n(void 0,void 0,void 0,function(){var n;return i(this,function(i){switch(i.label){case 0:return e(a)?(n=r,[4,t()]):[3,2];case 1:return[2,n.apply(void 0,[i.sent()])];case 2:return[2]}})})},[2,r(void 0)]})})}}));function k(e,t){var n=Object.entries(t.integrations??{}).reduce(function(e,t){var n,r,i=t[0],a=t[1];return typeof a==`object`?o(o({},e),(n={},n[i]=a,n)):o(o({},e),(r={},r[i]={},r))},{});return Object.entries(e.integrations).reduce(function(e,t){var r,i=t[0],a=t[1];return o(o({},e),(r={},r[i]=o(o({},a),n[i]),r))},{})}var A=e((()=>{t()}));function j(e,t){var n=t.methodName,r=t.integrationName,i=t.type,a=t.didError,o=a===void 0?!1:a;e.stats.increment(`analytics_js.integration.invoke${o?`.error`:``}`,1,[`method:${n}`,`integration_name:${r}`,`type:${i}`])}var M=e((()=>{}));export{O as a,E as c,m as d,p as f,k as i,g as l,j as n,D as o,A as r,T as s,M as t,h as u};
//# sourceMappingURL=metric-helpers-DPhSwte_.js.map