'use client';

import Image from 'next/image';
import { Swiper, SwiperSlide } from 'swiper/react';
import { Autoplay, Navigation, Pagination } from 'swiper/modules';
import 'swiper/css';
import 'swiper/css/navigation';
import 'swiper/css/pagination';

interface HotelCardCarouselProps {
  images: string[];
  index: number;
}

export default function HotelCardCarousel({ images, index }: HotelCardCarouselProps) {
  const navigationPrevClass = `swiper-button-prev-${index}`;
  const navigationNextClass = `swiper-button-next-${index}`;

  return (
    <div
      className="leisure-properties-carousel h-imgs-carousel position-relative"
      style={{ height: '200px', minHeight: '200px', maxHeight: '200px' }}
    >
      <Swiper
        modules={[Autoplay, Navigation, Pagination]}
        spaceBetween={0}
        slidesPerView={1}
        loop
        autoplay={
          images.length > 1
            ? {
                delay: 2500,
                disableOnInteraction: false,
                pauseOnMouseEnter: true,
              }
            : false
        }
        navigation={{
          prevEl: `.${navigationPrevClass}`,
          nextEl: `.${navigationNextClass}`,
        }}
        pagination={
          images.length > 1
            ? {
                clickable: true,
                dynamicBullets: false,
              }
            : undefined
        }
        className="hotel-card-swiper"
        style={{ width: '100%', height: '200px', minHeight: '200px', maxHeight: '200px' }}
      >
        {images.map((image, idx) => (
          <SwiperSlide key={idx} style={{ height: '200px', minHeight: '200px', maxHeight: '200px' }}>
            <Image
              src={image}
              width={300}
              height={200}
              className="d-block w-100 h-100"
              alt="Hotel"
              loading={idx === 0 ? 'eager' : 'lazy'}
              style={{ objectFit: 'cover', maxHeight: '200px' }}
            />
          </SwiperSlide>
        ))}
      </Swiper>

      {images.length > 1 && (
        <>
          <button
            className={`swiper-button-prev ${navigationPrevClass}`}
            type="button"
            onClick={(e) => e.preventDefault()}
          >
            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16">
              <path
                fillRule="evenodd"
                d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"
              />
            </svg>
          </button>
          <button
            className={`swiper-button-next ${navigationNextClass}`}
            type="button"
            onClick={(e) => e.preventDefault()}
          >
            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16">
              <path
                fillRule="evenodd"
                d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"
              />
            </svg>
          </button>
        </>
      )}
    </div>
  );
}
