// All mock data, in one place, so individual snippets stay small.

// === STRATEGIES (used by demo + history table) =====================
const STRATEGIES = [
  { id: "momo-nasdaq", name: "Momentum_Tech", color: "262 83% 67%",
    trades: 184, realized: 18420.10, unrealized: 3120.40, winRate: 64.2, avgTrade: 188.20,
    sharpe: 2.04, maxDD: -2.8, origin: "Sync" },
  { id: "momo-russell", name: "Momentum_SmallCap", color: "210 90% 62%",
    trades: 142, realized: 8430.55, unrealized: 1840.10, winRate: 58.5, avgTrade: 122.40,
    sharpe: 1.71, maxDD: -3.4, origin: "Sync" },
  { id: "wtt-sp500", name: "Trend_SP500", color: "145 60% 50%",
    trades: 96, realized: 11240.40, unrealized: -240.10, winRate: 61.4, avgTrade: 218.10,
    sharpe: 1.93, maxDD: -2.1, origin: "OC" },
  { id: "wtt-tsx", name: "Trend_TSX", color: "35 92% 58%",
    trades: 72, realized: 4320.18, unrealized: 980.40, winRate: 59.7, avgTrade: 134.20,
    sharpe: 1.55, maxDD: -3.0, origin: "OC" },
  { id: "momo-tsx60", name: "Momentum_LargeCap", color: "340 75% 65%",
    trades: 58, realized: 2860.40, unrealized: 1240.10, winRate: 56.9, avgTrade: 110.40,
    sharpe: 1.42, maxDD: -3.8, origin: "Sync" },
  { id: "connors", name: "MeanRev_SP500", color: "190 85% 55%",
    trades: 124, realized: 6420.20, unrealized: 540.30, winRate: 67.7, avgTrade: 86.40,
    sharpe: 1.84, maxDD: -2.4, origin: "CSV" },
  { id: "rotation-etf", name: "Rotation_ETF", color: "262 50% 78%",
    trades: 46, realized: 5210.80, unrealized: 2240.10, winRate: 65.2, avgTrade: 226.40,
    sharpe: 2.20, maxDD: -1.9, origin: "Man" },
  { id: "adaptive-growth", name: "Adaptive_Growth", color: "0 75% 62%",
    trades: 32, realized: 3640.40, unrealized: 1860.50, winRate: 62.5, avgTrade: 240.10,
    sharpe: 1.66, maxDD: -4.2, origin: "XML" },
];

// === DASHBOARD HERO STATS =========================================
const DASH = {
  assets: 284512.47,
  assetsChangePct: 4.5,
  pnl30d: 12420.18,
  perf30d: 4.5,
  cash: 42188.22,
  cashAccounts: 2,
  unrealized: 9840.30,
  realized: 28640.10,
  metrics: {
    sharpe: 1.86, sortino: 2.52, maxDD: -3.20,
    winRate: 61.8, profitFactor: 2.84,
    avgWin: 612, avgLoss: -301, expectancy: 174.20,
  },
};

// === Smooth 30-day equity curve (deterministic) ===================
function genCurve(start, end, n, seed) {
  // smooth random walk biased upward
  const pts = [];
  let v = start;
  let s = seed;
  const drift = (end - start) / (n - 1);
  for (let i = 0; i < n; i++) {
    s = (s * 9301 + 49297) % 233280;
    const noise = (s / 233280 - 0.5) * (Math.abs(end - start) * 0.04);
    v += drift + noise;
    pts.push(v);
  }
  // Force last point to end exactly:
  const fix = end - pts[pts.length - 1];
  return pts.map((p, i) => p + fix * (i / (n - 1)));
}

const CURVE_30D = genCurve(272092, 284512.47, 31, 4711);

// === HERO PERIOD TOGGLE ===========================================
const PERIODS = ["1D", "5D", "7D", "30D", "1Y", "ALL"];

// === INTEGRATIONS LOGOS ===========================================
const INTEGRATIONS = [
  { name: "Interactive Brokers", id: "ibkr" },
  { name: "OrderClerk",        id: "oc"   },
  { name: "RealTest",          id: "rt"   },
];

