/* global React */

const banners = [
  {
    tag: 'Logistics',
    headline: 'Fast and Reliable Logistics from China',
    sub: 'We deliver goods, equipment, and vehicles worldwide — safely and on time.',
    cta: 'Get a Quote',
    img: 'https://images.unsplash.com/photo-1601584115197-04ecc0da31d7?w=1600&q=80',
    accent: 'var(--vermillion)',
    layout: 'split-left',
  },
  {
    tag: 'Sourcing',
    headline: 'Your Trusted Partner for Sourcing in China',
    sub: 'We find verified factories, control quality, and ensure safe deals.',
    cta: 'Start Sourcing',
    img: 'https://images.unsplash.com/photo-1563770660941-20978e870e26?w=1600&q=80',
    accent: 'var(--gold)',
    layout: 'overlay',
  },
  {
    tag: 'Equipment',
    headline: 'Industrial Equipment Direct from Manufacturers',
    sub: 'Machinery, production lines, and spare parts from verified Chinese suppliers.',
    cta: 'Explore Equipment',
    img: 'https://images.unsplash.com/photo-1504917595217-d4dc5ebe6122?w=1600&q=80',
    accent: 'var(--vermillion)',
    layout: 'split-right',
  },
  {
    tag: 'Consulting',
    headline: 'Expert Consulting for China Trade',
    sub: 'Market insights, supplier analysis, and full business support from start to shipment.',
    cta: 'Book Consultation',
    img: 'https://images.unsplash.com/photo-1573164713988-8665fc963095?w=1600&q=80',
    accent: 'var(--gold)',
    layout: 'overlay',
  },
];

function Banners() {
  return (
    <section id="capabilities" style={{ background: 'var(--ink)', padding: '140px 0 120px', color: 'var(--paper)' }}>
      <div className="container">
        <div className="reveal" style={{ marginBottom: 80, display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 32 }}>
          <div style={{ maxWidth: 720 }}>
            <div className="eyebrow" style={{ marginBottom: 18, color: 'var(--gold)' }}>Capability Spotlights</div>
            <h2 className="display" style={{ fontSize: 'clamp(40px, 5vw, 68px)' }}>
              Four pillars. <em style={{ fontStyle: 'italic', color: 'var(--gold)' }}>One partner.</em>
            </h2>
          </div>
          <div style={{ display: 'flex', gap: 16, fontSize: 12, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'rgba(245,241,232,0.5)' }}>
            <span>01 — 04</span>
            <span style={{ color: 'var(--gold)' }}>Scroll ↓</span>
          </div>
        </div>

        <div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
          {banners.map((b, i) => <BannerCard key={i} b={b} index={i} />)}
        </div>
      </div>
    </section>
  );
}

function BannerCard({ b, index }) {
  const isOverlay = b.layout === 'overlay';
  const isRight = b.layout === 'split-right';
  return (
    <div className="reveal-scale" style={{
      position: 'relative',
      minHeight: isOverlay ? 460 : 380,
      overflow: 'hidden',
      border: '1px solid rgba(212, 168, 87, 0.18)',
      background: 'var(--ink-soft)',
    }}>
      {isOverlay ? (
        <OverlayBanner b={b} index={index} />
      ) : (
        <SplitBanner b={b} index={index} reverse={isRight} />
      )}
    </div>
  );
}

