/* /modules/ — the module hub. A visitor arrives with a problem, not a
   product name: the finder takes the problem and lands on the module, its
   fixed beta price, what the analysis hands over, who runs it, and three
   ways in (start and pay, see the demo, talk to us). The promises every
   buyer wants before paying sit next to the buttons, not in a FAQ. */

function ModuleCard({ m, prices, enabled }) {
  const price = modulePrice(m, prices);
  const live = m.status === 'live';
  return (
    <div id={m.id} className="card module-card" style={{ scrollMarginTop: 90, padding: 'clamp(20px,2.6vw,30px)', display: 'grid', gridTemplateColumns: 'minmax(0, 1.4fr) minmax(240px, 0.6fr)', gap: 'clamp(18px,3vw,36px)', borderColor: live ? 'var(--accent)' : 'var(--line-strong)' }}>
      <div>
        <div style={{ display: 'flex', gap: 10, alignItems: 'center', flexWrap: 'wrap', marginBottom: 8 }}>
          <span className="mono" style={{ fontSize: 10.5, letterSpacing: '0.1em', textTransform: 'uppercase', color: live ? 'var(--accent)' : 'var(--warn)' }}>{live ? 'Live' : 'Beta · analysis available now'}</span>
          {m.sensitive && <span className="mono" style={{ fontSize: 10.5, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--fg-subtle)' }}>Sensitive detail under NDA</span>}
        </div>
        <h2 style={{ fontFamily: 'var(--font-display)', fontSize: 'clamp(24px,2.6vw,32px)', fontWeight: 600, margin: '0 0 6px', letterSpacing: '-0.01em', lineHeight: 1.15 }}>Lojo {m.title}</h2>
        <p style={{ margin: '0 0 14px', color: 'var(--fg-muted)', fontSize: 15.5, lineHeight: 1.6 }}>{m.problem}</p>
        <div className="mono" style={{ fontSize: 10.5, letterSpacing: '0.09em', textTransform: 'uppercase', color: 'var(--fg-subtle)', marginBottom: 8 }}>What you get</div>
        <ul style={{ listStyle: 'none', margin: '0 0 14px', padding: 0, display: 'flex', flexDirection: 'column', gap: 8 }}>
          {m.gets.map((g) => <li key={g} style={{ display: 'flex', gap: 9, fontSize: 14.5, lineHeight: 1.5 }}><span style={{ color: 'var(--accent)', marginTop: 2, flex: '0 0 auto' }}><Icon name="check" size={15} stroke={2.4} /></span>{g}</li>)}
        </ul>
        <div style={{ fontSize: 13.5, color: 'var(--fg-muted)', lineHeight: 1.6 }}><b style={{ color: 'var(--fg)' }}>Who runs it:</b> {m.who}</div>
      </div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 10, padding: 'clamp(16px,2vw,22px)', borderRadius: 'var(--r-md)', background: 'var(--navy)', border: '1px solid var(--line)' }}>
        <div className="overline">{live ? 'Free to start' : 'Beta price · one-time'}</div>
        <div className="display" style={{ fontSize: 'clamp(30px,3.2vw,38px)', lineHeight: 1 }}>{moduleMoney(price)}<span style={{ fontSize: 13, fontFamily: 'var(--font-sans)', fontWeight: 400, color: 'var(--fg-muted)', marginLeft: 8 }}>{m.unit}</span></div>
        <div style={{ fontSize: 13, color: 'var(--fg-muted)', lineHeight: 1.55, flex: 1 }}>{m.time}{!live && ' Includes a 45-minute strategy walkthrough with the founders and 30 days in the workspace.'}</div>
        <a href={moduleStartUrl(m)} className="btn btn-primary" style={{ justifyContent: 'center' }}>{live ? 'Get the free report' : `Start ${m.title}`} <Icon name="arrow-right" size={16} /></a>
        <a href={moduleSampleUrl(m)} className="btn btn-ghost" style={{ justifyContent: 'center' }}>{live ? 'Read a sample report' : 'Read a sample analysis'}</a>
        {!live && <div style={{ display: 'flex', gap: 12, justifyContent: 'center', fontSize: 13 }}><a href={moduleDemoUrl(m)} style={{ color: 'var(--accent)' }}>Workspace demo</a><a href={'/app/?request=' + m.id} style={{ color: 'var(--fg-muted)' }}>Talk to us first</a></div>}
        {!live && !enabled && <div style={{ fontSize: 11.5, color: 'var(--fg-subtle)', textAlign: 'center' }}>Card payment is not switched on here yet; start anyway and we unlock it after a word.</div>}
      </div>
    </div>);
}

