import{d0 as ht,dV as kt,g8 as ft,g9 as yt,ga as mt,gb as gt,aU as Ct,G as bt,bi as At,dR as St,aQ as vt,C as Pt,bk as It,gc as Et,U as _t,gd as wt,bA as Dt,k as it,cH as Mt,ge as Ot,gf as Lt,T as H,gg as Nt,q as c,gh as Tt,gi as W,gj as Wt,gk as v}from"./app.B46ok1sD.js";const nt="checkout";class rt extends Error{name="TrekkieError"}class Rt{libraryLoaded=!1;analyticsWindow;trekkieLoadedCallback;get trekkie(){return this.analyticsWindow?.trekkie}set trekkie(i){if(!this.analyticsWindow)throw new rt("AnalyticsWindow is not set.");this.analyticsWindow.trekkie=i}get shopifyAnalytics(){return this.analyticsWindow.ShopifyAnalytics}set shopifyAnalytics(i){if(!this.analyticsWindow)throw new rt("AnalyticsWindow is not set.");this.analyticsWindow.ShopifyAnalytics=i}constructor({shop:i,checkoutToken:g="",locale:a,analyticsConfig:b,sourceUrl:C,themeId:f,themeCityHash:P,monorail:l,s2s:D,monorailRegion:e},L){if(this.trekkieLoadedCallback=L,this.analyticsWindow=window,this.trekkie=this.analyticsWindow.ShopifyAnalytics?.lib||this.analyticsWindow.trekkie||[],this.trekkie?.integrations){this.libraryLoaded=!0,this.trekkieLoadedCallback(this.analyticsWindow?.ShopifyAnalytics?.lib?.trekkie);return}const M=parseInt(ht(i.id),10),N=new Set([yt,mt,gt]),y=i.enabledBetas.filter(E=>N.has(E));this.trekkie.ready(()=>{this.libraryLoaded||(this.libraryLoaded=!0,this.shopifyAnalytics={...this.shopifyAnalytics,lib:this.trekkie},this.trekkieLoadedCallback(this.analyticsWindow?.ShopifyAnalytics?.lib?.trekkie))}),this.trekkie.load=E=>{this.trekkie.config=E;const{assetPath:T,sriHash:_}=i.trekkieLoadConfiguration,A=T&&_,S=document.getElementsByTagName("script")[0],k=document.createElement("script");k.type="text/javascript",k.onerror=function(){const m=document.createElement("script");m.type="text/javascript",m.onerror=function(){const u={schemaId:"trekkie_checkout_load_errors/1.1",payload:{appName:nt,shopId:M,themeId:f,contextUrl:window.location.href,sourceUrl:C}};l.record(u)},m.async=!0,m.src=C,A&&(m.setAttribute("integrity",_),m.setAttribute("crossorigin","anonymous")),S?.parentNode?.insertBefore(m,S)},k.async=!0,k.src=C,A&&(k.setAttribute("integrity",_),k.setAttribute("crossorigin","anonymous")),S?.parentNode?.insertBefore(k,S)};const I={appName:nt,development:ft,defaultAttributes:{shopId:M,isMerchantRequest:kt("_ab")?!0:null,themeId:f,themeCityHash:P,contentLanguage:a,currency:i.currencyCode,checkoutToken:g},isServerSideCookieWritingEnabled:!0,enabledBetaFlags:y};e&&(I.monorailRegion=e),this.trekkie.load({Trekkie:I,...b,"Session Attribution":{},S2S:D})}page(i="",g={},a){this.trekkie?.page(i,g,a)}track(i,g,a,b,C){this.trekkie?.track(i,g,a,b,C)}}function xt(r,i){return new Rt(r,i)}var h=(r=>(r.StartedOrder="Started Order",r.StartedOrderOncePerCheckout="Started Order Once Per Checkout",r.CompletedOrder="Completed Order",r.AddedPayment="Added Payment",r.CheckoutContactPageStarted="Checkout Contact Step Started",r.CheckoutContactInfoSubmitted="Checkout Contact Info Submitted",r.CheckoutAddressInfoSubmitted="Checkout Address Info Submitted",r.CheckoutShippingPageStarted="Checkout Shipping Step Started",r.CheckoutShippingInfoSubmitted="Checkout Shipping Info Submitted",r.CheckoutPaymentPageStarted="Checkout Payment Step Started",r.CheckoutOnePageView="Checkout One Page View",r))(h||{});function O(r){switch(r){case"/":case"/information":return{title:"Checkout - Contact Information",page:"/checkout/contact_information"};case"/shipping":return{title:"Checkout - Shipping",page:"/checkout/shipping"};case"/payment":return{title:"Checkout - Payment",page:"/checkout/payment"};case"/review":return{title:"Checkout - Review",page:"/checkout/review"};case"/processing":return{title:"Checkout - Processing",page:"/checkout/processing"};case"/thank-you":return{title:"Checkout - Receipt",page:"/checkout/thank_you"};case"/stock-problems":return{title:"Checkout - Stock problems",page:"/checkout/stock_problems"};case"/error":return{title:"Checkout - Error",page:"/checkout/error"};case"/no-address-location":return{title:"Checkout - No Address Location",page:"/checkout/no_address_location"};case"/shoppay_login":return{title:"ShopPay - Login",page:"/shop.app/pay/login"};case"/shoppay":return{title:"ShopPay - Payment",page:"/shop.app/pay/payment"};default:return{title:null,page:null}}}function B(r){return r.current.fields.merchandiseLines.peek()?.lines?.map(a=>{const b=a.lineAllocations.reduce((f,P)=>(P.allocations.filter(l=>l.discountDetails.discount.type==="code").forEach(l=>{l.amount.amount>f.amount&&(f.amount=l.amount.amount,f.code=l.discountDetails.title)}),f),{code:void 0,amount:0});return{variantId:W(a.variantId),productId:W(a.productId),productGid:a.productId,category:a.productType,coupon:b.code,currency:a.itemPrice?.currencyCode,name:a.title,price:a.itemPrice?.amount,quantity:a.quantity,brand:a.vendor,variant:a.subtitle,sku:a.sku}})}function Ht(){const r=Ct().isActive?"trekkie-checkout-one-shop-app":"trekkie-checkout-one",i=bt(),g=At(),a=g.checkoutSessionIdentifier||g.sourceId,b=St(),{locale:C}=vt().i18n,f=Pt(),P=It();let l=i.theme?.id===void 0||i.theme?.id===null?void 0:parseInt(i.theme.id,10);l&&l>Number.MAX_SAFE_INTEGER&&(l=void 0);const D=i.theme?.cityhash,e=Et(),{email:L,phone:M,shippingAddress:N}=_t(),y=wt(),{value:I}=Dt(),E=it("api-client-id"),T=it("api-client-id"),{currentPage:_}=Mt(),A=_&&["onePage"].includes(_.id),S=Ot(),k=Lt(),m=H(()=>({}),[]),u=Nt(),K=c(t=>{if(!t){f.notify(new Tt("Trekkie is not available"));return}u.value?.defaultAttributes!==t?.defaultAttributes&&u.setValue({defaultAttributes:t?.defaultAttributes})},[f,u]),n=H(()=>{const t=D===null?void 0:D,o=e.current.fields.buyerIdentity.peek(),s={facebookCapiEnabled:i.facebookCapiEnabled,source:r,customerId:W(o?.customerProfile?.id),cartApiClientId:E,apiClientId:T},p=`${P.services.trekkie.url}/${i.trekkieLoadConfiguration?.assetPath||"s/trekkie.storefront.min.js"}`;return S?null:xt({shop:i,checkoutToken:a,locale:C,analyticsConfig:m,sourceUrl:p,themeId:l,themeCityHash:t,monorail:b,monorailRegion:"shop_domain",s2s:s},K)},[i,a,C,m,l,D,b,K,e,E,T,r,S,P.services.trekkie.url]),z=c(t=>{const{title:o,page:s}=O(t);!o||!s||n?.page(o,{path:s})},[n]),F=c(t=>{const{title:o,page:s}=O(t);if(!o||!s)return;const p={name:o,path:s};n?.track(h.CheckoutOnePageView,p,void 0,void 0,{shopifyEmitted:!0})},[n]),q=H(()=>{let t={amount:void 0,currencyCode:void 0};return y&&I?.status==="filled"&&I.lines.forEach(o=>{if(o.status==="available"){const s=o.selectedDeliveryMethodHandle;s&&(t=o.methods.filter(d=>d.handle===s&&d.costAfterDiscounts!==void 0).reduce((d,x)=>{const w=d.amount===void 0?0:d.amount;return d.amount=w+x.costAfterDiscounts.amount,d.currencyCode=x.costAfterDiscounts.currencyCode,d},t))}}),t},[I,y]),$=c(()=>{const t=e.current.fields.subtotal.peek(),o=e.current.fields.subtotalAfterMerchandiseDiscounts.peek(),p={step:1,products:B(e),currency:t?.currencyCode,revenue:t?.amount,subtotalAfterMerchandiseDiscounts:o?.amount};n?.track(h.StartedOrder,p,void 0,void 0,{shopifyEmitted:!0})},[n,e]),U=c(()=>{const t=e.current.fields.subtotal.peek(),o=e.current.fields.subtotalAfterMerchandiseDiscounts.peek(),p={step:1,products:B(e),currency:t?.currencyCode,revenue:t?.amount,subtotalAfterMerchandiseDiscounts:o?.amount};n?.track(h.StartedOrderOncePerCheckout,p,void 0,void 0,{shopifyEmitted:!0})},[n,e]),X=c(()=>{if(!y||k.shouldPrevent())return;const t=B(e),o=y.purchaseOrder,s=W(y.orderIdentity.id),p=s?.toString(),d=o.billingAddress,w=e.current.fields.buyerIdentity.peek()?.customerProfile;let et=w?.firstName,G=w?.lastName;G||(et=d?.firstName,G=d?.lastName);const ot=e.current.fields.total.peek(),at=e.current.fields.subtotal.peek(),ct=e.current.fields.subtotalAfterMerchandiseDiscounts.peek(),ut=Wt(e),st=e.current.fields.contactInfo.peek(),dt=e.current.fields.discountLines.peek()?.lines.filter(V=>V.discount.type==="code").map(V=>V.discount.title)||[],lt=y.analytics?.checkoutCompletedEventId||void 0,pt=y.analytics?.emitConversionEvent||!1;n?.track(h.CompletedOrder,{customerEventData:{customer:{firstName:et,lastName:G,emailAddress:w?.email??st?.email,phoneNumber:w?.phone??st?.phone},address:{city:d?.city,province:d?.zoneCode,country:d?.countryCode,zip:d?.postalCode}},orderId:s,orderName:p,products:t,total:ot?.amount??0,currency:ot?.currencyCode,revenue:at?.amount??0,subtotalAfterMerchandiseDiscounts:ct?.amount??0,coupon:dt[0],tax:ut?.amount??0,shipping:q.amount??0},lt,pt,{shopifyEmitted:!0}),k.markAsEmitted()},[y,e,n,q.amount,k]),J=c(()=>{const t=e.current.fields.runningTotal.peek(),o=e.current.fields.subtotalAfterMerchandiseDiscounts.peek(),s={currency:t?.currencyCode,total:t?.amount,subtotalAfterMerchandiseDiscounts:o?.amount};n?.track(h.AddedPayment,s,void 0,void 0,{shopifyEmitted:!0})},[n,e]),Q=c(()=>{const{title:t,page:o}=O("/information"),s={name:t,path:o};n?.track(h.CheckoutContactPageStarted,s,void 0,void 0,{shopifyEmitted:!0})},[n]),Y=c(()=>{const t=L.peek(),o=M.peek(),s=e.current.fields.subtotalAfterMerchandiseDiscounts.peek(),p={email:t,phone:o,subtotalAfterMerchandiseDiscounts:s?.amount};n?.track(h.CheckoutContactInfoSubmitted,p,void 0,void 0,{shopifyEmitted:!0})},[n,L,M,e]),j=c(()=>{const t=N.peek(),o=e.current.fields.subtotalAfterMerchandiseDiscounts.peek(),s={city:t?.city,country:t?.countryCode,phone:t?.phone,province:t?.zoneCode,postalCode:t?.postalCode,firstName:t?.firstName,lastName:t?.lastName,address1:t?.address1,address2:t?.address2,subtotalAfterMerchandiseDiscounts:o?.amount};n?.track(h.CheckoutAddressInfoSubmitted,s,void 0,void 0,{shopifyEmitted:!0})},[n,N,e]),Z=c(()=>{const{title:t,page:o}=O("/shipping"),s={name:t,path:o};n?.track(h.CheckoutShippingPageStarted,s,void 0,void 0,{shopifyEmitted:!0})},[n]),R=c(()=>{const t=e.current.fields.runningTotal.peek(),o=e.current.fields.subtotalAfterMerchandiseDiscounts.peek(),s={total:t?.amount,currency:t?.currencyCode,subtotalAfterMerchandiseDiscounts:o?.amount};n?.track(h.CheckoutShippingInfoSubmitted,s,void 0,void 0,{shopifyEmitted:!0})},[n,e]),tt=c(()=>{const{title:t,page:o}=O("/payment"),s={name:t,path:o};n?.track(h.CheckoutPaymentPageStarted,s,void 0,void 0,{shopifyEmitted:!0})},[n]);return v(c(t=>{u.value.defaultAttributes&&t.type==="page_view"&&z(t.url)},[u,z])),v(c(t=>{u.value.defaultAttributes&&t.type==="initiate_checkout"&&$()},[u,$])),v(c(t=>{u.value.defaultAttributes&&t.type==="initiate_checkout_once_per_checkout"&&U()},[u,U])),v(c(t=>{u.value.defaultAttributes&&t.type==="complete_checkout"&&X()},[u,X])),v(c(t=>{u.value.defaultAttributes&&t.type==="add_payment_info"&&J()},[u,J])),v(c(t=>{u.value.defaultAttributes&&t.type==="one_page_checkout_page_view"&&F(t.url)},[u,F])),v(c(t=>{u.value.defaultAttributes&&(t.type==="section_interaction"&&A&&(t.section==="contact"?Q():t.section==="payment"&&(R(),tt())),t.type==="section_complete"&&(t.section==="contact"?Y():t.section==="deliveryAddress"&&j()),t.type==="shipping_methods_filled"&&A&&Z(),t.type==="page_submit"&&t.page==="shipping"&&!A&&R())},[u.value.defaultAttributes,A,Q,R,tt,Y,j,Z])),null}export{Ht as default};