function OverlayBanner({ b, index }) {
  return (
    <>
      <div style={{
        position: 'absolute', inset: 0,
        backgroundImage: `url(${b.img})`,
        backgroundSize: 'cover', backgroundPosition: 'center',
        transform: 'scale(1.02)',
      }} />
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(95deg, rgba(10,22,40,0.92) 0%, rgba(10,22,40,0.7) 50%, rgba(10,22,40,0.3) 100%)',
      }} />
      <div style={{
        position: 'relative', padding: 'clamp(40px, 6vw, 80px)',
        display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 48,
        alignItems: 'center', minHeight: 460,
      }} className="banner-overlay-grid">
        <div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 20, marginBottom: 28 }}>
            <span className="mono" style={{ fontSize: 12, color: b.accent, letterSpacing: '0.2em' }}>
              — 0{index + 1} / 04
            </span>
            <span className="mono" style={{ fontSize: 11, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'rgba(245,241,232,0.55)' }}>
              {b.tag}
            </span>
          </div>
          <h3 style={{ fontFamily: 'var(--sans)', fontSize: 'clamp(30px, 3.4vw, 46px)', marginBottom: 20, maxWidth: 580, fontWeight: 600, letterSpacing: '-0.02em', lineHeight: 1.1 }}>
            {b.headline}
          </h3>
          <p style={{ fontSize: 17, lineHeight: 1.5, color: 'rgba(245,241,232,0.75)', maxWidth: 460, marginBottom: 36 }}>
            {b.sub}
          </p>
          <a href="#contact" className="btn btn-primary" style={{ background: b.accent }}>
            {b.cta} <span className="arrow">→</span>
          </a>
        </div>
        <div /> {/* visual breathing room */}
      </div>
      <style>{`
        @media (max-width: 800px) {
          .banner-overlay-grid { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </>
  );
}

function SplitBanner({ b, index, reverse }) {
  return (
    <div style={{
      display: 'grid', gridTemplateColumns: reverse ? '1fr 1.1fr' : '1.1fr 1fr',
      minHeight: 380,
    }} className="banner-split-grid">
      <div style={{
        order: reverse ? 2 : 1,
        position: 'relative', overflow: 'hidden',
      }}>
        <div style={{
          position: 'absolute', inset: 0,
          backgroundImage: `url(${b.img})`,
          backgroundSize: 'cover', backgroundPosition: 'center',
        }} />
        <div style={{
          position: 'absolute', inset: 0,
          background: reverse
            ? 'linear-gradient(270deg, rgba(10,22,40,0.6), transparent 50%)'
            : 'linear-gradient(90deg, rgba(10,22,40,0.6), transparent 50%)',
        }} />
        {/* Vertical tag */}
        <div style={{
          position: 'absolute', top: 32, left: reverse ? 'auto' : 32, right: reverse ? 32 : 'auto',
          fontSize: 11, letterSpacing: '0.3em', textTransform: 'uppercase',
          color: 'var(--gold)',
          writingMode: 'vertical-rl', transform: reverse ? 'rotate(180deg)' : 'none',
        }}>
          {b.tag} — 0{index + 1}
        </div>
      </div>
      <div style={{
        order: reverse ? 1 : 2,
        padding: 'clamp(40px, 5vw, 72px)',
        display: 'flex', flexDirection: 'column', justifyContent: 'center',
        background: 'var(--ink-soft)',
      }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 16, marginBottom: 24 }}>
          <span className="mono" style={{ fontSize: 12, color: b.accent, letterSpacing: '0.2em' }}>
            — 0{index + 1} / 04
          </span>
          <span className="mono" style={{ fontSize: 11, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'rgba(245,241,232,0.55)' }}>
            {b.tag}
          </span>
        </div>
        <h3 style={{ fontFamily: 'var(--sans)', fontSize: 'clamp(28px, 3vw, 42px)', marginBottom: 20, maxWidth: 520, fontWeight: 600, letterSpacing: '-0.02em', lineHeight: 1.15 }}>
          {b.headline}
        </h3>
        <p style={{ fontSize: 16, lineHeight: 1.6, color: 'rgba(245,241,232,0.72)', marginBottom: 32, maxWidth: 460 }}>
          {b.sub}
        </p>
        <a href="#contact" className="btn btn-primary" style={{ alignSelf: 'flex-start', background: b.accent }}>
          {b.cta} <span className="arrow">→</span>
        </a>
      </div>
      <style>{`
        @media (max-width: 800px) {
          .banner-split-grid { grid-template-columns: 1fr !important; }
          .banner-split-grid > div:first-child { min-height: 280px; }
        }
      `}</style>
    </div>
  );
}

Object.assign(window, { Banners });
