import{a as K,b as U}from"/build/_shared/chunk-UXTJT2T4.js";import{a as q,b as J}from"/build/_shared/chunk-5MXO7FVF.js";import{a as Z}from"/build/_shared/chunk-JQVRFE3O.js";import{h as G}from"/build/_shared/chunk-CFZHMNHJ.js";import{a as W,d as j}from"/build/_shared/chunk-GFJB6RIL.js";import{a as P}from"/build/_shared/chunk-3NEASJTC.js";import{a as Q}from"/build/_shared/chunk-XZZCBT56.js";import{a as _}from"/build/_shared/chunk-EDK77NNA.js";import{$ as w,H as N,Ka as H,R,T as x,X as d,b as $,la as F,n as L}from"/build/_shared/chunk-QHBIDS7S.js";import{j as I}from"/build/_shared/chunk-OFAZKNI3.js";import{a as me,b as D}from"/build/_shared/chunk-JP7ZSRVB.js";import{f as A}from"/build/_shared/chunk-ZSCMMWXX.js";var o=A(me());var X="/build/_assets/style-KXVLS7SX.css";var e=A(D()),Ne=()=>[{rel:"stylesheet",href:X},...K(),...q()];function pe({AdData:T,afterTitle:y,beforeList:z,belowTitle:B,cardGap:u=16,cardWidth:fe=160,coupons:a,showAd:E,showAllBtn:M=!1,showScrollButtons:Y=!0,title:C,titleOrder:ee=2,titleRoute:p}){let v=(0,o.useRef)(null),i=(0,o.useRef)(null),[oe,te]=(0,o.useState)(0),[f,re]=(0,o.useState)(0),[ne,ae]=(0,o.useState)([]),[m,ie]=(0,o.useState)(0),[V,le]=(0,o.useState)(0),[l,g]=(0,o.useState)(0),[h,se]=(0,o.useState)(0),s=_(),b=L(`(min-width: ${P.TABLET})`,!0),c=L(`(max-width: ${P.MOBILE})`),O=Z();(0,o.useEffect)(()=>{if(v.current===null)return;let t=new ResizeObserver(r=>{var n;te((n=r[0].contentRect.width)!=null?n:0)});return t.observe(v.current),()=>t.disconnect()},[]),(0,o.useEffect)(()=>{if(i.current===null)return;let t=new ResizeObserver(r=>{var n;ie((n=r[0].contentRect.width)!=null?n:0)});return t.observe(i.current),()=>t.disconnect()},[]),(0,o.useEffect)(()=>{let t=G(O);re(t.cardsInFirstRow),le(t.cardsPerRow)},[oe,u,a,m,O]),(0,o.useEffect)(()=>{let t=a.slice(f),r=[],n=[];for(let S of t)n.length<V?n.push(S):(r.push(n),n=[]);n.length>0&&r.push(n),ae(r),se(r.length+1)},[a,f,V,m]),(0,o.useEffect)(()=>{(i==null?void 0:i.current)!==null&&i.current.scrollTo({left:l*m,behavior:"smooth"})},[l,h,m]),(0,o.useEffect)(()=>{m>0&&g(0)},[m]);let ce=()=>{i.current!==null&&l<h-1&&g(l+1)},de=()=>{i.current!==null&&l>0&&g(l-1)},k=(t,r,n=!1)=>(0,e.jsxs)(o.default.Fragment,{children:[(0,e.jsx)(U,{...t,width:220}),Boolean(n&&c)&&(0,e.jsx)(F,{c:"layout-strokes.0",orientation:"vertical"})]},r);return(0,e.jsxs)("section",{className:"carouselSection",children:[(0,e.jsxs)(x,{className:Q("coupon-list-carousel-header",c&&"mobile"),mb:"xs",px:c?16:0,children:[C&&(0,e.jsxs)(x,{hidden:!C,children:[(0,e.jsx)(H,{className:"coupon-list-title",fw:600,order:ee,children:C}),y&&p&&(0,e.jsx)(I,{"aria-label":y,className:"see-all-btn",to:p,children:y})]}),M&&p&&(0,e.jsx)("div",{className:"see-all-btn",children:(0,e.jsx)(I,{"aria-label":(s==null?void 0:s.see_all)||"",className:"see-all-btn",to:p,children:(s==null?void 0:s.see_all)||""})}),Y&&!M&&b&&(0,e.jsxs)(x,{children:[(0,e.jsxs)(w,{component:"p",fs:$(20),children:[l+1," ",(s==null?void 0:s.of)||"of"," ",h]}),(0,e.jsx)(R,{"aria-label":"Previous",color:"blue","data-testid":"prev-btn",disabled:l===0,radius:"xl",tabIndex:0,variant:"filled",onClick:de,children:(0,e.jsx)(W,{})}),(0,e.jsx)(R,{"aria-label":"Next",color:"blue","data-testid":"next-btn",disabled:l===h-1,radius:"xl",tabIndex:0,variant:"filled",onClick:ce,children:(0,e.jsx)(j,{})})]})]}),B&&(0,e.jsx)(w,{component:"p",children:B}),c&&(0,e.jsx)(F,{mb:"md",mt:"sm",mx:c?16:0,variant:"dashed"}),(0,e.jsx)(d,{ref:i,className:"scrollContainer",direction:"column",px:c?16:0,children:(0,e.jsxs)(d,{className:"scrollInner",gap:`${u}px`,children:[!b&&(0,e.jsxs)(d,{className:"full-width",direction:"column",children:[(0,e.jsx)(N,{px:c?16:0,children:E&&(0,e.jsx)("swiftly-ad",{"data-placement-id":"MidPage.0","data-screen-name":"DealsHome"})}),T&&(0,e.jsx)(J,{...T}),(0,e.jsx)(d,{className:"primary-carousel-row",gap:`${u}px`,children:a==null?void 0:a.slice(0,f).map((t,r)=>k(t,r,a.length-1!=r))})]}),b&&(0,e.jsxs)(d,{className:"cardContainer",gap:`${u}px`,children:[z&&(0,e.jsx)(w,{component:"p",children:z}),E&&(0,e.jsx)(N,{ref:v,className:"list-child-before",px:c?16:0,children:(0,e.jsx)("swiftly-ad",{"data-placement-id":"MidPage.0","data-screen-name":"DealsHome"})}),a==null?void 0:a.slice(0,f).map((t,r)=>k(t,r))]}),b&&ne.map((t,r)=>(0,e.jsx)(d,{className:"cardContainer",gap:`${u}px`,children:t.map((n,S)=>k(n,S))},r))]})})]})}export{Ne as a,pe as b};