// === BLOCK A — History By Strategies =============================
const HISTORY_ROWS = [
  { strat: "Momentum_Tech",       origin: "Sync", trades: 184, realized: 18420.10, unrealized: 3120.40, winRate: 64.2, avgTrade: 188.20 },
  { strat: "Momentum_SmallCap",     origin: "Sync", trades: 142, realized: 8430.55,  unrealized: 1840.10, winRate: 58.5, avgTrade: 122.40 },
  { strat: "Trend_SP500",             origin: "OC",   trades: 96,  realized: 11240.40, unrealized: -240.10, winRate: 61.4, avgTrade: 218.10 },
  { strat: "Trend_TSX",               origin: "OC",   trades: 72,  realized: 4320.18,  unrealized: 980.40,  winRate: 59.7, avgTrade: 134.20 },
  { strat: "Momentum_LargeCap",           origin: "Sync", trades: 58,  realized: 2860.40,  unrealized: 1240.10, winRate: 56.9, avgTrade: 110.40 },
  { strat: "MeanRev_SP500",  origin: "CSV",  trades: 124, realized: 6420.20,  unrealized: 540.30,  winRate: 67.7, avgTrade: 86.40 },
  { strat: "Rotation_ETF",               origin: "Man",  trades: 46,  realized: 5210.80,  unrealized: 2240.10, winRate: 65.2, avgTrade: 226.40 },
  { strat: "Adaptive_Growth",                  origin: "XML",  trades: 32,  realized: 3640.40,  unrealized: 1860.50, winRate: 62.5, avgTrade: 240.10 },
];

// === BLOCK B — Round-Trip fills ==================================
const AAPL_FILLS = [
  { date: "Apr 02", side: "BUY",  qty: 200, price: 169.42, ttype: "in"  },
  { date: "Apr 08", side: "BUY",  qty: 150, price: 171.05, ttype: "in"  },
  { date: "Apr 11", side: "SELL", qty: 250, price: 175.88, ttype: "out" },
  { date: "Apr 12", side: "BUY",  qty: 100, price: 174.20, ttype: "in"  },
  { date: "Apr 14", side: "SELL", qty: 200, price: 178.65, ttype: "out" },
];

// === BLOCK C — monthly P&L bars ==================================
const MONTHLY_PNL = [
  { m: "Jun", v:  1820 }, { m: "Jul", v:  2640 }, { m: "Aug", v: -1240 },
  { m: "Sep", v:  3280 }, { m: "Oct", v:  4120 }, { m: "Nov", v: -680 },
  { m: "Dec", v:  2940 }, { m: "Jan", v:  5210 }, { m: "Feb", v:  3820 },
  { m: "Mar", v: -1480 }, { m: "Apr", v:  4640 }, { m: "May", v:  3120 },
];

// === BLOCK D — Capital Allocation ================================
const CAPITAL_ROWS = [
  { date: "May 14, 2026", type: "Deposit",     strategy: "Momentum_Tech", amount:  10000.00, ccy: "USD", recurring: false, note: "Wire from IBKR" },
  { date: "May 01, 2026", type: "Contribution",strategy: "Rotation_ETF",         amount:   2500.00, ccy: "CAD", recurring: true,  note: "Monthly auto" },
  { date: "Apr 28, 2026", type: "Withdrawal",  strategy: "Trend_TSX",         amount:  -3000.00, ccy: "CAD", recurring: false, note: "Tax payment" },
  { date: "Apr 15, 2026", type: "Deposit",     strategy: "Adaptive_Growth",            amount:   5000.00, ccy: "USD", recurring: false, note: "Q2 top-up" },
  { date: "Apr 01, 2026", type: "Contribution",strategy: "Rotation_ETF",         amount:   2500.00, ccy: "CAD", recurring: true,  note: "Monthly auto" },
  { date: "Mar 22, 2026", type: "Deposit",     strategy: "Momentum_SmallCap",amount:  4000.00, ccy: "AUD", recurring: false, note: "AUD account" },
];

