import{Ft as e,Wt as n,Xt as i,Zt as t,en as a,nn as o,yt as s}from"./630ba094.L_X-5TXi.js";import{Bc as r,Gg as l,Il as d,JD as c,Jg as p,Kc as u,Kg as h,Lv as v,M_ as m,N_ as g,Np as _,P_ as y,Vc as f,Xg as I,Yf as E,_E as S,_p as C,aS as P,fy as T,hw as k,iS as L,jO as M,j_ as N,k_ as O,kp as D,l_ as R,oS as b,sS as x,tg as w,uv as A,wx as H,xO as z}from"./6ec9a0fa.rdcQt2v8.js";import{i as j,t as U}from"./4618373b.CjXafxDy.js";import{t as B}from"./19286c78.BbePfvbV.js";import{i as F,o as V}from"./77d9e668.B6Nt2tia.js";import{a as G,i as $,n as q,r as Y,t as K}from"./f3089cd3.9kJkcqkU.js";var W=new Set(["DELIVERY_OPTIONS_PHONE_NUMBER_REQUIRED","DELIVERY_OPTIONS_PHONE_NUMBER_DOES_NOT_MATCH_EXPECTED_PATTERN"]),X=new Set(["DELIVERY_OPTIONS_INSTRUCTIONS_INVALID"]),J=(e,n)=>{if("error"===e.type)for(const i of e.violations)if("UnprocessableTermViolation"===i.__typename&&n.has(i.code))return i.localizedMessage??i.nonLocalizedMessage},Q={textSize:"small",freeTextLetterCase:"uppercase"},Z={};function ee({renderExtensionSlot:l,id:D,type:H="ONE_TIME_PURCHASE",methods:ee,loadingAdditionalShippingRates:oe=!1,isInSplitCartModal:se=!1}){const re=v(),{i18n:le,checkout:{journey:de,negotiator:ce,requestGeolocation:pe},observability:ue}=z(),he="base",[ve,me]=t(pe.country.code),{shippingAddress:ge}=ce.parts,_e=A(),{deliveryExpectationLines:ye,deliveryExpectationLinesLoading:fe,status:Ie}=Y(),Ee=R("Checkout::ShippingMethodDetails::RenderAfter"),Se=R("Checkout::ShippingMethodDetails::RenderExpanded"),[Ce]=g(H,D),Pe=u(),[Te,ke]=m({type:H,id:D,deliveryMethodType:Pe.value?"SHIPPING":void 0}),Le=e(),{setInverseGroupDeliveryMethodHandle:Me,getInverseGroupDeliveryMethodHandle:Ne}=O(ee,H),Oe=ee.find(e=>e.handle===Te),{validated:De,value:Re,error:be}=function(e,n="ONE_TIME_PURCHASE",t){const a=L(),o=y(n,t),{i18n:s,checkout:{wallets:r,configuration:l,journey:d}}=z();return w(i(e=>{const n=J(e,W);n&&(a.value=n)},[a])),P({field:"deliveryNext",valueSignal:o,errorSignal:a,validate:n=>{const i=x(n);if(e&&e.phoneRequired)return i?void 0:s.translate("field_errors.shipping_line_phone_invalid")},reason:k.InvalidDeliveryMethodPhoneNumber,owner:()=>{const e=d.assessor.findShippingMethodsStepOwners(l.layout.trees.value?.checkout.pages);return e.length>0?{kind:"steps",stepIds:e}:{kind:"field",field:void 0}},shouldSkip:()=>Boolean(r.activeSession.value)}),{value:o,error:a,validated:b(o,a,void 0)}}(Oe,H,D),{validated:xe,value:we,error:Ae}=function(e="ONE_TIME_PURCHASE",n){const t=L(),a=N(e,n);return w(i(e=>{const n=J(e,X);n&&(t.value=n)},[t])),{value:a,error:t,validated:b(a,t,void 0)}}(H,D),He=e(!1),ze=He.value||void 0!==we.value;let je=ee;Ce.includes("PICKUP_POINT")&&(je=je.filter(e=>"PickupPointLocation"===e.pickupLocation?.type&&"PickupPointLocation"===Oe?.pickupLocation?.type&&e.pickupLocation?.handle===Oe?.pickupLocation?.handle));const Ue=je.map(e=>Boolean(e?.deliveryPredictionEligible));n(()=>{const{phone:e}=ge.fields,n=e.value;!De.value&&n&&De.onChange(n)},[]),n(()=>{const{countryCode:e}=ge.fields,n=e.value;n&&me(n)},[ge]);const Be=a(()=>({state:{phone:Re,instructions:we},errors:{phone:be,instructions:Ae}}),[Re,be,we,Ae]),Fe=i(()=>{De.clearError(),xe.clearError()},[De,xe]),Ve=i(([e=""])=>{if(Fe(),ke(e),_e.value&&null==D){const n=Ne(e);Me(n)}if(se)return void(Le.value=e);const n=n=>{"SHIPPING"===ee.find(n=>n.handle===e)?.methodType&&ue.counter({name:"shipping_method_selected_capture_skipped",value:1,attributes:{reason:n,page:de.currentPage.peek()?.id}})};(async()=>{const e=await ce.negotiate({withResultHandling:!0,silenceViolations:T(["deliveryNext"])});if("success"!==e.status&&"error"!==e.status)return void n(e.status);await ce.waitForFieldsToLoad();const i=ce.current.fields.taxes.peek()?.status;de.completing.peek()||"pending"!==i&&"unavailable"!==i?re("shippingMethodSelected",{timestamp:new Date}):n(`tax_${i}`)})()},[Le,Fe,ke,_e,D,se,ce,Ne,Me,re,ue,de,ee]);n(()=>{if(!se)return void(Le.value=void 0);const e=Le.value;e&&e!==Te&&ee.some(n=>n.handle===e)&&ke(e)},[se,ee,Te,ke,Le]);const Ge=(e,n,i)=>{const t=n||i,a=!se&&l?.("purchase.checkout.shipping-option-item.details.render",{options:{handle:e,isInModal:!1},render:t?void 0:e=>s(te,{children:e})}),r=Se.length>0&&!se,d=i&&!ze&&s(h,{onClick:()=>{He.value=!0},children:le.translate("shipping.add_delivery_instructions")});return t?s(te,{children:[s(F,{children:[n?s(I,{children:[s(B,{label:le.translate("shipping.shipping_line_delivery_phone_label"),countryCode:ve,prefillCountryCode:!0,...De}),s(C,{blockSize:"small-400"}),d]}):d,i&&ze&&s(I,{children:s(_,{autoFocus:He.value,maxLength:255,label:le.translate("shipping.optional_shipping_line_delivery_instructions_label"),rows:1,...xe})})]}),a&&s(j,{children:a}),r&&s(ne,{customizations:Se,isInModal:!1,handle:e})]}):r||a?s(o,{children:[r&&s(ne,{customizations:Se,handle:e,isInModal:!1,render:e=>s(te,{children:e})}),a&&s(j,{children:a})]}):null},$e=D?`_${c(D)}`:"",qe="ONE_TIME_PURCHASE"===H?`shipping_methods${$e}`:`${H.toLowerCase()}_shipping_methods${$e}`,Ye=Ee.length>0,Ke=1===je.length,We=a(()=>Te?[Te]:[],[Te]),Xe=se?Q:Z;return s(d,{...Be,children:s("div",{className:"sqcDF",children:s(V,{name:qe,title:le.translate("general.choose_shipping_method"),titleHidden:!0,values:We,onChange:Ve,hideRadioControl:Ke,children:[je.map((e,n)=>{const i=Ue[n]||e.brandedPromise?.handle===S.BuyWithPrime,{showEstimatedDeliveryLabel:t}=r(e,Boolean(i),ye,fe,Ie),{acceptsInstructions:a,cost:d,costAfterDiscounts:c,description:p,estimatedTimeInTransit:u,handle:h,hideDiscountedTotalOnShippingSelector:v,included:m,pickupLocation:g,phoneRequired:_}=e,y=ye?.find(e=>e.deliveryStrategyHandle===h),I=f({deliveryMethod:e,localDelivery:"LOCAL"===e.methodType?le.translate("shipping.local_delivery"):void 0}),C=l?.("purchase.checkout.shipping-option-item.render-after",{options:{handle:h,isInModal:se},render:ae});return s(U,{value:h,renderSelectedContentWhenCollapsed:!0,selectedContent:Ge(h,_,a)??void 0,details:s(o,{children:[i&&s(q,{deliveryMethod:e,deliveryExpectationLine:y,paragraphColor:he}),!i&&t&&s($,{timeInTransit:u,title:e?.deliveryPromisePresentmentTitle?.short,paragraphColor:he}),p&&!i&&s(E,{color:he,children:s("bdi",{children:p})}),"PickupInStoreLocation"===g?.type&&s(ie,{pickupLocation:g})]}),secondaryContent:s(G,{cost:d,costAfterDiscounts:c,included:m,styleOverrides:Xe,preDiscountCost:v}),tertiaryContent:(Ye||C)&&s(o,{children:[Ye&&s(ne,{customizations:Ee,handle:h,isInModal:se,render:ae}),C&&s(j,{children:C})]}),children:s(K,{methodTitle:I})},h)}),oe?s("div",{className:"z2IIo",children:s(M,{gridAutoFlow:"column",gridTemplateColumns:"minmax(auto, max-content) minmax(0, 1fr)",gridTemplateRows:"minmax(0, 1fr)",gap:"base",alignItems:"center",alignContent:"center",children:[s(I,{children:s(p,{})}),s(E,{color:"subdued",type:"small",children:le.translate("shipping.loading_progressive_rates")})]})}):null]})})})}function ne({customizations:e,handle:n,isInModal:i,render:t}){const o=a(()=>({handle:n,isInModal:i}),[n,i]);return s(j,{children:s(D,{customizations:e,options:o,render:t})})}function ie({pickupLocation:e}){const n=H(e.address,{hiddenFields:["firstName","lastName","phone","company","countryCode","postalCode"]});return s(o,{children:[s(E,{type:"small",children:n}),s(E,{type:"small",children:e.instructions})]})}function te({children:e}){return s(l,{gap:"large-200",children:e})}function ae(e){return s(l,{padding:"small-100 none none none",gap:"small-100",children:e})}export{ee as t};