import{E as EventHandler,g as getElementFromSelector,M as Manipulator,S as SelectorEngine,d as defineJQueryPlugin,B as BaseComponent,i as isVisible,t as triggerTransitionEnd,a as Swipe,b as getNextActiveElement,r as reflow,c as isRTL}from"./dom.min.js?5.2.3";const NAME="carousel",DATA_KEY="bs.carousel",EVENT_KEY=`.${DATA_KEY}`,DATA_API_KEY=".data-api",ARROW_LEFT_KEY="ArrowLeft",ARROW_RIGHT_KEY="ArrowRight",TOUCHEVENT_COMPAT_WAIT=500,ORDER_NEXT="next",ORDER_PREV="prev",DIRECTION_LEFT="left",DIRECTION_RIGHT="right",EVENT_SLIDE=`slide${EVENT_KEY}`,EVENT_SLID=`slid${EVENT_KEY}`,EVENT_KEYDOWN=`keydown${EVENT_KEY}`,EVENT_MOUSEENTER=`mouseenter${EVENT_KEY}`,EVENT_MOUSELEAVE=`mouseleave${EVENT_KEY}`,EVENT_DRAG_START=`dragstart${EVENT_KEY}`,EVENT_LOAD_DATA_API=`load${EVENT_KEY}.data-api`,EVENT_CLICK_DATA_API=`click${EVENT_KEY}.data-api`,CLASS_NAME_CAROUSEL="carousel",CLASS_NAME_ACTIVE="active",CLASS_NAME_SLIDE="slide",CLASS_NAME_END="carousel-item-end",CLASS_NAME_START="carousel-item-start",CLASS_NAME_NEXT="carousel-item-next",CLASS_NAME_PREV="carousel-item-prev",SELECTOR_ACTIVE=".active",SELECTOR_ITEM=".carousel-item",SELECTOR_ACTIVE_ITEM=".active.carousel-item",SELECTOR_ITEM_IMG=".carousel-item img",SELECTOR_INDICATORS=".carousel-indicators",SELECTOR_DATA_SLIDE="[data-bs-slide], [data-bs-slide-to]",SELECTOR_DATA_RIDE='[data-bs-ride="carousel"]',KEY_TO_DIRECTION={ArrowLeft:"right",ArrowRight:"left"},Default={interval:5e3,keyboard:!0,pause:"hover",ride:!1,touch:!0,wrap:!0},DefaultType={interval:"(number|boolean)",keyboard:"boolean",pause:"(string|boolean)",ride:"(boolean|string)",touch:"boolean",wrap:"boolean"};class Carousel extends BaseComponent{constructor(e,t){super(e,t),this._interval=null,this._activeElement=null,this._isSliding=!1,this.touchTimeout=null,this._swipeHelper=null,this._indicatorsElement=SelectorEngine.findOne(SELECTOR_INDICATORS,this._element),this._addEventListeners(),"carousel"===this._config.ride&&this.cycle()}static get Default(){return Default}static get DefaultType(){return DefaultType}static get NAME(){return NAME}next(){this._slide("next")}nextWhenVisible(){!document.hidden&&isVisible(this._element)&&this.next()}prev(){this._slide("prev")}pause(){this._isSliding&&triggerTransitionEnd(this._element),this._clearInterval()}cycle(){this._clearInterval(),this._updateInterval(),this._interval=setInterval((()=>this.nextWhenVisible()),this._config.interval)}_maybeEnableCycle(){this._config.ride&&(this._isSliding?EventHandler.one(this._element,EVENT_SLID,(()=>this.cycle())):this.cycle())}to(e){const t=this._getItems();if(e>t.length-1||e<0)return;if(this._isSliding)return void EventHandler.one(this._element,EVENT_SLID,(()=>this.to(e)));const i=this._getItemIndex(this._getActive());if(i===e)return;const s=e>i?"next":"prev";this._slide(s,t[e])}dispose(){this._swipeHelper&&this._swipeHelper.dispose(),super.dispose()}_configAfterMerge(e){return e.defaultInterval=e.interval,e}_addEventListeners(){this._config.keyboard&&EventHandler.on(this._element,EVENT_KEYDOWN,(e=>this._keydown(e))),"hover"===this._config.pause&&(EventHandler.on(this._element,EVENT_MOUSEENTER,(()=>this.pause())),EventHandler.on(this._element,EVENT_MOUSELEAVE,(()=>this._maybeEnableCycle()))),this._config.touch&&Swipe.isSupported()&&this._addTouchEventListeners()}_addTouchEventListeners(){for(const e of SelectorEngine.find(SELECTOR_ITEM_IMG,this._element))EventHandler.on(e,EVENT_DRAG_START,(e=>e.preventDefault()));const e={leftCallback:()=>this._slide(this._directionToOrder("left")),rightCallback:()=>this._slide(this._directionToOrder("right")),endCallback:()=>{"hover"===this._config.pause&&(this.pause(),this.touchTimeout&&clearTimeout(this.touchTimeout),this.touchTimeout=setTimeout((()=>this._maybeEnableCycle()),500+this._config.interval))}};this._swipeHelper=new Swipe(this._element,e)}_keydown(e){if(/input|textarea/i.test(e.target.tagName))return;const t=KEY_TO_DIRECTION[e.key];t&&(e.preventDefault(),this._slide(this._directionToOrder(t)))}_getItemIndex(e){return this._getItems().indexOf(e)}_setActiveIndicatorElement(e){if(!this._indicatorsElement)return;const t=SelectorEngine.findOne(".active",this._indicatorsElement);t.classList.remove("active"),t.removeAttribute("aria-current");const i=SelectorEngine.findOne(`[data-bs-slide-to="${e}"]`,this._indicatorsElement);i&&(i.classList.add("active"),i.setAttribute("aria-current","true"))}_updateInterval(){const e=this._activeElement||this._getActive();if(!e)return;const t=Number.parseInt(e.getAttribute("data-bs-interval"),10);this._config.interval=t||this._config.defaultInterval}_slide(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(this._isSliding)return;const i=this._getActive(),s="next"===e,n=t||getNextActiveElement(this._getItems(),i,s,this._config.wrap);if(n===i)return;const r=this._getItemIndex(n),a=t=>EventHandler.trigger(this._element,t,{relatedTarget:n,direction:this._orderToDirection(e),from:this._getItemIndex(i),to:r});if(a(EVENT_SLIDE).defaultPrevented)return;if(!i||!n)return;const o=Boolean(this._interval);this.pause(),this._isSliding=!0,this._setActiveIndicatorElement(r),this._activeElement=n;const l=s?CLASS_NAME_START:CLASS_NAME_END,E=s?CLASS_NAME_NEXT:CLASS_NAME_PREV;n.classList.add(E),reflow(n),i.classList.add(l),n.classList.add(l);this._queueCallback((()=>{n.classList.remove(l,E),n.classList.add("active"),i.classList.remove("active",E,l),this._isSliding=!1,a(EVENT_SLID)}),i,this._isAnimated()),o&&this.cycle()}_isAnimated(){return this._element.classList.contains("slide")}_getActive(){return SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM,this._element)}_getItems(){return SelectorEngine.find(SELECTOR_ITEM,this._element)}_clearInterval(){this._interval&&(clearInterval(this._interval),this._interval=null)}_directionToOrder(e){return isRTL()?"left"===e?"prev":"next":"left"===e?"next":"prev"}_orderToDirection(e){return isRTL()?"prev"===e?"left":"right":"prev"===e?"right":"left"}static jQueryInterface(e){return this.each((function(){const t=Carousel.getOrCreateInstance(this,e);if("number"!=typeof e){if("string"==typeof e){if(void 0===t[e]||e.startsWith("_")||"constructor"===e)throw new TypeError(`No method named "${e}"`);t[e]()}}else t.to(e)}))}}if(EventHandler.on(document,EVENT_CLICK_DATA_API,SELECTOR_DATA_SLIDE,(function(e){const t=getElementFromSelector(this);if(!t||!t.classList.contains("carousel"))return;e.preventDefault();const i=Carousel.getOrCreateInstance(t),s=this.getAttribute("data-bs-slide-to");return s?(i.to(s),void i._maybeEnableCycle()):"next"===Manipulator.getDataAttribute(this,"slide")?(i.next(),void i._maybeEnableCycle()):(i.prev(),void i._maybeEnableCycle())})),EventHandler.on(window,EVENT_LOAD_DATA_API,(()=>{const e=SelectorEngine.find(SELECTOR_DATA_RIDE);for(const t of e)Carousel.getOrCreateInstance(t)})),defineJQueryPlugin(Carousel),window.bootstrap=window.bootstrap||{},window.bootstrap.Carousel=Carousel,Joomla&&Joomla.getOptions){const e=Joomla.getOptions("bootstrap.carousel");"object"==typeof e&&null!==e&&Object.keys(e).forEach((t=>{const i=e[t],s={interval:i.interval?i.interval:5e3,keyboard:!i.keyboard||i.keyboard,pause:i.pause?i.pause:"hover",slide:!!i.slide&&i.slide,wrap:!i.wrap||i.wrap,touch:!i.touch||i.touch},n=Array.from(document.querySelectorAll(t));n.length&&n.map((e=>new window.bootstrap.Carousel(e,s)))}))}export{Carousel as C};