/* global React */

const services = [
  {
    num: '01',
    title: 'Logistics from China',
    short: 'Fast and reliable delivery of goods, machinery, and vehicles from China to any destination.',
    bullets: [
      'Timely delivery by sea, air, and land — anywhere in the world',
      'Full customs clearance, insurance, and shipment tracking',
      'All logistics paperwork handled end-to-end',
    ],
    img: 'https://images.unsplash.com/photo-1494412574643-ff11b0a5c1c3?w=1200&q=80',
  },
  {
    num: '02',
    title: 'Sourcing & Trade',
    short: 'Full-cycle support in product sourcing, factory verification, and secure purchasing.',
    bullets: [
      'Supplier verification and on-site factory audits',
      'Secure transactions with transparent pricing',
      'Personalized sourcing from inquiry to delivery',
    ],
    img: 'https://images.unsplash.com/photo-1565793298595-6a879b1d9492?w=1200&q=80',
  },
  {
    num: '03',
    title: 'Industrial Equipment',
    short: 'Purchase and delivery of industrial machinery and production lines from verified manufacturers.',
    bullets: [
      'Direct factory supply — competitive prices, no intermediaries',
      'Inspection and quality control before shipment',
      'Complete delivery support, including installation guidance',
    ],
    img: 'https://images.unsplash.com/photo-1581092918056-0c4c3acd3789?w=1200&q=80',
  },
  {
    num: '04',
    title: 'Consulting Services',
    short: 'Expert consulting on the Chinese market, suppliers, product analysis, and cost optimization.',
    bullets: [
      'Market and product analysis to identify opportunities',
      'Risk minimization through supplier vetting and contracts',
      'Guidance on customs, compliance, and cost optimization',
    ],
    img: 'https://images.unsplash.com/photo-1521737604893-d14cc237f11d?w=1200&q=80',
  },
];