function HowBuyingWorks() {
  const steps = [
    ['01', 'One short screen', 'Who you are, what you want the module to change, headcount and timing. Two minutes. That alone starts your analysis.'],
    ['02', 'Look, then unlock', 'The first insights appear free, every fact graded A to D, the unknowable listed rather than guessed. Pay by card to unlock the findings and recommendations, or talk to us first.'],
    ['03', 'Then run it', 'A 45-minute strategy walkthrough with the founders, then your workspace: 30 days included, monthly after that by modules and seats. Implement with your own people, a partner you bring, or a Lojo preferred partner.'],
  ];
  return (
    <div className="loop-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 'clamp(14px,1.8vw,22px)' }}>
      {steps.map(([n, t, d]) => <div key={n} className="card loop-card" style={{ padding: 'clamp(20px,2.4vw,28px)' }}>
        <div className="mono" style={{ fontSize: 12, color: 'var(--accent)', letterSpacing: '0.1em', marginBottom: 12 }}>{n}</div>
        <h3 style={{ fontFamily: 'var(--font-display)', fontSize: 'clamp(20px,1.9vw,24px)', fontWeight: 600, margin: '0 0 8px', letterSpacing: '-0.01em' }}>{t}</h3>
        <p style={{ margin: 0, color: 'var(--fg-muted)', fontSize: 14.5, lineHeight: 1.6 }}>{d}</p>
      </div>)}
    </div>);
}

function Promises() {
  return (
    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))', gap: 'clamp(14px,2vw,22px)' }}>
      {MODULE_PROMISES.map(([icon, t, d]) => <div key={t} className="card feature-card" style={{ padding: 'clamp(18px,2.4vw,26px)' }}>
        <div style={{ color: 'var(--accent)', marginBottom: 12 }}><Icon name={icon} size={22} stroke={1.7} /></div>
        <div style={{ fontFamily: 'var(--font-display)', fontSize: 18.5, fontWeight: 600, marginBottom: 6 }}>{t}</div>
        <p style={{ margin: 0, fontSize: 14, color: 'var(--fg-muted)', lineHeight: 1.6 }}>{d}</p>
      </div>)}
    </div>);
}

function WhoImplements() {
  const routes = [
    ['Your own people', 'Invite them as members. They work the roadmap, update actuals and tick fixes off in the workspace. Seats are the only cost.', '/app/', 'Open the workspace'],
    ['A partner you bring', 'Your agency, integrator or consultant. You invite them from Organization → Implementation; Lojo approves the invitation and they sign a strict confidentiality agreement before they see a record. They never use a seat.', '/app/', 'Invite from the workspace'],
    ['A Lojo preferred partner', 'Vetted firms you can choose from inside the workspace, by module and region. Same approval, same agreement. Lojo earns a share of their fees, never a markup on you.', '/partners/', 'See the programme'],
  ];
  return (
    <div className="loop-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 'clamp(14px,1.8vw,22px)' }}>
      {routes.map(([t, d, href, cta]) => <div key={t} className="card loop-card" style={{ padding: 'clamp(20px,2.4vw,28px)', display: 'flex', flexDirection: 'column' }}>
        <h3 style={{ fontFamily: 'var(--font-display)', fontSize: 'clamp(20px,1.9vw,24px)', fontWeight: 600, margin: '0 0 8px', letterSpacing: '-0.01em' }}>{t}</h3>
        <p style={{ margin: '0 0 14px', color: 'var(--fg-muted)', fontSize: 14.5, lineHeight: 1.6, flex: 1 }}>{d}</p>
        <a href={href} style={{ color: 'var(--accent)', fontSize: 13.5, fontWeight: 600 }}>{cta} →</a>
      </div>)}
    </div>);
}

