// PulseApp — Consumer Pulse Methodology landing page.

const { useState, useEffect, useRef } = React;

const HEADLINES = {
  howBuilt:      { lead: "Want to know how", body: "we", accent: "did it" },
  speedRigor:    { lead: "Speed without rigor is", body: "", accent: "noise" },
  behindNumbers: { lead: "The methodology", body: "behind the", accent: "numbers" },
  hoursNotWeeks: { lead: "Consumer insight in", body: "", accent: "hours, not weeks" },
};

const PulseApp = () => {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const formRef = useRef(null);

  const ac = pulseAccent(t.accentColor);
  const accent = ac.solid;
  const accentTint = ac.tint;
  const hl = HEADLINES[t.headline] || HEADLINES.howBuilt;

  const Italic = ({ children, color }) => (
    <span style={{
      fontFamily: "var(--font-serif)", fontStyle: "italic", fontWeight: 500,
      color: color || accent,
    }}>{children}</span>
  );

  const scrollToForm = () => {
    if (formRef.current) {
      const top = formRef.current.getBoundingClientRect().top + window.scrollY - window.innerHeight / 2 + formRef.current.offsetHeight / 2;
      window.scrollTo({ top, behavior: "smooth" });
    }
  };

  return (
    <div style={{ minHeight: "100vh", background: "var(--av-canvas)", color: "var(--av-ink)", fontFamily: "var(--font-sans)" }}>
      <NavBar />
      <HeroSection hl={hl} Italic={Italic} t={t} accent={accent} scrollToForm={scrollToForm} formRef={formRef} />
      <InsideSection t={t} Italic={Italic} />
      <ProofSection accent={accent} Italic={Italic} t={t} scrollToForm={scrollToForm} />

      <section className="pulse-logo-bar-section" style={{ maxWidth: 1320, margin: "0 auto", padding: "32px 40px 64px" }}>
        <PulseLogoBar />
      </section>

      <ClosingCTA t={t} accent={accent} accentTint={accentTint} scrollToForm={scrollToForm} Italic={Italic} />

      <footer className="pulse-footer" style={{
        maxWidth: 1320, margin: "0 auto", padding: "32px 40px",
        display: "flex", justifyContent: "space-between", alignItems: "center",
        fontSize: 12, color: "var(--av-ink-muted)", flexWrap: "wrap", gap: 16,
      }}>
        <span>© 2026 AlgoVerde</span>
        <span style={{ display: "flex", gap: 16 }}>
          <a href="https://algoverde.ai/privacy-policy" target="_blank" rel="noopener noreferrer" style={{ color: "inherit", textDecoration: "none" }}>Privacy</a>
          <a href="https://algoverde.ai/security" target="_blank" rel="noopener noreferrer" style={{ color: "inherit", textDecoration: "none" }}>Security</a>
        </span>
      </footer>

      <TweaksPanel title="Tweaks">
        <TweakSection label="Headline">
          <TweakSelect label="Variant" value={t.headline}
            options={[
              { value: "howBuilt", label: "Want to know how we did it?" },
              { value: "speedRigor", label: "Speed without rigor is noise" },
              { value: "behindNumbers", label: "The methodology behind the numbers" },
              { value: "hoursNotWeeks", label: "Consumer insight in hours, not weeks" },
            ]}
            onChange={(v) => setTweak("headline", v)} />
          <TweakText label="Eyebrow" value={t.eyebrowText}
            onChange={(v) => setTweak("eyebrowText", v)} />
        </TweakSection>
        <TweakSection label="Accent">
          <TweakRadio label="Color" value={t.accentColor}
            options={[
              { value: "iris", label: "Iris" },
              { value: "ember", label: "Ember" },
              { value: "verde", label: "Verde" },
            ]}
            onChange={(v) => setTweak("accentColor", v)} />
        </TweakSection>
        <TweakSection label="CTA & form">
          <TweakSelect label="Button label" value={t.ctaLabel}
            options={["Get the methodology", "Download methodology", "Send me the methodology", "Read the methodology"]}
            onChange={(v) => setTweak("ctaLabel", v)} />
        </TweakSection>
      </TweaksPanel>
    </div>
  );
};

window.PulseApp = PulseApp;
