// Forefront / One-page lead-gen components.
// Single-scroll landing page. Editorial monochrome, square, ruled.
// Reuses Button, Section, CapabilityList, EngagementGrid, PILLARS, ENGAGEMENTS, constants.

/* ---------------- FAQ + process content ---------------- */
const FAQ = [
  { q: 'What is the free growth audit?', a: 'A short, honest read on your current marketing. Where your leads come from, where they leak, and what we would change first. No deck, no obligation. It is how every relationship begins.' },
  { q: 'Do you work with our team, or replace it?', a: 'Either one. Under Setup and consult we build the foundations and train your people. Under Full operations we become the team, embedded and end to end. We will tell you which fits on the audit.' },
  { q: 'How quickly will we see results?', a: 'We do not promise a number on a timeline, because anyone who does is guessing. What we promise is a clear plan, work delivered on the day we said, and honest reporting on what is moving.' },
  { q: 'What does it cost?', a: 'It depends on the services and the scope. We price to your business, not a template. The audit gives us both enough to talk numbers properly.' },
  { q: 'What do you need from us?', a: 'Access, candour, and a decision maker in the room. The work moves at the speed of the slowest approval, so we keep the loop small.' },
];

const PROCESS_STEPS = [
  { num: 'i.', title: 'Audit', text: 'We start with the truth. Where your leads come from, where they leak, and what the numbers actually say. This is your free growth audit.' },
  { num: 'ii.', title: 'Build', text: 'Strategy, systems, funnels and creative, built to fit your business rather than a template. The foundations go in before a single dollar is spent on media.' },
  { num: 'iii.', title: 'Launch', text: 'Campaigns live, content publishing, pipeline moving. The engine starts turning and the first results come back.' },
  { num: 'iv.', title: 'Compound', text: 'We optimise and report, or we train and hand over. Either way, the work keeps paying long after it ships.' },
];

/* ---------------- Plus / minus indicator ---------------- */
const PlusMinus = ({ open, dark = false }) => {
  const c = dark ? PAPER : INK;
  return (
    <span style={{ position: 'relative', width: 20, height: 20, flexShrink: 0, display: 'inline-block' }}>
      <span style={{ position: 'absolute', top: '50%', left: 0, width: 20, height: 1, background: c, transform: 'translateY(-50%)' }} />
      <span style={{ position: 'absolute', left: '50%', top: 0, height: 20, width: 1, background: c, transform: `translateX(-50%) scaleY(${open ? 0 : 1})`, transformOrigin: 'center', transition: `transform 320ms ${EASE}` }} />
    </span>
  );
};

/* ---------------- Generic accordion row (conditional reveal + quiet fade) ---------------- */
const AccordionRow = ({ eyebrow, title, accent, titleSize = 40, open, onToggle, last, children }) => (
  <div style={{ borderBottom: last ? 'none' : `1px solid ${INK}` }}>
    <button
      onClick={onToggle}
      className="ff-acc-head"
      style={{
        width: '100%', background: 'transparent', border: 'none', cursor: 'pointer',
        display: 'grid', gridTemplateColumns: '90px 1fr 28px', gap: 28, alignItems: 'center',
        padding: '36px 0', textAlign: 'left', color: INK,
      }}
    >
      <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.2em', textTransform: 'uppercase', color: MUTE }}>{eyebrow}</span>
      <span style={{ fontFamily: 'var(--font-display)', fontWeight: 300, fontSize: `clamp(26px, ${titleSize / 18}vw, ${titleSize}px)`, lineHeight: 1.04, letterSpacing: '-0.025em', fontVariationSettings: '"opsz" 144' }}>
        {title}{accent && <> <em style={{ fontStyle: 'italic', fontWeight: 400 }}>{accent}</em></>}
      </span>
      <span style={{ justifySelf: 'end' }}><PlusMinus open={open} /></span>
    </button>
    {open && (
      <div className="ff-acc-panel" style={{ paddingLeft: 118, paddingBottom: 44, paddingRight: 48 }}>
        {children}
      </div>
    )}
  </div>
);

