"use client";

import Image from "next/image";
import { Swiper, SwiperSlide } from "swiper/react";
import "swiper/css";

import { OurServicesProps } from "@/types/aesthetic-offers-bulle";

export default function OurServices({
  title,
  heading,
  description,
  cards,
}: OurServicesProps) {
  return (
    <section
      className="relative mb-[58px] overflow-hidden bg-[#F2F4F6] py-10 sm:py-12 lg:py-[120px]"
      style={{
        backgroundImage: "url('/images/OUR SERVICES-BG.png')",
        backgroundRepeat: "no-repeat",
        backgroundPosition: "center",
        backgroundSize: "contain",
        top: 56,
      }}
    >
      <div className="relative z-[1] mx-auto w-full max-w-[1440px] px-5 sm:px-6 lg:px-20">
        {/* ================= HEADER ================= */}
        <div className="mb-8 flex flex-col gap-5 sm:mb-10 sm:grid sm:grid-cols-2 sm:items-end lg:mb-[56px] lg:gap-5">
          <div className="flex flex-col gap-2 lg:gap-3">
            {title && (
              <span className="font-['Satoshi'] text-[12px] font-medium uppercase leading-[1.4] tracking-[0.5px] text-[#334D72] md:text-[14px]">
                {title}
              </span>
            )}

            {heading && (
              <h2 className="font-['Satoshi'] text-[32px] font-medium leading-[1.2] tracking-[-0.5px] text-[#00204F] md:text-[40px]">
                {heading}
              </h2>
            )}
          </div>

          {description && (
            <p className="max-w-[631px] font-['Satoshi'] text-[16px] font-normal leading-[1.3] text-[#334D72] md:text-[20px]">
              {description}
            </p>
          )}
        </div>

        {/* ================= CARDS SWIPER ================= */}
        <Swiper
          spaceBetween={20}
          slidesPerView={1.1}
          grabCursor={true}
          allowTouchMove={true}
          breakpoints={{
            1024: {
              slidesPerView: 2.5,
              spaceBetween: 20,
            },
          }}
          className="!overflow-visible"
        >
          {cards?.map((card, index) => {
            const gradient =
              index === 0
                ? "linear-gradient(180deg, #EEDECC 0%, #F8F2EE 100%)"
                : index === 1
                  ? "linear-gradient(180deg, #F3EDEB 0%, #F7F8FA 100%)"
                  : "linear-gradient(180deg, #EFF0F0 0%, #F7F9FA 100%)";

            return (
              <SwiperSlide key={index} className="!h-auto">
                <div
                  className="group relative h-full overflow-hidden rounded-[16px] shadow-[0_0_8px_#C0C0C040] sm:rounded-[18px] lg:aspect-[630/384] lg:rounded-[24px]"
                  style={{ background: gradient }}
                >
                  {/* ================= CARD IMAGE ================= */}
                  {card.cards_image && (
                    <div
                      className={`absolute bottom-0 right-0 z-[1] h-full w-[58%] sm:w-[58%] lg:w-[69%] ${
                        index === 0
                          ? "lg:-right-[1px]"
                          : index === 1
                            ? "lg:-right-[1px]"
                            : "lg:-right-[22px]"
                      }`}
                    >
                      {card.cards_image &&(
                      <Image
                        src={card.cards_image}
                        alt={card.cards_title || ""}
                        fill
                        sizes="(max-width: 639px) 58vw, (max-width: 1023px) 58vw, 35vw"
                        className="object-cover object-center"
                      />
                      )}
                    </div>
                  )}

                  {/* ================= CARD CONTENT ================= */}
                  <div className="relative z-[2] flex h-full w-[60%] flex-col items-start p-4 sm:w-[58%] sm:p-5 lg:w-[48%] lg:p-8">
                    {/* Title */}
                    {card.cards_title && (
                      <h3 className="max-w-full font-['Satoshi'] text-[20px] font-bold leading-[1.3] text-[#00204F] md:text-[24px]">
                        {card.cards_title}
                      </h3>
                    )}

                    {/* Description */}
                    {card.cards_description && (
                      <p className="mb-5 mt-2 max-w-[220px] font-['Satoshi'] text-[12px] font-normal leading-[1.4] text-[#334D72] sm:text-[14px] md:mb-[28px] md:text-[16px] lg:mt-2">
                        {card.cards_description}
                      </p>
                    )}

                    {/* Lists */}
                    {card.cards_lists?.length > 0 && (
                      <div className="mt-3 flex flex-col gap-1.5 sm:mt-4 lg:mt-5 lg:gap-3">
                        {card.cards_lists.map((item, listIndex) => (
                          <div
                            key={listIndex}
                            className="flex items-center gap-1 sm:gap-1.5 lg:gap-1"
                          >
                            {item.icon && (
                              <Image
                                src={item.icon}
                                width={20}
                                height={20}
                                alt=""
                                className="h-[20px] w-[20px] shrink-0 object-contain"
                              />
                            )}

                            <span className="font-['Satoshi'] text-[14px] font-medium leading-[1.4] text-[#334D72] md:text-[16px]">
                              {item.list}
                            </span>
                          </div>
                        ))}
                      </div>
                    )}

                    {/* CTA */}
                    {card.cards_cta_text && (
                      <a
                        href={card.cards_cta_url || "#"}
                        className="mt-[32px] flex shrink-0 items-center gap-2 font-['Satoshi'] text-[18px] font-bold leading-[1.4] text-[#1718FF] lg:mt-[60px]"
                      >
                        <span>{card.cards_cta_text}</span>

                        <span className="flex h-[22px] w-[22px] shrink-0 items-center justify-center rounded-full border border-[#1718FF] text-[12px] leading-none sm:h-6 sm:w-6 lg:h-10 lg:w-10 lg:text-[16px]">
                          ↗
                        </span>
                      </a>
                    )}
                  </div>

                  {/* ================= NUMBER ================= */}
                  {card.cards_number && (
                    <div className="absolute right-[20px] top-3 z-[3] flex h-[42px] w-[59px] items-center justify-center rounded-[44%] bg-[rgba(255,255,255,0.7)] sm:right-4 sm:top-4 md:right-[27px]">
                      <span className="font-['Satoshi'] text-[16px] font-bold leading-[1.4] text-[#00204F]">
                        {card.cards_number}
                      </span>
                    </div>
                  )}

                  {/* ================= CARD ICON ================= */}
                  {card.cards_icon && (
                    <div className="absolute bottom-3 right-[36px] z-[3] flex h-auto w-auto items-center justify-center rounded-full bg-white sm:bottom-4 sm:right-4 md:right-[30px]">
                      <Image
                        src={card.cards_icon}
                        width={56}
                        height={56}
                        alt=""
                        className="h-[40px] w-[40px] object-contain md:h-[56px] md:w-[56px]"
                      />
                    </div>
                  )}
                </div>
              </SwiperSlide>
            );
          })}
        </Swiper>
      </div>
    </section>
  );
}