// Investor / Login — built on the design system.
//
// Composition:
//   <NetworkMap>            ambient US-city → vault → cities animation
//   <Header surface="bare"> floating wordmark + theme toggle
//   <Vignette>              soft radial readability mask, wrapping…
//     <Hero>                eyebrow + display headline + lede + 3 trust stats
//   <AuthPanel>             glass panel: wallet → email → providers
//   <Ticker>                bottom marquee of recent originations
//
// Page-level inline styles cover only: outer positioning and slot widths.
// Every visual atom (typography, chrome, padding, hairlines, icons,
// vignette gradient) lives in the design system or a primitive's variant.

// ─────────────────────────── Auth panel ───────────────────────────
// Glass surface (translucent + blur + heavy shadow). Positioning and
// slot width live on a wrapper <div> — Panel itself doesn't know it's
// floating on this page. Every visual atom (chrome, padding, typography,
// hairlines) comes from the design system.

function AuthPanel() {
  return (
    <div style={{
      position: "absolute",
      right: 80,
      top: "50%",
      transform: "translateY(-50%)",
      width: 420,
      zIndex: 3,
    }}>
      <Panel surface="glass" density="lg">
        <PanelHead
          title="Sign in"
          subtitle="Connect your wallet, or we'll set one up for you."
        />
        <PanelBody stack>
          <Button block>
            <WalletGlyph size={16} />
            Connect wallet
          </Button>

          <Divider>or</Divider>

          <Field>
            <MailGlyph />
            <input type="email" placeholder="name@firm.com" />
            <FieldAction>Continue</FieldAction>
          </Field>

          <div style={{ display: "flex", gap: 8 }}>
            <ProviderButton provider="google" />
            <ProviderButton provider="apple" />
            <ProviderButton provider="x" />
            <ProviderButton provider="farcaster" />
          </div>
        </PanelBody>
        <PanelFoot>
          <Eyebrow tone="faint">Powered by Dynamic</Eyebrow>
        </PanelFoot>
      </Panel>
    </div>
  );
}

// ─────────────────────────── Hero ───────────────────────────

function Hero() {
  return (
    <div style={{
      position: "absolute",
      left: 64,
      top: "50%",
      transform: "translateY(-54%)",
      maxWidth: 760,
      zIndex: 2,
    }}>
      <div style={{ marginBottom: 28 }}>
        <Eyebrow tone="brand" rule>Investor Access</Eyebrow>
      </div>

      <Display as="h1" size="xl">
        Yield, on a rail<br />
        of real assets.
      </Display>

      <Body lede style={{ margin: "26px 0 0", maxWidth: 520 }}>
        Deposit USDC into a diversified portfolio of short-term, senior-secured
        US mortgages. Originated, rated, and serviced on-chain.
      </Body>

      <div style={{ marginTop: 40 }}>
        <KpiStripQuiet items={[
          { value: "9.12%",  label: "Current portfolio APY" },
          { value: "$1.99B", label: "AUM" },
          { value: "1.25%",  label: "Delinquency · 90d" },
        ]} />
      </div>
    </div>
  );
}

// ─────────────────────────── Recent-origination ticker data ─────────────

const ORIGINATIONS = [
  { amt: "$483,200",  loc: "AUSTIN, TX",       type: "FIX & FLIP",   term: "12MO", apy: "8.9%", ago: "4M AGO" },
  { amt: "$1,240,000", loc: "DENVER, CO",       type: "BRIDGE",       term: "18MO", apy: "9.2%", ago: "12M AGO" },
  { amt: "$295,000",  loc: "PHOENIX, AZ",      type: "GROUND-UP",    term: "24MO", apy: "9.6%", ago: "23M AGO" },
  { amt: "$612,500",  loc: "CHARLOTTE, NC",    type: "FIX & FLIP",   term: "10MO", apy: "9.0%", ago: "31M AGO" },
  { amt: "$845,000",  loc: "MIAMI, FL",        type: "BRIDGE",       term: "15MO", apy: "9.4%", ago: "44M AGO" },
  { amt: "$378,400",  loc: "NASHVILLE, TN",    type: "FIX & FLIP",   term: "12MO", apy: "8.7%", ago: "58M AGO" },
  { amt: "$2,100,000", loc: "SEATTLE, WA",      type: "GROUND-UP",    term: "24MO", apy: "9.8%", ago: "1H AGO" },
  { amt: "$520,750",  loc: "TAMPA, FL",        type: "FIX & FLIP",   term: "11MO", apy: "8.8%", ago: "1H AGO" },
  { amt: "$1,675,000", loc: "BOSTON, MA",       type: "MULTIFAMILY",  term: "36MO", apy: "8.6%", ago: "2H AGO" },
  { amt: "$945,800",  loc: "BROOKLYN, NY",     type: "BRIDGE",       term: "14MO", apy: "9.1%", ago: "2H AGO" },
];

const ORIGINATION_COLUMNS = [
  { key: "amt", tone: "strong" },
  "loc",
  "type",
  "term",
  { key: "apy", tone: "brand", suffix: " APY" },
  { key: "ago", tone: "faint" },
];

// ─────────────────────────── Page assembly ───────────────────────────

function Login() {
  const [theme, setTheme] = useTheme();
  return (
    <div data-theme={theme} style={{
      width: "100vw", height: "100vh",
      position: "relative",
      overflow: "hidden",
      background: "var(--surface)",
      color: "var(--text)",
      fontFamily: "var(--font-sans)",
    }}>
      {/* US network map — ambient bg */}
      <NetworkMap opacity={0.7} theme={theme} />

      {/* Content frame — caps the composition at 1600 on ultrawide */}
      <div style={{ position: "absolute", inset: 0, maxWidth: 1600, margin: "0 auto" }}>
        {/* Floating header — page owns position, system owns chrome.
            `surface="bare"` drops the hairline so it reads as glass over
            the network map, not a top-edge divider. */}
        <div style={{ position: "absolute", top: 0, left: 0, right: 0, zIndex: 4 }}>
          <Header label="Investor" surface="bare" theme={theme} onThemeChange={setTheme} />
        </div>

        <Vignette>
          <Hero />
        </Vignette>
        <AuthPanel />
      </div>

      {/* Bottom ticker — recent originations tape */}
      <div style={{ position: "absolute", left: 0, right: 0, bottom: 0 }}>
        <Ticker
          label="Recent originations"
          speed="fast"
          items={ORIGINATIONS}
          columns={ORIGINATION_COLUMNS}
        />
      </div>
    </div>
  );
}

window.Login = Login;
