'use client';

import { Button } from "@/components/ui/button";
import { useEffect, useRef } from "react";

export default function AboutSection() {
  const logos = [
    { src: "/Logo1.png", alt: "Partner Logo 1" },
    { src: "/Logo2.png", alt: "Partner Logo 2" },
    { src: "/Logo3.png", alt: "Partner Logo 3" },
  ];

  const carouselRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const carousel = carouselRef.current;
    if (!carousel) return;

    let animationFrameId: number;
    let speed = 1;
    let position = 0;
    const logosWidth = logos.length * 160;

    const animate = () => {
      position -= speed;
      
      if (position <= -logosWidth) {
        position = 0;
      }
      
      carousel.style.transform = `translateX(${position}px)`;
      animationFrameId = requestAnimationFrame(animate);
    };

    animationFrameId = requestAnimationFrame(animate);

    return () => {
      cancelAnimationFrame(animationFrameId);
    };
  }, [logos.length]);

  return (
    <section className="relative w-full px-6 md:px-20 pt-20 pb-16 bg-white rounded-t-[4rem] -mt-10 z-20 shadow-lg overflow-hidden">
      {/* Colored gradient background elements */}
      <div className="absolute top-0 right-0 w-72 h-72 bg-gradient-to-br from-gray-100 to-white rounded-3xl opacity-60 blur-2xl -z-10" />
      <div className="absolute bottom-0 left-0 w-48 h-48 bg-gradient-to-tr from-gray-100 to-white rounded-3xl opacity-50 blur-2xl -z-10" />
      <div className="relative z-10">
        {/* Header with carousel */}
        <div className="flex flex-col md:flex-row items-center md:items-start justify-between mb-5 gap-6">
          <h2 className="text-3xl md:text-4xl font-bold text-teal-700 text-center md:text-left">
            Trusted by many partners
          </h2>

          <div className="relative w-full md:w-auto overflow-hidden max-w-[600px]">
            <div className="absolute inset-y-0 left-0 w-12 bg-gradient-to-r from-white to-transparent z-10" />
            <div className="absolute inset-y-0 right-0 w-12 bg-gradient-to-l from-white to-transparent z-10" />
            
            <div 
              ref={carouselRef}
              className="flex items-center gap-10 px-4"
            >
              {[...logos, ...logos, ...logos].map((logo, index) => (
                <div 
                  key={`${logo.alt}-${index}`}
                  className="flex-shrink-0 transition-all duration-300"
                  style={{
                    opacity: 0.7 + (0.3 * Math.sin((index % logos.length) * (Math.PI / logos.length)))
                  }}
                >
                  <img 
                    src={logo.src} 
                    alt={logo.alt} 
                    className="h-10 object-contain transition-all duration-300 hover:scale-110"
                  />
                </div>
              ))}
            </div>
          </div>
        </div>

        <div className="relative pt-16"> {/* Added pt-16 for padding top */}
  {/* Your about content */}
  <div className="relative z-10">
    <Button
      variant="outline"
      className="flex items-center gap-2 rounded-full border border-teal-500 text-teal-700 hover:bg-teal-50 mb-4"
    >
      <div className="w-2 h-2 rounded-full bg-[#0B6F6F]" />
      About us
    </Button>

    <h3 className="text-4xl font-bold text-teal-800 mb-4">Who we are?</h3>
    <p className="text-gray-600 mb-6 max-w-5xl">
      At DOTTINAT, we specialize in delivering innovative and comprehensive solutions across the pharmaceutical sector, medical devices, and medical supplies, with a strong focus on importation and distribution across Ethiopia.
    </p>

    <div className="flex gap-4 mb-6 max-w-4xl pl-5"> {/* Added pl-4 here */}
  <div className="w-3 rounded bg-gradient-to-b from-[#0B6F6F] to-[#FAE278]" />
  <div className="text-gray-700 space-y-3">
    <p>
     Our services span medical supply sourcing and pharmaceutical procurement, providing expert guidance in procurement strategy, logistics management, regulatory alignment, and market access. We work closely with our partners to ensure product quality, operational efficiency, and long-term success.
    </p>
    <p>
     Through our end-to-end approach, we manage sourcing, supply chain coordination, importation, and nationwide distribution—delivering reliable, compliant, and timely solutions tailored to the evolving needs of Ethiopia’s healthcare and commercial sectors.
    </p>
     <p>
     In addition, through our Dotti Cosmetics Brand, we bring over 10 years of experience in importation and distribution, delivering trusted cosmetic products to the Ethiopian market with a strong emphasis on quality, safety, and reliability.
    </p>
  </div>
</div>

    <p className="text-gray-700 font-medium">We're building a future of healthcare.</p>
  </div>

  {/* Right corner SVG */}
  <div className="absolute top-0 right-0 w-[300px] h-[300px] opacity-10 -z-10 pointer-events-none">
    <svg width="100%" height="100%" viewBox="0 0 304 304" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path opacity="1" fillRule="evenodd" clipRule="evenodd" d="M179.972 290.216C159.476 308.651 127.921 306.997 109.464 286.52L13.475 180.022C-5.00772 159.516 -3.35104 127.905 17.1739 109.443L123.789 13.5445C144.284 -4.89093 175.84 -3.23715 194.296 17.2396L290.286 123.738C308.768 144.244 307.112 175.855 286.587 194.317L179.972 290.216Z" fill="url(#paint0_linear)" />
      <defs>
        <linearGradient id="paint0_linear" x1="233.312" y1="242.32" x2="70.4483" y2="61.4406" gradientUnits="userSpaceOnUse">
          <stop stopColor="#00954A"/>
          <stop offset="0.625" stopColor="#137056"/>
          <stop offset="1" stopColor="#32346A"/>
        </linearGradient>
      </defs>
    </svg>
  </div>

  {/* Left corner SVG - mirrored */}
  <div className="absolute top-15 right-90 w-[300px] h-[300px] opacity-10 -z-10 pointer-events-none transform -scale-x-100">
    <svg width="50%" height="50%" viewBox="0 0 304 304" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path opacity="1" fillRule="evenodd" clipRule="evenodd" d="M179.972 290.216C159.476 308.651 127.921 306.997 109.464 286.52L13.475 180.022C-5.00772 159.516 -3.35104 127.905 17.1739 109.443L123.789 13.5445C144.284 -4.89093 175.84 -3.23715 194.296 17.2396L290.286 123.738C308.768 144.244 307.112 175.855 286.587 194.317L179.972 290.216Z" fill="url(#paint0_linear)" />
      <defs>
        <linearGradient id="paint0_linear" x1="233.312" y1="242.32" x2="70.4483" y2="61.4406" gradientUnits="userSpaceOnUse">
          <stop stopColor="#00954A"/>
          <stop offset="0.625" stopColor="#137056"/>
          <stop offset="1" stopColor="#32346A"/>
        </linearGradient>
      </defs>
    </svg>
  </div>
</div>
</div>
    </section>
  );
}