"use client";
import Link from "next/link";
import { useAbout } from "@/lib/hooks/useAbout";
import { AboutJourney } from "@/lib/api/aboutService";

const AboutStarter = () => {
  const { data, loading, error } = useAbout();

  if (loading) {
    return (
      <section className="about-journey-section">
        <div className="container">
          <div className="row">
            <div className="col-12">
              <div className="text-center py-4">
                <div className="spinner-border text-light" role="status">
                  <span className="visually-hidden">Loading...</span>
                </div>
                <p className="mt-2 text-muted">Loading journey content...</p>
              </div>
            </div>
          </div>
        </div>
      </section>
    );
  }

  if (error) {
    return (
      <section className="about-journey-section">
        <div className="container">
          <div className="row">
            <div className="col-12">
              <div className="text-center py-4">
                <div className="alert alert-danger" role="alert">
                  <h4 className="alert-heading">Error Loading Content</h4>
                  <p>{error}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>
    );
  }

  const journeyData = data?.journey as AboutJourney | undefined;
  const milestones = journeyData?.milestones && journeyData.milestones.length > 0 
    ? journeyData.milestones 
    : [
        { year: "2020", title: "Company Founded", description: "GNX Soft Ltd established in Burgas, Bulgaria" },
        { year: "2021", title: "Industry Specialization", description: "Specialized in 8 mission-critical industries" }
      ];

  return (
    <>
      <section className="hero-banner about-journey-section" suppressHydrationWarning>
        <div className="container">
          <div className="row align-items-center g-4">
            {/* Left Column - Text Content */}
            <div className="col-12 col-lg-6">
              <div className="journey-content">
                {/* Badge */}
                <div className="hero-badge">
                  <div className="badge-icon">
                    <i className={journeyData?.badge_icon || "fa-solid fa-rocket"}></i>
                  </div>
                  <span>{journeyData?.badge_text || "Our Journey"}</span>
                </div>

                {/* Main Title */}
                <h1 className="hero-title">
                  {journeyData?.title || "Building Enterprise Excellence Since 2020"}
                </h1>

                {/* Description */}
                <p className="hero-description">
                  {journeyData?.description || "Founded in 2020 in Burgas, Bulgaria, GNX Soft Ltd was established with a clear mission: to deliver world-class enterprise software solutions for mission-critical industries."}
                </p>

                {/* CTA Buttons */}
                <div className="hero-actions">
                  <Link href={journeyData?.cta_link || "services"} className="btn-primary">
                    <span>{journeyData?.cta_text || "Explore Solutions"}</span>
                    <i className="fa-solid fa-arrow-right"></i>
                  </Link>
                </div>
              </div>
            </div>

            {/* Right Column - Milestone Boxes */}
            <div className="col-12 col-lg-6">
              <div className="journey-milestones-wrapper">
                {milestones.map((milestone, index) => (
                  <div key={index} className="journey-milestone-box">
                    <div className="milestone-year-icon">
                      <span>{milestone.year}</span>
                    </div>
                    <div className="milestone-content">
                      <div className="milestone-title">{milestone.title}</div>
                      <div className="milestone-description">{milestone.description}</div>
                    </div>
                  </div>
                ))}
              </div>
            </div>
          </div>
        </div>
      </section>

      <style>{`
        /* Section Base Styles - Transparent Background - Seamless Continuous Flow */
        .about-journey-section {
          padding: 100px 0;
          position: relative;
          background: transparent;
          overflow: hidden;
          color: #000000 !important;
        }
        
        .about-journey-section * {
          color: inherit !important;
        }

        .about-journey-section::before {
          display: none;
        }
          
        .about-journey-section.hero-banner {
          background: transparent;
          min-height: auto;
          
          .hero-background {
            display: none;
          }
        }

        /* Journey Content - Left Column */
        .journey-content {
          text-align: left;
          position: relative;
          z-index: 2;
          
          .hero-badge {
            margin: 0 0 1.25rem 0;
            font-size: 0.75rem;
            padding: 0.5rem 1rem;
            background: linear-gradient(135deg, rgba(212, 175, 55, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
            border: 1px solid rgba(212, 175, 55, 0.3);
            color: #000000 !important;
            backdrop-filter: blur(10px);
            
            .badge-icon {
              width: 20px;
              height: 20px;
              background: linear-gradient(135deg, #d4af37 0%, #8b5cf6 100%);
              
              i {
                font-size: 0.7rem;
                color: #ffffff;
              }
            }
          }
          
          .hero-title {
            font-size: clamp(1.75rem, 3vw, 2.25rem);
            font-weight: 600;
            line-height: 1.3;
            margin: 0 0 1rem 0;
            text-align: left;
            color: #000000 !important;
          }
          
          .hero-description {
            font-size: 0.9375rem;
            line-height: 1.6;
            color: #000000 !important;
            margin: 0 0 1.5rem 0;
            text-align: left;
          }
          
          .hero-actions {
            justify-content: flex-start;
            margin-top: 0;
            
            .btn-primary {
              padding: 0.75rem 1.75rem;
              font-size: 0.875rem;
              background: linear-gradient(135deg, rgba(212, 175, 55, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
              border: 1px solid rgba(212, 175, 55, 0.3);
              color: #000000 !important;
            }
            
            .btn-primary:hover {
              background: linear-gradient(135deg, rgba(212, 175, 55, 0.2) 0%, rgba(139, 92, 246, 0.2) 100%);
              border-color: rgba(212, 175, 55, 0.5);
              box-shadow: 0 8px 24px rgba(212, 175, 55, 0.2);
              color: #000000 !important;
            }
          }
        }

        /* Journey Milestones Wrapper - Right Column */
        .journey-milestones-wrapper {
          display: flex;
          flex-direction: column;
          gap: 0.875rem;
        }

        /* Milestone Box - Compact Luxury */
        .journey-milestone-box {
          display: flex;
          align-items: flex-start;
          gap: 0.875rem;
          padding: 1rem;
          background: linear-gradient(135deg, rgba(212, 175, 55, 0.05) 0%, rgba(139, 92, 246, 0.03) 100%);
          border: 1px solid rgba(212, 175, 55, 0.2);
          border-radius: 10px;
          transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
          position: relative;
          overflow: hidden;
          backdrop-filter: blur(10px);
        }

        .journey-milestone-box::before {
          content: '';
          position: absolute;
          top: 0;
          left: 0;
          width: 2px;
          height: 100%;
          background: linear-gradient(180deg, #d4af37 0%, #8b5cf6 100%);
          opacity: 0;
          transition: opacity 0.25s ease;
        }

        .journey-milestone-box:hover::before {
          opacity: 1;
        }

        .journey-milestone-box:hover {
          background: linear-gradient(135deg, rgba(212, 175, 55, 0.08) 0%, rgba(139, 92, 246, 0.06) 100%);
          border-color: rgba(212, 175, 55, 0.4);
          transform: translateX(4px);
          box-shadow: 0 4px 20px rgba(212, 175, 55, 0.15);
        }

        .milestone-year-icon {
          flex-shrink: 0;
          width: 40px;
          height: 40px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: linear-gradient(135deg, #d4af37 0%, #8b5cf6 100%);
          border: 1px solid rgba(212, 175, 55, 0.4);
          border-radius: 8px;
          font-size: 0.875rem;
          font-weight: 600;
          color: #ffffff;
          transition: all 0.25s ease;
          box-shadow: 0 2px 8px rgba(212, 175, 55, 0.2);
        }

        .journey-milestone-box:hover .milestone-year-icon {
          background: linear-gradient(135deg, #f4d03f 0%, #9d6ef7 100%);
          border-color: rgba(212, 175, 55, 0.6);
          transform: scale(1.05);
          box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
        }

        .milestone-year-icon span {
          font-variant-numeric: tabular-nums;
          letter-spacing: -0.02em;
        }

        .milestone-content {
          flex: 1;
          padding-top: 0.125rem;
        }

        .milestone-title {
          font-size: 0.9375rem;
          font-weight: 600;
          color: #000000 !important;
          margin: 0 0 0.25rem 0;
          line-height: 1.4;
          letter-spacing: -0.01em;
        }

        .milestone-description {
          font-size: 0.8125rem;
          line-height: 1.5;
          color: #000000 !important;
          margin: 0;
        }

        /* Responsive Design */
        @media (max-width: 991px) {
          .about-journey-section {
            padding: 80px 0;
          }
          
          .journey-content {
            text-align: center;
            margin-bottom: 2.5rem;
            
            .hero-title,
            .hero-description {
              text-align: center;
            }
            
            .hero-actions {
              justify-content: center;
            }
          }
        }

        @media (max-width: 767px) {
          .about-journey-section {
            padding: 60px 0;
          }
          
          .journey-content {
            .hero-title {
              font-size: 1.5rem;
            }
            
            .hero-description {
              font-size: 0.875rem;
            }
          }
          
          .journey-milestone-box {
            padding: 0.875rem;
            gap: 0.75rem;
          }
          
          .milestone-year-icon {
            width: 36px;
            height: 36px;
            font-size: 0.8125rem;
          }
          
          .milestone-title {
            font-size: 0.875rem;
          }
          
          .milestone-description {
            font-size: 0.75rem;
          }
        }

        @media (max-width: 575px) {
          .about-journey-section {
            padding: 50px 0;
          }
          
          .journey-milestone-box {
            padding: 0.75rem;
          }
          
          .milestone-year-icon {
            width: 32px;
            height: 32px;
            font-size: 0.75rem;
          }
        }
      `}</style>
    </>
  );
};

export default AboutStarter;
