$(function () {
    let currentIndex = 0;
    const slides = $('.slide');
    const dots = $('.dot');
    const slideCount = slides.length;
    let interval;

    function showSlide(index) {
        slides.removeClass('active').eq(index).addClass('active');
        dots.removeClass('active').eq(index).addClass('active');
        currentIndex = index;
    }

    function nextSlide() {
        const nextIndex = (currentIndex + 1) % slideCount;
        showSlide(nextIndex);
    }

    dots.on('click', function () {
        const index = $(this).data('index');
        showSlide(index);
        resetInterval();
    });

    function resetInterval() {
        clearInterval(interval);
        interval = setInterval(nextSlide, 5000);
    }

    resetInterval();
});