// Shared layout for all legal / stub pages
function LegalPage({ go, breadcrumb, eyebrow, title, children }) {
  const wide = useWide();
  return (
    <div style={{ background: TH.bg, color: TH.ink, fontFamily: TH.serif, minHeight: '100vh' }}>
      <div style={{ borderBottom: `1px solid ${TH.rule}`, padding: wide ? '12px 32px' : '12px 20px', fontFamily: TH.mono, fontSize: 11, color: TH.muted, letterSpacing: 1.5 }}>
        <span onClick={() => go('landing')} style={{ cursor: 'pointer', color: TH.accent }}>HOME</span>
        <span style={{ margin: '0 10px' }}>›</span>
        <span>{breadcrumb}</span>
      </div>
      <div style={{ maxWidth: 720, margin: '0 auto', padding: wide ? '52px 32px 96px' : '32px 20px 72px' }}>
        <div style={{ fontFamily: TH.mono, fontSize: 11, color: TH.accent, letterSpacing: 2, marginBottom: 16 }}>{eyebrow}</div>
        <h1 style={{ fontFamily: TH.serif, fontSize: wide ? 48 : 32, fontWeight: 400, lineHeight: 1.05, letterSpacing: -1.2, margin: '0 0 28px', color: TH.ink }}>{title}</h1>
        <div style={{ height: 1, background: TH.rule, marginBottom: 4 }}/>
        {children}
      </div>
      <Footer/>
    </div>
  );
}

function LegalSection({ title, children }) {
  return (
    <div style={{ marginTop: 44 }}>
      <div style={{ fontFamily: TH.serif, fontSize: 20, fontWeight: 400, letterSpacing: -0.3, color: TH.ink, marginBottom: 14, paddingBottom: 10, borderBottom: `1px solid ${TH.rule}` }}>{title}</div>
      {children}
    </div>
  );
}

function LegalP({ children }) {
  return (
    <p style={{ fontFamily: TH.serif, fontSize: 15, lineHeight: 1.8, color: TH.inkSoft, margin: '14px 0' }}>{children}</p>
  );
}

function Terms({ go }) {
  return (
    <LegalPage go={go} breadcrumb="TERMS" eyebrow="§ LEGAL · TERMS" title="Terms of service">
      <div style={{ fontFamily: TH.mono, fontSize: 10, color: TH.muted, letterSpacing: 1.5, marginTop: 20, marginBottom: 8 }}>EFFECTIVE DATE · MAY 2026</div>
      <LegalP>
        Walkforward Trading ("Walkforward", "we", "us") provides a research and tooling platform for informational purposes. By accessing this site or purchasing a membership, you agree to these terms.
      </LegalP>

      <LegalSection title="Service">
        <LegalP>
          Walkforward provides research memos, a backtesting tool, video content, and access to a community chat. All content is for informational purposes only. Nothing constitutes investment advice, a solicitation, or a recommendation to trade any asset.
        </LegalP>
      </LegalSection>

      <LegalSection title="Membership and billing">
        <LegalP>
          Memberships are billed monthly or annually via Whop. You may cancel at any time from your billing page or directly in the Whop dashboard. A 30-day refund is available on request — no forms required. Archive access continues for 30 days after cancellation.
        </LegalP>
      </LegalSection>

      <LegalSection title="Conduct">
        <LegalP>
          Members may not redistribute paid content, automate access to the backtester in ways that place unreasonable load on the service, or use the platform in violation of applicable law.
        </LegalP>
      </LegalSection>

      <LegalSection title="Limitation of liability">
        <LegalP>
          Walkforward is not liable for trading losses, missed opportunities, or decisions made based on content published here. All strategies published are historical analyses, not forward-looking recommendations.
        </LegalP>
      </LegalSection>

      <div style={{ marginTop: 44, fontFamily: TH.mono, fontSize: 12, color: TH.inkSoft }}>
        Contact: <a href="mailto:contact@walkforwardtrading.com" style={{ color: TH.accent, textDecoration: 'none' }}>contact@walkforwardtrading.com</a>
      </div>
    </LegalPage>
  );
}

