// content-sub.jsx — Tier 4 sub-pyramids (Analyst markets, Strategist real estate)
// + the DNA assessment (questions, scoring, routing).

// Each sub-pyramid: levels bottom->top in array order index 0 = base.
// Each level has `cells` ordered left(conservative)->right(aggressive); the
// horizontal index maps onto the 5-stop risk gradient.
window.L180_SUBPYRAMIDS = {
  analyst: {
    key: "analyst",
    name: "The Analyst Path",
    domain: "Market Investing",
    dot: "🟢",
    theme: "#24CE62",
    tagline: "Your risk tolerance shapes your pyramid. Your discipline determines whether it stands.",
    gateway: "Risk Tolerance Assessment",
    axisNote: "Risk climbs as you go up — and as you move left to right within each level.",
    levels: [
      { name: "Foundation", note: "Where every Analyst pyramid begins.",
        cells: ["Money Market", "Treasuries", "Investment-Grade Bonds", "Broad Index ETFs", "Sector / Geo ETFs", "Materials & Gold"] },
      { name: "Targeted Allocation", note: "Tilting the core with intention.",
        cells: ["Quality / Dividend ETFs", "Low-Volatility Factor", "Value Tilts", "Growth Tilts", "Sector Overweights", "Thematic ETFs"] },
      { name: "Specialist-Driven & Trend-Aware", note: "You won't be right every time here. The goal is engagement, learning, and developing market sense.",
        cells: ["Defensive Rotation", "Trend-Following ETFs", "Macro Plays", "Tactical Sector Bets", "Aggressive Thematic"] },
      { name: "Conviction Positions", note: "Concentrated bets you can defend.",
        cells: ["Blue-Chip Dividend", "Blue-Chip Growth", "Alternatives", "BTC / ETH", "Conviction Stocks", "Higher-Risk Crypto"] },
      { name: "Peak / Speculative", note: "Optional. Many clients will never have a Level 5.",
        cells: ["Covered Calls / CSPs", "Defined-Risk Spreads", "Long Calls / Puts", "Speculative Small Caps", "Naked Options / Microcap"] },
    ],
    education: ["Continuous learning track / webinars", "Sample pyramids by risk profile", "Color-coded risk gradient at every level"],
  },
  strategist: {
    key: "strategist",
    name: "The Strategist Path",
    domain: "Real Estate",
    dot: "🔵",
    theme: "#1FC9E5",
    tagline: "Dirt, doors, and discipline.",
    gateway: "Real Estate Risk & Capacity Assessment",
    axisNote: "Passive to operator as you climb — passive to active within each level.",
    levels: [
      { name: "Passive REIT Foundation", note: "Real estate exposure without the toolbelt.",
        cells: ["REIT ETFs", "Public REITs", "Private REITs", "RE Crowdfunding", "Interval Funds"] },
      { name: "Secured Paper & Lending", note: "Be the bank.",
        cells: ["Tax Liens", "Performing Notes", "Private Mortgage Lending", "Non-Performing Notes", "Tax Deeds & Auctions"] },
      { name: "Individual Properties (Hold)", note: "Owning the dirt and the doors.",
        cells: ["Turnkey SFR", "Self-Managed SFR", "Land", "Short-Term Rentals", "BRRRR / Value-Add", "House Hacking"] },
      { name: "Active SFR & Flips", note: "Forcing equity with sweat and systems.",
        cells: ["Light Cosmetic Flips", "Standard Flips", "Heavy Rehab", "Wholesaling", "Wholetailing", "Distressed Plays"] },
      { name: "Syndications (Passive LP)", note: "Scale through other operators.",
        cells: ["Debt-Fund Synd.", "Stabilized Multifamily", "Storage / MHP / Industrial", "Value-Add Synd.", "Opportunistic Synd."] },
      { name: "Active Commercial & Development", note: "You are the operator now.",
        cells: ["Stabilized MF (Op)", "Commercial NNN", "Value-Add Commercial", "Lot Banking", "Ground-Up Development"] },
    ],
    education: ["Financing pyramid running parallel", "Tier 3 foundation-asset integration", "Underwriting, PM, 1031, cost-seg, tenant law"],
  },
};