function Services() {
  const [active, setActive] = React.useState(0);

  return (
    <section id="services" style={{
      background: 'var(--paper)',
      padding: '40px 0 140px',
    }}>
      <div className="container">
        <div className="reveal" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', marginBottom: 64, gap: 48, flexWrap: 'wrap' }}>
          <div style={{ maxWidth: 720 }}>
            <div className="eyebrow" style={{ marginBottom: 18 }}>What we do</div>
            <h2 className="display" style={{ fontSize: 'clamp(40px, 5vw, 72px)' }}>
              Services that drive your <em style={{ fontStyle: 'italic', color: 'var(--vermillion)' }}>global growth</em>.
            </h2>
          </div>
          <p style={{ maxWidth: 380, fontSize: 16, color: 'var(--ash)', lineHeight: 1.6 }}>
            Prime Global Trade provides integrated solutions for logistics, sourcing, and consulting services from China — delivered with one accountable team.
          </p>
        </div>

        {/* Two-pane: list left, visual right */}
        <div style={{
          display: 'grid', gridTemplateColumns: '1fr 1.2fr', gap: 0,
          border: '1px solid var(--line-strong)',
          background: 'var(--paper-warm)',
          minHeight: 620,
        }} className="services-grid reveal">
          {/* List */}
          <div style={{ borderRight: '1px solid var(--line)' }}>
            {services.map((s, i) => (
              <ServiceRow key={i} s={s} active={active === i} onActivate={() => setActive(i)} last={i === services.length - 1} />
            ))}
          </div>
          {/* Visual */}
          <div style={{ position: 'relative', overflow: 'hidden', background: 'var(--ink)' }}>
            {services.map((s, i) => (
              <div key={i} style={{
                position: 'absolute', inset: 0,
                opacity: active === i ? 1 : 0,
                transition: 'opacity 700ms ease',
              }}>
                <div style={{
                  position: 'absolute', inset: 0,
                  backgroundImage: `url(${s.img})`,
                  backgroundSize: 'cover', backgroundPosition: 'center',
                  transform: active === i ? 'scale(1)' : 'scale(1.08)',
                  transition: 'transform 1400ms cubic-bezier(0.2, 0.8, 0.2, 1)',
                }} />
                <div style={{
                  position: 'absolute', inset: 0,
                  background: 'linear-gradient(135deg, rgba(10,22,40,0.4) 0%, rgba(10,22,40,0.85) 100%)',
                }} />
                <div style={{
                  position: 'absolute', inset: 0, padding: 48,
                  display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
                  color: 'var(--paper)',
                }}>
                  <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
                    <div>
                      <div className="display tabular" style={{ fontSize: 14, color: 'var(--gold)', letterSpacing: '0.2em' }}>
                        — {s.num} / 04
                      </div>
                    </div>
                    <div className="mono" style={{
                      padding: '10px 16px',
                      border: '1px solid var(--gold)',
                      color: 'var(--gold)', fontSize: 11,
                      letterSpacing: '0.2em', textTransform: 'uppercase',
                    }}>
                      Service / {s.num}
                    </div>
                  </div>
                  <div>
                    <h3 className="display" style={{ fontSize: 'clamp(36px, 4vw, 54px)', marginBottom: 20 }}>
                      {s.title}
                    </h3>
                    <p style={{ fontSize: 16, lineHeight: 1.6, color: 'rgba(245,241,232,0.8)', maxWidth: 480, marginBottom: 28 }}>
                      {s.short}
                    </p>
                    <ul style={{ listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 12, marginBottom: 32 }}>
                      {s.bullets.map((b, j) => (
                        <li key={j} style={{ display: 'flex', gap: 14, alignItems: 'flex-start', fontSize: 14, color: 'rgba(245,241,232,0.9)' }}>
                          <span style={{ color: 'var(--gold)', flexShrink: 0, marginTop: 2 }}>✓</span>
                          {b}
                        </li>
                      ))}
                    </ul>
                    <a href="#contact" style={{
                      display: 'inline-flex', alignItems: 'center', gap: 12,
                      color: 'var(--paper)', textDecoration: 'none', fontSize: 13,
                      fontWeight: 600, letterSpacing: '0.06em', textTransform: 'uppercase',
                      borderBottom: '1px solid var(--gold)', paddingBottom: 6,
                    }}>
                      Discuss this service <span>→</span>
                    </a>
                  </div>
                </div>
              </div>
            ))}
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px) {
          .services-grid { grid-template-columns: 1fr !important; }
          .services-grid > div:first-child { border-right: none !important; border-bottom: 1px solid var(--line); }
          .services-grid > div:last-child { min-height: 480px; }
        }
      `}</style>
    </section>
  );
}

function ServiceRow({ s, active, onActivate, last }) {
  return (
    <button
      onMouseEnter={onActivate}
      onClick={onActivate}
      style={{
        width: '100%', textAlign: 'left',
        padding: '36px 40px',
        background: active ? 'var(--paper)' : 'transparent',
        border: 'none',
        borderBottom: last ? 'none' : '1px solid var(--line)',
        cursor: 'pointer',
        display: 'flex', gap: 24, alignItems: 'flex-start',
        transition: 'background 280ms ease',
        position: 'relative',
        fontFamily: 'var(--sans)',
      }}
    >
      {/* Active indicator */}
      <span style={{
        position: 'absolute', left: 0, top: 0, bottom: 0, width: 3,
        background: 'var(--vermillion)',
        transform: active ? 'scaleY(1)' : 'scaleY(0)',
        transformOrigin: 'top',
        transition: 'transform 360ms cubic-bezier(0.2, 0.8, 0.2, 1)',
      }} />
      <div className="display tabular" style={{
        fontSize: 18, color: active ? 'var(--vermillion)' : 'var(--ash)',
        fontWeight: 500, marginTop: 6, transition: 'color 280ms',
      }}>
        {s.num}
      </div>
      <div style={{ flex: 1 }}>
        <h3 className="display" style={{
          fontSize: 'clamp(26px, 2.6vw, 36px)', fontWeight: 400,
          color: active ? 'var(--ink)' : 'var(--ink-soft)',
          marginBottom: 8,
        }}>
          {s.title}
        </h3>
        <p style={{
          fontSize: 14, color: 'var(--ash)', lineHeight: 1.5,
          maxHeight: active ? 80 : 0, overflow: 'hidden',
          opacity: active ? 1 : 0,
          transition: 'max-height 400ms ease, opacity 300ms ease',
        }}>
          {s.short}
        </p>
      </div>
      <div style={{
        fontSize: 18, color: 'var(--ash)',
        transform: active ? 'translateX(4px) rotate(-45deg)' : 'rotate(0)',
        transition: 'all 320ms cubic-bezier(0.2, 0.8, 0.2, 1)',
        marginTop: 6,
      }}>→</div>
    </button>
  );
}

Object.assign(window, { Services });
