"use strict";const n=require("react/jsx-runtime"),r=require("react"),p=require("../button/button.cjs"),d=require("../tools/tools.cjs"),L=require("./carousel-caption.cjs"),P=require("./carousel-item.cjs"),f=function(T){const{as:q="div",className:N,controls:M=!0,dropOldClass:S,fade:b,indicators:X,onChange:x,options:_,pause:h,ride:o,slide:g=!0,style:j,touch:m,variables:E,...B}=T,R=(_??[]).map((e,s)=>({...e,id:e.id??s,interval:e.interval??3e3})),[a,K]=r.useState(R),[c,V]=r.useState(0),[v,i]=r.useState(!1),[C,k]=r.useState(null),D=r.useMemo(()=>{const e=d.classx(!S&&"carousel",g&&"slide",b&&"carousel-fade",N),s=d.stylex((t,l)=>({tKey:d.convertBsKeyToVar(l)}),E,j);return{className:e,style:s}},[N,S,b,g,j,E]),O=r.useCallback((e,s,t)=>{const l=a[e],I=a[s];l.active=!0,l.carouselItemStart=t==="next"||t==="nextIndicator",l.carouselItemEnd=t==="prev"||t==="prevIndicator",l.carouselItemNext=!1,l.carouselItemPrev=!1,I.active=!1,I.carouselItemNext=t==="next"||t==="nextIndicator",I.carouselItemStart=t==="next"||t==="nextIndicator",I.carouselItemPrev=t==="prev"||t==="prevIndicator",I.carouselItemEnd=t==="prev"||t==="prevIndicator",K([...a])},[a]),u=r.useCallback(e=>{const s=a.length;if(s===0)return;o===!0&&!h&&s>1&&i(!0);const t=d.calculateLoopIndex(c,s,0),l=d.calculateLoopIndex(c,s,e==="next"||e==="nextIndicator"?1:-1);O(t,l,e),V(l),x==null||x(a[l].id,e)},[c,x,a,h,o,O]),F=r.useCallback(()=>{v&&i(!1)},[v]),W=r.useCallback(()=>{o==="carousel"&&i(!0)},[o]),$=r.useCallback(e=>{m&&k(e.touches[0].clientX)},[m]),w=r.useCallback(e=>{if(m&&C!==null){const s=e.changedTouches[0].clientX,t=C-s;t>50?u("next"):t<-50&&u("prev"),k(null)}},[u,m,C]);return r.useEffect(()=>{o==="carousel"&&a.length>1?i(!0):o===!0&&i(!1)},[a.length,o]),r.useEffect(()=>{const e=()=>{document.hidden?i(!1):(o==="carousel"||o===!0)&&!h&&i(!0)};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[o,h]),r.useEffect(()=>{let e=null;return v&&(e=setInterval(()=>{u("next")},a[c].interval)),()=>{e&&clearInterval(e)}},[c,v,u,a]),n.jsxs(q,{...B,...D,onMouseEnter:F,onMouseLeave:W,onTouchEnd:w,onTouchStart:$,children:[X&&n.jsx("div",{className:"carousel-indicators",children:a.map((e,s)=>{const{isNext:t}=d.getLoopIndexDirection(c,s,a.length);return n.jsx(p.Button,{"aria-current":s===c?"true":"false","aria-label":`Slide ${s+1}`,className:d.classxWithOptions(null,s===c&&"active"),"data-bs-target":"",dropOldClass:!0,onClick:()=>u(t?"nextIndicator":"prevIndicator")},e.id)})}),n.jsx("div",{className:"carousel-inner",children:a.map(e=>n.jsxs(P.CarouselItem,{active:e.active,carouselItemEnd:e.carouselItemEnd,carouselItemNext:e.carouselItemNext,carouselItemPrev:e.carouselItemPrev,carouselItemStart:e.carouselItemStart,children:[e.item,e.caption&&n.jsx(L.CarouselCaption,{children:e.caption})]},e.id))}),M&&n.jsxs(n.Fragment,{children:[n.jsxs(p.Button,{className:"carousel-control-prev",dropOldClass:!0,onClick:()=>u("prev"),children:[n.jsx("span",{"aria-hidden":"true",className:"carousel-control-prev-icon"}),n.jsx("span",{className:"visually-hidden",children:"Previous"})]}),n.jsxs(p.Button,{className:"carousel-control-next",dropOldClass:!0,onClick:()=>u("next"),children:[n.jsx("span",{"aria-hidden":"true",className:"carousel-control-next-icon"}),n.jsx("span",{className:"visually-hidden",children:"Next"})]})]})]})};f.Item=P.CarouselItem;f.Caption=L.CarouselCaption;f.displayName="BRL.Carousel";exports.Carousel=f;
//# sourceMappingURL=carousel.cjs.map
