"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const re=require("@gsap/react"),o=require("gsap"),y=require("../../node_modules/.pnpm/gsap@3.13.0/node_modules/gsap/Flip.cjs.js"),F=require("../../node_modules/.pnpm/gsap@3.13.0/node_modules/gsap/Draggable.cjs.js"),s=require("react");o.registerPlugin(y.Flip);o.registerPlugin(F.Draggable);const v=12,ne=({images:r})=>{if(r.length>0&&r.length<v){const e=[...r];for(;r.length<v;)r.push(...e)}const[d,W]=s.useState(0),E=s.useRef(d);E.current=d;const[p,M]=s.useState(!1),U=s.useRef(null),t=s.useRef(null),C=s.useRef([]),R=s.useRef(null),b=s.useRef(null),j=s.useRef(null),x=s.useRef(null),u=["atom","small","medium","large","medium","small","atom"],z=["atom","small","medium","large","x-large","large","medium","small","atom"],[S,A]=s.useState(0),[f,P]=s.useState(typeof window!="undefined"&&window.innerWidth<=930?u:z),G=u.indexOf("large"),V=f.indexOf("x-large"),T=o.matchMedia(),I=s.useCallback(e=>{var q,N,_,$;if(!t.current)return;let i=0;if(window.innerWidth<=930){const l=t.current.querySelector('[data-size="large"]');i=l?l.offsetHeight:0}else{const l=t.current.querySelector('[data-size="x-large"]');i=l?l.offsetHeight:0,o.set(t.current,{x:0})}if(i>0&&(A(i),o.set(t.current,{height:i})),o.set((q=t.current)==null?void 0:q.querySelectorAll("[data-size]"),{y:0}),!C.current.length)return;const c=(N=t.current)==null?void 0:N.querySelector('[data-size="x-large"]'),n=c==null?void 0:c.getBoundingClientRect(),g=(_=t.current)==null?void 0:_.querySelector('[data-size="large"]'),a=g==null?void 0:g.getBoundingClientRect();T.add({isMobile:"(max-width: 930px)",isDesktop:"(min-width: 931px)"},l=>{var D,H,K;const{isDesktop:B,isMobile:Z}=l.conditions||{};if(A(((D=t.current)==null?void 0:D.offsetHeight)||0),Z){if(P(u),o.set(t.current,{height:S||((H=t.current)==null?void 0:H.offsetHeight)||"auto"}),!a)return;const h=window.innerWidth/2,w=a.right-a.width/2,L=h-w;o.set(t.current,{x:`+=${L}`});const ee=h-a.width/2;o.set(R.current,{width:a.width,marginLeft:ee}),C.current.forEach((O,k)=>{O&&k<u.length&&(u.forEach(te=>{O.classList.remove(`size-${te}`)}),O.classList.add(`size-${u[k]}`))})}B&&(P(z),o.set(t.current,{height:S||((K=t.current)==null?void 0:K.offsetHeight)||"auto"}),o.set(R.current,{width:n?n.width:"auto",marginLeft:n?n.left:0}),C.current.forEach((h,w)=>{h&&w<f.length&&(f.forEach(L=>{h.classList.remove(`size-${L}`)}),h.classList.add(`size-${f[w]}`))}))}),((($=R.current)==null?void 0:$.querySelectorAll(".description-item"))||[]).forEach((l,B)=>{l.style.zIndex=`${r.length-B}`}),M(!0),x.current=y.Flip.getState(C.current,{simple:!0}),W(e),o.delayedCall(0,()=>{y.Flip.from(x.current,{duration:.3,ease:"power3.out",absolute:!0,onComplete:()=>{M(!1)}}),o.fromTo(b.current,{opacity:0,y:20},{opacity:1,y:0,duration:.5,ease:"power3.out",onComplete:()=>{x.current=null}})})},[f,u,r.length,S]),J=()=>{if(p)return;const e=(d-1+r.length)%r.length;I(e)},Q=()=>{if(p)return;const e=(d+1)%r.length;I(e)};function X(e,i){const c=[];if(typeof window!="undefined"&&window.innerWidth<=930)for(let n=0;n<u.length;n++)c.push(e[(i+n)%e.length]);else for(let n=0;n<f.length;n++)c.push(e[(i+n)%e.length]);return c}const Y=X(r,d);return re.useGSAP(()=>{I(d);const e=t.current;e&&T.add("(max-width: 930px)",()=>{const i={x:0},c=F.Draggable.create(e,{type:"x",onDragStart:()=>{p||(i.x=e.scrollLeft+e.getBoundingClientRect().left)},onDragEnd:()=>{const g=e.scrollLeft+e.getBoundingClientRect().left-i.x,a=20;if(g>a){if(p)return;const m=(E.current-1+r.length)%r.length;I(m)}else if(g<-a){if(p)return;const m=(E.current+1)%r.length;I(m)}}});return()=>{c[0]&&c[0].kill()}})},[]),{MOBILE_BREAKPOINT:930,containerRef:U,carouselRef:t,imageRefs:C,descriptionRef:R,descriptionItemRef:b,progressButtonContainerRef:j,visible:Y,cardSizes:f,handleCustomPrevClick:J,handleCustomNextClick:Q,current:d,mobileCardIndex:G,xLargeCardIndex:V}};exports.useComplexImageCarousel=ne;