function ModulesPage() {
  const { prices, enabled, workspace } = useModulePrices();
  React.useEffect(() => { countOpen('modules_page'); }, []);
  const [pick, setPick] = React.useState('');
  const paid = MODULE_CATALOG.filter((m) => m.status !== 'live');
  const choose = (id) => { setPick(id); document.getElementById(id)?.scrollIntoView({ behavior: 'smooth', block: 'start' }); };
  return (
    <React.Fragment>
      <PageNav active="/modules/" cta={{ href: '#finder', label: 'Find your module' }} />
      <header className="section" style={{ paddingTop: 136, paddingBottom: 'clamp(24px,4vw,40px)', position: 'relative', overflow: 'hidden' }}>
        <div style={{ position: 'absolute', top: -120, left: '50%', transform: 'translateX(-50%)', width: 900, height: 520,
          background: 'radial-gradient(closest-side, var(--accent-glow), transparent)', opacity: 0.45, pointerEvents: 'none', filter: 'blur(20px)', maxWidth: '150vw' }}></div>
        <div className="wrap" style={{ position: 'relative', textAlign: 'center' }}>
          <div className="overline" style={{ marginBottom: 16 }}>Modules</div>
          <h1 className="display" style={{ fontSize: 'clamp(34px,6.4vw,66px)', margin: '0 auto', maxWidth: 940 }}>
            Start with the problem.<br />The module <span style={{ color: 'var(--accent)' }}>follows</span>.
          </h1>
          <p className="lede" style={{ maxWidth: 640, margin: '20px auto 0', color: 'var(--fg-muted)' }}>
            Each module is one analysis of your organization by the Lojo engine, graded fact by fact, at a fixed beta price you can pay today.
            The first insights are free, so you look before you pay. AI visibility is the free entry point.
          </p>
          <div id="finder" style={{ scrollMarginTop: 90, marginTop: 28 }}>
            <div className="overline" style={{ marginBottom: 12 }}>What do you need to do?</div>
            <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', justifyContent: 'center' }}>
              {MODULE_CATALOG.map((m) => <button key={m.id} className={'tour-tab' + (pick === m.id ? ' on' : '')} style={{ padding: '9px 14px', fontSize: 13.5 }} onClick={() => choose(m.id)}>{m.goal}</button>)}
            </div>
          </div>
        </div>
      </header>

      <section className="section" style={{ paddingTop: 0 }}>
        <div className="wrap" style={{ display: 'flex', flexDirection: 'column', gap: 'clamp(14px,2vw,22px)' }}>
          {MODULE_CATALOG.map((m) => <ModuleCard key={m.id} m={m} prices={prices} enabled={enabled} />)}
        </div>
      </section>

      <section className="section" style={{ background: 'var(--navy)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
        <div className="wrap">
          <SectionHead over="How starting works" center title="Two minutes in.<br>Paid when it has earned it." />
          <HowBuyingWorks />
        </div>
      </section>

      <section id="workspace" className="section" style={{ scrollMarginTop: 90 }}>
        <div className="wrap">
          <SectionHead over="Then run it" center title="The analysis is one-time.<br>Running it is the workspace, monthly."
            sub="The module price buys the analysis and the strategy. Execution happens in the Lojo workspace: the opportunity ledger, approvals, actuals, the roadmap, and the people doing the work. Pay for the modules you keep live and the seats you use." />
          <div style={{ maxWidth: 1040, margin: '0 auto' }}><WorkspacePricing workspace={workspace} /></div>
        </div>
      </section>

      <section id="implement" className="section" style={{ scrollMarginTop: 90, background: 'var(--navy)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
        <div className="wrap">
          <SectionHead over="Who implements" center title="Lojo analyses and plans.<br>You choose who does the work."
            sub="Lojo does not do the implementation itself. Three ways to get it done, all inside the same workspace, with every external hand approved by Lojo and bound by a strict confidentiality agreement." />
          <WhoImplements />
        </div>
      </section>

      <section className="section">
        <div className="wrap">
          <SectionHead over="Before you pay" center title="The questions every buyer asks,<br>answered up front." />
          <Promises />
        </div>
      </section>

      <section className="section" style={{ background: 'var(--navy)', borderTop: '1px solid var(--line)' }}>
        <div className="wrap">
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))', gap: 'clamp(16px,2.4vw,28px)' }}>
            <div className="card" style={{ padding: 'clamp(22px,2.8vw,32px)' }}>
              <div className="overline" style={{ marginBottom: 10 }}>Not sure which module?</div>
              <h3 style={{ fontFamily: 'var(--font-display)', fontSize: 24, fontWeight: 600, margin: '0 0 8px' }}>Thirty minutes with the founders.</h3>
              <p style={{ margin: '0 0 16px', color: 'var(--fg-muted)', fontSize: 14.5, lineHeight: 1.6 }}>Tell us what is going on and we will say which module fits, or that none does. No pitch; a straight answer within one business day.</p>
              <a href="/app/?request=1" className="btn btn-ghost">Book a call <Icon name="arrow-right" size={16} /></a>
            </div>
            <div className="card" style={{ padding: 'clamp(22px,2.8vw,32px)' }}>
              <div className="overline" style={{ marginBottom: 10 }}>Several modules, or a whole company</div>
              <h3 style={{ fontFamily: 'var(--font-display)', fontSize: 24, fontWeight: 600, margin: '0 0 8px' }}>One request covers them all.</h3>
              <p style={{ margin: '0 0 16px', color: 'var(--fg-muted)', fontSize: 14.5, lineHeight: 1.6 }}>Start with one module and add the others from your analysis page; everything Lojo learns carries across. Implementation firms: apply to the preferred partner programme.</p>
              <div style={{ display: 'flex', gap: 10, flexWrap: 'wrap' }}><a href="/app/?demo=1" className="btn btn-ghost">See the whole platform demo</a><a href="/partners/" className="btn btn-ghost">Become a preferred partner</a><a href="/pricing/" style={{ alignSelf: 'center', fontSize: 13.5, color: 'var(--accent)' }}>All prices →</a></div>
            </div>
          </div>
        </div>
      </section>
      <Footer />
    </React.Fragment>);
}

ReactDOM.createRoot(document.getElementById('root')).render(<ModulesPage />);