// === BLOCK E — Upcoming Orders ===================================
const UPCOMING = [
  { date: "Tue · May 19", orders: [
    { strategy: "Momentum_Tech",   sym: "NVDA",  side: "BUY",   qty: 28,  status: "Queued" },
    { strategy: "Momentum_Tech",   sym: "AVGO",  side: "BUY",   qty: 14,  status: "Queued" },
    { strategy: "Trend_SP500",         sym: "PLTR",  side: "SELL",  qty: 120, status: "Sent" },
    { strategy: "MeanRev_SP500",    sym: "DIS",   side: "BUY",   qty: 60,  status: "Queued" },
  ]},
  { date: "Wed · May 20", orders: [
    { strategy: "Momentum_SmallCap", sym: "BROS",  side: "BUY",   qty: 110, status: "Queued" },
    { strategy: "Adaptive_Growth",              sym: "TQQQ",  side: "BUY",   qty: 80,  status: "Queued" },
    { strategy: "Momentum_SmallCap", sym: "RBRK",  side: "SHORT", qty: 200, status: "Queued" },
  ]},
  { date: "Thu · May 21", orders: [
    { strategy: "Trend_TSX",           sym: "SHOP",  side: "BUY",   qty: 35,  status: "Queued" },
    { strategy: "Momentum_LargeCap",       sym: "CNR",   side: "COVER", qty: 50,  status: "Queued" },
    { strategy: "Trend_TSX",           sym: "ENB",   side: "SELL",  qty: 90,  status: "Queued" },
  ]},
];

// === BLOCK F — Dividends ========================================
const DIVIDENDS = [
  { exDate: "May 10", sym: "MSFT", grossUsd: 412.50, allocations: [
    { strat: "Momentum_Tech", pct: 62 }, { strat: "Adaptive_Growth", pct: 24 }, { strat: "Rotation_ETF", pct: 14 },
  ]},
  { exDate: "May 03", sym: "AAPL", grossUsd: 268.20, allocations: [
    { strat: "Momentum_Tech", pct: 71 }, { strat: "MeanRev_SP500", pct: 29 },
  ]},
  { exDate: "Apr 28", sym: "JNJ",  grossUsd: 184.40, allocations: [
    { strat: "MeanRev_SP500", pct: 100 },
  ]},
  { exDate: "Apr 21", sym: "ENB",  grossUsd: 142.60, ccy: "CAD", allocations: [
    { strat: "Trend_TSX", pct: 100 },
  ]},
  { exDate: "Apr 14", sym: "JPM",  grossUsd: 312.10, allocations: [
    { strat: "Momentum_SmallCap", pct: 58 }, { strat: "MeanRev_SP500", pct: 42 },
  ]},
];

// === BLOCK G — Open Positions ===================================
const OPEN_POS = [
  { sym: "NVDA",  strat: "Momentum_Tech",    qty: 120, avg: 802.40,  mkt: 884.10, days: 18, ccy: "USD" },
  { sym: "AVGO",  strat: "Momentum_Tech",    qty: 38,  avg: 1342.20, mkt: 1418.50,days: 14, ccy: "USD" },
  { sym: "TQQQ",  strat: "Adaptive_Growth",                qty: 240, avg: 64.18,  mkt: 71.20,  days: 26, ccy: "USD" },
  { sym: "SHOP",  strat: "Trend_TSX",             qty: 180, avg: 96.40,  mkt: 102.10, days:  9, ccy: "CAD" },
  { sym: "PLTR",  strat: "Trend_SP500",           qty: 320, avg: 22.40,  mkt: 21.18,  days:  5, ccy: "USD" },
  { sym: "SPY",   strat: "MeanRev_SP500",qty: 60,  avg: 502.10, mkt: 511.80, days:  7, ccy: "USD" },
  { sym: "ENB",   strat: "Trend_TSX",             qty: 220, avg: 48.20,  mkt: 49.65,  days: 21, ccy: "CAD" },
];

// === BLOCK H — Manual + CSV import ==============================
const MANUAL_ENTRIES = [
  { date: "May 12", sym: "AAPL", side: "BUY",  qty: 100, price: 178.40, strat: "Momentum_Tech",  note: "Manual round-trip" },
  { date: "May 12", sym: "AAPL", side: "SELL", qty: 100, price: 181.20, strat: "Momentum_Tech",  note: "" },
  { date: "May 09", sym: "GOOGL",side: "BUY",  qty: 40,  price: 162.80, strat: "MeanRev_SP500",   note: "Pre-OC era" },
];