// DNA types
window.L180_DNA = {
  strategist:   { key: "strategist",   name: "Strategist",   color: "#1FC9E5", domain: "Real Estate",  blurb: "Wired to control hard assets — dirt, doors, and leverage.", meaning: "You build wealth by controlling tangible assets. Your edge is leverage, negotiation, and forcing value where others only see risk.", routesTo: "strategist" },
  analyst:      { key: "analyst",      name: "Analyst",      color: "#24CE62", domain: "Markets",      blurb: "Wired to compound in markets with research and discipline.", meaning: "You build wealth by compounding in markets with research and patience. Your edge is discipline and a long horizon — not chasing.", routesTo: "analyst" },
  builder:      { key: "builder",      name: "Builder",      color: "#F97316", domain: "Business",     blurb: "Wired to build companies, teams, and cash-flowing engines.", meaning: "You build wealth by creating cash-flowing engines. Your edge is leverage through people, systems, and relentless reinvestment.", routesTo: "lens" },
  professional: { key: "professional", name: "Professional", color: "#A855F7", domain: "Expertise",    blurb: "Wired to convert mastery of a craft into premium income.", meaning: "You build wealth by converting elite skill into premium income. Your edge is mastery — and protecting the earner that makes it all work.", routesTo: "lens" },
  innovator:    { key: "innovator",    name: "Innovator",    color: "#DC2626", domain: "Creation",     blurb: "Wired to create original output — IP, invention, licensing.", meaning: "You build wealth by creating original value. Your edge is IP and leverage through what only you can make — funded by a stable floor.", routesTo: "lens" },
};

// Assessment. Each option awards points to one or more DNA types.
// The final question captures current reality (Path A–D logic).
window.L180_DNA_QUESTIONS = [
  {
    id: "energizes", q: "When you imagine building wealth, what energizes you most?",
    why: "Your instinctive draw is the strongest DNA signal.",
    opts: [
      { t: "Acquiring property — tangible doors and dirt", dna: { strategist: 3 } },
      { t: "Researching markets and optimizing a portfolio", dna: { analyst: 3 } },
      { t: "Building a company, a team, a product", dna: { builder: 3 } },
      { t: "Becoming elite at a craft that commands income", dna: { professional: 3 } },
      { t: "Creating something original — IP, art, invention", dna: { innovator: 3 } },
    ],
  },
  {
    id: "work", q: "How do you most want your money to work?",
    why: "Preferred mechanism reveals wiring beyond surface interest.",
    opts: [
      { t: "Leverage and control over hard assets", dna: { strategist: 2, builder: 1 } },
      { t: "Compounding in markets, hands mostly off", dna: { analyst: 2, professional: 1 } },
      { t: "Reinvested into a growing business", dna: { builder: 2, strategist: 1 } },
      { t: "Funding my expertise so I earn more", dna: { professional: 2, innovator: 1 } },
      { t: "Royalties and licensing from what I make", dna: { innovator: 2, analyst: 1 } },
    ],
  },
  {
    id: "week", q: "Your ideal productive week looks like…",
    why: "Where you want to spend energy predicts what you'll sustain.",
    opts: [
      { t: "Walking properties and running numbers on deals", dna: { strategist: 2 } },
      { t: "Reading research and rebalancing positions", dna: { analyst: 2 } },
      { t: "Leading a team and shipping the next thing", dna: { builder: 2 } },
      { t: "Deep work mastering my profession", dna: { professional: 2 } },
      { t: "Making something that didn't exist yesterday", dna: { innovator: 2 } },
    ],
  },
  {
    id: "risk", q: "How would you describe your relationship to risk?",
    why: "Sets the horizontal starting point inside your pyramid.",
    risk: true,
    opts: [
      { t: "Protect first — I want to sleep at night", risk: 0, dna: { analyst: 1 } },
      { t: "Mostly cautious, some calculated bets", risk: 1, dna: { professional: 1 } },
      { t: "Balanced — offense and defense", risk: 2, dna: { strategist: 1 } },
      { t: "Growth-leaning, I can stomach swings", risk: 3, dna: { builder: 1 } },
      { t: "Aggressive — fortune favors conviction", risk: 4, dna: { innovator: 1 } },
    ],
  },
  {
    id: "reality", q: "Where do you actually live today?",
    why: "DNA says who you're becoming. This says what you need now.",
    reality: true,
    opts: [
      { t: "I actively invest in real estate", reality: "strategist", active: true },
      { t: "I actively invest in the markets", reality: "analyst", active: true },
      { t: "I run a business with real revenue", reality: "builder", active: true },
      { t: "I earn strong income from my profession", reality: "professional", active: true },
      { t: "I'm building something not yet earning", reality: "innovator", active: false },
      { t: "None of these — I'm just getting started", reality: "none", active: false },
    ],
  },
];

