/**
 * Initializes Plyr audio player on the front-end
 * Note: Plyr is loaded as a dependency via PHP (see audio-player.php)
 */

// Initialize Plyr on all audio elements with the js-plyr class
document.addEventListener("DOMContentLoaded", () => {
	// Check if Plyr is available (loaded via PHP)
	if (typeof Plyr === "undefined") {
		/* eslint-disable no-console */
		console.error("Plyr library not loaded");
		/* eslint-enable no-console */
		return;
	}

	const players = Array.from(document.querySelectorAll(".js-plyr")).map(
		(element) =>
			new Plyr(element, {
				controls: [
					"play-large",
					"play",
					"progress",
					"current-time",
					"duration",
					"mute",
					"volume",
					"settings",
				],
				settings: ["speed"],
				speed: { selected: 1, options: [0.5, 0.75, 1, 1.25, 1.5, 2] },
			}),
	);
});
