1import{b as K,j as t}from"./vendor-query-CniT1WJL.js";import{r as w}from"./vendor-react-69GsFwrV.js";import{u as M,$ as Z,aS as Q,aT as V,aU as $,aV as G,F as Y,V as v,G as N,aW as W,a1 as C,aX as X,aY as _,aZ as H,a_ as J,a$ as k,B as O,q as ee,P as D,I as te,m as se,b0 as P}from"./index-KjAD5lCC.js";import{A as ie}from"./AccountNav-CGK2802V.js";import{A as ae,a as le}from"./AccountSection-B7Ueu1lP.js";import{A as ne,d as F,a as de}from"./AddressUseSelect-6JVVOxBe.js";import{ag as U,a3 as re,N as A,b7 as ce,ax as oe}from"./vendor-ui-Ad3ANzF6.js";import"./vendor-forms-q6h4WU-p.js";const ue={label:"",fullName:"",phone:"",line1:"",line2:"",city:"",state:"",zip:"",country:"US",type:"both",isDefault:!1,isDefaultBilling:!1};function me(i){return{label:i.label??"",fullName:i.fullName??"",phone:i.phone??"",line1:i.line1,line2:i.line2??"",city:i.city,state:C(i.state)??i.state,zip:i.zip,country:i.country,type:i.type??"both",isDefault:i.isDefaultShipping??i.isDefault,isDefaultBilling:i.isDefaultBilling??!1}}function o({id:i,label:d,value:p,onChange:u,onBlur:r,optional:c,className:m,autoComplete:g}){return t.jsxs("div",{className:m,children:[t.jsxs("label",{htmlFor:i,className:"text-caption font-semibold text-ink-2",children:[d,c&&t.jsx("span",{className:"font-normal text-ink-3",children:" (optional)"})]}),t.jsx(te,{id:i,value:p,onChange:s=>u(s.target.value),onBlur:r,autoComplete:g,className:"mt-1.5 rounded-xl"})]})}function E({id:i,label:d,checked:p,onChange:u,blocked:r}){return t.jsxs("div",{className:"mt-3",children:[t.jsxs("label",{htmlFor:i,className:"flex items-center gap-2 text-sm text-ink-2",children:[t.jsx("input",{id:i,type:"checkbox",checked:p,disabled:r!=null,onChange:c=>u(c.target.checked),className:"size-4 rounded border-ink-3 accent-[hsl(var(--primary))] disabled:opacity-50"}),d]}),r&&t.jsx("p",{className:"ml-6 mt-0.5 text-caption text-ink-3",children:r})]})}function Ne(){const{isAuthenticated:i}=M(),{toast:d}=se(),p=K(),{data:u,isLoading:r}=Z({query:{queryKey:P(),enabled:i}}),c=Q(),m=V(),g=$(),[s,h]=w.useState(null),[x,f]=w.useState(null),n=G();if(!i)return null;const y=()=>p.invalidateQueries({queryKey:P()}),l=e=>h(a=>a&&{...a,...e}),b=()=>{s&&n.check({address1:s.line1,address2:s.line2,city:s.city,state:s.state,zip:s.zip})},S=()=>{f(null),n.reset(),h({...ue,isDefault:(u??[]).length===0})},R=e=>{f(e.id),n.reset(),h(me(e))},z=()=>{h(null),f(null),n.reset()};async function q(e){const a={label:e.label.trim()||null,fullName:e.fullName.trim()||null,phone:e.phone.trim()||null,line1:e.line1.trim(),line2:e.line2.trim()||null,city:e.city.trim(),state:e.state.trim(),zip:e.zip.trim(),country:e.country.trim()||"US",type:e.type,isDefault:e.isDefault,isDefaultShipping:e.isDefault,isDefaultBilling:e.isDefaultBilling};try{x==null?await c.mutateAsync({data:a}):await m.mutateAsync({id:x,data:a}),y(),z(),d({title:x==null?"Address added":"Address updated"})}catch(j){d({title:"Could not save",description:j instanceof Error?j.message:String(j),variant:"destructive"})}}async function I(){if(!s)return;if(!s.line1.trim()||!s.city.trim()||!s.state.trim()||!s.zip.trim()){d({title:"Street, city, state and ZIP are required",variant:"destructive"});return}if(!await n.ensureResolvedForSubmit({address1:s.line1,address2:s.line2,city:s.city,state:s.state,zip:s.zip})){d({title:"Check the USPS suggestion",description:"Review the suggested address below the address fields, then save again."});return}await q(s)}async function L(e){try{await m.mutateAsync({id:e.id,data:{...pe(e),isDefault:!0}}),y()}catch(a){d({title:"Could not set default",description:a instanceof Error?a.message:String(a),variant:"destructive"})}}async function T(e){try{await g.mutateAsync({id:e}),y(),d({title:"Address removed"})}catch(a){d({title:"Could not remove",description:a instanceof Error?a.message:String(a),variant:"destructive"})}}const B=u??[];return t.jsxs(t.Fragment,{children:[t.jsx(ie,{}),t.jsx(Y,{width:"narrow",className:"pb-8 pt-6 md:pb-12",children:t.jsxs(ae,{children:[t.jsxs("div",{className:"mb-6 flex items-end justify-between gap-4",children:[t.jsx("div",{children:t.jsx("h1",{className:"font-display text-t1 text-ink",children:"Address book"})}),s==null&&t.jsxs(v,{onClick:S,className:"shrink-0 gap-1.5",children:[t.jsx(U,{className:"size-4","aria-hidden":"true"})," Add address"]})]}),s!=null&&t.jsxs(N,{className:"mb-5",children:[t.jsx("h2",{className:"mb-4 text-sm font-semibold text-ink",children:x==null?"New address":"Edit address"}),t.jsxs("form",{onSubmit:e=>{e.preventDefault(),I()},children:[t.jsxs("div",{className:"grid grid-cols-1 gap-3.5 sm:grid-cols-2",children:[t.jsx(o,{id:"ad-label",label:"Label",optional:!0,value:s.label,onChange:e=>l({label:e})}),t.jsx(o,{id:"ad-name",label:"Recipient name",optional:!0,value:s.fullName,onChange:e=>l({fullName:e})})]}),t.jsx(o,{id:"ad-phone",label:"Recipient phone",optional:!0,className:"mt-3.5",value:s.phone,onChange:e=>l({phone:e})}),t.jsxs("div",{className:"mt-3.5",children:[t.jsx("label",{htmlFor:"ad-line1",className:"text-caption font-semibold text-ink-2",children:"Street address"}),t.jsx("div",{className:"mt-1.5",children:t.jsx(W,{id:"ad-line1",value:s.line1,onChange:e=>l({line1:e}),onSelect:e=>{const a=C(e.state)??s.state;l({city:e.city,state:a,zip:e.zip5}),n.check({address1:e.address1,address2:s.line2,city:e.city,state:a,zip:e.zip5})},onBlur:b,className:"flex h-9 w-full rounded-xl border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"})})]}),t.jsx(o,{id:"ad-line2",label:"Apt, suite, etc.",optional:!0,className:"mt-3.5",value:s.line2,onChange:e=>l({line2:e})}),t.jsxs("div",{className:"mt-3.5 grid grid-cols-1 gap-3.5 sm:grid-cols-3",children:[t.jsx(o,{id:"ad-city",label:"City",autoComplete:"address-level2",value:s.city,onChange:e=>l({city:e}),onBlur:b}),t.jsxs("div",{children:[t.jsx("label",{htmlFor:"ad-state",className:"text-caption font-semibold text-ink-2",children:"State"}),t.jsx(X,{id:"ad-state",value:s.state,onChange:e=>{l({state:e}),s&&n.check({address1:s.line1,address2:s.line2,city:s.city,state:e,zip:s.zip})},className:"mt-1.5 rounded-xl"})]}),t.jsx(o,{id:"ad-zip",label:"ZIP",autoComplete:"postal-code",value:s.zip,onChange:e=>l({zip:e}),onBlur:b})]}),n.outcome&&n.entered&&t.jsx(_,{className:"mt-3",outcome:n.outcome,entered:n.entered,onUseSuggested:e=>{s&&(l({line1:e.address1,line2:J(e,s.line2),city:e.city,state:C(e.state)??s.state,zip:H(e)}),n.acceptSuggested(e))},onKeepMine:n.keepMine}),t.jsx(o,{id:"ad-country",label:"Country",className:"mt-3.5",value:s.country,onChange:e=>l({country:e})}),t.jsx(ne,{id:"ad-type",className:"mt-3.5",label:"Use this address for",value:s.type,onCh
1ange:e=>l({type:e,isDefault:s.isDefault&&k(e,"shipping"),isDefaultBilling:s.isDefaultBilling&&k(e,"billing")})}),t.jsx(E,{id:"ad-default-shipping",label:"Default shipping address",checked:s.isDefault,onChange:e=>l({isDefault:e}),blocked:F(s.type,"shipping")}),t.jsx(E,{id:"ad-default-billing",label:"Default billing address",checked:s.isDefaultBilling,onChange:e=>l({isDefaultBilling:e}),blocked:F(s.type,"billing")}),t.jsxs("div",{className:"mt-5 flex gap-2",children:[t.jsx(v,{type:"submit",disabled:c.isPending||m.isPending,children:c.isPending||m.isPending?"Savingâ¦":"Save address"}),t.jsx(O,{type:"button",variant:"outline",onClick:z,children:"Cancel"})]})]})]}),r?t.jsx(ee,{className:"h-40 rounded-card"}):B.length===0&&s==null?t.jsx(N,{children:t.jsx(le,{icon:re,message:"No saved addresses yet.",bordered:!1,children:t.jsxs(v,{onClick:S,className:"mt-3 gap-1.5",children:[t.jsx(U,{className:"size-4","aria-hidden":"true"})," Add your first address"]})})}):t.jsx("div",{className:"space-y-3",children:B.map(e=>t.jsx(N,{children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-semibold text-ink",children:e.label||e.fullName||"Address"}),(e.isDefaultShipping??e.isDefault)&&t.jsxs(D,{variant:"mint",children:[t.jsx(A,{className:"size-3","aria-hidden":"true"})," Default shipping"]}),e.isDefaultBilling&&t.jsxs(D,{variant:"mint",children:[t.jsx(A,{className:"size-3","aria-hidden":"true"})," Default billing"]}),e.type&&e.type!=="both"&&t.jsx(D,{variant:"neutral",children:de(e.type)})]}),e.fullName&&e.label&&t.jsx("p",{className:"text-caption text-ink-2",children:e.fullName}),t.jsxs("p",{className:"text-caption text-ink-2",children:[e.line1,e.line2?`, ${e.line2}`:""]}),t.jsxs("p",{className:"text-caption text-ink-2",children:[e.city,", ",e.state," ",e.zip," · ",e.country]}),e.phone&&t.jsx("p",{className:"mt-0.5 text-caption text-ink-3 tabular-nums",children:e.phone})]}),t.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>R(e),className:"flex items-center gap-1 text-caption text-ink-2 hover:text-ink",children:[t.jsx(ce,{className:"size-3.5","aria-hidden":"true"})," Edit"]}),!(e.isDefaultShipping??e.isDefault)&&k(e.type,"shipping")&&t.jsxs("button",{type:"button",onClick:()=>{L(e)},className:"flex items-center gap-1 text-caption text-ink-2 hover:text-ink",children:[t.jsx(A,{className:"size-3.5","aria-hidden":"true"})," Default"]}),t.jsxs("button",{type:"button",onClick:()=>{T(e.id)},className:"flex items-center gap-1 text-caption text-ink-3 hover:text-destructive",children:[t.jsx(oe,{className:"size-3.5","aria-hidden":"true"})," Remove"]})]})]})},e.id))})]})})]})}function pe(i){return{label:i.label??null,fullName:i.fullName??null,phone:i.phone??null,line1:i.line1,line2:i.line2??null,city:i.city,state:i.state,zip:i.zip,country:i.country,type:i.type,isDefaultBilling:i.isDefaultBilling}}export{Ne as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.