// Scoring + routing. Returns { primary, secondary, scores, risk, riskLabel,
// reality, path, route }.
window.l180ScoreDNA = function (answers) {
  const scores = { strategist: 0, analyst: 0, builder: 0, professional: 0, innovator: 0 };
  let risk = 2, reality = "none", realityActive = false;
  L180_DNA_QUESTIONS.forEach((Q) => {
    const choice = answers[Q.id];
    if (choice == null) return;
    const opt = Q.opts[choice];
    if (!opt) return;
    if (opt.dna) for (const k in opt.dna) scores[k] += opt.dna[k];
    if (Q.risk && typeof opt.risk === "number") risk = opt.risk;
    if (Q.reality) { reality = opt.reality; realityActive = !!opt.active; }
  });
  const ranked = Object.keys(scores).sort((a, b) => scores[b] - scores[a]);
  const primary = ranked[0];
  const secondary = ranked[1];
  const dna = L180_DNA[primary];

  // Path logic (A–D)
  let path, route, pathNote;
  const matchesReality = reality === primary;
  if (primary === "strategist") {
    path = "A"; route = "strategist";
    pathNote = matchesReality
      ? "Active or aspiring Strategist — entering the Real Estate sub-pyramid at your current capacity."
      : "Strategist DNA. We'll enter the Real Estate sub-pyramid and calibrate the entry level to where you are today.";
  } else if (primary === "analyst") {
    path = "B"; route = "analyst";
    pathNote = matchesReality
      ? "Active or aspiring Analyst — entering the Markets sub-pyramid at your current portfolio level."
      : "Analyst DNA. We'll enter the Markets sub-pyramid and set the entry level to your current portfolio.";
  } else if (realityActive && (reality === "builder" || reality === "professional")) {
    path = "C"; route = "lens";
    pathNote = `${dna.name} DNA with an active engine — staying on the main pyramid with ${dna.name}-specific emphasis at Tiers 2, 3, and 5.`;
  } else {
    path = "D"; route = "lens";
    const dmap = {
      builder: "Builder DNA without a business yet — we serve you as a Professional today; your foundation asset becomes future startup capital.",
      professional: "Professional DNA — a light-touch setup until income stabilizes, then we scale.",
      innovator: "Innovator DNA without output yet — we serve you as a Professional today; your foundation asset funds the creative leap.",
    };
    pathNote = dmap[primary] || "We'll serve you where you live today and honor where you're heading.";
  }

  return {
    primary, secondary, scores, risk,
    riskLabel: L180_BRAND.riskLabels[risk],
    reality, realityActive, path, route, pathNote,
  };
};
