"use client"; 

import { CloudArrowUpIcon, LockClosedIcon, ServerIcon } from '@heroicons/react/20/solid'
import { useState, useEffect } from 'react'

const features = [
  {
    name: 'Advanced Communication.',
    description:
      'Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores impedit perferendis suscipit eaque, iste dolor cupiditate blanditiis ratione.',
    icon: CloudArrowUpIcon,
  },
  {
    name: 'Creative Collaboration.',
    description: 'Anim aute id magna aliqua ad ad non deserunt sunt. Qui irure qui lorem cupidatat commodo.',
    icon: LockClosedIcon,
  },
  {
    name: 'Build Your Verse.',
    description: 'Ac tincidunt sapien vehicula erat auctor pellentesque rhoncus. Et magna sit morbi lobortis.',
    icon: ServerIcon,
  },
  {
    name: 'Event Management.',
    description: 'Ac tincidunt sapien vehicula erat auctor pellentesque rhoncus. Et magna sit morbi lobortis.',
    icon: ServerIcon,
  },
  {
    name: 'OurVerse Studio.',
    description: 'Ac tincidunt sapien vehicula erat auctor pellentesque rhoncus. Et magna sit morbi lobortis.',
    icon: ServerIcon,
  },

]

// List of carousel images
const carouselImages = [
  '/images/feature1.jpg',
  '/images/feature2.jpg',
  '/images/feature3.jpg',
  '/images/feature4.jpg',
  '/images/feature5.jpg',
]

export default function Example() {
  const [currentIndex, setCurrentIndex] = useState(0)

  // Autoplay logic to change image every 3 seconds
  useEffect(() => {
    const interval = setInterval(() => {
      setCurrentIndex((prevIndex) =>
        prevIndex === carouselImages.length - 1 ? 0 : prevIndex + 1
      )
    }, 3000)

    return () => clearInterval(interval) // Cleanup on unmount
  }, [])

  return (
    <div className="overflow-hidden bg-white py-24 sm:py-32">
      <div className="mx-auto max-w-7xl px-6 lg:px-8">
        <div className="mx-auto grid max-w-2xl grid-cols-1 gap-x-8 gap-y-16 sm:gap-y-20 lg:mx-0 lg:max-w-none lg:grid-cols-2">
          <div className="lg:ml-auto lg:pl-4 lg:pt-4">
            <div className="lg:max-w-lg">
              <h2 className="text-base font-medium font-mono leading-7 text-purple-600">Features</h2>
              <p className="mt-2 font-display text-3xl font-semibold tracking-tighter h3-title-new sm:text-5xl">The Future of Communication</p>
              <p className="mt-6 text-lg leading-8 text-purple-600">
              OurVerse offers cutting-edge tools designed to bring your events, meetings, and creative projects to life in new and exciting ways.
              </p>
              <dl className="mt-6 max-w-xl space-y-8 text-base leading-7 text-purple-600 lg:max-w-none">
                {features.map((feature) => (
                  <div key={feature.name} className="relative pl-9">
                    <dt className="inline font-semibold text-purple-900">
                      <feature.icon aria-hidden="true" className="absolute left-1 top-1 h-5 w-5 text-indigo-600" />
                      {feature.name}
                    </dt>{' '}
                    <dd className="inline">{feature.description}</dd>
                  </div>
                ))}
              </dl>
            </div>
          </div>
          <div className="flex items-start justify-end lg:order-first">
            {/* Carousel */}
            <img
              alt="Product screenshot"
              src={carouselImages[currentIndex]}
              width={2432}
              height={1442}
              className="w-[48rem] max-w-none rounded-xl shadow-xl ring-1 ring-purple-400/10 sm:w-[57rem]"
            />
          </div>
        </div>
      </div>
    </div>
  )
}
