import{e as C,f as D,p as _,h as P}from"./Cfh3kXIQ.js";import{w as S,k as y,b as k}from"./DEIzhR9A.js";import{u as A}from"./BQKfvuZz.js";const g=(e,s)=>{const o=s===void 0?0:s;if(e==null)return o;const l=parseFloat(e);return isNaN(l)?o:l},N="dl_user_agent_id",w="OptanonConsent",E="genVendors",O="dl:1",I=()=>{const e=C(),{$dresslifeReady:s}=e,o=()=>new Promise(i=>{if(s.value)i();else{const c=S(()=>{s.value&&(i(),c())})}});return{getDresslifeSDK:async()=>{await o();const i=e.$dresslife;if(!i)throw new Error("Dresslife SDK failed to initialize.");return i},isReady:s}},F=()=>{const e=new PerformanceObserver(()=>{e.takeRecords().forEach(s=>{"type"in s&&s.type})});e.observe({type:"navigation",buffered:!0}),e.disconnect()},b=()=>{const e=D(w);return y(()=>{var l,i;const o=(l=e.value??"")==null?void 0:l.split("&");if(o&&o.length>1){const c=(i=o.find(f=>f.includes(E)))==null?void 0:i.split("=")[1];return c==null?void 0:c.split(",").filter(Boolean).includes(O)}return!1})},T=e=>({trackOpenPLP:(r,a,t)=>{const n=t==null?void 0:t.map(u=>String(u.id));e({eventName:"category_opened",shopCategory:r,offset:a,colorgroupIds:n,numberOfColorgroups:n==null?void 0:n.length,shopGenderCategory:"women"})},trackOpenPDP:(r,a="other")=>{e({eventName:"product_detail_page_opened",source:a,colorgroupId:`${r==null?void 0:r.id}`})},trackAddToCartDL:(r,a,t,n,u)=>{e({eventName:"variant_added_to_cart",variantId:String(r),price:{currency:u,netAmount:g(t/100),grossAmount:g(n/100)},source:a})},trackPurchaseConfirmed:(r,a,t,n,u)=>{const d=[];a.forEach(p=>{const v=d.find(m=>m.variantId===String(p.variant.id));return v?v.quantity++:d.push({variantId:String(p.variant.id),quantity:1,grossPrice:g(p.price.withTax/100)})}),e({eventName:"purchase_confirmed",orderId:String(r),variants:d,totalPrice:{netAmount:g(t/100),grossAmount:g(n/100),currency:u}})},trackFiltersApplied:(r,a,t,n)=>{const u=a.map(d=>String(d.id));e({eventName:"filters_applied",filters:r,colorgroupIds:u,numberOfColorgroups:u.length,shopCategory:t,source:n})},trackProductsViewed:(r,a)=>{const t=r.map(n=>({colorgroupId:String(n.id)}));e({eventName:"products_viewed",colorgroups:t,source:a})},trackPageNavigation:r=>{e({eventName:"page_navigated",navigationType:r})}}),M=()=>{const{getDresslifeSDK:e}=I(),s=_(),o=P().public.dresslife,l=F(),i=b(),c=k(),f=D(N,{maxAge:60*60*24*365*2,path:"/",secure:!0,httpOnly:!1}),x=()=>{let t;if(f.value)t=f.value;else{const n=K();t=n,f.value=n}return t},r=async()=>{var t;if(!c.value){const{user:n}=await A({autoFetch:!0});c.value=(t=n.value)==null?void 0:t.id}return c.value};return{...T(async t=>{if(!o.trackingEnabled||i.value===!1)return;let n;try{n=await e()}catch(h){console.error("Failed to get Dresslife SDK:",h);return}const u=x(),d=await r(),v=s.value.locale.split("-")[1],m={userData:{userAgentId:u,...d!==void 0&&{customerId:String(d)}},eventData:t,createdAt:new Date,countryCode:v.toUpperCase()};return await n.sendEvent(m)}),listenForNavigation:l,assignCookies:x}};function K(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const s=Math.random()*16|0;return(e==="x"?s:s&3|8).toString(16)})}export{N as D,b as a,M as u};