import React from 'react';
import { useEffect, useState } from 'react';
import './Carousel.css';
import p0 from '/EngagmentSession_06.23.2024-131.jpg';
import p1 from '/EngagmentSession_06.23.2024-161.jpg';
import p2 from '/EngagmentSession_06.23.2024-164.jpg';
import p3 from '/EngagmentSession_06.23.2024-259.jpg';
import p4 from '/EngagmentSession_06.23.2024-267.jpg';
import p5 from '/EngagmentSession_06.23.2024-284.jpg';
import useMediaQuery from '@mui/material/useMediaQuery';

function Home() {
  const [currentIndex, setIndex] = useState<number>(0);
  const photos = [p0, p1, p2, p3, p4, p5];
  const isMobile = useMediaQuery('(max-width: 768px)');

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

  return (
    <div className="carousel-container">
      {isMobile && (
        <img
          style={{
            position: 'absolute',
            top: 64,
            right: 32,
            height: 150,
            width: 150,
          }}
          src="/dove.png"
        />
      )}
      <div className="carousel">
        {photos.map((photo, index) => (
          <div
            key={index}
            className={
              index === currentIndex
                ? 'carousel-slide active-slide'
                : 'carousel-slide'
            }
          >
            <img src={photo}></img>
          </div>
        ))}
      </div>
      {isMobile && (
        <img
          style={{
            position: 'absolute',
            bottom: 32,
            left: 0,
            height: 200,
            width: 200,
          }}
          src="/branch.png"
        />
      )}
    </div>
  );
}

export default Home;
