import{r as u,j as t}from"./react-WWJ_A68P.js";import{p as N,s as pt,m as S,b as et,o as y,f as K,t as T,n as j,e as z,i as U,H as ct,z as At,E as kt}from"./@fxts-cXD7MMns.js";import{u as Dt,k as wt,d as _,a as mt}from"./@tanstack-BR86rpua.js";import{i as St}from"./axios-Da_2YOEl.js";import{L as Q}from"./react-router-dom-B4YB8MrN.js";import{$ as G,a0 as Y,a1 as Tt,a as D,f as lt,w as xt,u as nt,x as Et,K as O,a2 as Z,a3 as dt,z as Ot,b as ht,a4 as ot,a5 as rt,P as E,a6 as $t,c as Mt,C as It,a7 as zt,U as Bt,a8 as Gt,a9 as X,aa as tt}from"./index-BPJ5U2d6.js";import"./dayjs-CZ9ViMNG.js";import{i as Ht}from"./usehooks-ts-CCkIaz9n.js";import{S as Rt}from"./index-3cBPcmMA.js";import{d as n,l as Vt}from"./styled-components-BHeWolSk.js";import{S as Wt,a as Ut}from"./plus-black-DWz4trt7.js";import{c as Zt}from"./react-select-CI241hL_.js";import{F as Ft}from"./index-dD61-Ci-.js";import{u as qt}from"./useProductListByProductNos-DPsS3tCs.js";import{S as B}from"./line-style-dot-gray-BRuOHXOD.js";import{S as ut}from"./warning-round-small-gray-DostLkGx.js";import{u as Kt}from"./useDeactivateCheck-DSrGULYL.js";import{a as _t}from"./react-router-BOGNRwMt.js";import"./call-bind-oCmkau44.js";import"./get-intrinsic-BKEvijrG.js";import"./es-errors-DzOT6E3C.js";import"./has-symbols-eVqrYdw7.js";import"./has-proto-JnoBQRdH.js";import"./function-bind-BbkWVFrm.js";import"./hasown-DYqjtFKE.js";import"./set-function-length-B5OANX0j.js";import"./define-data-property-DO9o5wXF.js";import"./es-define-property-tzmkNPou.js";import"./gopd-CEkvUycD.js";import"./has-property-descriptors-DphFXkuo.js";import"./react-dom-CvjNlBjt.js";import"./scheduler-CzFDRTuY.js";import"./@remix-run-DhIrJP8L.js";import"./react-helmet-async-jeYtsOp6.js";import"./react-fast-compare-Dxyd5FYM.js";import"./invariant-Bm-uj-iG.js";import"./shallowequal-F1vAqOm6.js";import"./react-redux-DlpFpBQ0.js";import"./use-sync-external-store-KK8Bpy9o.js";import"./redux-persist-Cbb21slr.js";import"./redux-DITMfSWq.js";import"./framer-motion-DbOul5S8.js";import"./crypto-js-C0tVhymU.js";import"./universal-cookie-Cmu-M0pA.js";import"./react-error-boundary-DEyRbsfJ.js";import"./dompurify-CqxHTgmJ.js";import"./react-device-detect-BAEcyX2V.js";import"./ua-parser-js-BBZA8f28.js";import"./qs-LNWgR29u.js";import"./side-channel-CpYS7sho.js";import"./object-inspect-CL2AiSqO.js";import"./@reduxjs-DYPsSoVN.js";import"./immer-DqxjFn0G.js";import"./redux-thunk-ClJT1hhx.js";import"./redux-logger-B8JP_rc7.js";import"./qrcode.react-CJWQPexu.js";import"./swiper-DLv7ejQn.js";import"./@hookform-Dc6jS12O.js";import"./react-hook-form-BJXGuiwr.js";import"./@marsidev-F19kFZ1X.js";import"./currency.js-9OAR_aOO.js";import"./styled-reset-B7ZXsPC1.js";/* empty css */import"./@emotion-DwO3GsBP.js";import"./hoist-non-react-statics-Buxaj0Kl.js";import"./react-is-8JwjhRSi.js";import"./stylis-YPZU7XtI.js";import"./lodash.debounce-CDHjgjOA.js";import"./@babel-CabbEptY.js";import"./@floating-ui-NvD4EidW.js";import"./use-isomorphic-layout-effect-MPmsYcaj.js";import"./memoize-one-BdPwpGay.js";const Qt=({params:i,memberNo:x,options:g})=>Dt({queryKey:G.price(x,i),queryFn:async()=>{const{data:r}=await Y.getSelectedCartPrice(i);return r},placeholderData:wt,...g}),Yt=()=>{const{mutateAsync:i}=_({mutationFn:async({checkedCartList:x,divideInvalidProducts:g=!0})=>await Tt.getCart(x,{divideInvalidProducts:g})});return{guestCartCalculate:i}},Jt=n.div` background: #f2f3f5; `,Xt=n.div` padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; background: #fff; `,te=n.button` display: flex; align-items: center; > svg { margin-right: 6px; width: 22px; height: 22px; } > span { color: #202020; font-size: 1.4rem; } `,ee=n.div``,oe=n.button` ${D.medium}; font-size: 1.4rem; `,re=n.ul` margin-bottom: 8px; `,ne=n.li` background: #fff; &:not(:last-child) { margin-bottom: 8px; } `,ie=n.div``,se=n.div` display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #f2f3f5; `,ae=n.div` display: flex; align-items: center; justify-content: space-between; > button { margin-right: 6px; > svg { width: 22px; height: 22px; } } > a { color: var(--color-textPrimary); font-size: 1.46em; ${D.bold}; } `,ce=n.button` > svg { margin-right: 8px; } `,le=n.ul` padding: 0 20px; `,de=n.li` display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 0 20px; border-bottom: 1px solid #f2f3f5; `,ue=n.div` width: 30px; `,pe=n.div` width: calc(100% - 30px); `,me=n.div` display: flex; justify-content: start; align-items: flex-start; width: 100%; margin-bottom: 16px; `,xe=n.div` margin-right: 10px; img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; } `,he=n.div` width: calc(100% - 75px); `,fe=n.p` font-size: 1.5rem; color: var(--color-textPrimary); margin-bottom: 8px; `,Ce=n.p` color: var(--color-textGray); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.4rem; `,ge=n.div``,ye=n.div` &:not(:last-child) { margin-bottom: 20px; } `,je=n.div` margin-bottom: 10px; `,Ne=n.div` display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; `,Pe=n.div` color: var(--color-textDarkGray); font-size: 1.4rem; `,be=n.button` flex-shrink: 0; color: var(--color-textGray); font-size: 1.3rem; text-decoration: underline; opacity: ${i=>i.disabled?"0.5":"1"}; `,Le=n.div``,ve=n.div` display: flex; justify-content: space-between; align-items: center; `,Ae=n.div``,ke=n.div` border: 1px solid #e9eaef; border-radius: 6px; background-color: #fff; ${lt}; padding: 6px; gap: 4px; > * { ${lt}; flex: 1; } input { text-align: center; } `,De=n.span` font-size: 1.4rem; color: var(--color-textPrimary); `,we=n.div` display: flex; justify-content: space-between; align-items: center; padding: 20px; `,Se=n.span` color: var(--color-textPrimary); font-size: 1.6rem; `,Te=n.span` font-size: 1.6rem; ${D.bold}; color: var(--color-textPrimary); `,Ee=n.span` font-size: 1.6rem; color: var(--color-highlight); `,Oe=n.div` background: #fff; `,$e=n.div``,Me=n.div` padding: 20px; margin-bottom: 12px; `,Ie=n.ul` li { display: flex; justify-content: space-between; align-items: center; &:not(:last-child) { margin-bottom: 12px; } } `,ze=n.div` font-size: 1.6rem; color: ${({$isEmphasize:i})=>i?"var(--color-highlight)":"var(--color-textPrimary)"}; `,Be=n.div` display: flex; justify-content: space-between; color: var(--color-textSecondary); padding: 18.5px 20px; `,Ge=n.span` font-size: 1.8rem; ${D.bold}; `,He=n.span` font-size: 2.2rem; ${D.extraBold}; letter-spacing: -0.5px; span { font-size: 1.6rem; letter-spacing: 0; ${D.medium}; } `,Re=n.div` padding: 0 20px 13px; > div { padding: 16px; background: #f6f6fa; border-radius: 8px; border: 1px solid #e9eaef; } `,Ve=n.span` font-size: 1.3rem; ${D.bold}; color: var(--color-textGray); margin-bottom: 8px; display: flex; align-items: end; > svg { margin-right: 4px; } `,We=n.ul` font-size: 1.2rem; color: var(--color-textGray); li { display: flex; align-items: flex-start; &:not(:last-child) { margin-bottom: 4px; } } b { ${D.bold}; color: var(--color-textGray); } `,Ue=n.div` border-top: 1px solid #f2f3f5; padding: 12px; background: #fff; `,Ze=n.button` width: 100%; height: 52px; background: #0d0f71; color: #fff; text-align: center; font-size: 1.6rem; ${D.medium}; border-radius: 8px; opacity: ${i=>i.disabled&&"0.7"}; cursor: ${i=>i.disabled&&"not-allowed"}; `,Fe=n.div` background-color: #fff; padding-top: 162px; `,qe=n.div` margin-bottom: 162px; padding: 0 20px; text-align: center; > svg { margin-bottom: 16px; } > p { color: var(--color-textLightGray); font-size: 1.8rem; } `,Ke=n(Q)` color: #fff; background: #0d0f71; padding: 13.5px 16px; border-radius: 24px; margin: 32px auto 0; width: fit-content; ${D.medium}; font-size: 1.6rem; `,_e=n.p` font-size: 1.5rem; ${D.regular}; white-space: nowrap; overflow: auto hidden; -ms-overflow-style: none; // IE, Edge scrollbar-width: none; // Firefox ::-webkit-scrollbar { display: none; // Chrome, Safari } color: var(--color-textPrimary); ${i=>i.$isDisabled&&Vt` & { color: var(--color-textLightGray) !important; } `} `,o={Container:Jt,CartHeader:Xt,SelectAllButton:te,CartListSection:ee,DeleteSelectedCartButton:oe,DeliveryGroupContainer:ie,DeliveryGroupList:re,DeliveryGroupListItem:ne,DeliveryGroupHeader:se,SelectDeliveryGroupButton:ae,DeleteSelectedDeliveryButton:ce,ProductList:le,ProductListItem:de,ProductCheckbox:ue,ProductContainer:pe,ProductInfoContainer:me,ProductImage:xe,ProductInfo:he,ProductName:fe,ProductDeliveryPrice:Ce,ProductOptionContainer:ge,CartOptionList:ye,ProductOptionLabelContainer:je,ProductOptionHeader:Ne,ProductOptionLabel:Pe,DeleteOptionButton:be,ProductOptionSelectContainer:Le,ProductPriceContainer:ve,ProductCountContainer:Ae,ProductCount:ke,ProductTotalPrice:De,DeliveryGroupPriceInfo:we,DeliveryGroupPriceTitle:Se,DeliveryGroupPrice:Te,CategoryText:Ee,PriceContainer:$e,CartFooter:Oe,PriceCategoryContainer:Me,PriceCategoryList:Ie,PriceCategory:ze,TotalPriceContainer:Be,TotalPriceTitle:Ge,TotalPrice:He,WarningTextContainer:Re,WarningTitle:Ve,WarningTextList:We,PurchaseContainer:Ue,PurchaseButton:Ze,EmptyCartContainer:Fe,EmptyMessageContainer:qe,GoRankingPageButton:Ke,FormatOptionLabel:_e},Qe=({label:i,disabled:x,changeCartCount:g,orderProductOption:r,updateOption:v,deleteOption:h})=>{var F,q,R,V;const[m,P]=u.useState(r.orderCnt),f=xt(),{isLogin:k}=nt();u.useEffect(()=>{P(r.orderCnt)},[r.orderCnt]);const b=Ht(g,400),A=()=>{if(m!==1){if(k){P(a=>a>1?(b(r.cartNo,a-1),Z({productNo:r.productNo,count:a-1}),a-1):(b(r.cartNo,a),Z({productNo:r.productNo,count:a}),a));return}f(dt({optionNo:r.optionNo,orderCnt:m-1})),Z({productNo:r.productNo,count:m-1}),P(a=>a-1)}},p=()=>{if(k){P(a=>(b(r.cartNo,a+1),Z({productNo:r.productNo,count:a+1}),a+1));return}f(dt({optionNo:r.optionNo,orderCnt:m+1})),Z({productNo:r.productNo,count:m+1}),P(a=>a+1)},[H,$]=u.useState(null),d=Et({productNo:r.productNo,options:{enabled:!0}});u.useEffect(()=>{var I;if(!((I=d.data)!=null&&I.flatOptions))return;const a=d.data.flatOptions.find(W=>W.optionNo===r.optionNo);$(a||null)},[r.optionNo,(F=d.data)==null?void 0:F.flatOptions]);const C=(((R=(q=d.data)==null?void 0:q.flatOptions)==null?void 0:R.length)??0)>1,M=a=>t.jsx(Zt.SingleValue,{...a,children:t.jsx(o.FormatOptionLabel,{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:a.data.value})});return t.jsxs(o.CartOptionList,{children:[C&&t.jsxs(o.ProductOptionLabelContainer,{children:[t.jsxs(o.ProductOptionHeader,{children:[t.jsx(o.ProductOptionLabel,{children:i}),t.jsx(o.DeleteOptionButton,{type:"button",onClick:()=>h(r),disabled:x,"aria-label":`${i} 삭제`,children:"삭제"})]}),t.jsx(o.ProductOptionSelectContainer,{children:t.jsx(Rt,{name:"type",placeholder:r.optionValue,options:((V=d.data)==null?void 0:V.flatOptions)||[],getOptionLabel:a=>a.value,getOptionValue:a=>a.optionNo.toString(),value:H,isDisabled:!k,onChange:a=>{a&&v(a)},isOptionDisabled:a=>"stockCnt"in a&&a.saleType==="SOLDOUT",formatOptionLabel:a=>{const I="stockCnt"in a&&a.saleType==="SOLDOUT";return t.jsx(o.FormatOptionLabel,{$isDisabled:"stockCnt"in a&&a.saleType==="SOLDOUT",children:I?`(품절) ${a.value}`:a.value})},components:{SingleValue:M}})})]}),!C&&t.jsxs(o.ProductOptionHeader,{children:[t.jsx(o.ProductOptionLabel,{children:i}),t.jsx(o.DeleteOptionButton,{type:"button",onClick:()=>h(r),disabled:x,"aria-label":`${i} 삭제`,children:"삭제"})]}),t.jsxs(o.ProductPriceContainer,{children:[t.jsx(o.ProductCountContainer,{children:t.jsxs(o.ProductCount,{children:[t.jsx("button",{onClick:A,disabled:x,children:t.jsx(Wt,{})}),t.jsx("div",{children:t.jsx("input",{size:2,type:"text",value:m,readOnly:!0})}),t.jsx("button",{onClick:p,disabled:x,children:t.jsx(Ut,{})})]})}),t.jsx(o.ProductTotalPrice,{children:O(r.price.buyAmt).format()})]})]})},Ye=()=>{const[i,x]=u.useState(!1),{mutateAsync:g}=_({mutationFn:async m=>await Y.deleteCart(m)}),{mutateAsync:r}=Ot(),v=mt();return{updateCart:async({cartNo:m,orderCnt:P,optionNo:f,optionInputs:k,productNo:b})=>{try{x(!0),await g({cartNo:[m]}),await r([{productNo:b,orderCnt:P,optionNo:f,optionInputs:k}]),v.invalidateQueries({predicate:A=>[...G.all,"cartCount"].includes(A.queryKey[0])})}catch(A){console.error(A),alert("장바구니 수정에 실패했습니다.")}finally{x(!1)}},isLoading:i}},Je=({orderProduct:i,checkCart:x,isCartChecked:g,deliveryCondition:r,changeCartCount:v,cartDeliveryFeeList:h,disabled:m,deleteOption:P})=>{const{openDialog:f}=ht(),{isLogin:k}=nt(),{updateCart:b}=Ye(),A=d=>C=>{if(N(i.orderProductOptions,y("optionNo"),et(C.optionNo))){f("이미 선택된 옵션입니다.");return}if(k){b({orderCnt:d.orderCnt,optionInputs:d.optionInputs,productNo:d.productNo,cartNo:d.cartNo,optionNo:C.optionNo});return}f("비회원은 옵션 변경이 불가능합니다.")},p=h.find(d=>d.productNo===i.productNo),H=N(i.orderProductOptions,S(d=>d.price.buyAmt),pt),$=()=>{const d=()=>(p==null?void 0:p.deliveryAmt)===0||r.deliveryAmt===0||(p==null?void 0:p.deliveryConditionType)==="CONDITIONAL"&&H>=r.aboveDeliveryAmt,C=d()?"무료 배송":`배송비 ${O((p==null?void 0:p.deliveryAmt)||0).format()}`,M=d()?"":(p==null?void 0:p.deliveryConditionType)==="CONDITIONAL"?` (${O(r.aboveDeliveryAmt).format()} 이상 무료배송)`:"";return C+M};return t.jsx(o.ProductList,{children:t.jsxs(o.ProductListItem,{children:[t.jsx(o.ProductCheckbox,{children:t.jsx("button",{onClick:()=>x(i.productNo),children:g?t.jsx(ot,{}):t.jsx(rt,{})})}),t.jsxs(o.ProductContainer,{children:[t.jsxs(o.ProductInfoContainer,{children:[t.jsx(o.ProductImage,{children:t.jsx(Q,{to:`${E.PRODUCT.LIST}/${i.productNo}`,children:t.jsx("img",{src:i.imageUrl,alt:"상품 사진"})})}),t.jsxs(o.ProductInfo,{children:[t.jsx(o.ProductName,{children:t.jsx(Q,{to:`${E.PRODUCT.LIST}/${i.productNo}`,children:i.productName})}),t.jsx(o.ProductDeliveryPrice,{children:$()})]})]}),t.jsx(o.ProductOptionContainer,{children:i.orderProductOptions.map((d,C)=>t.jsx(Qe,{label:`선택 ${C+1}`,disabled:m,changeCartCount:v,orderProductOption:d,updateOption:A(d),deleteOption:P},d.optionNo))})]})]})})},Xe=(i,x)=>{const g=[];let r=[];const v=h=>x&&x.length>0?!!K(m=>m.productNo===h,x):!0;return i.forEach(h=>{h.orderProducts.forEach(m=>{r.push({...m,isChecked:v(m.productNo),brandName:m.brandName,deliveryAmt:h.deliveryAmt})}),g.push({...h,orderProducts:r}),r=[]}),g},to=i=>u.createElement("svg",{width:65,height:64,viewBox:"0 0 65 64",fill:"none",xmlns:"http://www.w3.org/2000/svg",...i},u.createElement("g",{clipPath:"url(#clip0_6863_21648)"},u.createElement("path",{d:"M2.53906 6C1.43449 6 0.539062 6.89543 0.539062 8C0.539062 9.10457 1.43449 10 2.53906 10V6ZM11.0111 8L12.9859 7.68306C12.8302 6.71325 11.9934 6 11.0111 6V8ZM59.3993 18.0916L61.3809 18.362C61.459 17.7897 61.2858 17.2116 60.906 16.7765C60.5262 16.3413 59.9768 16.0916 59.3993 16.0916V18.0916ZM56.3619 40.3525L54.3802 40.0821L56.3619 40.3525ZM16.2111 40.399L14.2364 40.716L16.2111 40.399ZM2.53906 10H11.0111V6H2.53906V10ZM18.1858 44.0821H54.3802V40.0821H18.1858V44.0821ZM58.3435 40.6229L61.3809 18.362L57.4176 17.8212L54.3802 40.0821L58.3435 40.6229ZM59.3993 16.0916H35.7194V20.0916H59.3993V16.0916ZM9.0364 8.31694L14.2364 40.716L18.1858 40.0821L12.9859 7.68306L9.0364 8.31694ZM35.7194 16.0916H13.0559V20.0916H35.7194V16.0916ZM54.3802 44.0821C56.3804 44.0821 58.0731 42.6047 58.3435 40.6229L54.3802 40.0821V44.0821ZM18.1858 40.0821L18.1858 40.0821L14.2364 40.716C14.5477 42.6556 16.2214 44.0821 18.1858 44.0821V40.0821Z",fill:"#E9EAEF"}),u.createElement("path",{d:"M25.8788 59.5277C28.5906 59.5277 30.7889 57.3294 30.7889 54.6176C30.7889 51.9058 28.5906 49.7075 25.8788 49.7075C23.1671 49.7075 20.9688 51.9058 20.9688 54.6176C20.9688 57.3294 23.1671 59.5277 25.8788 59.5277Z",stroke:"#E9EAEF",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{d:"M46.8671 59.5277C49.5789 59.5277 51.7772 57.3294 51.7772 54.6176C51.7772 51.9058 49.5789 49.7075 46.8671 49.7075C44.1554 49.7075 41.957 51.9058 41.957 54.6176C41.957 57.3294 44.1554 59.5277 46.8671 59.5277Z",stroke:"#E9EAEF",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round"})),u.createElement("defs",null,u.createElement("clipPath",{id:"clip0_6863_21648"},u.createElement("rect",{width:64,height:64,fill:"white",transform:"translate(0.5)"})))),eo=i=>u.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...i},u.createElement("path",{d:"M18 18L6 6",stroke:"#84858A",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{d:"M18 6L5.99997 18",stroke:"#84858A",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})),Nr=()=>{Kt();const{openDialog:i}=ht(),x=_t(),g=mt(),[r,v]=u.useState(null),{cartInfo:h,refetch:m}=$t(),P=xt(),{isLogin:f}=nt(),{data:k}=Mt(),[b,A]=u.useState({standardAmt:0,totalDeliveryAmt:0,totalDiscountPrice:0,totalAccumulation:0,totalAmt:0,buyAmt:0}),p=u.useMemo(()=>N(r??[],y("orderProducts"),j,z(e=>e.isChecked),y("orderProductOptions"),j,S(e=>({cartNo:e.cartNo,optionInputs:e.optionInputs,optionNo:e.optionNo,orderCnt:e.orderCnt,productNo:e.productNo})),T),[r]);u.useEffect(()=>{h!=null&&h.deliveryGroups&&v(Xe(h.deliveryGroups,p))},[h==null?void 0:h.deliveryGroups]);const H=N(r??[],y("orderProducts"),j,y("orderProductOptions"),j,S(e=>e.productNo),T),$=qt({searchParams:{productNos:H},options:{select:e=>N(e.products,S(s=>({...s.deliveryFee,productNo:s.baseInfo.productNo})),T)}}),d=u.useMemo(()=>N(r??[],y("orderProducts"),j,z(e=>e.isChecked),y("orderProductOptions"),j,S(e=>f?e.cartNo:e.optionNo),T),[f,r]),{data:C}=Qt({params:{cartNo:d,divideInvalidProducts:!0},memberNo:(k==null?void 0:k.memberNo)||0,options:{enabled:f}}),M=e=>{v(s=>{const c=[];let l=[];return s==null||s.forEach(L=>{L.orderProducts.forEach(w=>{l.push({...w,isChecked:e})}),c.push({...L,orderProducts:l}),l=[]}),c})},F=({partnerNo:e},s)=>{v(c=>{if(!c)return[];const l=[];let L=[];return c.forEach(w=>{w.orderProducts.forEach(at=>{w.partnerNo===e?L.push({...at,isChecked:s}):L.push(at)}),l.push({...w,orderProducts:L}),L=[]}),l})},q=e=>{v(s=>{if(!s)return[];const c=[];let l=[];return s.forEach(L=>{L.orderProducts.forEach(w=>{w.productNo===e?l.push({...w,isChecked:!w.isChecked}):l.push(w)}),c.push({...L,orderProducts:l}),l=[]}),c})},R=u.useMemo(()=>U(r)?!1:N(r,y("orderProducts"),j,ct(e=>e.isChecked)),[r]),V=({partnerNo:e})=>{const s=N(r??[],z(c=>c.partnerNo===e),y("orderProducts"),j,T);return U(s)?!1:ct(c=>c.isChecked,s)},a=e=>!!N(r||[],y("orderProducts"),j,K(s=>s.productNo===e&&s.isChecked)),I=e=>K(c=>c.partnerNo===e,r||[])?N(r||[],z(c=>c.partnerNo===e),y("orderProducts"),j,z(c=>c.isChecked),y("orderProductOptions"),j,S(c=>c.price.buyAmt),pt):0,W=u.useMemo(()=>r?U(r)?"EMPTY_CART":"CART":"LOADING",[r]),{guestCartCalculate:it}=Yt();u.useEffect(()=>{if(f){if(!C){A({standardAmt:0,totalDeliveryAmt:0,totalDiscountPrice:0,totalAmt:0,totalAccumulation:0,buyAmt:0});return}if(U(d)){A({standardAmt:0,totalDeliveryAmt:0,totalDiscountPrice:0,totalAmt:0,totalAccumulation:0,buyAmt:0});return}A({standardAmt:C.standardAmt,totalDeliveryAmt:C.totalDeliveryAmt,totalDiscountPrice:C.discountAmt,totalAmt:C.totalAmt,totalAccumulation:C.accumulationAmtWhenBuyConfirm,buyAmt:C.buyAmt})}},[C,f,d]),u.useEffect(()=>{f||it({checkedCartList:p},{onSuccess:({data:e})=>{A({standardAmt:e.price.standardAmt,totalDeliveryAmt:e.price.totalDeliveryAmt,totalDiscountPrice:e.price.discountAmt,totalAmt:e.price.totalAmt,totalAccumulation:e.price.accumulationAmtWhenBuyConfirm,buyAmt:e.price.buyAmt})}})},[f,p,it]);const{mutateAsync:J,isPending:ft}=_({mutationFn:async e=>await Y.deleteCart(e),onSuccess:async e=>{e.status===Gt.HTTP_OK?(await i("선택된 상품을 장바구니에서 삭제하였습니다."),g.invalidateQueries({predicate:s=>[...G.all,"cartCount"].includes(s.queryKey[0])})):await i("장바구니 삭제시 오류가 발생하였습니다. 관리자에게 문의해주세요.")},onError:()=>{}}),Ct=async({partnerNo:e})=>{const s=N(r??[],z(l=>l.partnerNo===e),y("orderProducts"),j,y("orderProductOptions"),j,S(l=>({cartNo:l.cartNo,optionInputs:l.optionInputs,optionNo:l.optionNo,orderCnt:l.orderCnt,count:l.orderCnt,productNo:l.productNo})),T),c=N(s,S(l=>f?l.cartNo:l.optionNo),T);X({productList:s}),f?await J({cartNo:c}):(P(tt({deleteList:c})),await i("선택한 상품을 장바구니에서 삭제하였습니다."),m())},gt=async()=>{if(p.length===0){i("선택된 상품이 없습니다.");return}const e=N(p,S(s=>({...s,count:s.orderCnt})),T);X({productList:e}),f?await J({cartNo:d}):P(tt({deleteList:d})),await g.invalidateQueries({queryKey:G.all})},yt=async e=>{const{cartNo:s,optionNo:c,orderCnt:l,productNo:L}=e;if(X({productList:[{productNo:L,count:l}]}),f){await J({cartNo:[s]}),await g.invalidateQueries({queryKey:G.all});return}P(tt({deleteList:[c]})),await i("선택한 옵션을 장바구니에서 삭제하였습니다."),m()},st=_({mutationFn:async e=>await Y.updateCart(e),onError:e=>{var s;St(e)&&i(((s=e.response)==null?void 0:s.data.message)??"장바구니 수정에 실패했습니다.")}}),jt=(e,s)=>{const c=N(r||[],y("orderProducts"),j,y("orderProductOptions"),j,K(l=>l.cartNo===e));kt(c)||st.mutate([{cartNo:c.cartNo,orderCnt:s,optionInputs:c.optionInputs}],{onSuccess:()=>{g.invalidateQueries({predicate:l=>et(l.queryKey[0],[...G.all])})}})},Nt=(e,s)=>{jt(e,s)},{write:{mutate:Pt,isPending:bt}}=It(),Lt=u.useMemo(()=>N(p,S(e=>({productNo:e.productNo,optionNo:e.optionNo,orderCnt:e.orderCnt,optionInputs:e.optionInputs})),T),[p]),vt=()=>{if(U(p)){i("1개 이상의 상품을 선택해주세요.");return}Pt({data:{products:Lt,productCoupons:[],cartNos:d,trackingKey:""}},{onSuccess:({data:e})=>{f?x({pathname:`${E.ORDER.MAIN}/${e.orderSheetNo}`}):x({pathname:E.AUTH.LOGIN,search:`returnUrl=${E.ORDER.MAIN}/${e.orderSheetNo}`},{state:{type:"guestOrder"}})},onError:async e=>{var s,c,l;if(e.isAxiosError){if(((s=e.response)==null?void 0:s.data.code)==="PPVE0004"){await i("비회원 구매 불가 상품입니다.
로그인 후 구매해주세요.",[{type:"cancel",label:"닫기"},{type:"ok",label:"로그인"}])&&x(`${E.AUTH.LOGIN}?returnUrl=${window.location.pathname}`);return}et((c=e.response)==null?void 0:c.data.code,["O3336","O3338"])||await i(((l=e.response)==null?void 0:l.data.message)??"알수 없는 오류가 발생했습니다."),m();return}else i(e.message??"알수 없는 오류가 발생했습니다.")}})};return zt({cart:h}),t.jsxs(o.Container,{children:[W==="LOADING"&&t.jsx("div",{children:t.jsx(Bt,{})}),W==="CART"&&t.jsxs(t.Fragment,{children:[t.jsxs(o.CartHeader,{children:[t.jsxs(o.SelectAllButton,{onClick:()=>M(!R),children:[R?t.jsx(ot,{}):t.jsx(rt,{}),t.jsx("span",{children:"전체선택"})]}),t.jsx(o.DeleteSelectedCartButton,{onClick:gt,children:"선택 삭제"})]}),t.jsx(o.CartListSection,{children:t.jsx(o.DeliveryGroupList,{children:r==null?void 0:r.map(e=>t.jsx(o.DeliveryGroupListItem,{children:t.jsxs(o.DeliveryGroupContainer,{children:[t.jsxs(o.DeliveryGroupHeader,{children:[t.jsxs(o.SelectDeliveryGroupButton,{children:[t.jsx("button",{onClick:()=>F({partnerNo:e.partnerNo},!V(e)),children:V(e)?t.jsx(ot,{}):t.jsx(rt,{})}),t.jsx(Q,{to:e.partnerNo?`${E.PRODUCT.PARTNER.MAIN}/${e.partnerNo}`:"",state:{partnerNo:e.partnerNo,partnerName:e.partnerName},children:e.partnerName})]}),t.jsx(o.DeleteSelectedDeliveryButton,{onClick:()=>Ct({partnerNo:e.partnerNo}),children:t.jsx(eo,{})})]}),e.orderProducts.map(s=>t.jsx(Je,{orderProduct:s,checkCart:q,isCartChecked:a(s.productNo),deliveryCondition:e.deliveryCondition,changeCartCount:Nt,deleteOption:c=>yt(c),disabled:st.isPending||ft,cartDeliveryFeeList:($==null?void 0:$.data)||[]},s.productNo)),t.jsxs(o.DeliveryGroupPriceInfo,{children:[t.jsx(o.DeliveryGroupPriceTitle,{children:"상품 금액"}),t.jsxs(o.DeliveryGroupPrice,{children:[At(e.partnerNo)?0:O(I(e.partnerNo)).format()," "]})]})]})},`${e.deliveryTemplateNo}${e.partnerNo}`))})}),t.jsxs(o.CartFooter,{children:[t.jsxs(o.PriceContainer,{children:[t.jsx(o.PriceCategoryContainer,{children:t.jsxs(o.PriceCategoryList,{children:[t.jsxs("li",{children:[t.jsx(o.PriceCategory,{children:"총 상품금액"}),t.jsx(o.PriceCategory,{children:O(b.standardAmt).format()})]}),t.jsxs("li",{children:[t.jsx(o.PriceCategory,{children:"총 할인금액"}),t.jsxs(o.PriceCategory,{$isEmphasize:!0,children:[b.totalDiscountPrice>0&&"- ",O(b.totalDiscountPrice).format()]})]}),t.jsxs("li",{children:[t.jsx(o.PriceCategory,{children:"총 배송비"}),t.jsx(o.PriceCategory,{$isEmphasize:!0,children:O(b.totalDeliveryAmt).format()})]})]})}),t.jsxs(o.TotalPriceContainer,{children:[t.jsx(o.TotalPriceTitle,{children:"총 결제 예상 금액"}),t.jsx(o.TotalPrice,{dangerouslySetInnerHTML:{__html:O(b.totalAmt).format({symbol:"원",pattern:"#원"})}})]})]}),t.jsx(o.WarningTextContainer,{children:t.jsxs("div",{children:[t.jsxs(o.WarningTitle,{children:[t.jsx(ut,{})," 유의 사항"]}),t.jsxs(o.WarningTextList,{children:[t.jsxs("li",{children:[t.jsx(B,{}),t.jsxs("p",{children:["장바구니는 ",t.jsx("b",{children:"30일간 보관"}),"되며, 상품의 판매 종료 또는 품절시"," ",t.jsx("b",{children:"자동 삭제"})," 됩니다."]})]}),t.jsxs("li",{children:[t.jsx(B,{}),t.jsx("p",{children:"계속 보관을 원하시면 찜 기능을 이용해보세요."})]}),t.jsxs("li",{children:[t.jsx(B,{}),t.jsx("p",{children:t.jsx("b",{children:"묶음 결제 후 부분 취소 시 결제 금액 환불은 카드사의 정책으로 익일에 적용됩니다."})})]})]})]})}),t.jsx(Ft,{buttonList:[{children:"구매하기",onClick:vt,isLoadingDisabled:bt}]})]})]}),W==="EMPTY_CART"&&t.jsxs(o.EmptyCartContainer,{children:[t.jsxs(o.EmptyMessageContainer,{children:[t.jsx(to,{}),t.jsx("p",{children:"장바구니가 비어있어요"}),t.jsx(o.GoRankingPageButton,{to:E.BEST,children:"마켓 랭킹 보기"})]}),t.jsx(o.WarningTextContainer,{children:t.jsxs("div",{children:[t.jsxs(o.WarningTitle,{children:[t.jsx(ut,{})," 유의 사항"]}),t.jsxs(o.WarningTextList,{children:[t.jsxs("li",{children:[t.jsx(B,{}),t.jsxs("p",{children:["장바구니는 ",t.jsx("b",{children:"30일간 보관"}),"되며, 상품의 판매 종료 또는 품절시"," ",t.jsx("b",{children:"자동 삭제"})," 됩니다."]})]}),t.jsxs("li",{children:[t.jsx(B,{}),t.jsx("p",{children:"계속 보관을 원하시면 찜 기능을 이용해보세요."})]}),t.jsxs("li",{children:[t.jsx(B,{}),t.jsx("p",{children:t.jsx("b",{children:"묶음 결제 후 부분 취소 시 결제 금액 환불은 카드사의 정책으로 익일에 적용됩니다."})})]})]})]})})]})]})};export{Nr as default};