// Challenge — the pivot from "about him" to "about you". Designed as an editorial
// report grid: left-aligned headline, two-column blocks (title left / body right)
// with a drawing vertical rule, and break-out gold pull-quote punchlines.
// Scroll-triggered reveals: vertical translate + opacity only, micro-staggered.
function useReveal(options) {
  const ref = React.useRef(null);
  const [shown, setShown] = React.useState(false);
  React.useEffect(() => {
    const el = ref.current;
    if (!el) return;
    if (!('IntersectionObserver' in window)) { setShown(true); return; }
    const io = new IntersectionObserver(([entry]) => {
      if (entry.isIntersecting) { setShown(true); io.disconnect(); }
    }, { rootMargin: '0px 0px -12% 0px', threshold: 0.12, ...(options || {}) });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return [ref, shown];
}

function Reveal({ as = 'div', delay = 0, slow = false, className = '', style, children, ...rest }) {
  const [ref, shown] = useReveal();
  const Tag = as;
  return (
    <Tag
      ref={ref}
      className={`reveal${slow ? ' reveal-slow' : ''}${shown ? ' is-visible' : ''}${className ? ' ' + className : ''}`}
      style={{ transitionDelay: (shown ? delay : 0) + 'ms', ...style }}
      {...rest}
    >
      {children}
    </Tag>
  );
}

function Para({ children }) {
  return (
    <p style={{
      margin: 0, fontFamily: 'var(--font-body)', fontWeight: 400,
      fontSize: 'clamp(1.04rem, 1.3vw, 1.16rem)', lineHeight: 1.72,
      color: 'var(--color-ink-muted)', textWrap: 'pretty',
    }}>{children}</p>
  );
}

function ChallengeBlock({ title, paragraphs, punch }) {
  // one observer per block so the rule-draw + title→body→punch stagger stay in sync
  const [ref, shown] = useReveal();
  const vis = shown ? ' is-visible' : '';
  return (
    <div ref={ref} className={`challenge-block${vis}`}>
      <span className="challenge-rule" aria-hidden="true"></span>
      <h3 className={`challenge-title reveal${vis}`} style={{ margin: 0, transitionDelay: (shown ? 0 : 0) + 'ms' }}>
        {title}
      </h3>
      <div className="challenge-body">
        <div className={`reveal${vis}`} style={{ transitionDelay: (shown ? 150 : 0) + 'ms', display: 'flex', flexDirection: 'column', gap: 22 }}>
          {paragraphs.map((p, i) => <Para key={i}>{p}</Para>)}
        </div>
        <p className={`challenge-pull reveal reveal-slow${vis}`} style={{ transitionDelay: (shown ? 360 : 0) + 'ms' }}>{punch}</p>
      </div>
    </div>
  );
}

function Challenge() {
  return (
    <section id="challenge" style={{ padding: 'clamp(40px, 6vh, 72px) 0 clamp(48px, 7vh, 80px)' }}>
      <div className="container" style={{ display: 'flex', flexDirection: 'column' }}>

        {/* header — left-aligned, authoritative */}
        <Reveal style={{ marginBottom: 'clamp(36px, 5vh, 52px)' }}>
          <span className="rule-label-left">The challenge</span>
        </Reveal>
        <Reveal as="h2" delay={90} style={{
          margin: 0, marginBottom: 'clamp(36px, 5vh, 52px)',
          fontFamily: 'var(--font-display)', fontWeight: 600,
          fontSize: 'clamp(1.9rem, 3.4vw, 2.85rem)', lineHeight: 1.2, letterSpacing: '-0.015em',
          color: 'var(--color-ink)', textWrap: 'pretty', maxWidth: 'none',
        }}>
          Every business knows AI matters.<br /><span className="challenge-line2" style={{ color: 'var(--color-ink-muted)' }}>Very few know what to actually do about it.</span>
        </Reveal>

        {/* report-grid blocks */}
        <div style={{ display: 'flex', flexDirection: 'column', gap: 'clamp(72px, 11vh, 120px)' }}>

          <ChallengeBlock
            title="Everybody's talking, nothing is clear"
            paragraphs={[
              "You know AI should be part of how your business operates. But which functions? Which processes? What gets prioritized first? The technology itself changes every few weeks — new models, new capabilities, new ways to deploy.",
            ]}
            punch="Keeping up with what's possible is a full-time job, and you already have one."
          />

          <ChallengeBlock
            title="The wrong people are leading your AI strategy"
            paragraphs={[
              "You've tried to make it work — maybe you're doing it yourself between everything else on your plate. Maybe you've handed it to someone on your team who's now the unofficial \u201cAI person\u201d on top of their actual job. Or maybe you've hired someone junior who knows the tools but has no idea how your business actually runs.",
              "None of them can tell you which processes to transform, what the ROI looks like, or how to build something that scales.",
            ]}
            punch="You don't have a strategy. You have a workaround."
          />

          <ChallengeBlock
            title="Your competitors aren't waiting"
            paragraphs={[
              "The businesses in your market that figure this out first don't just save time — they operate at a completely different level. Better margins, faster delivery, fewer people doing more.",
            ]}
            punch="Every month you spend figuring this out on your own is a month they use to pull ahead."
          />

        </div>
      </div>
    </section>
  );
}
window.Challenge = Challenge;
