import{j as e,h as Q,f as M,l as B,c as G,m as V,b as _,g as b}from"./main-7700519c.js";import{r as Y}from"./chunk-react-caacd912.js";import{B as H,a as W,b as z,c as q}from"./chunk-index-69956742.js";import{m as v,G as r,n as o,B as l,C as K,E as J,J as Z}from"./chunk-material-ui-241eb317.js";const $=v(t=>({skeletonWrapper:{"&:not(:last-child)":{paddingBottom:15,marginBottom:15,borderBottom:"0.5px solid #E0E3E6"}},image:{width:128,height:160,backgroundColor:t.color.black20},textHeader:{width:174,height:22,backgroundColor:t.color.black20},textInfo:{width:94,height:14,backgroundColor:t.color.black20},textPrice:{width:74,height:22,backgroundColor:t.color.black20},btnQuantity:{width:80,height:32,backgroundColor:t.color.black20},skeletonItem:{display:"flex",flexDirection:"column",flexWrap:"wrap"},itemDescription:{flexGrow:2,"& > *:not(:last-child)":{marginBottom:15}},itemPrice:{flexGrow:0}}),{name:"CartSkeleton"});function X(){const t=$();return e.jsxs(r,{container:!0,item:!0,children:[e.jsx(r,{item:!0,xl:12,lg:12,sm:12,md:12,xs:12,classes:{root:t.skeletonWrapper},children:e.jsxs(r,{container:!0,item:!0,spacing:3,children:[e.jsx(r,{item:!0,xl:"auto",children:e.jsx(o,{classes:{root:t.image},variant:"rect",animation:"wave"})}),e.jsxs(r,{item:!0,xl:6,classes:{root:t.skeletonItem},children:[e.jsxs(l,{className:t.itemDescription,children:[e.jsx(o,{classes:{root:t.textHeader},variant:"rect",animation:"wave"}),e.jsx(o,{classes:{root:t.textInfo},variant:"rect",animation:"wave"}),e.jsx(o,{classes:{root:t.btnQuantity},variant:"rect",animation:"wave"})]}),e.jsx(l,{className:t.itemPrice,children:e.jsx(o,{classes:{root:t.textPrice},variant:"rect",animation:"wave"})})]})]})}),e.jsx(r,{item:!0,xl:12,lg:12,sm:12,md:12,xs:12,classes:{root:t.skeletonWrapper},children:e.jsxs(r,{container:!0,item:!0,spacing:3,children:[e.jsx(r,{item:!0,xl:"auto",children:e.jsx(o,{classes:{root:t.image},variant:"rect",animation:"wave"})}),e.jsxs(r,{item:!0,xl:6,classes:{root:t.skeletonItem},children:[e.jsxs(l,{className:t.itemDescription,children:[e.jsx(o,{classes:{root:t.textHeader},variant:"rect",animation:"wave"}),e.jsx(o,{classes:{root:t.textInfo},variant:"rect",animation:"wave"}),e.jsx(o,{classes:{root:t.btnQuantity},variant:"rect",animation:"wave"})]}),e.jsx(l,{className:t.itemPrice,children:e.jsx(o,{classes:{root:t.textPrice},variant:"rect",animation:"wave"})})]})]})}),e.jsx(r,{item:!0,xl:12,lg:12,sm:12,md:12,xs:12,classes:{root:t.skeletonWrapper},children:e.jsxs(r,{container:!0,item:!0,spacing:3,children:[e.jsx(r,{item:!0,xl:"auto",children:e.jsx(o,{classes:{root:t.image},variant:"rect",animation:"wave"})}),e.jsxs(r,{item:!0,xl:6,classes:{root:t.skeletonItem},children:[e.jsxs(l,{className:t.itemDescription,children:[e.jsx(o,{classes:{root:t.textHeader},variant:"rect",animation:"wave"}),e.jsx(o,{classes:{root:t.textInfo},variant:"rect",animation:"wave"}),e.jsx(o,{classes:{root:t.btnQuantity},variant:"rect",animation:"wave"})]}),e.jsx(l,{className:t.itemPrice,children:e.jsx(o,{classes:{root:t.textPrice},variant:"rect",animation:"wave"})})]})]})})]})}const ee=v(t=>({basketContainer:{height:"100%",display:"flex","flex-direction":"column"},basketBottomContainer:{width:"100%",boxShadow:"0px -16px 24px rgba(58, 71, 78, 0.02)",borderTop:"1px solid #F0F3F6",left:0,bottom:0,position:"relative",backgroundColor:"#fff",zIndex:100},loader:{zIndex:t.zIndex.drawer,position:"absolute",backgroundColor:"rgba(255, 255, 255, 0.5)"}}),{name:"Basket"}),re=({itemsBasket:t={},pricesBasket:n,loading:P,couponList:D})=>{const d=ee(),[A,{isLoading:U}]=Q(),[w,{isLoading:k}]=M(),[S,{isLoading:f}]=B(),y=k||U||f,i=Object.values(t),L=i.reduce((a,s)=>s.QUANTITY+a,0),F=a=>w({url:_.basket.deleteItem,sku:a,...b({bitrix_sessid:"bitrix_sessid",SITE_ID:"lid"})}),p=(a,s)=>A({url:_.basket.setQuantity,sku:a,quantity:s,...b({bitrix_sessid:"bitrix_sessid",SITE_ID:"lid"})});return Y.useEffect(()=>{var a;G("view_cart",{currency:(a=i[0])==null?void 0:a.CURRENCY,item_list_name:"Basket",value:n==null?void 0:n.PRODUCTS_PRICE,items:i==null?void 0:i.map((s,m)=>{var c,x,u,E,C,R,I,h,O,j,T,g,N;return{item_name:s.NAME,item_id:s.PRODUCT_ID,price:s.PRICE,item_brand:(u=(x=(c=s.PRODUCT_INFO)==null?void 0:c.PARENT)==null?void 0:x.BRAND)==null?void 0:u.NAME,item_variant:(R=(C=(E=s.PRODUCT_INFO)==null?void 0:E.TREE_PROPS)==null?void 0:C.COLOR)==null?void 0:R.VALUE,is_peak:!!((j=(O=(h=(I=s==null?void 0:s.PRODUCT_INFO)==null?void 0:I.PARENT)==null?void 0:h.PROPERTIES)==null?void 0:O.PEAK)!=null&&j.VALUE),item_category2:(N=(g=(T=s.PRODUCT_INFO)==null?void 0:T.PARENT)==null?void 0:g.SECTION)==null?void 0:N.NAME,quantity:s.QUANTITY,index:m+1}})})},[]),e.jsxs("div",{className:d.basketContainer,children:[e.jsx(H,{headerText:t&&Object.keys(t).length?"Ваша корзина":"Корзина пока пуста",itemsCount:L}),e.jsxs(W,{children:[P&&e.jsx(X,{}),!P&&i.map(a=>{var m,c;const s=(m=a.PROPERTIES.find(x=>x.CODE==="CML2_ARTICLE"))==null?void 0:m.VALUE;return e.jsx(z,{sku:a.PRODUCT_ID,itemName:a.NAME,brand:a.PRODUCT_INFO.PARENT.BRAND.NAME,link:a.PRODUCT_INFO.DETAIL_PAGE_URL,color:a.PRODUCT_INFO.TREE_PROPS.COLOR.VALUE,size:a.PRODUCT_INFO.TREE_PROPS.SIZE.VALUE,peakProduct:(c=a.PRODUCT_INFO.PARENT.PROPERTIES.PEAK)==null?void 0:c.VALUE,sectionName:a.PRODUCT_INFO.PARENT.SECTION.NAME,quantity:a.QUANTITY,currentPrice:a.PRICE,currency:a.CURRENCY,basePrice:a.BASE_PRICE,article:s,imgPath:V(a.PRODUCT_INFO.OFFERS_GALLERY,a.PRODUCT_INFO.TREE_PROPS.COLOR.VALUE,"200x200"),onChangeQuantity:p,onDeleteItem:F},a.ID)})]}),i.length&&e.jsx(K,{classes:{root:d.basketBottomContainer},children:e.jsx(q,{showDiscountPrice:!0,showSumPrice:!0,showFinalPrice:!0,discountBasket:n==null?void 0:n.PRODUCTS_DISCOUNT,finalPrice:n==null?void 0:n.PRODUCTS_PRICE,sumBasket:n==null?void 0:n.PRODUCTS_BASE_PRICE,onOrderBtn:!0,onAddPromoCode:S,couponList:D})}),y&&e.jsx(J,{classes:{root:d.loader},open:!0,children:e.jsx(Z,{color:"primary"})})]})};export{re as B};