"use client";
import Image from "next/image";
import Link from "next/link";
import { useAbout } from "@/lib/hooks/useAbout";
import { AboutService as AboutServiceType, AboutProcess } from "@/lib/api/aboutService";
import { getValidImageUrl, FALLBACK_IMAGES } from "@/lib/imageUtils";
import thumb from "@/public/images/service/two.png";
import thumbTwo from "@/public/images/service/three.png";

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-5">
                <div className="spinner-border text-primary" role="status">
                  <span className="visually-hidden">Loading...</span>
                </div>
                <p className="mt-3">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-5">
                <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;

  return (
    <>
      <section className="about-service-section" suppressHydrationWarning>
        <div className="container">
          <div className="row g-5 align-items-start">
            {/* Image Column */}
            <div className="col-12 col-lg-6">
              <div className="about-image-wrapper">
                <div className="about-image-container">
                  {serviceData?.image_url ? (
                    <img
                      src={getValidImageUrl(serviceData.image_url, FALLBACK_IMAGES.SERVICE)}
                      className="about-image"
                      alt="Enterprise Technology Solutions"
                      width={600}
                      height={700}
                    />
                  ) : (
                    <Image
                      src={thumb}
                      className="about-image"
                      alt="Enterprise Technology Solutions"
                      width={600}
                      height={700}
                    />
                  )}
                  <div className="image-overlay"></div>
                </div>
              </div>
            </div>

            {/* Content Column */}
            <div className="col-12 col-lg-6">
              <div className="about-content-wrapper">
                <div className="luxury-badge">
                  <i className={serviceData?.badge_icon || "fa-solid fa-users"}></i>
                  <span>{serviceData?.badge_text || "About Our Company"}</span>
                </div>
                
                <h2 className="luxury-title">
                  {serviceData?.title || "GNX Soft Ltd. - Software Excellence"}
                </h2>
                
                <p className="luxury-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>

                <div className="luxury-features-grid">
                  {serviceData?.features && serviceData.features.length > 0 ? (
                    serviceData.features.map((feature, index) => (
                      <div key={index} className="luxury-feature-card">
                        <div className="feature-icon-wrapper">
                          <i className={feature.icon}></i>
                        </div>
                        <div className="feature-text">
                          <h6 className="feature-title">{feature.title}</h6>
                          <p className="feature-description">{feature.description}</p>
                        </div>
                      </div>
                    ))
                  ) : (
                    <>
                      <div className="luxury-feature-card">
                        <div className="feature-icon-wrapper">
                          <i className="fa-solid fa-shield-halved"></i>
                        </div>
                        <div className="feature-text">
                          <h6 className="feature-title">Enterprise Security</h6>
                          <p className="feature-description">Defense-Grade Protection</p>
                        </div>
                      </div>
                      <div className="luxury-feature-card">
                        <div className="feature-icon-wrapper">
                          <i className="fa-solid fa-cloud"></i>
                        </div>
                        <div className="feature-text">
                          <h6 className="feature-title">Cloud Native</h6>
                          <p className="feature-description">AWS, Azure, GCP Partners</p>
                        </div>
                      </div>
                    </>
                  )}
                </div>

                <div className="luxury-cta">
                  <Link href={serviceData?.cta_link || "service-single"} className="luxury-btn">
                    <span>{serviceData?.cta_text || "Explore Our Solutions"}</span>
                    <i className="fa-solid fa-arrow-right"></i>
                  </Link>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>

      <section className="about-process-section">
        <div className="container">
          <div className="row g-5 align-items-start">
            {/* Content Column */}
            <div className="col-12 col-lg-6 order-2 order-lg-1">
              <div className="about-content-wrapper">
                <div className="luxury-badge">
                  <i className={processData?.badge_icon || "fa-solid fa-cogs"}></i>
                  <span>{processData?.badge_text || "Our Methodology"}</span>
                </div>
                
                <h2 className="luxury-title">
                  {processData?.title || "Enterprise Development Process"}
                </h2>
                
                <p className="luxury-description">
                  {processData?.description || "Our proven enterprise development methodology combines agile practices with enterprise-grade security, scalability, and compliance requirements."}
                </p>

                <div className="luxury-process-steps">
                  {processData?.steps && processData.steps.length > 0 ? (
                    processData.steps.map((step, index) => (
                      <div key={index} className="luxury-process-step">
                        <div className="step-number-badge">{step.step_number}</div>
                        <div className="step-content-wrapper">
                          <h6 className="step-title">{step.title}</h6>
                          <p className="step-description">{step.description}</p>
                        </div>
                      </div>
                    ))
                  ) : (
                    <>
                      <div className="luxury-process-step">
                        <div className="step-number-badge">01</div>
                        <div className="step-content-wrapper">
                          <h6 className="step-title">Discovery & Planning</h6>
                          <p className="step-description">Comprehensive analysis and architecture design</p>
                        </div>
                      </div>
                      <div className="luxury-process-step">
                        <div className="step-number-badge">02</div>
                        <div className="step-content-wrapper">
                          <h6 className="step-title">Development & Testing</h6>
                          <p className="step-description">Agile development with continuous testing</p>
                        </div>
                      </div>
                    </>
                  )}
                </div>

                <div className="luxury-cta">
                  <Link href={processData?.cta_link || "service-single"} className="luxury-btn">
                    <span>{processData?.cta_text || "View Our Services"}</span>
                    <i className="fa-solid fa-arrow-right"></i>
                  </Link>
                </div>
              </div>
            </div>

            {/* Image Column */}
            <div className="col-12 col-lg-6 order-1 order-lg-2">
              <div className="about-image-wrapper">
                <div className="about-image-container">
                  {processData?.image_url ? (
                    <img
                      src={getValidImageUrl(processData.image_url, FALLBACK_IMAGES.SERVICE)}
                      className="about-image"
                      alt="Enterprise Development Process"
                      width={600}
                      height={700}
                    />
                  ) : (
                    <Image
                      src={thumbTwo}
                      className="about-image"
                      alt="Enterprise Development Process"
                      width={600}
                      height={700}
                    />
                  )}
                  <div className="image-overlay"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>

      <style>{`
        /* Section Base Styles */
        .about-service-section,
        .about-process-section {
          padding: 120px 0;
          position: relative;
          background: #0a0a0a;
        }

        .about-process-section {
          border-top: 1px solid rgba(255, 255, 255, 0.08);
        }

        /* Image Wrapper - Perfect Alignment */
        .about-image-wrapper {
          position: sticky;
          top: 120px;
          height: fit-content;
        }

        .about-image-container {
          position: relative;
          border-radius: 24px;
          overflow: hidden;
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
                      0 0 0 1px rgba(255, 255, 255, 0.05);
          background: rgba(255, 255, 255, 0.02);
          transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .about-image-container:hover {
          transform: translateY(-8px);
          box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6),
                      0 0 0 1px rgba(255, 255, 255, 0.1);
        }

        .about-image {
          width: 100%;
          height: auto;
          display: block;
          object-fit: cover;
          border-radius: 24px;
          transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .about-image-container:hover .about-image {
          transform: scale(1.05);
        }

        .image-overlay {
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background: linear-gradient(
            180deg,
            rgba(0, 0, 0, 0) 0%,
            rgba(0, 0, 0, 0.3) 100%
          );
          pointer-events: none;
          border-radius: 24px;
        }

        /* Content Wrapper - Perfect Alignment */
        .about-content-wrapper {
          padding: 0;
          display: flex;
          flex-direction: column;
          gap: 2rem;
        }

        @media (min-width: 992px) {
          .about-content-wrapper {
            padding-left: 3rem;
          }
        }

        /* Luxury Badge */
        .luxury-badge {
          display: inline-flex;
          align-items: center;
          gap: 0.75rem;
          padding: 0.5rem 1.25rem;
          background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.03) 100%);
          border: 1px solid rgba(255, 255, 255, 0.1);
          border-radius: 50px;
          font-size: 0.875rem;
          font-weight: 500;
          letter-spacing: 0.5px;
          color: rgba(255, 255, 255, 0.9);
          width: fit-content;
          backdrop-filter: blur(10px);
        }

        .luxury-badge i {
          font-size: 0.875rem;
          color: #fff;
        }

        /* Luxury Title */
        .luxury-title {
          font-size: clamp(2rem, 4vw, 3rem);
          font-weight: 700;
          line-height: 1.2;
          letter-spacing: -0.02em;
          color: #ffffff;
          margin: 0;
          background: linear-gradient(135deg, #ffffff 0%, rgba(255, 255, 255, 0.8) 100%);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
          background-clip: text;
        }

        /* Luxury Description */
        .luxury-description {
          font-size: 1.125rem;
          line-height: 1.8;
          color: rgba(255, 255, 255, 0.75);
          margin: 0;
          font-weight: 400;
        }

        /* Features Grid */
        .luxury-features-grid {
          display: grid;
          grid-template-columns: 1fr;
          gap: 1.25rem;
          margin: 1rem 0;
        }

        @media (min-width: 768px) {
          .luxury-features-grid {
            grid-template-columns: repeat(2, 1fr);
          }
        }

        .luxury-feature-card {
          display: flex;
          align-items: flex-start;
          gap: 1rem;
          padding: 1.5rem;
          background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
          border: 1px solid rgba(255, 255, 255, 0.08);
          border-radius: 16px;
          transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .luxury-feature-card:hover {
          background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.04) 100%);
          border-color: rgba(255, 255, 255, 0.15);
          transform: translateY(-4px);
        }

        .feature-icon-wrapper {
          flex-shrink: 0;
          width: 56px;
          height: 56px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
          border: 1px solid rgba(255, 255, 255, 0.1);
          border-radius: 14px;
        }

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

        .feature-text {
          flex: 1;
        }

        .feature-title {
          font-size: 1.125rem;
          font-weight: 600;
          color: #ffffff;
          margin: 0 0 0.5rem 0;
          line-height: 1.4;
        }

        .feature-description {
          font-size: 0.9375rem;
          line-height: 1.6;
          color: rgba(255, 255, 255, 0.65);
          margin: 0;
        }

        /* Process Steps */
        .luxury-process-steps {
          display: flex;
          flex-direction: column;
          gap: 1.25rem;
          margin: 1rem 0;
        }

        .luxury-process-step {
          display: flex;
          align-items: flex-start;
          gap: 1.25rem;
          padding: 1.75rem;
          background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
          border: 1px solid rgba(255, 255, 255, 0.08);
          border-radius: 18px;
          transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .luxury-process-step:hover {
          background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.04) 100%);
          border-color: rgba(255, 255, 255, 0.15);
          transform: translateX(8px);
        }

        .step-number-badge {
          flex-shrink: 0;
          width: 64px;
          height: 64px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.08) 100%);
          border: 1px solid rgba(255, 255, 255, 0.15);
          border-radius: 16px;
          font-size: 1.5rem;
          font-weight: 700;
          color: #ffffff;
        }

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

        .step-title {
          font-size: 1.25rem;
          font-weight: 600;
          color: #ffffff;
          margin: 0 0 0.5rem 0;
          line-height: 1.4;
        }

        .step-description {
          font-size: 1rem;
          line-height: 1.7;
          color: rgba(255, 255, 255, 0.7);
          margin: 0;
        }

        /* Luxury CTA Button */
        .luxury-cta {
          margin-top: 0.5rem;
        }

        .luxury-btn {
          display: inline-flex;
          align-items: center;
          gap: 0.75rem;
          padding: 1rem 2rem;
          background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
          border: 1px solid rgba(255, 255, 255, 0.2);
          border-radius: 12px;
          color: #ffffff;
          font-size: 1rem;
          font-weight: 500;
          text-decoration: none;
          transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
          backdrop-filter: blur(10px);
        }

        .luxury-btn:hover {
          background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.08) 100%);
          border-color: rgba(255, 255, 255, 0.3);
          transform: translateY(-2px);
          box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
        }

        .luxury-btn i {
          transition: transform 0.3s ease;
        }

        .luxury-btn:hover i {
          transform: translateX(4px);
        }

        /* Responsive Design */
        @media (max-width: 991px) {
          .about-service-section,
          .about-process-section {
            padding: 80px 0;
          }

          .about-image-wrapper {
            position: relative;
            top: 0;
            margin-bottom: 3rem;
          }

          .about-content-wrapper {
            padding-left: 0 !important;
            padding-right: 0 !important;
          }

          .luxury-features-grid {
            grid-template-columns: 1fr;
          }
        }

        @media (max-width: 575px) {
          .luxury-title {
            font-size: 1.75rem;
          }

          .luxury-description {
            font-size: 1rem;
          }

          .luxury-feature-card,
          .luxury-process-step {
            padding: 1.25rem;
          }
        }
      `}</style>
    </>
  );
};

export default AboutServiceComponent;
