import{u as e,M as n,t as i,p as t,G as o,h as a,v as s,o as r,a7 as l}from"./2c1ab0fe.Dbn2KvkT.js";import{d,f as c,L as p,cN as u,bH as h,cO as m,o as v,w as g,cP as _,p as y,cQ as f,cR as E,v as I,bN as C,Q as P,cS as T,c4 as L,S,Z as b,b as O,c as D,cT as N,U as M,cU as R,cV as k}from"./164ad2e3.FTBuhkTQ.js";import{b as A}from"./efa0389a.BBF5Yj3v.js";import{F as x}from"./3ca8ef7e.CoLpsNbY.js";import{C as H}from"./a422df8c.Cf87EYCO.js";import{u as w,S as U,a as z,E as B,e as j}from"./347b440c.Cr4Lo5jt.js";import{d as V,bn as F,b6 as q,b7 as G,ci as $,b8 as Q,bd as W,_ as Y,w as X,W as K}from"./4b4bc88f.z1yoAwwH.js";import{P as Z}from"./47b970b2.DCFIpVFI.js";function J(){const{i18n:i,checkout:t}=V();return t.configuration.layout.isOnePage.value?null:e(n,{children:[e(d,{blockSize:"small-400"}),e(c,{children:i.translate("shipping.shipping_line_delivery_instructions")})]})}function ee({displayAddInstructionsButton:n,onPress:i}){const{i18n:t,checkout:o}=V();return o.configuration.layout.isOnePage.value?n?e(p,{onClick:i,children:t.translate("shipping.add_delivery_instructions")}):null:e(c,{children:t.translate("shipping.shipping_line_delivery_phone")})}const ne=new Set(["DELIVERY_OPTIONS_PHONE_NUMBER_REQUIRED","DELIVERY_OPTIONS_PHONE_NUMBER_DOES_NOT_MATCH_EXPECTED_PATTERN"]),ie=new Set(["DELIVERY_OPTIONS_INSTRUCTIONS_INVALID"]),te=(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},oe={OnTop:"sqcDF",LoadingOption:"z2IIo",LoadingOptionBorderNone:"qi1py",LoadingOptionBorderFull:"pcf8k"},ae={textSize:"small",freeTextLetterCase:"uppercase"},se={};function re({id:p,type:M="ONE_TIME_PURCHASE",methods:R,loadingAdditionalShippingRates:re=!1,isInSplitCartModal:pe=!1}){const ue=v(),{i18n:he,checkout:me}=V(),ve="base",{negotiate:ge}=g(),{geolocation:_e}=_(),[ye,fe]=o(_e.country.code),{shippingAddress:Ee}=me.negotiator.parts,Ie=W(),{deliveryExpectationLines:Ce,deliveryExpectationLinesLoading:Pe,status:Te}=w(),Le=y("Checkout::ShippingMethodDetails::RenderAfter"),Se=y("Checkout::ShippingMethodDetails::RenderExpanded"),[be]=f(M,p),Oe=E(),[De,Ne]=I({type:M,id:p,deliveryMethodType:Oe.value?"SHIPPING":void 0}),Me=t(),{setInverseGroupDeliveryMethodHandle:Re,getInverseGroupDeliveryMethodHandle:ke}=C(R,M),Ae=R.find(e=>e.handle===De),{validated:xe,value:He,error:we}=function(e,n="ONE_TIME_PURCHASE",o){const a=F(),s=u(n,o),{i18n:r,checkout:{wallets:l}}=V();h(i(e=>{const n=te(e,ne);n&&(a.value=n)},[a]));const d=t(void 0),c=l.activeSession.value?d:a;return q(s,c,n=>{if(l.activeSession.value)return;const i=$(n);return e&&e.phoneRequired?i?void 0:r.translate("field_errors.shipping_line_phone_invalid"):void 0},G.InvalidDeliveryMethodPhoneNumber),{value:s,error:a,validated:Q(s,a,void 0)}}(Ae,M,p),{validated:Ue,value:ze,error:Be}=function(e="ONE_TIME_PURCHASE",n){const t=F(),o=m(e,n);return h(i(e=>{const n=te(e,ie);n&&(t.value=n)},[t])),{value:o,error:t,validated:Q(o,t,void 0)}}(M,p),je=me.configuration.layout.isOnePage.value,[Ve,Fe]=o(!je||void 0!==Ue?.value);let qe=R;be.includes("PICKUP_POINT")&&(qe=qe.filter(e=>"PickupPointLocation"===e.pickupLocation?.type&&"PickupPointLocation"===Ae?.pickupLocation?.type&&e.pickupLocation?.handle===Ae?.pickupLocation?.handle));const Ge=qe.map(e=>Boolean(e?.deliveryPredictionEligible));a(()=>{const{phone:e}=Ee.fields,n=e.value;!xe.value&&n&&xe.onChange(n)},[]),a(()=>{const{countryCode:e}=Ee.fields,n=e.value;n&&fe(n)},[Ee]);const $e=s(()=>({state:{phone:He,instructions:ze},errors:{phone:we,instructions:Be}}),[He,we,ze,Be]),Qe=i(()=>{xe.clearError(),Ue.clearError()},[xe,Ue]),{optionList:{border:We="full"}}=P(),Ye=i(([e=""])=>{if(Qe(),Ne(e),Ie.value&&null==p){const n=ke(e);Re(n)}pe?Me.value=e:(ge({silenceViolations:Y(["deliveryNext"])}),ue("shippingMethodSelected",{timestamp:new Date}))},[Me,Qe,Ne,Ie,p,pe,ge,ke,Re,ue]);a(()=>{if(!pe)return void(Me.value=void 0);const e=Me.value;e&&e!==De&&R.some(n=>n.handle===e)&&Ne(e)},[pe,R,De,Ne,Me]);const Xe=(n,i,t)=>{const o=i||t,a=Se.length>0&&!pe;return o?e(ce,{children:[e(x,{children:[i&&e(O,{children:[e(Z,{label:he.translate("shipping.shipping_line_delivery_phone_label"),countryCode:ye,prefillCountryCode:!0,...xe}),e(d,{blockSize:"small-400"}),e(ee,{displayAddInstructionsButton:t&&!Ve,onPress:()=>Fe(!0)})]}),t&&Ve&&e(O,{children:[e(k,{autoFocus:!0,maxLength:255,label:he.translate("shipping.optional_shipping_line_delivery_instructions_label"),rows:1,...Ue}),e(J,{})]})]}),a&&e(le,{customizations:Se,isInModal:!1,handle:n})]}):a?e(le,{customizations:Se,handle:n,isInModal:!1,render:n=>e(ce,{children:n})}):null},Ke=p?`_${X(p)}`:"",Ze="ONE_TIME_PURCHASE"===M?`shipping_methods${Ke}`:`${M.toLowerCase()}_shipping_methods${Ke}`,Je=Le.length>0,en=1===qe.length,nn=s(()=>De?[De]:[],[De]),tn=pe?ae:se;return e(N,{...$e,children:e("div",{className:oe.OnTop,children:e(H,{name:Ze,title:he.translate("general.choose_shipping_method"),titleHidden:!0,values:nn,onChange:Ye,hideRadioControl:en,children:[qe.map((i,t)=>{const o=Ge[t]||i.brandedPromise?.handle===K.BuyWithPrime,{showEstimatedDeliveryLabel:a}=T(i,Boolean(o),Ce,Pe,Te),{acceptsInstructions:s,cost:r,costAfterDiscounts:l,description:d,estimatedTimeInTransit:p,handle:u,hideDiscountedTotalOnShippingSelector:h,included:m,pickupLocation:v,phoneRequired:g}=i,_=Ce?.find(e=>e.deliveryStrategyHandle===u),y=L({deliveryMethod:i,localDelivery:"LOCAL"===i.methodType?he.translate("shipping.local_delivery"):void 0});return e(A,{value:u,renderSelectedContentWhenCollapsed:!0,selectedContent:Xe(u,g,s)??void 0,details:e(n,{children:[o&&e(B,{deliveryMethod:i,deliveryExpectationLine:_,paragraphColor:ve}),!o&&a&&e(j,{timeInTransit:p,minDeliveryDateTime:i?.minDeliveryDateTime,maxDeliveryDateTime:i?.maxDeliveryDateTime,title:i?.deliveryPromisePresentmentTitle?.short,paragraphColor:ve}),d&&!o&&e(c,{color:ve,children:e("bdi",{children:d})}),"PickupInStoreLocation"===v?.type&&e(de,{pickupLocation:v})]}),secondaryContent:e(z,{cost:r,costAfterDiscounts:l,included:m,styleOverrides:tn,preDiscountCost:h}),tertiaryContent:Je&&e(le,{customizations:Le,handle:u,isInModal:pe,render:n=>e(S,{padding:"small-100 none none none",gap:"small-100",children:n})}),children:e(U,{methodTitle:y})},u)}),re?e("div",{className:r([oe.LoadingOption,oe[l("LoadingOptionBorder",We)]]),children:e(b,{gridAutoFlow:"column",gridTemplateColumns:"minmax(auto, max-content) minmax(0, 1fr)",gridTemplateRows:"minmax(0, 1fr)",gap:"base",alignItems:"center",alignContent:"center",children:[e(O,{children:e(D,{})}),e(c,{color:"subdued",type:"small",children:he.translate("shipping.loading_progressive_rates")})]})}):null]})})})}function le({customizations:n,handle:i,isInModal:t,render:o}){const a=s(()=>({handle:i,isInModal:t}),[i,t]);return e(M,{customizations:n,options:a,render:o})}function de({pickupLocation:i}){const t=R(i.address,{hiddenFields:["firstName","lastName","phone","company","countryCode","postalCode"]});return e(n,{children:[e(c,{type:"small",children:t}),e(c,{type:"small",children:i.instructions})]})}function ce({children:n}){return e(S,{gap:"large-200",children:n})}export{re as S};