/**
 * Public slider runtime (Splide). Enqueued only when a hero/slider block is present.
 * WordPress prints this handle at most once per page.
 */
import {
	initBmSliders,
	remountBmSliders,
	goBmSlider,
	pauseBmSlider,
	holdBmSlider,
	releaseBmSlider,
} from './slider/BmSlider';

let booted = false;

function boot() {
	if ( booted ) {
		return;
	}
	booted = true;
	initBmSliders( document );
}

if ( typeof window !== 'undefined' ) {
	const prev = window.jocbmSlider;
	if ( ! prev || typeof prev.init !== 'function' ) {
		window.jocbmSlider = {
			init: initBmSliders,
			remount: remountBmSliders,
			go: goBmSlider,
			pause: pauseBmSlider,
			hold: holdBmSlider,
			release: releaseBmSlider,
		};
	}

	if ( document.readyState === 'loading' ) {
		document.addEventListener( 'DOMContentLoaded', boot, { once: true } );
	} else {
		boot();
	}
}
