"use strict";

let slideIndex = 0;

function showSlide(index) {
    const slides = Array.from(document.querySelectorAll(".m-slideshow .slides"));
    const items = Array.from(document.querySelectorAll(".progress .item-inner"));
    if (!slides.length) {
        return;
    }

    if (index >= slides.length) {
        slideIndex = 0;
    } else if (index < 0) {
        slideIndex = slides.length - 1;
    } else {
        slideIndex = index;
    }

    slides.forEach((slide, idx) => {
        slide.classList.toggle("active", idx === slideIndex);
    });
    items.forEach((item, idx) => {
        item.style.width = idx === slideIndex ? "100%" : "0";
    });
}

function move(step) {
    showSlide(slideIndex + step);
}

document.addEventListener("DOMContentLoaded", () => {
    showSlide(0);
    window.setInterval(() => move(1), 5200);
});
