import{h0 as Se,h1 as xe,h2 as Ee,h3 as Fe,h4 as Te,h5 as De,h6 as Ne,h7 as Oe,h8 as we,h9 as Re,ha as Be,hb as Ve,hc as G,hd as Ge,he as Qe,hf as Ue,hg as _e,hh as qe,e9 as U,hi as Ye,hj as He,hk as ze,hl as We,hm as Je,hn as je,ho as Xe,hp as Ke,hq as Z,hr as $e,hs as Ze,ht as et,hu as tt,hv as nt,hw as st,hx as ee,hy as it,hz as at,bS as K,hA as rt,hB as ot,hC as lt}from"./app.B46ok1sD.js";class dt extends Error{name="UnknownMerchandiseTypeError"}function ct(e){let t=null;const s=()=>(t===null&&(t=new Map(e.lines.map(n=>[n.stableId,n]))),t);return{merchandiseLines:e.lines.map(n=>({...Q(n,s),lineComponentsSource:n.lineComponentsSource,lineComponents:n.lineComponents.map(a=>Q(a,s))}))}}function ut(e){switch(e.typename){case"ContextualizedProductVariantMerchandise":case"ProductVariantMerchandise":return{productVariantReference:{id:e.id,variantId:e.variantId,properties:$(e.properties),sellingPlanId:e.sellingPlan?.id??null,sellingPlanDigest:e.sellingPlan?.digest??null}};case"SourceProvidedMerchandise":return{sourceProvidedMerchandise:{title:e.title,subtitle:e.subtitle??void 0,price:{value:{amount:e.itemPrice.amount.toFixed(2),currencyCode:e.itemPrice.currencyCode}},giftCard:e.giftCard,productType:e.productType,sku:e.sku,variantId:e.variantId??void 0,productIdV2:e.productId??void 0,properties:$(e.properties),requiresShipping:e.requiresShipping,vendor:e.vendor??void 0,taxCode:e.taxCode??void 0,taxable:e.taxable??!0,taxesIncluded:e.taxesIncluded,optionalIdentifier:e.optionalIdentifier??void 0,weight:e.weight?{value:e.weight.value,unit:e.weight.unit}:void 0}};default:throw new dt(`Unrecognized merchandise type: ${e.typename}`)}}function $(e){return e.map(t=>{switch(t.sourceType){case"MerchandisePropertyValueNull":return{name:t.name,value:t.value};case"MerchandisePropertyValueString":return{name:t.name,value:{string:t.value}};case"MerchandisePropertyValueInt":return{name:t.name,value:{integer:t.value}};case"MerchandisePropertyValueFloat":return{name:t.name,value:{float:t.value}};case"MerchandisePropertyValueBoolean":return{name:t.name,value:{boolean:t.value}};case"MerchandisePropertyValueJson":return{name:t.name,value:{json:JSON.parse(t.value)}};default:xe(t)}})}function Q(e,t){const s=e.totalPrice.currencyCode,n=Se(s),a={stableId:e.stableId,merchandise:ut(e),quantity:{items:{value:e.quantity}},expectedTotalPrice:{value:{amount:e.totalPrice.amount.toFixed(n),currencyCode:s}}};if("parentRelationship"in e&&e.parentRelationship?.parent){const o=t().get(e.parentRelationship.parent.stableId);o&&(a.parent=Q(o,t))}return a}function pt(e,t,s,n){if(!t)return;if(!e)return n;const a=n===void 0||n.optIn===!1?!1:{...n.optIn,vaultPhone:n.optIn?.vaultPhone||"",vaultEmail:s?"":n.optIn?.vaultEmail};return{...n,optIn:a}}function mt(e,t,s){return Ee(e)||Fe(e,"APPLE_PAY")||s&&Te(e)?!1:!!(t&&t.optIn!==!1)}class ht extends Error{name="MissingSessionTokenError"}const yt={any:!0};function gt(e,t,s,n){const a=s&&s[0];return!a||a.method.type!=="wallet"||t&&e&&a.method.name==="APPLE_PAY"?!1:["GOOGLE_PAY","APPLE_PAY"].includes(a.method.name)?!0:a.method.name!=="PAYPAL_EXPRESS"?!1:rt(n)}function ft(e){return e.find(t=>t.method.type===K.CreditCard||t.method.type===K.PayPal)}function bt(e,t){const{parts:s,source:n,facts:a}=e,o=e.current.peek(),r=s.paymentLines.peek(),f=a.delivery?.[0]?.deliveryAddress??s.shippingAddress.peek(),b=s.billingAddress.peek(),d=!b.address1&&a.billingAddress?a.billingAddress:b,y=s.billingAddressOption.peek(),M=o.isShippingRequired,k=n?.type==="orderEdit"?a.requiresShipping:M,P=ft(r);if(P)return t?.log("[getPaymentAddress] Using vaulted payment billing address"),P.method.billingAddress;const v=nt(r),A=y==="shipping"&&v,m=(()=>{const u=o.buyerIdentity?.customerProfile;if(G(u)){if(y==="billing"&&u?.billingAddress)return u.billingAddress;if(A)return u?.shippingAddress??f}})();return m?(t?.log("[getPaymentAddress] Using company location address"),m):y==="billing-fact"?(t?.log("[getPaymentAddress] Using billing-fact address"),d):gt(G(o.buyerIdentity?.customerProfile),e.context.enabledBetas.includes(st),r,o.paymentMethods)?(t?.log("[getPaymentAddress] Using wallet billing address"),d):k&&A?(t?.log("[getPaymentAddress] Using shipping address"),f):(t?.log("[getPaymentAddress] Using default billing address"),d)}function Pt(e){return e.current.token??null}function vt({acceptEmailMarketing:e,acceptSmsMarketing:t,smsMarketingPhone:s,smsMarketingCountryCode:n,email:a,isBusinessCustomer:o}){const r=[];return o||(s&&t&&r.push({sms:{value:s,countryCode:n}}),a&&e&&r.push({email:{value:a}})),r}function At(e){const t=e.email.peek().trim(),s=e.phone.peek().trim(),n=e.acceptEmailMarketing.peek(),a=e.acceptSmsMarketing.peek(),o=e.smsMarketingPhone.peek(),r=e.purchaseOrderNumber.peek(),g=e.acceptPaymentVaulting.peek(),f=e.shopPayArtifact.peek(),b=e.optionalDuties.peek(),d=e.captcha.peek(),y=e.shippingAddress.peek(),M=e.billingAddress.peek(),k=e.availableRedeemables.peek(),P=e.attribution.peek(),v=e.saleAttributions.peek(),A=e.reduction.peek(),m=e.deliveryLines.peek(),u=e.externalDeliveryIds.peek(),L=e.discountLines.peek(),c=e.merchandiseLines.peek(),I=e.locationAddress.peek(),S=e.useProgressiveRates.peek(),x=e.interfaceFlow.peek(),E=e.tipLines.peek(),F=e.note.peek(),T=e.attributes.peek(),D=e.cartMetafields.peek(),N=e.memberships.peek(),C=e.alternativePaymentCurrency.peek(),O=e.rememberMe.peek();return{attributes:T,email:t,phoneNumber:s,acceptEmailMarketing:n,acceptSmsMarketing:a,smsMarketingPhone:o,purchaseOrderNumber:r,acceptPaymentVaulting:g,shopPayArtifact:f,optionalDuties:b,captcha:d,shippingAddress:y,billingAddress:M,availableRedeemables:k,attribution:P,saleAttributions:v,reduction:A,proposedDeliveryLines:m,externalDeliveryIds:u,discountLines:L,merchandiseLines:c,locationAddress:I,useProgressiveRates:S,interfaceFlow:x,tipLines:E,note:F,alternativePaymentCurrency:C,rememberMe:O,cartMetafields:D,memberships:N}}function Mt(e){return e.localizationExtensions.peek().map(t=>{const{key:s,value:n}=t.peek();return{key:s,value:n||""}})}function kt(e){return e.deliveryExpectations&&e.deliveryExpectations.status==="filled"&&e.deliveryExpectations.deliveryExpectationLines.filter(t=>t.signedHandle).map(t=>({signedHandle:t.signedHandle}))||[]}class Lt extends Error{name="DirectPaymentLinesMismatchError"}function It(e,t,s){const n=ot(t);return e.cachedMembershipViolations.value.filter(a=>lt(a,s,n))}function Ct(e,t,s){if(e.status!=="filled")return{memberships:[],violations:[]};const n=It(t,e,s),a=n.map(r=>r.handle);return{memberships:e.memberships.map(r=>{const g=!a.includes(r.handle);return{handle:r.handle,apply:g?r.apply:!1}}),violations:n}}function St(e){return{memberships:e.map(t=>({handle:t.handle,apply:t.apply}))}}function te(e){return e?e.type==="local"&&e.name==="IDEAL"||e.type==="customOnsite":!1}function xt(e,t){return te(e)?!0:U.selectedPaymentMethod.value?.paymentMethod==="IDEAL"&&t?.some(ee)}function Dt(e,{isCompleting:t=!1,customizeNegotiation:s,errorLogger:n,telemetryClient:a}={}){if(!e.sessionToken)throw new ht("No session token");const{context:o,parts:r,throttle:g,checkpoint:f}=e,{attributes:b,email:d,phoneNumber:y,acceptEmailMarketing:M,acceptSmsMarketing:k,smsMarketingPhone:P,purchaseOrderNumber:v,acceptPaymentVaulting:A,shopPayArtifact:m,optionalDuties:u,captcha:L,shippingAddress:c,billingAddress:I,availableRedeemables:S,attribution:x,saleAttributions:E,reduction:F,proposedDeliveryLines:T,externalDeliveryIds:D,discountLines:N,merchandiseLines:C,locationAddress:O,useProgressiveRates:ne,interfaceFlow:se,tipLines:ie,alternativePaymentCurrency:ae,note:re,rememberMe:oe,cartMetafields:le,memberships:_}=At(r);let l=r.paymentLines.peek();const w=l[0]?.method,R=bt(e,a);if(t&&m?.shopUser&&xt(w,e.current.fields.paymentMethods.peek())){const h=te(w)?w:Ft(e.current.fields.paymentMethods.peek());l=De(l,Et({paymentMethod:h,billingAddress:R}))}const i=e.current.peek(),B=i.shippingAddress,q=i.contactInfo?.email,de=i.merchandiseLines?.lines?.[0]?.totalPrice.currencyCode||i.buyerIdentity?.presentmentCurrency,Y=Ne(C,de),ce=Oe(Y),ue=!!we(i)?.amount,H=!B||!Re(c,B,["phone"]);H&&B?.oneTimeUse&&(c.oneTimeUse=!1);const z=o.enabledBetas.includes(Be)&&t&&l.length===1&&l[0].method.type==="wallet"&&l[0].method.name==="APPLE_PAY"&&l[0].cost&&l[0].cost.amount!==0,{proposedTotalAmount:pe,proposedTotalIncludedAmount:me,proposedMixedStateTotalAmount:he,proposedExemptions:ye}=Ve(i.taxes,i.duties,i.taxExemptions,{useIntervalForTaxAndPayment:z}),ge=i.buyerIdentity?.customerProfile,fe=G(ge),W=Ge(r),be=vt({acceptEmailMarketing:M,acceptSmsMarketing:k,smsMarketingPhone:P,smsMarketingCountryCode:W,email:d,isBusinessCustomer:fe}),Pe=Qe(i.merchandiseLines?.lines),ve=Ue(i.merchandiseLines?.lines).some(h=>h.sellingPlan?.isFixed),Ae=i.nonNegotiableTerms?.contents?.some(h=>h.targetTerms==="DISCOUNT")||!1,J=_e({customAttributes:i.customAttributes}),Me=qe({customAttributes:i.customAttributes}),ke=J&&!!c&&Me,Le=U.secureData.peek(),Ie=e.source?.type==="draftOrder",j=_?Ct(_,e.context,c):void 0;e.context.cachedMembershipViolations.value=j?.violations||[];const Ce=St(j?.memberships||[]);if(t&&n){const h=i.paymentMethods?.map(p=>p.type==="direct"?{paymentMethodIdentifier:p.paymentMethodIdentifier,name:p.name}:void 0).filter(Boolean),V=l.find(p=>!!(p.method.type==="direct"&&p.method.creditCardLastFourDigits&&p.method.brand))?.method.paymentMethodIdentifier;c.countryCode==="US"&&V&&!h?.some(p=>p?.paymentMethodIdentifier===V)&&n?.notify(new Lt("Completing with a direct payment line mismatch with seller proposal available payment methods"),{metadata:{value:{buyerDirectPaymentMethodIdentifiers:JSON.stringify(V),availableDirectPaymentMethods:JSON.stringify(h)}}})}const X={checkpointData:f.current.token,sessionInput:{sessionToken:e.sessionToken},queueToken:Pt(g),discounts:{lines:tt({lines:N},C,n),acceptUnexpectedDiscounts:Ie?i.acceptUnexpectedDiscounts:!Ae},delivery:{deliveryLines:Ze({shippingAddress:c,proposedDeliveryLines:T,externalDeliveryIds:D,destinationChanged:H,isSubmitForCompletion:t,isPointOfSale:J,isPointOfSaleShipToHome:ke,negotiatedDelivery:i.deliveryNext,filteredMerchandiseStableIds:ce,locationAddress:O,retailLocationId:et({customAttributes:i.customAttributes}),isShippingRequired:i.isShippingRequired,availableDeliveryAddresses:i.availableDeliveryAddresses}),noDeliveryRequired:[],useProgressiveRates:ne,prefetchShippingRatesStrategy:null,interfaceFlow:se,supportsSplitShipping:!0},deliveryExpectations:{deliveryExpectationLines:kt(i)},merchandise:ct({lines:Y}),memberships:Ce,availableRedeemables:$e(S),payment:{totalAmount:yt,paymentLines:Ke({paymentDue:i.paymentDue,deferredTotal:i.deferredTotal,checkoutTotal:i.checkoutTotal},{lines:l},Z(R),{isCompleting:t,hasSellingPlan:Pe,hasFixedSellingPlan:ve,acceptPaymentVaulting:A,hasPayableDeposit:ue,useIntervalForTaxAndPayment:z}),billingAddress:Xe(l,R,r.billingAddressOption.peek()),paymentFlexibilityTermsId:i.paymentFlexibilityPaymentTermsTemplate?.id},buyerIdentity:{customer:{presentmentCurrency:i.buyerIdentity?.presentmentCurrency,countryCode:i.buyerIdentity?.countryCode},email:d||void 0,...d?{emailChanged:!q||q!==d}:{},phone:y||void 0,phoneCountryCode:W||void 0,marketingConsent:be,shopPayOptInPhone:{number:c.phone||I.phone,countryCode:c?.countryCode||I?.countryCode||i.buyerIdentity?.countryCode},shopUserSecureData:Le,rememberMe:oe},tip:{tipLines:je(ie)},poNumber:v===""?null:v,taxes:{proposedAllocations:null,proposedTotalAmount:pe,proposedTotalIncludedAmount:me,proposedMixedStateTotalAmount:he,proposedExemptions:ye},note:Je(i,re,b),localizationExtension:{fields:Mt(r)},shopPayArtifact:pt(t,mt(l,m,!!i.managedByMarketsPro),d,m),nonNegotiableTerms:i.nonNegotiableTerms?We(i.nonNegotiableTerms):null,scriptFingerprint:i.scriptFingerprint,transformerFingerprintV2:i.transformerFingerprintV2,optionalDuties:u?ze(u.buyerRefusesDuties):null,attribution:x,captcha:He(L),reduction:F,saleAttributions:E,alternativePaymentCurrency:Ye(ae),cartMetafields:le};return s?s(X):X}function Et({paymentMethod:e,billingAddress:t}){const s=Z(t);return{method:{type:"wallet",name:"SHOP_PAY",walletContent:e.type==="local"?it({paymentMethodIdentifier:e.paymentMethodIdentifier,billingAddress:s,selectedLPMBillingAddress:U.selectedLPMBillingAddress.value}):at({billingAddress:s,paymentMethodIdentifier:e.paymentMethodIdentifier||"",paymentAttributes:e.paymentAttributes})}}}function Ft(e){return{type:"local",paymentMethodIdentifier:e.find(s=>ee(s)).paymentMethodIdentifier,name:"IDEAL"}}export{Dt as g,xt as s};