// === COMPARISON TABLE ===========================================
// row: feature, df: text or true, sheets: text or false, broker: text or partial
const COMPARISON = [
  ["Multi-strategy attribution",       "Strategy-tagged on every round-trip",                  "Manual tag columns, error-prone",    "No native strategy concept"],
  ["Performance analytics",            "TWR (Modified Dietz), MWR (XIRR), Sharpe and drawdowns, per strategy and per portfolio", "Manual formulas, easy to break", "TWR / MWR per account, not per strategy"],
  ["FIFO round-trip matching",         "Automatic, split-adjusted, cross-account aware",       "Hand-rolled per trade",              "Account-wide FIFO, not strategy-segmented"],
  ["Multi-currency P&L",               "USD · CAD · AUD and more, daily FX, unified base",     "Static rates, drift in days",        "Each currency reported separately, no unified base"],
  ["Corporate actions",                "Splits, mergers, spinoffs, renames and delistings, with automatic symbol aliases", "Manual symbol fix-ups",  "Reported in statements, not always reconciled in views"],
  ["Cross-currency mergers",           "Capital-displacement stepper with forex order pre-fill", "Manual cash-tracking gymnastics",   "Foreign proceeds left in-currency, no guidance"],
  ["Dividend & interest tracking",     "Auto-matched to positions, attributed to the strategy that held the shares", "Manual entry, no position match", "Per-security in statements, not per-strategy"],
  ["Customizable dashboard",           "Drag-to-reorder widgets, sector donut, best/worst trades",  "No dashboard",                  "Portfolio Analyst, limited layout customization"],
  ["Earnings calendar",                "Filtered by open positions, EPS estimates",             "N/A",                               "Available in TWS, not tied to positions"],
  ["Portfolio comparison",             "Overlay charts, side-by-side metrics, monthly heatmap", "Manual side-by-side tabs",          "Not available"],
  ["Trade analysis",                   "Malformed round-trip heuristics, intraday anomalies, day-trade detection", "Manual review", "Not available"],
  ["RealTest + OrderClerk integration", "RT signals → upcoming orders · OC Sync auto-imports matched to IB executions", "Copy-paste from CSV, manual reconciliation", "Not supported"],
  ["Automated data sync",              "Flex Query scheduled imports (1×–3×/day), OC Sync agent", "Manual export/import every time", "Flex API exists, no built-in scheduling UI"],
  ["Historical backfill",              "CSV / XML import, overlap detection, duplicate keyed on tradeId", "Copy-paste, version conflicts", "Statements only, no consolidated re-import"],
  ["Multi-account support",            "Cross-account matching for transfers and FIFO",         "One tab per account, manual roll-up", "Consolidated view, no strategy split"],
  ["Time to onboard",                  "Minutes, with one Flex token and pre-defined queries",         "Hours to days, ongoing maintenance", "Already in place, but limited"],
];

// === TESTIMONIALS ===============================================
const TESTIMONIALS = [
  {
    initials: "MD",
    name: "Marc-Antoine Dubois",
    bio: "Solo systematic trader · 8 strategies · Montréal",
    quote: "I was running 8 strategies across two accounts and tracking everything in Google Sheets. Every month-end was a nightmare: broken formulas, missing dividends, wrong P&L. DashFolio imported 5 years of trades in 5 minutes and matched every round-trip automatically. My sheets are retired.",
  },
  {
    initials: "RM",
    name: "Ryan Mitchell",
    bio: "Systematic trader · New York",
    quote: "Splitting interest across strategies in Excel was the one task I never looked forward to. Look up each strategy's capital weight, make sure the total still adds up. DashFolio lets me assign interest to any strategy or portfolio I want in two clicks. I don't miss that spreadsheet.",
  },
  {
    initials: "AK",
    name: "Anika Kowalski",
    bio: "Co-founder, Skyline Capital Partners · 2-trader prop",
    quote: "I trade TSX in CAD, NYSE in USD, and ASX in AUD. My broker shows P&L in each currency separately, which is useless for seeing the full picture. DashFolio converts everything to my base currency with daily FX rates. First time I actually know my real total return.",
  },
  {
    initials: "JT",
    name: "Jordan Thieriault",
    bio: "Quant developer · RealTest user since 2019",
    quote: "I backtest in RealTest and needed a way to see if my live results match. DashFolio pulls my OrderClerk trades, matches them to IB executions, and gives me per-strategy P&L that lines up with my backtests. No Python scripts, no CSV gymnastics.",
  },
];

// === CHANGELOG ==================================================
const CHANGELOG = [
  { ago: "3 days ago",  title: "Unified cross-currency displacement system",  desc: "RT-level and dividend-level FX actions now share a single pending queue with deterministic match keys." },
  { ago: "1 week ago",  title: "Capital allocation polish with FX totals",     desc: "Per-strategy totals now show inline FX-converted base totals for CAD and AUD movements." },
  { ago: "2 weeks ago", title: "OrderClerk priority handling for CSV conflicts", desc: "When OrderClerk and CSV disagree on a trade, OC wins and the CSV row is flagged for review." },
];

