"use client";
import React, { useState, useEffect } from "react";
import Header from "../components/Header";
import Footer from "../components/Footer";
import { Button } from "@/components/ui/button";
import Image from "next/image";
import { ArrowDownRight } from "lucide-react";

export default function AboutPage() {
  type DescriptionKey = "Pharmaceutical sector" | "Medical devices and Medical supplies" | "cosmotics";

  const descriptions: Record<DescriptionKey, string> = {
    "Pharmaceutical sector": `We ensure hospitals and clinics receive top-tier equipment—like gloves, masks, and tools—on time and within budget. By refining procurement strategies, we reduce inefficiencies and enhance reliability. DOTTINAT is committed to supporting healthcare systems with sustainable, high-quality solutions that make a difference.

We tackle challenges with tailored approaches, ensuring consistent quality. By collaborating with certified suppliers, we meet global standards and prioritize patient safety. Our goal is to strengthen healthcare infrastructure with dependable resources, minimizing delays and improving care.`,

    "Medical devices and Medical supplies": `We are laying the groundwork for innovative growth in the medical devices and medical supplies sector, expanding our capabilities to meet the evolving needs of healthcare systems. Our plans include advancing sourcing, distribution, and future manufacturing partnerships, while strengthening digital platforms to enhance accessibility and operational efficiency for our partners.

By investing in new technologies, logistics infrastructure, and quality systems, DOTTINAT aims to deliver reliable, compliant, and high-impact solutions across Ethiopia and beyond. We are committed to evolving alongside modern healthcare demands, ensuring consistent supply and dependable service.`,
    "cosmotics": `We streamline the sourcing and distribution of cosmetic products for retailers, distributors, and business partners. Our efforts ensure the market receives high-quality, safe, and trusted cosmetic products—delivered on time and within budget. By refining procurement and import strategies, we reduce inefficiencies and strengthen supply reliability. Dotti Cosmetics is committed to supporting the beauty and personal care industry with sustainable, high-standard solutions that truly make a difference.`,
  };

  const images: Record<DescriptionKey, string> = {
    "Pharmaceutical sector": "/boat.png",
    "cosmotics": "/cosmo.jpg",
    "Medical devices and Medical supplies": "/import.jpg",
  };

  const [activeDescription, setActiveDescription] = useState<string>(
    descriptions["Pharmaceutical sector"]
  );
  const [activeImage, setActiveImage] = useState<string>(images["Pharmaceutical sector"]);
  const [activeCategory, setActiveCategory] = useState<string | null>(null);
  const [isVisible, setIsVisible] = useState({
    mission: false,
    vision: false,
    values: false
  });

  useEffect(() => {
    const observer = new IntersectionObserver(
      (entries) => {
        entries.forEach((entry) => {
          if (entry.isIntersecting) {
            const section = entry.target.getAttribute('data-section');
            if (section) {
              setIsVisible((prev) => ({ ...prev, [section]: true }));
            }
          }
        });
      },
      { threshold: 0.2 }
    );

    const sections = document.querySelectorAll('[data-section]');
    sections.forEach((section) => observer.observe(section));

    return () => observer.disconnect();
  }, []);

  return (
    <div className="min-h-screen flex flex-col">
      <Header />

      <main className="flex-grow">
        <section className="container mx-auto px-4 pt-8">
          <div className="flex flex-col md:flex-row items-start gap-12">
            <div className="max-w-md text-center md:text-left mb-8 md:mb-0 md:pt-12">
              <div className="flex md:justify-start mb-6">
                <Button
                  variant="outline"
                  className="flex items-center gap-2 rounded-full border border-teal-500 text-teal-700 hover:bg-teal-50"
                >
                  <div className="w-2 h-2 rounded-full bg-[#0B6F6F]"></div>
                  About us
                </Button>
              </div>
              <h2 className="text-6xl mb-6 text-[#0B6F6F] font-bold">
                Bridging gaps in Healthcare
              </h2>
              <p className="text-xl mb-8 text-[#8C8C8C]">
                Strong, mission-driven, and concise.
              </p>
              <Button
                onClick={() =>
                  document
                    .getElementById("mission-section")
                    ?.scrollIntoView({ behavior: "smooth" })
                }
                className="w-full md:w-auto px-10 py-6 text-lg group hover:shadow-lg transition-all"
                style={{ backgroundColor: "#0B6F6F", borderRadius: "90px" }}
              >
                <span className="px-4 py-2">Explore Who we are</span>
                <ArrowDownRight className="ml-2 h-5 w-5 transform group-hover:translate-x-1 group-hover:translate-y-1 transition-transform" />
              </Button>
            </div>
            <div className="w-full md:w-1/2 relative mr-20">
              <div className="w-full h-auto md:w-[798.67px] md:h-[733.33px]">
                <Image
                  src="/about.png"
                  alt="Healthcare professionals working"
                  width={798.67}
                  height={733.33}
                  className="rounded-md object-cover shadow-lg w-full h-auto"
                  priority
                />
              </div>
            </div>
          </div>
        </section>

        {/* Mission Section */}
        <section 
          id="mission-section"
          data-section="mission"
          className={`py-16 px-4 bg-white transition-all duration-1000 ${
            isVisible.mission ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-10'
          }`}
        >
          <div className="container mx-auto flex flex-col-reverse md:flex-row items-center">
            {/* Image: appears last on mobile, first on desktop */}
            <div className="md:w-1/2 mt-6 md:mt-0 md:mr-8">
              <img
                src="/mission.png"
                alt="Our Mission"
                className="w-full h-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300"
              />
            </div>

            {/* Text: appears first on mobile, second on desktop */}
            <div className="md:w-1/2">
              <div className="w-20 h-20 mb-4">
                <img src="/mission.gif" alt="Mission Icon" className="w-full h-full object-contain" />
              </div>
              <h2 className="text-4xl font-bold text-[#0B6F6F] mb-4">
                Our Mission
              </h2>
              <p className="text-lg text-gray-700">
                At DOTTINAT, we're committed to solving critical challenges in
                healthcare procurement. By streamlining supply chains, we
                empower our partners—hospitals, businesses, and
                distributors—with high-quality, sustainable solutions.
              </p>
            </div>
          </div>
        </section>

        {/* Vision Section */}
        <section 
          data-section="vision"
          className={`py-16 px-4 bg-gray-50 transition-all duration-1000 ${
            isVisible.vision ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-10'
          }`}
        >
          <div className="container mx-auto flex flex-col md:flex-row items-center">
            {/* Text: appears first on both mobile and desktop */}
            <div className="md:w-1/2 mb-6 md:mb-0 md:mr-8">
              <div className="w-20 h-20 mb-4">
                <img src="/visionn.gif" alt="Vision Icon" className="w-full h-full object-contain" />
              </div>
              <h2 className="text-4xl font-bold text-[#0B6F6F] mb-4">
                Our Vision
              </h2>
              <p className="text-lg text-gray-700">
                To become the leading global partner in healthcare procurement,
                setting new standards for quality, reliability, and innovation.
                We envision a world where every healthcare provider has seamless
                access to the resources they need to deliver exceptional care.
              </p>
            </div>

            {/* Image: appears last on mobile, second on desktop */}
            <div className="md:w-1/2">
              <img
                src="/vision.jpg"
                alt="Our Vision"
                className="w-full h-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300"
              />
            </div>
          </div>
        </section>

        {/* Values Section */}
        <section 
          data-section="values"
          className={`py-16 px-4 bg-white transition-all duration-1000 ${
            isVisible.values ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-10'
          }`}
        >
          <div className="container mx-auto flex flex-col-reverse md:flex-row items-center">
            {/* Image: appears last on mobile, first on desktop */}
            <div className="md:w-1/2 mt-6 md:mt-0 md:mr-8">
              <img
                src="/values.jpg"
                alt="Our Values"
                className="w-full h-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300"
              />
            </div>

            {/* Text: appears first on mobile, second on desktop */}
            <div className="md:w-1/2">
              <div className="w-20 h-20 mb-4">
                <img src="/value.gif" alt="Values Icon" className="w-full h-full object-contain" />
              </div>
              <h2 className="text-4xl font-bold text-[#0B6F6F] mb-4">
                Our Values
              </h2>
              <p className="text-lg text-gray-700">
                Excellence, Integrity, and Innovation drive everything we do.
                We believe in building lasting partnerships through transparency,
                accountability, and a relentless commitment to quality. Our
                values guide us in creating meaningful impact across the
                healthcare industry.
              </p>
            </div>
          </div>
        </section>

        <section
          id="mission-content"
          className="container mx-auto px-4 py-16 scroll-mt-28"
        >
          <h1 className="text-5xl font-bold mb-5 text-[#0B6F6F]">
            We are working on
          </h1>
          <p className="text-xl text-gray-700 mb-12">
            At DOTTINAT, We're Dedicated To Advancing Healthcare Procurement
            With Innovative Solutions. Led By Dr. Meswat Birru, Our Team is
            Enhancing Supply Chains And Unlocking New Opportunities For
            Hospitals, Businesses, And Distributors Worldwide.
          </p>
          <div className="flex flex-col lg:flex-row items-start gap-6">
            {/* Buttons Section */}
            <div className="w-full lg:w-1/4">
              <div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-1">
                <Button
                  className={`w-full px-6 py-6 ${
                    activeCategory === "healthcare"
                      ? "bg-[#0B6F6F] text-white"
                      : "bg-[#F6F6F6] text-black hover:bg-[#0B6F6F] hover:text-white"
                  }`}
                  onClick={() => {
                    setActiveCategory("Pharmaceutical sector");
                    setActiveDescription(descriptions["Pharmaceutical sector"]);
                    setActiveImage(images["Pharmaceutical sector"]);
                  }}
                >
                  Pharmaceutical sector
                </Button>

                <Button
                  className={`w-full px-6 py-6 ${
                    activeCategory === "cosmotics"
                      ? "bg-[#0B6F6F] text-white"
                      : "bg-[#F6F6F6] text-black hover:bg-[#0B6F6F] hover:text-white"
                  }`}
                  onClick={() => {
                    setActiveCategory("cosmotics");
                    setActiveDescription(descriptions["cosmotics"]);
                    setActiveImage(images["cosmotics"]);
                  }}
                >
                  cosmotics sector
                </Button>

                <Button
                  className={`w-full px-6 py-6 ${
                    activeCategory === "Medical devices and Medical supplies"
                      ? "bg-[#0B6F6F] text-white"
                      : "bg-[#F6F6F6] text-black hover:bg-[#0B6F6F] hover:text-white"
                  }`}
                  onClick={() => {
                    setActiveCategory("Medical devices and Medical supplies");
                    setActiveDescription(descriptions["Medical devices and Medical supplies"]);
                    setActiveImage(images["Medical devices and Medical supplies"]);
                  }}
                >
                 Medical devices and Medical supplies
                </Button>
              </div>
            </div>

            {/* Content Section */}
            <div className="w-full lg:w-3/4 flex flex-col md:flex-row gap-4">
              <div className="flex-1 flex items-start justify-start">
                <p className="text-md text-gray-700 whitespace-pre-line text-left w-full">
                  {activeDescription}
                </p>
              </div>

              <div className="flex-1">
                <Image
                  src={activeImage}
                  alt="Dynamic Section Image"
                  width={600}
                  height={400}
                  className="rounded-md object-cover shadow-lg w-full h-auto"
                  priority
                />
              </div>
            </div>
          </div>
        </section>



      </main>
      <Footer />
    </div>
  );
}
