import{af as j,ar as D,j as e,bw as N,bx as U,by as de,a as f,ag as F,d as L,s as k,c as h,G as v,a9 as w,T as c,U as C,aC as A,aD as g,E as M,L as G,k as E,R as B,ai as $,m as he,bz as ue,az as xe,n as z,aB as pe,aE as je,bA as me,a8 as ge,bB as fe,o as _,W as H,z as be,a6 as ye,N as q,l as Ce,bC as K,bD as Z,aM as Ne,aA as R,Z as Se,aq as Ie}from"../index.Crez7j-Y.bundle.js";import{u as ve,b as J,a as Q}from"./useCartHooks.CwGnxama.bundle.js";import{u as V,a as X,b as T}from"./useFetchMemberCart.NM8yfOgH.bundle.js";import{N as Y}from"./OrderSheetAPIs.DiQ9xHhr.bundle.js";import{E as ee}from"./EmptyContent.BRQ9JwMr.bundle.js";import{B as Le}from"./Breadcrumbs.DEki5OLn.bundle.js";import{d as te}from"./DragHandle.DMVs2AZT.bundle.js";function ke(s){return j(D,r=>r.isLogin)?e.jsx(Pe,{...s}):e.jsx(Oe,{...s})}function Oe(s){const{cartItemList:t}=s,{selectedCartNoList:r,resetStore:n}=j(N,i=>({selectedCartNoList:i.selectedCartNoList,resetStore:i.resetStore})),a=j(U,i=>i.deleteGuestCartItemList),o=()=>{if(r.length===0){k("warning","삭제할 상품을 선택해주세요.");return}a(r),n()},l=t.filter(i=>r.includes(i.cartNo));return e.jsx(re,{onDeleteButtonClick:o,isPending:!1,selectedCartNoList:r,selectedCartItemList:l})}function Pe(s){const{cartItemList:t}=s,{selectedCartNoList:r,resetStore:n}=j(N,d=>({selectedCartNoList:d.selectedCartNoList,resetStore:d.resetStore})),{deleteCartItemAsync:a,isDeletePending:o}=de(),l=()=>{a(r),n()},i=t.filter(d=>r.includes(d.cartNo));return e.jsx(re,{onDeleteButtonClick:l,isPending:o,selectedCartNoList:r,selectedCartItemList:i})}function re({onDeleteButtonClick:s,isPending:t,selectedCartNoList:r,selectedCartItemList:n}){const a=()=>{if(r.length===0){k("warning","견적서를 출력할 제품을 선택해주세요.");return}const u=new URLSearchParams({cartNo:r.join(",")});window.open("".concat(C.CART_ESTIMATE,"?").concat(u),"_blank","width=740,height=800")},{isDesktop:o,isMobile:l}=f(),{createNaverPayOrderSheetByCartItemAsync:i}=F(),d=L.useCallback(async()=>{if(n.length===0){await k("error","옵션을 선택해주세요.");return}const u=await i(n);l&&u?window.location.href=u:window.open(u)},[n,i,l]);return e.jsxs(h,{display:"flex",justifyContent:"space-between",alignItems:l?"flex-end":"flex-start",flexDirection:l?"column":"row",gap:2,mt:2,children:[e.jsxs(v,{desktop:3,mobile:6,gap:2,display:"flex",children:[e.jsx(w,{fullWidth:!0,size:"small",variant:"outlined",color:"inherit",onClick:s,disabled:t,sx:{py:1},children:e.jsx(c,{variant:"button",children:"선택 삭제"})}),o&&e.jsx(w,{fullWidth:!0,size:"small",variant:"outlined",color:"inherit",onClick:a,disabled:t,sx:{py:1},children:e.jsx(c,{variant:"button",children:"견적서 출력"})})]}),o&&e.jsx(Y,{isSoldOut:!1,isWishButtonShow:!1,onPurchaseButtonClick:d})]})}function se(s){const{productOption:t}=s,{selectedCartNoList:r,addSelectedCartNo:n,deleteSelectedCartNo:a}=j(N,u=>({selectedCartNoList:u.selectedCartNoList,addSelectedCartNo:u.addSelectedCartNo,deleteSelectedCartNo:u.deleteSelectedCartNo})),o=(u,p)=>{p?n(t.cartNo):a(t.cartNo)},l=t.price.salePrice+t.price.addPrice-t.price.immediateDiscountAmt,{isDesktop:i,isMobile:d}=f();return e.jsxs(e.Fragment,{children:[i&&e.jsx(we,{...s,productOptionPrice:l,selectedCartNoList:r,onToggleSelectCart:o}),d&&e.jsx(De,{...s,productOptionPrice:l,selectedCartNoList:r,onToggleSelectCart:o})]})}const we=s=>{const{productOption:t,productNo:r,productImageUrl:n,productName:a,selectedCartNoList:o,onToggleSelectCart:l}=s,i=he.장바구니제품;return e.jsxs(A,{children:[e.jsx(g,{align:"center",children:e.jsx(M,{checked:o.includes(t.cartNo),onChange:l})}),e.jsx(g,{children:e.jsxs(h,{display:"flex",gap:2,alignItems:"center",children:[e.jsx(h,{display:"flex",flexDirection:"column",alignItems:"center",gap:1,children:e.jsx(G,{href:"".concat(C.PRODUCT_DETAIL,"?productNo=").concat(r),underline:"none",children:e.jsx("img",{src:"".concat(n,"?").concat(i,"x").concat(i),alt:String(r),width:i,height:i,style:{border:"1px solid ".concat(E)}})})}),e.jsx(h,{flex:2,display:"flex",flexDirection:"column",gap:1,children:e.jsxs(h,{children:[e.jsx(c,{variant:"body",children:"(주)인바디"}),e.jsx(c,{variant:"subtitle1",children:a})]})})]})}),e.jsx(g,{align:"center",colSpan:4,children:e.jsx(c,{variant:"subtitle1",color:B,component:"p",children:"구매 불가능한 상품입니다. 상품을 삭제해주세요."})})]},t.optionNo)},De=s=>{const{productOption:t,productOptionPrice:r,productNo:n,productImageUrl:a,productName:o,selectedCartNoList:l,onToggleSelectCart:i}=s,d=ue.장바구니제품,{formatPriceWithCommas:u}=$();return e.jsx(e.Fragment,{children:e.jsxs(h,{display:"flex",component:"li",gap:1,py:2,children:[e.jsx(M,{sx:{p:0},checked:l.includes(t.cartNo),onChange:i}),e.jsxs(h,{width:"100%",display:"flex",flexDirection:"column",gap:1,children:[e.jsxs(h,{display:"flex",alignItems:"center",gap:2,children:[e.jsx(G,{href:"".concat(C.PRODUCT_DETAIL,"?productNo=").concat(n),underline:"none",border:"1px solid ".concat(E),children:e.jsx("img",{src:"".concat(a,"?").concat(d,"x").concat(d),alt:t.optionName,width:d,height:d})}),e.jsxs(h,{children:[e.jsx(c,{variant:"body",children:"(주)인바디"}),e.jsx(c,{variant:"subtitle1",children:o}),e.jsx(c,{variant:"subtitle1",children:u(r,"WON")})]})]}),e.jsx(h,{display:"flex",alignItems:"center",gap:5,children:e.jsx(h,{flex:1,display:"flex",alignItems:"center",justifyContent:"space-between",children:e.jsx(c,{})})})]})]})})};function Me(s){const{cartItemList:t}=s,{selectedCartNoList:r,setSelectedCartNo:n}=j(N,i=>({selectedCartNoList:i.selectedCartNoList,setSelectedCartNo:i.setSelectedCartNo})),a=(i,d)=>{if(d&&t){const u=t.map(p=>p.cartNo);n(u)}else n([])},{isMobile:o,isDesktop:l}=f();return e.jsxs(e.Fragment,{children:[l&&e.jsx($e,{...s,selectedCartNoList:r,onToggleCheckedAll:a}),o&&e.jsx(We,{...s,selectedCartNoList:r,onToggleCheckedAll:a})]})}const $e=s=>{const{cartItemList:t,fetchCartData:r,selectedCartNoList:n,onToggleCheckedAll:a}=s;return e.jsxs(xe,{size:"small",sx:{"& th":{py:1,px:0,bgcolor:z},"& td":{px:0,py:2}},children:[e.jsx(pe,{children:e.jsxs(A,{children:[e.jsx(g,{align:"center",width:50,children:e.jsx(M,{sx:{p:0},checked:n.length>0&&n.length===t.length,onChange:a})}),e.jsx(g,{align:"center",width:500,children:e.jsx(c,{variant:"body",fontWeight:500,children:"상품/옵션 정보"})}),e.jsx(g,{align:"center",width:100,children:e.jsx(c,{variant:"body",fontWeight:500,children:"상품금액"})}),e.jsx(g,{align:"center",width:100,children:e.jsx(c,{variant:"body",fontWeight:500,children:"수량"})}),e.jsx(g,{align:"center",width:100,children:e.jsx(c,{variant:"body",fontWeight:500,children:"합계금액"})}),e.jsx(g,{align:"center",width:100,children:e.jsx(c,{variant:"body",fontWeight:500,children:"배송비"})})]})}),e.jsxs(je,{children:[r&&e.jsxs(e.Fragment,{children:[r.deliveryGroups.map((o,l)=>{const i=o.orderProducts.reduce((d,u)=>d+u.orderProductOptions.length,0);return e.jsx(ne,{orderProductList:o.orderProducts,deliveryAmt:o.deliveryAmt,deliveryPayType:o.deliveryPayType,deliveryGroupItemLength:i},l)}),r.invalidProducts.map((o,l)=>e.jsx(e.Fragment,{children:o.orderProductOptions.map(i=>e.jsx(se,{productName:o.productName,productNo:o.productNo,productImageUrl:o.imageUrl,productOption:i},l))}))]}),r&&r.deliveryGroups.length===0&&r.invalidProducts.length===0&&e.jsx(A,{children:e.jsx(g,{colSpan:7,children:e.jsx(ee,{height:"40dvh",text:"장바구니에 담긴 상품이 없습니다."})})})]})]})},We=s=>{const{cartItemList:t,fetchCartData:r,selectedCartNoList:n,onToggleCheckedAll:a}=s;return e.jsxs(h,{children:[e.jsx(h,{py:2,children:e.jsxs(me,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(M,{sx:{pl:0,py:0},checked:n.length>0&&n.length===t.length,onChange:a}),e.jsx(c,{variant:"subtitle1",children:"전체 선택"})]})}),e.jsxs(h,{component:"section",borderTop:"2px solid ".concat(ge),children:[r&&e.jsxs(e.Fragment,{children:[r.deliveryGroups.map((o,l)=>{const i=o.orderProducts.reduce((d,u)=>d+u.orderProductOptions.length,0);return e.jsx(ne,{orderProductList:o.orderProducts,deliveryAmt:o.deliveryAmt,deliveryPayType:o.deliveryPayType,deliveryGroupItemLength:i},l)}),r.invalidProducts.map((o,l)=>e.jsx(e.Fragment,{children:o.orderProductOptions.map(i=>e.jsx(se,{productName:o.productName,productNo:o.productNo,productImageUrl:o.imageUrl,productOption:i},l))}))]}),r&&r.deliveryGroups.length===0&&r.invalidProducts.length===0&&e.jsx(ee,{height:"40dvh",text:"장바구니에 담긴 상품이 없습니다."})]})]})};function ne({orderProductList:s,deliveryAmt:t,deliveryGroupItemLength:r,deliveryPayType:n}){return e.jsx(e.Fragment,{children:s.map((a,o)=>e.jsx(Ae,{product:a,deliveryAmt:t,deliveryPayType:n,deliveryGroupItemLength:r,deliveryGroupIdx:o},a.productNo))})}function Ae({product:s,deliveryAmt:t,deliveryPayType:r,deliveryGroupItemLength:n,deliveryGroupIdx:a}){const{data:o}=ve(s.productNo),l=o==null?void 0:o.optionInfos.flatMap(i=>i.options);return e.jsx(e.Fragment,{children:s.orderProductOptions.map((i,d)=>e.jsx(fe,{productNo:s.productNo,productImageUrl:s.imageUrl,productName:s.productName,option:i,deliveryGroupIdx:a+d,optionList:l,deliveryGroupItemLength:n,deliveryAmt:t,deliveryPayType:r},i.cartNo))})}function Ee(){return j(D,t=>t.isLogin)?e.jsx(Be,{}):e.jsx(Te,{})}function Be(){const s=_(),{createOrderSheetAsync:t,createMemberOrderSheetRequest:r}=J(),[n]=H(),a=n.get("channelType"),o=n.get("trackingKey"),{convertOrderSheetDto:l}=r(a,o),{data:i}=V(),d=(i==null?void 0:i.deliveryGroups.flatMap(x=>x.orderProducts.flatMap(S=>S.orderProductOptions.map(I=>I))))||[],u=()=>{const x=d.map(I=>I.cartNo),S=l(x,d);t(S).then(I=>{I&&s("".concat(C.ORDER_SHEET,"?orderSheetNo=").concat(I.orderSheetNo))})},p=j(N,x=>x.selectedCartNoList),b=d.filter(x=>p.includes(x.cartNo)),O=()=>{if(p.length===0){k("error","선택된 상품이 없습니다.");return}const x=l(p,b);t(x).then(S=>{S&&s("".concat(C.ORDER_SHEET,"?orderSheetNo=").concat(S.orderSheetNo))})},{data:P}=X(p),{isDesktop:W,isMobile:m}=f(),y=b.map(x=>({cartNo:x.cartNo,channelType:a,optionInputs:x.optionInputs,optionNo:x.optionNo,orderCnt:x.orderCnt,productNo:x.productNo}));return e.jsxs(e.Fragment,{children:[W&&e.jsx(oe,{createAllItemOrderSheet:u,createSelectedItemOrderSheet:O}),m&&e.jsx(ie,{createAllItemOrderSheet:u,createSelectedItemOrderSheet:O,selectedItemsTotalPrice:P==null?void 0:P.totalAmt,selectedItemCount:b.length,selectedCartItemList:y})]})}function Te(){const s=_(),{createOrderSheetAsync:t,createGuestOrderSheetRequest:r}=J(),[n]=H(),a=n.get("channelType"),o=n.get("trackingKey"),{convertOrderSheetDto:l}=r(a,o),i=j(U,m=>m.cartItemList),d=()=>{const m=l(i);t(m).then(y=>{y&&s("".concat(C.ORDER_SHEET,"?orderSheetNo=").concat(y.orderSheetNo))})},u=j(N,m=>m.selectedCartNoList),p=i.filter(m=>u.includes(m.cartNo)),{data:b}=T(p),O=()=>{if(p.length===0){k("error","선택된 상품이 없습니다.");return}const m=l(p);t(m).then(y=>{y&&s("".concat(C.ORDER_SHEET,"?orderSheetNo=").concat(y.orderSheetNo))})},{isDesktop:P,isMobile:W}=f();return e.jsxs(e.Fragment,{children:[P&&e.jsx(oe,{createAllItemOrderSheet:d,createSelectedItemOrderSheet:O}),W&&e.jsx(ie,{createAllItemOrderSheet:d,createSelectedItemOrderSheet:O,selectedItemsTotalPrice:b==null?void 0:b.price.totalAmt,selectedItemCount:p.length,selectedCartItemList:p})]})}const oe=s=>{const{createAllItemOrderSheet:t,createSelectedItemOrderSheet:r}=s;return e.jsxs(h,{display:"flex",justifyContent:"center",gap:3,width:500,mx:"auto",children:[e.jsx(w,{fullWidth:!0,variant:"outlined",color:"black",sx:{py:1.5},onClick:r,children:e.jsx(c,{variant:"button",children:"선택 상품 주문하기"})}),e.jsx(w,{fullWidth:!0,variant:"contained",color:"black",sx:{py:1.5},onClick:t,children:e.jsx(c,{variant:"button",children:"전체 상품 주문하기"})})]})},ie=s=>{const{createSelectedItemOrderSheet:t,selectedItemsTotalPrice:r,selectedItemCount:n,selectedCartItemList:a}=s,{formatPriceWithCommas:o}=$(),{createNaverPayOrderSheetByCartItemAsync:l}=F(),i=L.useCallback(async()=>{if(a.length===0){await k("error","옵션을 선택해주세요.");return}const d=await l(a);d&&(window.location.href=d)},[a,l]);return e.jsxs(h,{width:"100%",position:"fixed",p:3,bottom:0,zIndex:be.MobileCartButton,bgcolor:ye,borderTop:"1px solid ".concat(E),children:[e.jsxs(h,{display:"flex",children:[e.jsxs(h,{flex:2,children:[e.jsxs(c,{variant:"subtitle1",children:["총 결제금액"," (".concat(n,"개)")]}),e.jsx(c,{variant:"title",color:B,children:o(r!=null?r:0,"WON")})]}),e.jsx(h,{flex:3,children:e.jsx(w,{fullWidth:!0,variant:"contained",color:"black",sx:{height:"100%"},onClick:t,children:e.jsx(c,{variant:"button",children:"주문하기"})})})]}),e.jsx(h,{display:"flex",justifyContent:"flex-end",mt:2,children:e.jsx(Y,{isSoldOut:!1,isWishButtonShow:!1,onPurchaseButtonClick:i})})]})};function Re(){return e.jsxs(v,{item:!0,my:5,desktop:12,container:!0,justifyContent:"space-between",alignItems:"center",children:[e.jsx(c,{variant:"title",children:"장바구니"}),e.jsx(q,{spacing:2,children:e.jsxs(Le,{separator:e.jsx(Ce,{fontSize:"small"}),children:[e.jsx(c,{variant:"subtitle1",color:B,fontWeight:600,children:"01 장바구니"},1),e.jsx(c,{variant:"subtitle1",fontWeight:400,children:"02 주문서 작성/결제"},2),e.jsx(c,{variant:"subtitle1",fontWeight:400,children:"03 주문완료"},3)]})})]})}function Ue(){return j(D,t=>t.isLogin)?e.jsx(Fe,{}):e.jsx(Ge,{})}function Fe(){const s=j(N,a=>a.selectedCartNoList),{data:t}=X(s),{isDesktop:r,isMobile:n}=f();return e.jsxs(e.Fragment,{children:[r&&e.jsx(ae,{prePaidDeliveryAmt:t==null?void 0:t.totalPrePaidDeliveryAmt,productAmt:t==null?void 0:t.buyAmt,totalAmt:t==null?void 0:t.totalAmt}),n&&e.jsx(ce,{prePaidDeliveryAmt:t==null?void 0:t.totalPrePaidDeliveryAmt,productAmt:t==null?void 0:t.buyAmt,totalAmt:t==null?void 0:t.totalAmt})]})}function Ge(){const{selectedGuestCartItemList:s}=K(),{data:t}=T(s),{isDesktop:r,isMobile:n}=f();return e.jsxs(e.Fragment,{children:[r&&e.jsx(ae,{prePaidDeliveryAmt:t==null?void 0:t.price.totalDeliveryAmt,productAmt:t==null?void 0:t.price.buyAmt,totalAmt:t==null?void 0:t.price.totalAmt}),n&&e.jsx(ce,{prePaidDeliveryAmt:t==null?void 0:t.price.totalDeliveryAmt,productAmt:t==null?void 0:t.price.buyAmt,totalAmt:t==null?void 0:t.price.totalAmt})]})}function ae({productAmt:s,prePaidDeliveryAmt:t,totalAmt:r}){const{formatPriceWithCommas:n}=$();return e.jsx(h,{p:2,mb:5,display:"flex",justifyContent:"center",bgcolor:z,children:e.jsxs(q,{direction:"row",spacing:2,alignItems:"center",children:[e.jsx(c,{variant:"subtitle1",fontWeight:400,children:"상품금액 합계"}),e.jsx(c,{variant:"subtitle1",children:n(s!=null?s:0,"WON")}),e.jsx(Z,{fontSize:"small",sx:{border:"2px solid black",borderRadius:"50%"}}),e.jsx(c,{variant:"subtitle1",fontWeight:400,children:"배송비 합계"}),e.jsx(c,{variant:"subtitle1",children:n(t!=null?t:0,"WON")}),e.jsx(te,{fontSize:"small",sx:{border:"2px solid black",borderRadius:"50%"}}),e.jsx(c,{variant:"subtitle1",fontWeight:400,children:"총 결제금액"}),e.jsx(c,{variant:"subtitle1",children:n(r!=null?r:0,"WON")})]})})}function ce({productAmt:s,prePaidDeliveryAmt:t,totalAmt:r}){const{formatPriceWithCommas:n}=$();return e.jsxs(e.Fragment,{children:[e.jsx(Ne,{sx:{mb:4}}),e.jsx(h,{py:1,mb:4,display:"flex",justifyContent:"center",bgcolor:R,children:e.jsx(c,{variant:"subtitle1",children:"배송비 합계"})}),e.jsxs(h,{p:3,display:"flex",justifyContent:"center",flexDirection:"column",bgcolor:R,gap:1,children:[e.jsxs(h,{display:"flex",justifyContent:"space-between",children:[e.jsx(c,{variant:"subtitle1",children:"상품금액 합계"}),e.jsx(c,{variant:"subtitle1",children:n(s!=null?s:0,"WON")})]}),e.jsxs(h,{display:"flex",justifyContent:"space-between",children:[e.jsx(c,{variant:"subtitle1",children:"배송비 합계"}),e.jsxs(h,{display:"flex",alignItems:"center",gap:1,children:[e.jsx(Z,{fontSize:"small",sx:{border:"2px solid black",borderRadius:"50%"}}),e.jsx(c,{variant:"subtitle1",children:n(t!=null?t:0,"WON")})]})]}),e.jsxs(h,{display:"flex",justifyContent:"space-between",children:[e.jsx(c,{variant:"subtitle1",children:"총 결제금액"}),e.jsxs(h,{display:"flex",alignItems:"center",gap:1,children:[e.jsx(te,{fontSize:"small",sx:{border:"2px solid black",borderRadius:"50%"}}),e.jsx(c,{variant:"subtitle1",children:n(r!=null?r:0,"WON")})]})]})]})]})}function Xe(){return j(D,t=>t.isLogin)?e.jsx(ze,{}):e.jsx(_e,{})}function ze(){const{extractCartItemListFromDelivery:s,initializeSelectedCartNoList:t}=Q(),{data:r,isPending:n}=V(),a=L.useMemo(()=>s(r),[r]);return L.useEffect(()=>{a.length>0&&t(a)},[a,t]),e.jsx(le,{cartItemList:a,fetchCartData:r,isPending:n})}function _e(){const{validGuestCartItemList:s}=K(),{extractCartItemListFromDelivery:t,initializeSelectedCartNoList:r}=Q(),{data:n,isPending:a}=T(s),o=L.useMemo(()=>t(n),[n]);return L.useEffect(()=>{o.length>0&&r(o)},[n,r]),e.jsx(le,{cartItemList:o,fetchCartData:n,isPending:a})}function le({cartItemList:s,fetchCartData:t,isPending:r}){const{isMobile:n,isDesktop:a}=f();return e.jsxs(Se,{children:[e.jsxs(v,{item:!0,desktop:12,mobile:12,children:[a&&e.jsx(Re,{}),n&&e.jsx(Ie,{title:"장바구니"})]}),e.jsxs(v,{item:!0,desktop:12,mobile:11,py:2,mx:"auto",component:"section",children:[e.jsx(Me,{cartItemList:s,fetchCartData:t,isPending:r}),e.jsx(ke,{cartItemList:s})]}),e.jsx(v,{item:!0,desktop:12,mobile:11,mx:"auto",component:"section",children:t&&t.deliveryGroups.length>0&&e.jsx(Ue,{})}),e.jsx(v,{item:!0,desktop:12,mobile:12,mx:"auto",component:"section",children:t&&t.deliveryGroups.length>0&&e.jsx(Ee,{})})]})}export{Xe as default};