// === FAQ ========================================================
const FAQS = [
  ["How does DashFolio connect to Interactive Brokers?",
   "Through Interactive Brokers' Flex Web Service. Enable it in Account Management, create each report by following our step-by-step tutorial, then paste your token (encrypted at rest with AES-256-GCM) and each Query ID into DashFolio. We auto-fetch the XML reports on the schedule you choose, from 1× to 5× per day. Access is read-only, so we cannot place trades on your behalf."],
  ["Can you place trades on my behalf?",
   "No. DashFolio connects to your broker with read-only access, so it can see your trades and positions but has no ability to execute anything. Your capital is never at risk from the connection itself."],
  ["What can the Flex token actually do?",
   "The Flex token is a read-only credential issued by Interactive Brokers specifically for their Flex Web Service. It can do one thing: fetch the XML or CSV reports you've explicitly set up in Account Management (trades, cash transactions, dividends, open positions, and so on). It cannot submit, modify, or cancel orders, transfer funds, change account preferences, or access your IBKR username and password. You stay in full control: the token is created by you, scoped by you, and revocable by you directly inside IBKR Account Management."],
  ["Do you store my IBKR password or login credentials?",
   "No. Your IBKR login and password never leave your hands. They're not part of the connection flow and we have no way to receive them. The only credential we hold is the Flex token, which you generate yourself inside IBKR Account Management and paste into DashFolio. It's a separate, read-only credential designed exactly for this kind of integration. On our side it's encrypted at rest with AES-256-GCM and only decrypted in memory when we fetch a report. You can revoke it from IBKR at any time, with or without telling us."],
  ["Does it work with RealTest Backtesting Software?",
   "Yes. RealTest is a backtesting and signal-generation platform for systematic traders. It produces daily order files tagged by strategy. The supported flow is RealTest → OrderClerk (which routes execution to IBKR), with our DashFolioSync Agent uploading the order files and syncing OrderClerk's trade history back. That round-trip is what lets DashFolio match every IBKR fill to the strategy that originated it automatically."],
  ["Can I track multiple IBKR accounts in one workspace?",
   "Yes. Whether you have a master account with linked sub-accounts, or several independent IBKR accounts, DashFolio ingests them all into one workspace. Each trade keeps its account number, and dividends, transfers between sub-accounts, and cash balances are tracked per account so nothing is double-counted."],
  ["What asset classes are supported?",
   "Stocks and ETFs, plus mutual funds on US and Canadian markets."],
  ["What currencies are supported?",
   "USD, CAD, and AUD are first-class today, because that's where the trade volume lives. The converter supports seven currencies in total (USD, CAD, AUD, EUR, GBP, JPY, CHF) with daily FX rates. Realised P&L stays locked at the broker rate at trade time, so historical reports never silently re-price."],
  ["Can I import historical trades from CSV?",
   "Yes. Drag a CSV or XML file onto the upload panel and map each trade to a strategy. DashFolio imports every valid row and shows you a clear report of what was imported and what was skipped, so you can backfill years of trading history with confidence."],
  ["How often is my data refreshed?",
   "You choose. IBKR auto-sync runs 1× to 5× per day on the schedule you pick. Typical setups pull once after market close so today's fills land in your dashboard the same evening. File uploads, manual entries, and DashFolioSync syncs land instantly. Intraday prices on open positions update throughout the trading day for live P&L."],
  ["How far back can I import history?",
   "As far back as you have records. IBKR's Flex Web Service auto-sync delivers up to one year of rolling history, but if you want more, just download Activity Statements directly from IBKR (XML or CSV) and drag them into the upload panel. There's no limit on how many years of historical files you can import."],
  ["What happens if I cancel?",
   "You can cancel anytime, with no lock-in. Before you go, you can export your full history (round-trip lifecycles, dividend allocations, and capital movements) as CSV or XML, so your data is always yours to take with you. If you'd rather wipe the slate clean, you can permanently delete all your trades and data yourself from your account settings."],
];

Object.assign(window, {
  STRATEGIES, DASH, CURVE_30D, PERIODS, INTEGRATIONS,
  HISTORY_ROWS, AAPL_FILLS, MONTHLY_PNL, CAPITAL_ROWS, UPCOMING,
  DIVIDENDS, OPEN_POS, MANUAL_ENTRIES, COMPARISON, TESTIMONIALS, CHANGELOG, FAQS,
  genCurve,
});
