(function(u){typeof define=="function"&&define.amd?define(u):u()})(function(){"use strict";class u{constructor(){this._data=[]}get(){return this._data}set(e){this._data=e}}class _{constructor(e){this._key=e,this._storage=window.localStorage}get(){const e=this._storage.getItem(this._key);return e?JSON.parse(e):[]}set(e){this._storage.setItem(this._key,JSON.stringify(e))}}class M{constructor(e){this._key=e,this._storage=window.sessionStorage,this._bid=void 0}get(){try{return this._storage.getItem(this._key)??void 0}catch{return this._bid}}set(e){this._bid=e;try{this._storage.setItem(this._key,e)}catch{}}}const P="ts-t",v="ts-q",N=250,A=3,R=25,C=250,m=9,L=0;function U(t,e){return e>0?t+(Math.random()+Math.pow(2,e))*1e3:0}function q(){var e;const t=new _(P);try{const s="3";if(t.set([{x:s}]),((e=t.get()[0])==null?void 0:e.x)===s)return new _(v)}catch{}return new u}class x{constructor(e){this._store=q(),this._processing=new Set,this._scheduled=!1,this._processor=e}append(e,s){let o=this._store.get();o.push({e,r:0,p:s!=null&&s.highPriority?m:L}),o=o.slice(-N),this._setEntries(o)}async _processNow(e){if(!e.length)return;const s=[];for(let i=e.length-1;i>=0&&s.lengthc.id===i)||n.push(i);this._processing=new Set(n);const r=this._store.get(),d=[];for(const i of r)o.done.has(i.e.id)||(o.retry.has(i.e.id)?i.rs.p===m)||this._store instanceof u?this._processNow(e):this._scheduleProcessing())}_scheduleProcessing(){this._scheduled||(this._scheduled=!0,setTimeout(()=>{this._scheduled=!1,this._processNow(this._store.get())},C))}}const H="2.3.1";async function B(t,e){try{const s=(e.url||"https://api.topsort.com")+"/v2/events",o=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-UA":`ts.js/${H}`,Authorization:"Bearer "+e.token},body:JSON.stringify(t),keepalive:!0});return{ok:o.ok,retry:o.status===429||o.status>=500}}catch{return{ok:!1,retry:!0}}}const S=2500,D=.5;let a=new Set;const I=new M("ts-b");function E(){var t,e;return((e=(t=window.URL).createObjectURL)==null?void 0:e.call(t,new Blob).split("/").pop())||Math.random()+""}let l;function g(){if(l)return l;const t=j();if(t)return l=t,t;const e=E();return y(e),e}function y(t){const e=window.TS.cookieName||"tsuid";l=t,document.cookie=e+"="+t+";max-age=31536000"}function X(){return l=void 0,document.cookie="tsuid=",g()}window.TS.setUserId=y,window.TS.getUserId=g,window.TS.resetUserId=X;function j(){var s;const t=window.TS.cookieName||"tsuid";return(s=new RegExp("(^|;)\\s*"+t+"\\s*=\\s*([^;]+)").exec(document.cookie))==null?void 0:s.pop()}function z(t){const e=t.type,s={path:t.page};let o;t.product&&(o={type:"product",id:t.product});let n;t.additionalProduct&&(n={type:"product",id:t.additionalProduct});const r=new Date(t.t).toISOString();switch(e){case"Click":return{clicks:[{resolvedBidId:t.bid,entity:o,additionalAttribution:n,placement:s,occurredAt:r,opaqueUserId:t.uid,id:t.id}]};case"Impression":return{impressions:[{resolvedBidId:t.bid,entity:o,additionalAttribution:n,placement:s,occurredAt:r,opaqueUserId:t.uid,id:t.id}]};case"Purchase":return{purchases:[{occurredAt:r,opaqueUserId:t.uid,items:(t.items||[]).map(d=>({productId:d.product,quantity:d.quantity,unitPrice:d.price})),id:t.id}]}}}async function J(t){const e={done:new Set,retry:new Set},s=[];for(const o of t)s.push(B(z(o),window.TS).then(n=>{(n.retry?e.retry:e.done).add(o.id)}).catch(()=>{e.done.add(o.id)}));return await Promise.all(s),e}const Y=new x(J);function f(t,e){const s=G(t);if(a.has(s))return;if(a.add(s),a.size>S){const n=a.values();for(let r=0;r{for(const e of t)if(e.isIntersecting){const s=e.target;s instanceof HTMLElement&&(f(p("Impression",s),s),w&&w.unobserve(s))}},{threshold:D}):void 0,b="[data-ts-product],[data-ts-action],[data-ts-items],[data-ts-resolved-bid]";function $(t){const e=t.querySelectorAll("[data-ts-clickable]");(e.length===0?[t]:e).forEach(o=>o.addEventListener("click",Z))}function T(t){W(t)?f(p("Purchase",t),t):(w?w.observe(t):f(p("Impression",t),t),$(t))}function k(t){const e=t.querySelectorAll(b);for(let s=0;s