"use client";
import Link from "next/link";
import { useAbout } from "@/lib/hooks/useAbout";
import { AboutService as AboutServiceType, AboutProcess } from "@/lib/api/aboutService";

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

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

  if (error) {
    return (
      <section className="about-service-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 serviceData = data?.service as AboutServiceType | undefined;
  const processData = data?.process as AboutProcess | undefined;

  const features = serviceData?.features && serviceData.features.length > 0 
    ? serviceData.features 
    : [
        { icon: "fa-solid fa-shield-halved", title: "Enterprise Security", description: "Defense-Grade Protection" },
        { icon: "fa-solid fa-cloud", title: "Cloud Native", description: "AWS, Azure, GCP Partners" }
      ];

  const steps = processData?.steps && processData.steps.length > 0 
    ? processData.steps 
    : [
        { step_number: "01", title: "Discovery & Planning", description: "Comprehensive analysis and architecture design" },
        { step_number: "02", title: "Development & Testing", description: "Agile development with continuous testing" }
      ];

  return (
    <>
      <section className="hero-banner about-service-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="service-content">
                {/* Badge */}
                <div className="hero-badge">
                  <div className="badge-icon">
                    <i className={serviceData?.badge_icon || "fa-solid fa-users"}></i>
                  </div>
                  <span>{serviceData?.badge_text || "About Our Company"}</span>
                </div>

                {/* Main Title */}
                <h1 className="hero-title">
                  {serviceData?.title || "GNX Soft Ltd. - Software Excellence"}
                </h1>

                {/* Description */}
                <p className="hero-description">
                  {serviceData?.description || "Founded in 2020, GNX Soft Ltd. has emerged as a premier enterprise software company, delivering mission-critical software solutions across various industries."}
                </p>

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

            {/* Right Column - Feature Boxes */}
            <div className="col-12 col-lg-6">
              <div className="service-features-wrapper">
                {features.map((feature, index) => (
                  <div key={index} className="service-feature-box">
                    <div className="feature-icon">
                      <i className={feature.icon}></i>
                    </div>
                    <div className="feature-content">
                      <div className="feature-title">{feature.title}</div>
                      <div className="feature-description">{feature.description}</div>
                    </div>
                  </div>
                ))}
              </div>
            </div>
          </div>
        </div>
      </section>

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

                {/* Main Title */}
                <h1 className="hero-title">
                  {processData?.title || "Enterprise Development Process"}
                </h1>

                {/* Description */}
                <p className="hero-description">
                  {processData?.description || "Our proven enterprise development methodology combines agile practices with enterprise-grade security, scalability, and compliance requirements."}
                </p>

                {/* CTA Buttons */}
                <div className="hero-actions">
                  <Link href={processData?.cta_link || "service-single"} className="btn-primary">
                    <span>{processData?.cta_text || "View Our Services"}</span>
                    <i className="fa-solid fa-arrow-right"></i>
                  </Link>
                </div>
              </div>
            </div>

            {/* Right Column - Process Step Boxes */}
            <div className="col-12 col-lg-6">
              <div className="process-steps-wrapper">
                {steps.map((step, index) => (
                  <div key={index} className="process-step-box">
                    <div className="step-number-icon">
                      <span>{step.step_number}</span>
                    </div>
                    <div className="step-content">
                      <div className="step-title">{step.title}</div>
                      <div className="step-description">{step.description}</div>
                    </div>
                  </div>
                ))}
              </div>
            </div>
          </div>
        </div>
      </section>

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

        .about-process-section {
          padding: 50px 0 100px 0;
          position: relative;
          background: transparent;
          overflow: hidden;
          margin-top: -1px;
          padding-top: 51px;
          color: #000000 !important;
        }
        
        .about-process-section * {
          color: inherit !important;
        }

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

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

        .about-service-section::before,
        .about-process-section::before {
          display: none;
        }

        /* Service/Process Content - Left Column */
        .service-content,
        .process-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;
            }
          }
        }

        /* Service Features Wrapper - Right Column */
        .service-features-wrapper {
          display: flex;
          flex-direction: column;
          gap: 0.875rem;
        }

        /* Service Feature Box - Compact Luxury */
        .service-feature-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);
        }

        .service-feature-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;
        }

        .service-feature-box:hover::before {
          opacity: 1;
        }

        .service-feature-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);
        }

        .feature-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;
          transition: all 0.25s ease;
          box-shadow: 0 2px 8px rgba(212, 175, 55, 0.2);
        }

        .service-feature-box:hover .feature-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);
        }

        .feature-icon i {
          font-size: 1rem;
          color: #ffffff;
        }

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

        .feature-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;
        }

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

        /* Process Steps Wrapper - Right Column */
        .process-steps-wrapper {
          display: flex;
          flex-direction: column;
          gap: 0.875rem;
        }

        /* Process Step Box - Compact Luxury */
        .process-step-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);
        }

        .process-step-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;
        }

        .process-step-box:hover::before {
          opacity: 1;
        }

        .process-step-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);
        }

        .step-number-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: 700;
          color: #ffffff;
          transition: all 0.25s ease;
          box-shadow: 0 2px 8px rgba(212, 175, 55, 0.2);
        }

        .process-step-box:hover .step-number-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);
        }

        .step-number-icon span {
          font-variant-numeric: tabular-nums;
        }

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

        .step-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;
        }

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

        /* Responsive Design */
        @media (max-width: 991px) {
          .about-service-section {
            padding: 80px 0 40px 0;
          }
          
          .about-process-section {
            padding: 40px 0 80px 0;
            padding-top: 41px;
          }
          
          .service-content,
          .process-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-service-section {
            padding: 60px 0 30px 0;
          }
          
          .about-process-section {
            padding: 30px 0 60px 0;
            padding-top: 31px;
          }
          
          .service-content,
          .process-content {
            .hero-title {
              font-size: 1.5rem;
            }
            
            .hero-description {
              font-size: 0.875rem;
            }
          }
          
          .service-feature-box,
          .process-step-box {
            padding: 0.875rem;
            gap: 0.75rem;
          }
          
          .feature-icon,
          .step-number-icon {
            width: 36px;
            height: 36px;
            font-size: 0.8125rem;
          }
          
          .feature-icon i {
            font-size: 0.9375rem;
          }
          
          .feature-title,
          .step-title {
            font-size: 0.875rem;
          }
          
          .feature-description,
          .step-description {
            font-size: 0.75rem;
          }
        }

        @media (max-width: 575px) {
          .about-service-section {
            padding: 50px 0 25px 0;
          }
          
          .about-process-section {
            padding: 25px 0 50px 0;
            padding-top: 26px;
          }
          
          .service-feature-box,
          .process-step-box {
            padding: 0.75rem;
          }
          
          .feature-icon,
          .step-number-icon {
            width: 32px;
            height: 32px;
            font-size: 0.75rem;
          }
        }
      `}</style>
    </>
  );
};

export default AboutServiceComponent;

