"use client";

import { useEffect, useRef, useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { ArrowRight, ChevronDown, ChevronUp } from "lucide-react";
import { gsap } from "@/lib/gsap";
import Navbar from "@/components/Navbar";
import Breadcrumbs from "@/components/Breadcrumbs";
import Footer from "@/components/Footer";
import ScrollAnimations from "@/components/ScrollAnimations";
import StatsAndStory from "@/components/sections/StatsAndStory";
import { cn } from "@/lib/utils";


// Register GSAP plugins
export default function AboutPage() {
    const mainRef = useRef<HTMLDivElement>(null);
    const [isGovernanceExpanded, setIsGovernanceExpanded] = useState(false);

    useEffect(() => {
        const ctx = gsap.context(() => {
            // Hero Animations
            const heroTl = gsap.timeline();
            heroTl.from(".about-hero-title", { y: 40, opacity: 0, duration: 1.2, delay: 0.5 });

            // Reveal animations for scroll
            gsap.utils.toArray<HTMLElement>(".reveal-up").forEach((element) => {
                gsap.from(element, {
                    scrollTrigger: {
                        trigger: element,
                        start: "top 85%",
                        toggleActions: "play none none reverse",
                    },
                    y: 50,
                    opacity: 0,
                    duration: 1,
                    ease: "power3.out",
                });
            });

        }, mainRef);

        return () => ctx.revert();
    }, []);

    return (
        <main ref={mainRef} className="min-h-screen bg-white">
            <ScrollAnimations />
            <Navbar />

            {/* ABOUT HERO - Banner */}
            <section className="relative pt-24 pb-8 md:pt-40 md:pb-16 min-h-[20px] w-full flex items-center justify-center overflow-hidden">
                <Image
                    src="/images/pexels9.webp"
                    alt="About Us Background"
                    fill
                    className="object-cover"
                    priority
                />
                {/* Dark overlay for text readability */}
                <div className="absolute inset-0 bg-brand-dark/70" />

                <div className="relative z-10 text-center px-6 flex flex-col items-center">
                    <h1 className="about-hero-title text-4xl md:text-6xl lg:text-7xl font-medium text-white tracking-tight mt-6">
                        About Us
                    </h1>
                </div>
            </section>

            {/* IDEA GROUP LEGACY */}
            <section className="bg-white">
                <div className="max-w-[1400px] mx-auto px-8 md:px-16 lg:px-32 xl:px-40 pb-8 pt-8">
                    <Breadcrumbs items={[{ label: "About Us" }]} className="mb-12" />
                </div>
            </section>

            <StatsAndStory />

            <section className="bg-white pt-24">
                <div className="max-w-[1400px]  mx-auto px-8 md:px-16 lg:px-32 xl:px-40 grid grid-cols-1 xl:grid-cols-2 gap-24 items-start">
                    <div className="relative group xl:sticky xl:top-32 reveal-up hidden xl:block">
                        <div className="relative aspect-[4/5] overflow-hidden shadow-sm">
                            <Image
                                src="/images/713-x-692-web-banner.webp"
                                alt="Idea Group Legacy"
                                fill
                                sizes="(min-width: 1280px) 40vw, 100vw"
                                className="object-cover"
                            />
                            <div className="absolute inset-0 bg-brand-dark/10 group-hover:bg-transparent transition-colors duration-1000" />
                        </div>
                    </div>

                    <div className="space-y-12 reveal-up">
                        <div>
                            <div className="flex items-center gap-4 mb-4">
                                <div className="h-[1.5px] w-8 bg-brand-accent" />
                                <span className="text-[11px] font-medium text-brand-accent uppercase tracking-[0.4em]">Corporate Legacy</span>
                                <div className="h-[1.5px] w-8 bg-brand-accent" />
                            </div>
                            <h2 className="text-3xl md:text-5xl font-semibold text-brand-dark tracking-tighter leading-[1.1] mb-6 xl:mb-12">
                                Company Overview
                            </h2>
                            {/* Mobile Image */}
                            <div className="block xl:hidden relative aspect-[4/5] overflow-hidden shadow-sm mb-8 reveal-up">
                                <Image
                                    src="/images/713-x-692-web-banner.webp"
                                    alt="Idea Group Legacy"
                                    fill
                                    sizes="(min-width: 1280px) 40vw, 100vw"
                                    className="object-cover"
                                />
                                <div className="absolute inset-0 bg-brand-dark/10 transition-colors duration-1000" />
                            </div>
                            <div className="space-y-6 text-base md:text-md text-brand-dark/50 font-normal leading-relaxed">
                                <p>
                                    <span className="text-brand-dark font-normal">Idea Group Limited</span> is a leading Sri Lankan business conglomerate that operates with a
                                    progressive global mindset. Since our inception in 2008 as a software development firm, we have
                                    strategically expanded our horizons to become a diversified conglomerate. Today, we are honored
                                    to be ranked among the <span className="text-brand-dark font-normal">LMD Top 50 Financial Performing Entities</span> in Sri Lanka, a testament to
                                    our stability, growth, and unwavering commitment to excellence.
                                </p>
                                <p>
                                    With a vast portfolio that includes our own home-grown brands and 14 strategic acquisitions, we
                                    have become a household name in the construction and home improvement sectors. Our success
                                    is built on a foundation of innovation, professional endorsement, and the trust of millions of
                                    residential and commercial customers nationwide.
                                </p>

                            </div>
                        </div>

                    </div>
                </div>
            </section>

            {/* OUR HERITAGE */}
            <section className="py-24 bg-white border-b border-brand-dark/5">
                <div className="max-w-[1400px] mx-auto px-8 md:px-16 lg:px-32 xl:px-40">
                    <div className="flex items-center gap-4 mb-4 reveal-up">
                        <div className="h-[1.5px] w-8 bg-brand-accent" />
                        <span className="text-[11px] font-medium text-brand-accent uppercase tracking-[0.4em]">Our Legacy</span>
                        <div className="h-[1.5px] w-8 bg-brand-accent" />
                    </div>
                    <h2 className="text-3xl md:text-5xl font-semibold text-brand-dark tracking-tighter leading-[1.1] mb-16 reveal-up">
                        Our Heritage
                    </h2>

                    <div className="grid grid-cols-1 xl:grid-cols-2 gap-16 items-start mb-24 reveal-up">
                        <div>
                            <h3 className="text-2xl font-bold text-brand-dark mb-6 tracking-tight">From Humble Beginnings to Market Leadership</h3>
                            <p className="text-base text-brand-dark/60 leading-relaxed font-normal">
                                Our journey began in 2008, driven by a passion for technology and innovation. What started as a tech-focused entity soon expanded its horizons to identify and seize new opportunities in the manufacturing and trading sectors. Over the years, we have mastered the art of diversification, transforming into a multi-brand powerhouse that leads the market through quality and reliability.
                            </p>
                        </div>
                        <div>
                            <h3 className="text-2xl font-bold text-brand-dark mb-6 tracking-tight">The Birth of I-Roof</h3>
                            <p className="text-base text-brand-dark/60 leading-relaxed font-normal">
                                In our quest to revolutionize the Sri Lankan construction landscape, we introduced I-Roof—our flagship roofing brand. Born from the engineering expertise of Idea Group, I-Roof was created to provide a superior, eco-friendly, and durable alternative to traditional roofing materials. Today, I-Roof stands as a crown of our brand portfolio, embodying the &quot;Quality & Innovation&quot; that Idea Group represents.
                            </p>
                        </div>
                    </div>

                    <div className="reveal-up">
                        <h3 className="text-3xl md:text-4xl font-bold text-brand-dark tracking-tight mb-12 text-center">Our Strategic Pillars</h3>
                        <div className="grid grid-cols-1 md:grid-cols-3 gap-8">
                            {/* Vision */}
                            <div className="p-10 bg-zinc-50 border border-brand-dark/5 shadow-sm hover:shadow-xl transition-all duration-700 group text-center">
                                <h4 className="text-xl font-bold text-brand-dark mb-4 group-hover:text-brand-accent transition-colors">Vision</h4>
                                <p className="text-sm text-brand-dark/50 leading-relaxed">To be the most innovative and trusted roofing solutions provider globally, setting new standards in quality and sustainability.</p>
                            </div>

                            {/* Mission */}
                            <div className="p-10 bg-zinc-50 border border-brand-dark/5 shadow-sm hover:shadow-xl transition-all duration-700 group text-center">
                                <h4 className="text-xl font-bold text-brand-dark mb-4 group-hover:text-brand-accent transition-colors">Mission</h4>
                                <p className="text-sm text-brand-dark/50 leading-relaxed">To deliver cutting-edge, eco-friendly building materials that empower communities, protect investments, and respect the environment.</p>
                            </div>

                            {/* Core Values */}
                            <div className="p-10 bg-zinc-50 border border-brand-dark/5 shadow-sm hover:shadow-xl transition-all duration-700 group text-center">
                                <h4 className="text-xl font-bold text-brand-dark mb-4 group-hover:text-brand-accent transition-colors">Core Values</h4>
                                <p className="text-sm text-brand-dark/50 leading-relaxed">Innovation, Integrity, Sustainability, Excellence, and Customer-Centricity form the bedrock of everything we do.</p>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            {/* CORPORATE GOVERNANCE SECTION */}
            <section className="relative py-24 md:py-32 bg-brand-dark overflow-hidden border-y border-brand-dark/5">
                <Image
                    src="/images/office-room1.webp"
                    alt="Corporate Governance"
                    fill
                    className="object-cover opacity-100"
                />

                <div className="max-w-[1400px] mx-auto px-8 md:px-16 lg:px-20 xl:px-20 relative z-10">
                    <div className="flex justify-end">
                        <div className="w-full xl:w-[60%] bg-[#5b677a]/90 backdrop-blur-sm p-12 md:p-12 md:pr-24 text-white shadow-2xl reveal-up text-left">
                            {/* <h2 className="text-3xl md:text-5xl font-semibold mb-6 tracking-tighter">
                                Corporate Governance & Leadership
                            </h2> */}
                            <h2 className="text-base md:text-2xl font-bold text-white/90 mb-8">
                                Guided by Visionary Leadership & Professional Integrity
                            </h2>
                            <div className="text-sm md:text-base text-zinc-200/80 leading-relaxed font-normal mb-8">
                                <p className={cn(
                                    "transition-all duration-500",
                                    !isGovernanceExpanded ? "line-clamp-4" : ""
                                )}>
                                    At Idea Group Limited, we believe that a strong leadership foundation is the driving force behind every successful innovation. Our organization is steered by a Board of Directors and a senior management team consisting of visionary professionals with decades of experience in Industrial Engineering, Strategic Finance, and Global Marketing.
                                    <br /><br />
                                    We adhere to the highest standards of Corporate Governance, ensuring absolute accountability, ethical business conduct, and transparency. This disciplined professional management ensures that every i-Roof product delivered to the market meets stringent international quality benchmarks and adheres to our environmental policies.
                                </p>
                            </div>

                            <button
                                onClick={() => setIsGovernanceExpanded(!isGovernanceExpanded)}
                                className="inline-flex items-center justify-center gap-2 px-8 py-4 border border-white/30 text-white font-bold uppercase tracking-widest text-[10px] hover:bg-white hover:text-[#5b677a] transition-all duration-500 rounded-sm"
                            >
                                {isGovernanceExpanded ? "View Less" : "View More"}
                                {isGovernanceExpanded ? <ChevronUp className="w-4 h-4" /> : <ChevronDown className="w-4 h-4" />}
                            </button>
                        </div>
                    </div>
                </div>
            </section>


            {/* OUR EVENTS SECTION */}
            <section className="py-24 bg-zinc-50 border-y border-brand-dark/5 overflow-hidden">
                <div className="max-w-[1400px] mx-auto px-8 md:px-16 lg:px-32 xl:px-40">
                    <div className="grid grid-cols-1 xl:grid-cols-2 gap-16 xl:gap-24 items-center">
                        <div className="relative w-full aspect-[4/3] xl:aspect-square reveal-up hidden xl:block">
                            <Image
                                src="/images/512-x-341-web-image.webp"
                                alt="Our Events"
                                fill
                                sizes="(min-width: 1280px) 50vw, 100vw"
                                className="object-contain"
                            />
                        </div>
                        <div className="reveal-up">
                            <h2 className="text-3xl md:text-4xl font-bold text-brand-dark tracking-tight mb-4">
                                Our Events
                            </h2>
                            <h3 className="text-sm font-bold text-brand-accent uppercase tracking-widest mb-6 xl:mb-8">
                                Engagement Beyond Business
                            </h3>
                            {/* Mobile Image */}
                            <div className="block xl:hidden relative w-full aspect-[4/3] mb-8 reveal-up">
                                <Image
                                    src="/images/512-x-341-web-image.webp"
                                    alt="Our Events"
                                    fill
                                    sizes="(min-width: 1280px) 50vw, 100vw"
                                    className="object-contain"
                                />
                            </div>
                            <p className="text-brand-dark/60 leading-relaxed font-medium mb-10">
                                We actively engage with the industry and our community through various national and regional events. From showcasing our latest innovations at premier construction exhibitions like Architect, JITF and Kedella to conducting educational workshops for consumers, contractors and architectors island-wide, our events are designed to build knowledge and strengthen the bonds with our valued stakeholders across Sri Lanka.
                            </p>
                            <Link href="/news" className="inline-flex items-center justify-center px-10 py-4 border border-brand-accent/50 text-brand-accent font-bold uppercase tracking-widest text-[11px] hover:bg-brand-accent hover:text-white transition-all duration-500 rounded-sm">
                                Read More
                            </Link>
                        </div>
                    </div>
                </div>
            </section>

            {/* AWARDS & CERTIFICATIONS SECTION */}
            <section id="awards" className="pt-12 bg-white overflow-hidden border-b border-brand-dark/5">
                <div className="max-w-[1400px] mx-auto px-8 md:px-16 lg:px-32 xl:px-40">
                    {/* New Achievements UI (Intro to Grid) */}
                    <div className="grid grid-cols-1 xl:grid-cols-2 gap-16 xl:gap-24 items-center mb-24">
                        <div className="xl:order-1 reveal-up">
                            <h2 className="text-3xl md:text-4xl font-bold text-brand-dark tracking-tight mb-4">
                                Our Achievements and Certifications
                            </h2>
                            <h3 className="text-sm font-bold text-brand-accent uppercase tracking-widest mb-6 xl:mb-8">
                                A Journey of Excellence and Recognition
                            </h3>
                            {/* Mobile Image */}
                            <div className="block xl:hidden relative w-full aspect-[4/3] mb-8 reveal-up">
                                <Image
                                    src="/images/i-roof-achievements.webp"
                                    alt="Awards and Certifications Trophy"
                                    fill
                                    sizes="(min-width: 1280px) 50vw, 100vw"
                                    className="object-contain drop-shadow-2xl"
                                />
                            </div>
                            <p className="text-brand-dark/60 leading-relaxed font-medium mb-10">
                                Our commitment to quality and innovation has been consistently honored with numerous prestigious accolades. From being ranked among the LMD Top 50 financial entities to receiving The Best Product Awards for Roofing Categorty, these achievements reflect our market leadership. Backed by ISO certifications, every milestone we reach reinforces our dedication to delivering world-class roofing solutions that Sri Lankans can trust.
                            </p>
                            <Link
                                href="/awards"
                                className="inline-flex items-center justify-center px-10 py-4 border border-brand-accent/50 text-brand-accent font-bold uppercase tracking-widest text-[11px] hover:bg-brand-accent hover:text-white transition-all duration-500 rounded-sm"
                            >
                                Read More
                            </Link>
                        </div>
                        <div className="relative w-full aspect-[4/3] xl:aspect-square xl:order-2 reveal-up hidden xl:block">
                            <Image
                                src="/images/i-roof-achievements.webp"
                                alt="Awards and Certifications Trophy"
                                fill
                                sizes="(min-width: 1280px) 50vw, 100vw"
                                className="object-contain drop-shadow-2xl"
                            />
                        </div>
                    </div>

                </div>
            </section>

            {/* CALL TO ACTION SECTION */}
            <section className="py-20 bg-zinc-50 border-t border-zinc-100">
                <div className="max-w-[1400px] mx-auto px-8 md:px-16 lg:px-32 xl:px-40 text-center">
                    <div className="max-w-2xl mx-auto flex flex-col items-center">
                        <div className="flex items-center gap-3 text-brand-accent text-[11px] font-extrabold tracking-[0.4em] uppercase mb-6">
                            <span className="w-6 h-[1.5px] bg-brand-accent rounded-full" />
                            Build with Trust
                            <span className="w-6 h-[1.5px] bg-brand-accent rounded-full" />
                        </div>
                        <h2 className="text-3xl md:text-[40px] font-extrabold text-brand-dark leading-none mb-6">
                            Ready to Elevate Your Roof?
                        </h2>
                        <p className="text-sm md:text-base text-zinc-500 font-sans leading-relaxed mb-10 max-w-lg">
                            Get in touch with our team of experts today or request a custom quotation tailored to your architectural plans.
                        </p>
                        <div className="flex flex-col sm:flex-row gap-4 justify-center items-center w-full sm:w-auto">
                            <Link
                                href="/contact#quotation"
                                className="w-full sm:w-auto inline-flex items-center justify-center bg-brand-accent hover:bg-brand-dark text-white px-8 py-4 rounded-xl text-[10px] font-black uppercase tracking-[0.2em] transition-all duration-300 hover:scale-105 active:scale-95 shadow-[0_10px_20px_-5px_rgba(177,32,40,0.4)] group"
                            >
                                Get a Free Quote
                                <ArrowRight className="w-4 h-4 ml-2 transition-transform duration-300 group-hover:translate-x-1" />
                            </Link>
                            <Link
                                href="/contact"
                                className="w-full sm:w-auto inline-flex items-center justify-center border border-zinc-300 hover:border-brand-dark text-brand-dark hover:text-white hover:bg-brand-dark px-8 py-4 rounded-xl text-[10px] font-black uppercase tracking-[0.2em] transition-all duration-300 hover:scale-105 active:scale-95"
                            >
                                Contact Us
                            </Link>
                        </div>
                    </div>
                </div>
            </section>

            <Footer />
        </main>
    );
}