/* ---------------- One-page Nav ---------------- */
const OneNav = ({ onBook }) => {
  const links = [
    { id: 'services', label: 'Services' },
    { id: 'process', label: 'How it works' },
    { id: 'faq', label: 'FAQ' },
  ];
  const jump = (e, id) => { e.preventDefault(); const el = document.getElementById(id); if (el) window.scrollTo({ top: el.offsetTop - 72, behavior: 'smooth' }); };
  return (
    <nav style={oneNavStyles.nav}>
      <a href="#top" onClick={(e) => { e.preventDefault(); window.scrollTo({ top: 0, behavior: 'smooth' }); }} style={oneNavStyles.brand}>
        Fore<em style={{ fontStyle: 'italic', fontWeight: 400 }}>front</em>
      </a>
      <div style={oneNavStyles.right}>
        <ul style={oneNavStyles.ul}>
          {links.map(l => (
            <li key={l.id}>
              <a href={`#${l.id}`} onClick={(e) => jump(e, l.id)} style={oneNavStyles.link}
                onMouseEnter={(e) => e.currentTarget.style.color = INK}
                onMouseLeave={(e) => e.currentTarget.style.color = MUTE}>{l.label}</a>
            </li>
          ))}
        </ul>
        <Button size="sm" variant="primary" onClick={onBook}>Free audit →</Button>
      </div>
    </nav>
  );
};
const oneNavStyles = {
  nav: { position: 'sticky', top: 0, background: PAPER, borderBottom: `1px solid ${INK}`, padding: '16px 60px', display: 'flex', justifyContent: 'space-between', alignItems: 'center', zIndex: 100, fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.15em', textTransform: 'uppercase' },
  brand: { fontFamily: 'var(--font-display)', fontWeight: 300, fontSize: 24, letterSpacing: '-0.02em', textTransform: 'none', color: INK, textDecoration: 'none', fontVariationSettings: '"opsz" 144' },
  right: { display: 'flex', alignItems: 'center', gap: 36 },
  ul: { listStyle: 'none', display: 'flex', gap: 30, margin: 0, padding: 0 },
  link: { textDecoration: 'none', color: MUTE, transition: `color 240ms ${EASE}` },
};

/* ---------------- Hero ---------------- */
const Hero = ({ t, onAudit }) => (
  <header id="top" className="ff-hero" style={heroStyles.hero}>
    <div style={heroStyles.middle}>
      <div className="ff-eyebrow" style={{ marginBottom: 28 }}>Predictable lead flow, quietly engineered</div>
      <h1 style={heroStyles.h1}>
        {t.heroHeadline}{' '}<em style={{ fontStyle: 'italic', fontWeight: 400 }}>{t.heroAccent}</em>.
      </h1>
      <p style={heroStyles.sub}>
        Forefront runs your paid ads and creates the content that makes them convert, so the right customers find you every day. We set it up and train your team, or we run the whole thing for you.
      </p>
      <div style={{ display: 'flex', gap: 14, flexWrap: 'wrap', marginTop: 8 }}>
        <Button variant="primary" size="lg" onClick={onAudit}>Get your free audit →</Button>
      </div>
    </div>
    <div style={heroStyles.bottom}>
      {['Meta ads', 'Google ads', 'Content creation', 'and more'].map((d, i) => (
        <span key={i}>{i < 3 ? `0${i + 1} · ${d}` : d}</span>
      ))}
    </div>
  </header>
);
const heroStyles = {
  hero: { minHeight: '78vh', display: 'flex', flexDirection: 'column', justifyContent: 'space-between', padding: '40px 60px 52px', borderBottom: `1px solid ${INK}`, background: PAPER },
  top: { display: 'flex', justifyContent: 'space-between', fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.2em', textTransform: 'uppercase', color: MUTE, gap: 24 },
  middle: { margin: 0, maxWidth: 1160 },
  h1: { fontFamily: 'var(--font-display)', fontWeight: 300, fontSize: 'clamp(52px, 9vw, 140px)', lineHeight: 0.92, letterSpacing: '-0.04em', fontVariationSettings: '"opsz" 144', color: INK, margin: '0 0 32px', maxWidth: '14ch', textWrap: 'balance' },
  sub: { fontFamily: 'var(--font-body)', fontWeight: 300, fontSize: 'clamp(17px, 1.5vw, 21px)', lineHeight: 1.55, color: MUTE, maxWidth: '54ch', margin: '0 0 40px' },
  bottom: { display: 'flex', flexWrap: 'wrap', gap: 40, fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.15em', textTransform: 'uppercase', color: MUTE, borderTop: `1px solid ${HAIR}`, paddingTop: 28 },
};

Object.assign(window, { FAQ, PROCESS_STEPS, PlusMinus, AccordionRow, OneNav, Hero });
