var _____WB$wombat$assign$function_____=function(name){return (globalThis._wb_wombat && globalThis._wb_wombat.local_init && globalThis._wb_wombat.local_init(name))||globalThis[name];};if(!globalThis.__WB_pmw){globalThis.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}var window = _____WB$wombat$assign$function_____("window");
var self = _____WB$wombat$assign$function_____("self");
var document = _____WB$wombat$assign$function_____("document");
var location = _____WB$wombat$assign$function_____("location");
var top = _____WB$wombat$assign$function_____("top");
var parent = _____WB$wombat$assign$function_____("parent");
var frames = _____WB$wombat$assign$function_____("frames");
var opener = _____WB$wombat$assign$function_____("opener");
import{c8 as M,c9 as U,ca as C,cb as H,cc as z,i as m,a2 as I,b7 as K,cd as G,ce as L,a as e,I as _,G as v,D as f,cf as b,E as D,aC as B,cg as j,ch as Y,ci as $,cj as X,ck as Z,aj as J,cl as w,bZ as A,cm as Q,aX as F,cn as ee,al as ne,a7 as S,a0 as R,co as se,K as W,cp as ae,d as p,cq as re,cr as oe,cs as ie,ct as N,cu as te,bf as le,U as O,z as k,cv as de,cw as ce,cx as he,cy as ue,cz as E,cA as pe,cB as me}from"./app.ZXowmuNl.js";function T(){return M(new Set([...U].filter(a=>a.startsWith("DELIVERY_COMPANY"))))}function ge(a){const{showIcon:r}=a,s=C(),n=H(),i=z(),o=m(),t=I(),d=r?o("shipping.add_address","Use a different address"):o("review.blocks.change_link_label","Change"),{inMemoryAmazonPayParts:{hasPaymentSheetError:l}}=K();return!G()||s.status!==L.Available||i?null:e(B,{onClick:()=>{try{s.sdk.buywithprime.changeShippingAddress({amazonPayOptions:{amazonCheckoutSessionId:n()}})}catch(c){l.value=!0,t.notify(new j(`Error on changing buyer shipping address. Details: ${c}`,{cause:c}))}},children:e(_,{blockAlignment:"center",spacing:"none",children:[r?e(v,{children:[e(f,{type:"arrow-up-right",size:"small",appearance:"monochrome"}),e(b,{spacing:"small200"})]}):null,e(D,{children:d})]})})}const ye=Z("AmazonPayChangeAddressLinkButton");function Pe(){const a=I(),r=m(),s=C(),n=Y(),i=z(),o=$(void 0,ye),t=r("shipping.add_address","Use a different address");return!n||s.status!==L.Available||i?null:e(B,{onClick:()=>{try{const{checkout_session_id:l}=X(n.method.walletParams);s.sdk.Pay.changeShippingAddress({amazonCheckoutSessionId:l})}catch(l){a.notify(new Ae(`Error on changing buyer shipping address. Details: ${l}`,{cause:l}))}},id:o,children:e(_,{blockAlignment:"center",spacing:"none",children:[e(f,{type:"arrow-up-right",size:"small",appearance:"monochrome"}),e(b,{spacing:"small200"}),e(D,{children:t})]})})}class Ae extends Error{name="AmazonPayChangeAddressLinkError"}function fe({loading:a,countryCode:r,phone:s}){const n=J(),i=w(),o=A(()=>i.isRequired("phone",r),[r,i]),t=m(),{validatePhoneNumber:d,isPhoneNumberUtilLoaded:l}=Q(),h=F(c=>{const g=ee(c);if(o&&!g)return t("field_errors.phone_blank","Enter a phone number");if(g&&!d(c??"",r))return t("field_errors.shipping_line_phone_invalid","Enter a valid phone number")},[o,d,r,t]),u=ne(!1);return S(()=>{if(u.current||!l||a)return;const c=h(s);n.value=c,u.current=!0},[o,l,a,s,n,h]),A(()=>({errorSignal:n,validatePhoneField:h,isPhoneRequired:o}),[n,o,h])}function be({errorSignal:a,isRequired:r,validatePhoneField:s}){const n=m(),{shippingAddress:i}=R(),o=i.value,t=se(i.fields.phone,a,s),[d,l]=W(!1);if(ae(()=>{a.value&&l(!0)}),!d)return null;const h=n("contact.phone_label","Phone"),u=n("contact.optional_phone_label","Phone (optional)");return e(p,{children:[e(p,{padding:"small400"}),e(re,{name:"phone",countryCode:o.countryCode||"",label:r?h:u,hideCountries:!0,required:r,autocomplete:"shipping tel",autoFocus:!0,...t})]})}function Se(){const a=w(),{shippingAddress:r}=R(),[s]=T()??[],n=A(()=>oe(),[]);return S(()=>{s&&(n.company.value=s)},[n.company,s]),s?e(p,{children:[e(p,{padding:"small400"}),e(ie,{address:r,addressErrors:n,addressType:"shipping",addressSettings:a,editDisabled:!1})]}):null}function ke({isPhoneRequired:a,phoneErrorSignal:r,validatePhoneField:s}){const{formattedAddress:n,address:{firstName:i,lastName:o}}=N(["phone","firstName","lastName","company"]);return e(de,{id:"amazon_address_edit",titleHidden:!0,selectedItems:["1"],onChange:()=>{},hideRadioButton:!0,children:e(te,{id:"1",children:e(le,{spacing:"base",blockAlignment:"start",children:e(O,{inlineAlignment:"start",cornerRadius:"base",padding:"none",children:e(p,{borderRadius:"base",children:[e(p,{padding:"none",children:[e(k,{children:[i," ",o]}),e(k,{color:"subdued",children:n})]}),e(Se,{}),e(be,{errorSignal:r,isRequired:a,validatePhoneField:s})]})})})})})}function Ce(){const a=m(),r=ce(),{formattedAddress:s,address:{phone:n,countryCode:i}}=N(["company"]),t=!he(),{errorSignal:d,validatePhoneField:l,isPhoneRequired:h}=fe({loading:t,phone:n,countryCode:i}),u=!!T()?.length,c=!!ue()?.length,g=!!d.value,y=!!(c||u||g),[V,P]=W(!1);S(()=>{y&&P(!0)},[y]);const x=F(()=>P(q=>!q),[P]);return e(me,{id:"amazonPayDeliveryAddress",label:a("shipping.shipping_address_title","Ship to"),summary:t?e(E,{}):e("div",{style:{display:"flex"},children:[y&&e(v,{children:[e(f,{appearance:"critical",type:"alert-circle"}),e(b,{spacing:"small400"})]}),s]}),onToggle:x,open:V,children:t?e(E,{}):e(O,{children:[c&&e(pe,{}),e(ke,{isPhoneRequired:h,phoneErrorSignal:d,validatePhoneField:l}),e(p,{children:r?e(ge,{showIcon:!0}):e(Pe,{})})]})})}export{Ce as default};