/*
author: wang
version: 2023.10.31
 */

function Slide() {
    this.currentIndex = 0;
    this.slides = document.getElementsByClassName("slide-item");
    this.interval = 5000;
    this.playHandle = null;
}

Slide.prototype.play = function () {
    let that = this;
    if (this.slides.length > 1) {
        this.playHandle = setInterval(() => {
            that.showNext(1);
        }, that.interval);
    }
}

Slide.prototype.stop = function () {
    if (this.playHandle != null) {
        clearInterval(this.playHandle);
    }
}

Slide.prototype.showNext = function (n) {
    this.currentIndex = (this.currentIndex + n) % this.slides.length;
    if (this.currentIndex < 0) {
        this.currentIndex = this.slides.length - 1;
    }
    for (let i = 0; i < this.slides.length; i++) {
        this.slides[i].style.display = "none";
    }
    this.slides[this.currentIndex].style.display = "block";
}
Slide.prototype.showNextLeft = function () {
    this.showNext(-1);
}
Slide.prototype.showNextRight = function () {
    this.showNext(1);
}