function Privacy({ go }) {
  return (
    <LegalPage go={go} breadcrumb="PRIVACY" eyebrow="§ LEGAL · PRIVACY" title="Privacy policy">
      <div style={{ fontFamily: TH.mono, fontSize: 10, color: TH.muted, letterSpacing: 1.5, marginTop: 20, marginBottom: 8 }}>EFFECTIVE DATE · MAY 2026</div>

      <LegalSection title="What we collect">
        <LegalP>
          Account creation: email address, display name (optional), connected wallet address (optional). We do not collect payment information directly — all billing is handled by Whop.
        </LegalP>
      </LegalSection>

      <LegalSection title="How we use it">
        <LegalP>
          Email is used to manage your account and send membership-related communications. We do not send marketing email beyond what you explicitly opt in to. We do not sell or share your data with third parties for advertising purposes.
        </LegalP>
      </LegalSection>

      <LegalSection title="Third parties">
        <LegalP>
          Whop handles billing and payment processing. Binance and Yahoo Finance APIs are used to fetch market data (no personal data is sent). Fonts are loaded from Google Fonts.
        </LegalP>
      </LegalSection>

      <LegalSection title="Your rights">
        <LegalP>
          You may request deletion of your account and associated data at any time by emailing{' '}
          <a href="mailto:contact@walkforwardtrading.com" style={{ color: TH.accent, textDecoration: 'none' }}>contact@walkforwardtrading.com</a>.
          {' '}We will process requests within 30 days.
        </LegalP>
      </LegalSection>
    </LegalPage>
  );
}

function Risk({ go }) {
  return (
    <LegalPage go={go} breadcrumb="RISK DISCLOSURE" eyebrow="§ LEGAL · RISK DISCLOSURE" title="Risk disclosure">
      <LegalSection title="Trading risk">
        <LegalP>
          Trading financial instruments, including cryptocurrencies, involves substantial risk of loss. Past performance — including the backtest results published on this site — is not indicative of future results.
        </LegalP>
      </LegalSection>

      <LegalSection title="Backtest limitations">
        <LegalP>
          All strategies published by Walkforward are historical analyses produced under specific assumptions (fees, slippage, data source, parameter values). Live trading results will differ from backtest results due to execution differences, market impact, data latency, and the inherent unpredictability of markets.
        </LegalP>
        <LegalP>
          Walk-forward validation reduces but does not eliminate the risk of overfitting. A strategy that passes a walk-forward test may still fail in live trading. The research published here is one input — position sizing, risk management, and execution decisions are the sole responsibility of the trader.
        </LegalP>
      </LegalSection>

      <LegalSection title="No investment advice">
        <LegalP>
          Walkforward Trading is not a registered investment adviser. Nothing on this site constitutes investment advice, a solicitation, or a recommendation to buy or sell any financial instrument.
        </LegalP>
      </LegalSection>

      <div style={{ marginTop: 44, padding: '14px 18px', border: `1px solid ${TH.rule}`, fontFamily: TH.mono, fontSize: 10, color: TH.muted, letterSpacing: 2 }}>
        IF YOU DO NOT UNDERSTAND THESE RISKS, DO NOT TRADE.
      </div>
    </LegalPage>
  );
}

function Changelog({ go }) {
  return (
    <LegalPage go={go} breadcrumb="CHANGELOG" eyebrow="§ CHANGELOG" title="Changelog">
      <LegalP>
        No public changelog yet. Member release notes are posted in the Telegram community.
      </LegalP>
    </LegalPage>
  );
}

function Press({ go }) {
  return (
    <LegalPage go={go} breadcrumb="PRESS" eyebrow="§ PRESS" title="Press">
      <LegalP>
        No press kit yet. For media enquiries contact{' '}
        <a href="mailto:contact@walkforwardtrading.com" style={{ color: TH.accent, textDecoration: 'none' }}>contact@walkforwardtrading.com</a>.
      </LegalP>
    </LegalPage>
  );
}

function Contact({ go }) {
  return (
    <LegalPage go={go} breadcrumb="CONTACT" eyebrow="§ CONTACT" title="Contact">
      <LegalP>
        For general enquiries, billing questions, or account issues, email{' '}
        <a href="mailto:contact@walkforwardtrading.com" style={{ color: TH.accent, textDecoration: 'none' }}>contact@walkforwardtrading.com</a>.
      </LegalP>
      <LegalP>
        For urgent account or billing issues, you can also reach us via the Telegram community.
      </LegalP>
    </LegalPage>
  );
}

Object.assign(window, { Terms, Privacy, Risk, Changelog, Press, Contact });
