import React from 'react';
import { useEffect, useState } from 'react';
import './Carousel.css';
import { BlurryLoadImg } from './BlurryLoadImg';

const images = [
  { small: '/small/engagement1.webp', full: '/full/engagement1.jpg' },
  { small: '/small/engagement2.webp', full: '/full/engagement2.jpg' },
  { small: '/small/engagement3.webp', full: '/full/engagement3.jpg' },
  { small: '/small/engagement4.webp', full: '/full/engagement4.jpg' },
  { small: '/small/engagement5.webp', full: '/full/engagement5.jpg' },
  { small: '/small/engagement6.webp', full: '/full/engagement6.jpg' },
];

function Home() {
  const [currentIndex, setIndex] = useState<number>(0);

  useEffect(() => {
    const interval = setInterval(() => {
      setIndex((prevIndex) =>
        prevIndex === images.length - 1 ? 0 : prevIndex + 1
      );
    }, 3000);
    return () => clearInterval(interval);
  }, [images.length]);

  return (
    <div className="carousel-container">
      <div className="carousel">
        {images.map((image, index) => (
          <div
            key={index}
            className={
              index === currentIndex
                ? 'carousel-slide active-slide'
                : 'carousel-slide'
            }
          >
            <BlurryLoadImg
              src={image.small}
              data-large={`${image.full}`}
            ></BlurryLoadImg>
          </div>
        ))}
      </div>
    </div>
  );
}

export default Home;
