function S(t){let n,e,r="",s;for(t+="",n=0,e=t.length;n=0&&a.search("email")>=0){let o=a.match('"email":s?"(.*?)"');if(o&&o[1])return o[1];let l=a.slice(a.search("customer")+10);if(t=(e=JSON.parse(l.slice(0,l.search("}")+1)))==null?void 0:e.email,t)break}}}}function I(){let t="UShopAidCustomer",n=null;try{n=JSON.parse(localStorage.getItem(t)||"{}")}catch{n={}}return n.email=(()=>_()||n.email)(),n.token=(()=>n.token||v(window.location.host))(),localStorage.setItem(t,JSON.stringify(n)),n}async function k(t,n){return await(await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})).json()}const b="https://store.ushopaid.com";function h(t,n){window.addEventListener("message",e=>{e.data.event===t&&n(e.data.data)})}function A(t){function n(e,r){var c;let s={email:t.email,shopDomain:((c=window.Shopify)==null?void 0:c.shop)||"",customerToken:t.token,phoneNumber:t.phoneNumber,behavior:e,payload:r};k(`${b}/store/v3/events`,s).then(u=>{})}h("site_active",e=>{n("site_active",e)}),h("product_view",e=>{n("product_view",e)}),h("cart_update",e=>{n("cart_update",e)})}function g(t,n){window.postMessage({event:t,data:n},window.location.origin)}const C="UShopAidCart";function x(t){sessionStorage.setItem(C,JSON.stringify(t))}const E=async()=>{try{const t=await P();t&&x(O(t))}catch(t){console.warn(t),x({token:"",items:[]})}};async function P(){var n,e,r,s,c,u;let t=await q();return t?{token:t.id,itemCount:t.totalQuantity||0,totalPrice:parseInt(((((r=(e=t.cost)==null?void 0:e.totalAmount)==null?void 0:r.amount)||0)*100).toFixed(0)),currency:(c=(s=t.cost)==null?void 0:s.totalAmount)==null?void 0:c.currencyCode,items:((u=t.lines)==null?void 0:u.map(a=>{var l,i,m;let o=a.merchandise;return{productId:(l=o==null?void 0:o.product)==null?void 0:l.id,variantId:o==null?void 0:o.id,price:parseInt(((((i=o==null?void 0:o.price)==null?void 0:i.amount)||0)*100).toFixed(0)),quantity:a.quantity,title:(m=o==null?void 0:o.product)==null?void 0:m.title}}))||[]}:(t=await T(),t?{token:t.token,itemCount:t.item_count||0,totalPrice:t.total_price||0,currency:t.currency,items:((n=t.items)==null?void 0:n.map(a=>({productId:a.product_id,variantId:a.id,price:a.price,quantity:a.quantity})))||[]}:null)}function q(){return new Promise((t,n)=>{var e;try{let r;const s=document.querySelector("#web-pixels-manager-setup"),c=document.querySelector("#web-pixels-manager-setup-esm");s?r=[s]:c?r=[c]:r=[...document.querySelectorAll("script")];for(let u of r){let a=u.innerHTML,o=a.search(/\}\)\(\{/),l=a.search(",function");const i=new Function("return "+a.slice(o+3,l))();t((e=i==null?void 0:i.initData)==null?void 0:e.cart)}}catch{throw new Error("Can't get cart info")}})}function T(){return new Promise((t,n)=>{fetch(`https://${j()}/cart.js`).then(e=>e.json()).then(e=>{t(e)})})}const N=t=>{var n,e;return(e=(n=document.cookie)==null?void 0:n.split(";").map(r=>r.split("=")).find(r=>r[0].trim()===t))==null?void 0:e[1]},O=t=>{const n={token:N("cart"),items:[]};let{items:e}=t;return e==null||e.forEach(r=>n.items.push({productId:r.productId,price:r.price,quantity:r.quantity,variantId:r.variantId,title:r.title})),n},U=()=>{var u,a,o,l,i,m;let t,n="";const e=document.querySelector("#web-pixels-manager-setup"),r=document.querySelector("#web-pixels-manager-setup-esm");e?t=[e]:r?t=[r]:t=[...document.querySelectorAll("script")],t.forEach(p=>{n=p.innerHTML});let s=/"productVariants":(\[[\s\S]*?\])/,c=n.match(s);if(c){const p=JSON.parse(c[1])||[];if(p.length>0)return{productId:(a=(u=p[0])==null?void 0:u.product)==null?void 0:a.id,productTitle:(l=(o=p[0])==null?void 0:o.product)==null?void 0:l.title,productImage:(m=(i=p[0])==null?void 0:i.image)==null?void 0:m.src}}else return null},D=()=>{let n=window.location.href.split("/"),e=n.indexOf("products");return e>-1&&ewindow.location.host;(function(){var o,l;const t=I(),n=(()=>{var i;return(i=window.Shopify)==null?void 0:i.shop})();let e="__USHOPAID_SDK_READY";function r(i){return i&&(window[e]=Object.assign({},window[e],{[i.key]:i.value})),window[e]}let s=Math.floor(Math.random()*1e11);if((o=r())!=null&&o.sign||r({key:"sign",value:s}),((l=r())==null?void 0:l.sign)!==s)return;const c=()=>{const i=new URLSearchParams(window.location.search),m=i.get("ushopaid_preview_id"),p=i.get("ushopaid_preview_variant_id"),f=m||p,d={};d.shopDomain=n,d.customerEmail=t.email,d.customerToken=t.token,d.phoneNumber=t.phoneNumber,d.mode="SHOP",f&&(d.mode="PREVIEW",d.campaignId=m,d.variantId=p),Promise.allSettled([a(d),E()]).then(w=>{import("./form/launcher.979fa55a.js").then(()=>{console.log("load form completed.")})})},u=()=>{if(!n)return;let i=sessionStorage.getItem("UShopAidSiteActive");sessionStorage.setItem("UShopAidSiteActive",t.token),D()?setTimeout(()=>{g("product_view",U())},0):setTimeout(()=>{i!==t.token&&g("site_active",{pageUrl:window.location.href,userAgent:window.navigator.userAgent})},0)},a=i=>{let m="https://store.ushopaid.com/store/v3/load";return new Promise(p=>{fetch(m,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).then(f=>f.json()).then(f=>{let{data:d,code:w}=f;w===200&&(window.UShopAid={shopDomain:n,customerEmail:t.email,customerToken:t.token,phoneNumber:t.phoneNumber,...d},p(!0))})})};n&&t&&(A(t),c(),u())})();