import{u as H,Q as D,ao as U,d as k,ap as Z,s as S,a as W,j as e,aC as M,aD as h,T as o,c as u,R as N,a9 as b,k as C,G as l,az as V,n as X,aB as ee,aE as re,b as g,aX as se,a_ as te,c0 as ne,aP as oe,bA as y,t as v,aQ as A,aA as E,aR as ie,E as le,bb as ae,a8 as de,bc as ce,a$ as he,bJ as ue,a6 as xe,Z as pe,aq as je,K as me}from"../index.Crez7j-Y.bundle.js";import{E as G}from"./EmptyContent.BRQ9JwMr.bundle.js";const be=r=>{const{getMyShippingAddress:s}=F();return H({queryKey:D.shippingAddress(),queryFn:()=>s(),...r})};function J(r){const{address:s,onOpenModal:n}=r,a=U(),t=k.useCallback(()=>{n(s)},[n,s]),{deleteMyShippingAddress:d}=F(),i=Z({mutationFn:x=>d(x)}),c=k.useCallback(()=>{s.defaultYn==="Y"?S("error","기본 배송지는 삭제할 수 없습니다.\n기본 배송지를 변경 후 삭제해주세요."):S("warning","배송지를 삭제하시겠습니까?",void 0,"취소").then(async x=>{x.isConfirmed&&(await i.mutateAsync(s.addressNo),a.invalidateQueries({queryKey:D.shippingAddress()}),S("success","배송지가 삭제되었습니다."))})},[s]),{isMobile:p,isDesktop:j}=W();return e.jsxs(e.Fragment,{children:[j&&e.jsx(ve,{address:s,onClickUpdateButton:t,onClickDeleteButton:c}),p&&e.jsx(ge,{address:s,onClickUpdateButton:t,onClickDeleteButton:c})]})}function ve(r){var t;const{address:s,onClickDeleteButton:n,onClickUpdateButton:a}=r;return e.jsxs(M,{children:[e.jsxs(h,{align:"center",children:[e.jsx(o,{variant:"subtitle1",children:s.addressName}),s.defaultYn==="Y"&&e.jsx(u,{border:"1px solid ".concat(N),borderRadius:2,px:1,children:e.jsx(o,{variant:"subtitle1",color:N,fontWeight:500,children:"기본배송지"})})]}),e.jsx(h,{align:"center",children:e.jsx(o,{variant:"body",children:s.receiverName})}),e.jsx(h,{align:"center",children:e.jsx(o,{variant:"body",component:"p",children:"(".concat(s.receiverZipCd,") ")+s.receiverAddress+" "+((t=s.receiverDetailAddress)!=null?t:"")})}),e.jsxs(h,{align:"center",children:[e.jsx(o,{variant:"body",component:"p",children:s.receiverContact1}),e.jsx(o,{variant:"body",component:"p",children:s.receiverContact2})]}),e.jsx(h,{align:"center",children:e.jsxs(u,{display:"flex",flexDirection:"column",justifyContent:"center",gap:1,px:2,children:[e.jsx(b,{fullWidth:!0,variant:"outlined",color:"inherit",size:"small",onClick:a,sx:{borderColor:C},children:e.jsx(o,{variant:"body",children:"수정"})}),e.jsx(b,{fullWidth:!0,variant:"outlined",color:"inherit",size:"small",onClick:n,sx:{borderColor:C,color:"red"},children:e.jsx(o,{variant:"body",children:"삭제"})})]})})]})}function ge(r){var t,d;const{address:s,onClickDeleteButton:n,onClickUpdateButton:a}=r;return e.jsxs(u,{py:2,borderBottom:"1px solid ".concat(C),children:[e.jsxs(u,{display:"flex",alignItems:"center",gap:2,pb:1,children:[s.defaultYn==="Y"&&e.jsx(u,{border:"1px solid ".concat(N),borderRadius:2,px:1,children:e.jsx(o,{variant:"subtitle1",color:N,fontWeight:500,children:"기본배송지"})}),e.jsx(o,{variant:"subtitle1",children:s.addressName})]}),e.jsxs(l,{container:!0,children:[e.jsxs(l,{mobile:9,children:[e.jsx(o,{variant:"body",fontWeight:400,children:s.receiverName}),e.jsx(o,{variant:"body",component:"p",children:"(".concat(s.receiverZipCd,") ")+s.receiverAddress+" "+((t=s.receiverDetailAddress)!=null?t:"")}),e.jsx(o,{variant:"body",fontWeight:400,children:s.receiverContact1+" "+((d=s.receiverContact2)!=null?d:"")})]}),e.jsxs(l,{mobile:3,container:!0,rowSpacing:1,my:"auto",children:[e.jsx(l,{item:!0,mobile:12,children:e.jsx(b,{fullWidth:!0,variant:"outlined",color:"inherit",size:"small",onClick:a,sx:{borderColor:C},children:e.jsx(o,{variant:"button",children:"수정"})})}),e.jsx(l,{item:!0,mobile:12,children:e.jsx(b,{fullWidth:!0,variant:"outlined",color:"inherit",size:"small",onClick:n,sx:{borderColor:C,color:"red"},children:e.jsx(o,{variant:"button",children:"삭제"})})})]})]})]})}function K(r){const{isDesktop:s,isMobile:n}=W();return e.jsxs(u,{mb:6,children:[s&&e.jsx(fe,{...r}),n&&e.jsx(ye,{...r})]})}function fe(r){const{shippingAddress:s,isPending:n,onOpenModal:a}=r;return e.jsxs(V,{size:"small",sx:{"& th":{py:1,px:0,bgcolor:X},"& td":{px:0}},children:[e.jsx(ee,{children:e.jsxs(M,{children:[e.jsx(h,{width:"100",align:"center",children:e.jsx(o,{variant:"body",fontWeight:500,children:"배송지 이름"})}),e.jsx(h,{width:"80",align:"center",children:e.jsx(o,{variant:"body",fontWeight:500,children:"받는 사람"})}),e.jsx(h,{width:"250",align:"center",children:e.jsx(o,{variant:"body",fontWeight:500,children:"주소"})}),e.jsx(h,{width:"100",align:"center",children:e.jsx(o,{variant:"body",fontWeight:500,children:"연락처"})}),e.jsx(h,{width:"100",align:"center",children:e.jsx(o,{variant:"body",fontWeight:500,children:"관리"})})]})}),e.jsxs(re,{children:[s&&s.bookedAddresses.length===0&&e.jsx(M,{children:e.jsx(h,{colSpan:5,children:e.jsx(G,{text:"등록된 배송지가 없습니다.",height:"40dvh"})})}),n&&Array.from({length:3}).map((t,d)=>e.jsxs(M,{children:[e.jsx(h,{children:e.jsx(g,{variant:"rectangular"})}),e.jsx(h,{children:e.jsx(g,{variant:"rectangular"})}),e.jsx(h,{children:e.jsx(g,{variant:"rectangular"})}),e.jsx(h,{children:e.jsx(g,{variant:"rectangular"})}),e.jsx(h,{children:e.jsxs(u,{display:"flex",flexDirection:"column",gap:1,children:[e.jsx(g,{variant:"rectangular"}),e.jsx(g,{variant:"rectangular"})]})})]},d)),s&&s.bookedAddresses.map(t=>e.jsx(J,{address:t,onOpenModal:a},t.addressNo))]})]})}function ye(r){const{shippingAddress:s,isPending:n,onOpenModal:a}=r;return e.jsxs(e.Fragment,{children:[s&&s.bookedAddresses.length===0&&e.jsx(G,{text:"등록된 배송지가 없습니다.",height:"40dvh"}),n&&Array.from({length:3}).map((t,d)=>e.jsx(u,{children:e.jsx(g,{variant:"rectangular",height:80,sx:{my:2}})},d)),s&&s.bookedAddresses.map(t=>e.jsx(J,{address:t,onOpenModal:a},t.addressNo))]})}function L(r){const{totalCount:s,onOpenModal:n}=r;return e.jsxs(u,{display:"flex",justifyContent:"space-between",alignItems:"center",children:[e.jsx(o,{variant:"subtitle1",children:"총 ".concat(s,"건")}),e.jsx(b,{variant:"contained",color:"black",type:"button",onClick:()=>n(null),children:e.jsx(o,{variant:"body",children:"배송지 등록"})})]})}function Ce(r,s,n){var $,w,I,O,z,T,P,Y,R;const a=U(),t=r===null,d={receiverName:($=r==null?void 0:r.receiverName)!=null?$:"",receiverJibunAddress:(w=r==null?void 0:r.receiverJibunAddress)!=null?w:"",receiverZipCd:(I=r==null?void 0:r.receiverZipCd)!=null?I:"",receiverDetailAddress:(O=r==null?void 0:r.receiverDetailAddress)!=null?O:"",receiverAddress:(z=r==null?void 0:r.receiverAddress)!=null?z:"",addressName:(T=r==null?void 0:r.addressName)!=null?T:null,receiverContact1:(P=r==null?void 0:r.receiverContact1)!=null?P:"",receiverContact2:(Y=r==null?void 0:r.receiverContact2)!=null?Y:null,defaultYn:(R=r==null?void 0:r.defaultYn)!=null?R:"N"},i=se({defaultValues:d,resolver:te(ne)}),{setValue:c,trigger:p}=i,{createMyShippingAddress:j,updateMyShippingAddress:x}=F(),f=Z({mutationFn:m=>t?j(m):x(r.addressNo,m),onSuccess:()=>{a.invalidateQueries({queryKey:D.shippingAddress()})}});return{methods:i,postShippingAddress:async m=>{const _={...m,addressMemo:"",receiverLastName:null,addressType:"BOOK",customsIdNumber:null,countryCd:"KR",receiverCity:null,receiverState:null,receiverFirstName:null};try{await f.mutateAsync(_),(await S("success",t?"배송지가 등록되었습니다.":"배송지가 수정되었습니다.")).isConfirmed&&s()}catch(q){console.error(q)}},onSelectAddress:m=>{c("receiverAddress",m.address),c("receiverZipCd",m.zipCode),c("receiverJibunAddress",m.jibunAddress),n(!1),p("receiverAddress")}}}function ke({onCloseModal:r,setOpenAddressModal:s}){var d,i,c,p,j;const{register:n,control:a,formState:{errors:t}}=oe();return e.jsxs(l,{container:!0,gap:1,flexDirection:"column",desktop:11,mobile:11,mx:"auto",py:3,children:[e.jsx(l,{desktop:12,mobile:12,children:e.jsx(y,{htmlFor:"addressName",children:e.jsx(o,{variant:"subtitle1",children:"배송지 이름"})})}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(v,{fullWidth:!0,...n("addressName"),id:"addressName",size:"small",error:!!t.addressName,helperText:(d=t.addressName)==null?void 0:d.message,placeholder:"배송지 이름을 입력해주세요."})}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(y,{htmlFor:"receiverName",children:e.jsx(A,{variant:"subtitle1",children:"받으시는 분"})})}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(v,{fullWidth:!0,...n("receiverName"),id:"receiverName",size:"small",error:!!t.receiverName,helperText:(i=t.receiverName)==null?void 0:i.message,placeholder:"받으시는 분을 입력해주세요."})}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(A,{variant:"subtitle1",children:"주소"})}),e.jsxs(l,{desktop:12,mobile:12,display:"flex",justifyContent:"space-between",alignItems:"center",gap:1,children:[e.jsx(u,{flex:3,children:e.jsx(v,{fullWidth:!0,...n("receiverZipCd"),size:"small",disabled:!0,sx:{bgcolor:E}})}),e.jsx(u,{flex:2,children:e.jsx(b,{fullWidth:!0,id:"find-address-modal-button",variant:"outlined",color:"inherit",onClick:()=>s(!0),children:e.jsx(o,{variant:"button",children:"우편번호 검색"})})})]}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(v,{fullWidth:!0,...n("receiverAddress"),size:"small",disabled:!0,sx:{bgcolor:E},error:!!t.receiverAddress,helperText:(c=t.receiverAddress)==null?void 0:c.message,placeholder:"우편변호를 검색하여 배송지를 입력해주세요."})}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(v,{fullWidth:!0,...n("receiverDetailAddress"),size:"small",label:"상세 주소 입력",InputLabelProps:{shrink:!0},error:!!t.receiverDetailAddress,helperText:(p=t.receiverDetailAddress)==null?void 0:p.message,placeholder:"상세주소를 입력해 주세요."})}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(y,{htmlFor:"receiverContact1",children:e.jsx(A,{variant:"subtitle1",children:"휴대폰 번호"})})}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(v,{fullWidth:!0,...n("receiverContact1"),id:"receiverContact1",size:"small",placeholder:"휴대폰 번호를 입력해주세요.",error:!!t.receiverContact1,helperText:(j=t.receiverContact1)==null?void 0:j.message})}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(y,{htmlFor:"receiverContact2",children:e.jsx(o,{variant:"subtitle1",children:"전화번호"})})}),e.jsx(l,{desktop:12,mobile:12,children:e.jsx(v,{id:"receiverContact2",fullWidth:!0,...n("receiverContact2"),size:"small",placeholder:"전화 번호를 입력해주세요."})}),e.jsxs(l,{desktop:12,mobile:12,display:"flex",alignItems:"center",children:[e.jsx(ie,{name:"defaultYn",control:a,render:({field:x})=>e.jsx(le,{...x,sx:{p:0},checked:x.value==="Y",onChange:f=>x.onChange(f.target.checked?"Y":"N"),id:"defaultYn"})}),e.jsx(y,{htmlFor:"defaultYn",sx:{cursor:"pointer"},children:e.jsx(o,{variant:"subtitle1",children:"기본 배송지로 지정"})})]}),e.jsx(l,{desktop:12,mobile:12,my:3,children:e.jsxs(l,{desktop:9,mobile:9,mx:"auto",display:"flex",justifyContent:"center",gap:2,children:[e.jsx(b,{fullWidth:!0,type:"button",variant:"contained",color:"white",onClick:r,sx:{py:1.5},children:e.jsx(o,{variant:"button",children:"취소"})}),e.jsx(b,{fullWidth:!0,variant:"contained",type:"submit",color:"black",sx:{py:1.5},children:e.jsx(o,{variant:"button",children:"등록"})})]})})]})}function Q({isModalOpened:r,onCloseModal:s,initialAddress:n}){const{isMobile:a}=W();return e.jsx(ae,{open:r,fullScreen:a,disableRestoreFocus:!0,children:e.jsxs(u,{minWidth:{desktop:600},children:[e.jsxs(u,{component:"header",borderBottom:"1px solid ".concat(de),p:3,position:"relative",children:[e.jsx(o,{variant:"titleLarge",align:"center",children:"배송지 등록"}),e.jsx(ce,{onClick:s})]}),e.jsx(Se,{onCloseModal:s,initialAddress:n},n?n.addressNo:"new")]})})}function Se({initialAddress:r,onCloseModal:s}){const[n,a]=k.useState(!1),{methods:t,postShippingAddress:d,onSelectAddress:i}=Ce(r,s,a);return e.jsx(he,{...t,children:e.jsxs("form",{onSubmit:t.handleSubmit(d),children:[e.jsx(ke,{onCloseModal:s,setOpenAddressModal:a}),e.jsx(ue,{open:n,onModalClose:()=>a(!1),onAddressSelect:i})]})})}function Ae(){var x,f;const[r,s]=k.useState(!1),[n,a]=k.useState(null),t=B=>{a(B||null),s(!0)},d=()=>{s(!1),a(null)},{data:i,isPending:c}=be(),{isMobile:p,isDesktop:j}=W();return e.jsxs(e.Fragment,{children:[j&&e.jsxs(u,{bgcolor:xe,borderRadius:2,p:4,gap:3,component:"section",display:"flex",flexDirection:"column",children:[e.jsx(o,{variant:"title",children:"배송지 관리"}),e.jsx(L,{onOpenModal:t,totalCount:(x=i==null?void 0:i.bookedAddresses.length)!=null?x:0}),e.jsx(K,{onOpenModal:t,shippingAddress:i,isPending:c}),e.jsx(Q,{isModalOpened:r,onCloseModal:d,initialAddress:n})]}),p&&e.jsxs(pe,{children:[e.jsx(l,{mobile:12,mx:"auto",children:e.jsx(je,{title:"배송지 관리"})}),e.jsx(l,{mobile:11,mx:"auto",mt:3,children:e.jsx(L,{onOpenModal:t,totalCount:(f=i==null?void 0:i.bookedAddresses.length)!=null?f:0})}),e.jsx(l,{mobile:11,mx:"auto",children:e.jsx(K,{onOpenModal:t,shippingAddress:i,isPending:c})}),e.jsx(l,{mobile:11,mx:"auto",children:e.jsx(Q,{isModalOpened:r,onCloseModal:d,initialAddress:n})})]})]})}function F(){const r=me("shopByAPI"),s="profile/shipping-addresses";return{getMyShippingAddress:()=>r.get("".concat(s)).then(i=>i.data),createMyShippingAddress:i=>r.post("".concat(s),i).then(c=>c.data),updateMyShippingAddress:(i,c)=>r.put("".concat(s,"/").concat(i),c).then(p=>p.data),deleteMyShippingAddress:i=>r.delete("".concat(s,"/").concat(i)).then(c=>c.data)}}export{Ae as default};