// Shared data + helpers — Swing & Position Trader persona
const INSTRUMENTS = [
  { sym: 'GOLD',    bid: 2641.10, ask: 2641.30, close: 2611.50, pct:  1.14, pctDir: 'up',   fundingRate: -0.0012, fundingCostPerDay: 1.68,  trend: 'up',   alert: null  },
  { sym: 'SILVER',  bid: 32.48,   ask: 32.50,   close: 31.96,   pct:  1.70, pctDir: 'up',   fundingRate: -0.0009, fundingCostPerDay: 0.42,  trend: 'up',   alert: 33.00 },
  { sym: 'US30',    bid: 42384,   ask: 42386,   close: 42510,   pct: -0.29, pctDir: 'down', fundingRate: -0.0021, fundingCostPerDay: 5.82,  trend: 'flat', alert: null  },
  { sym: 'EUR/USD', bid: 1.0842,  ask: 1.0844,  close: 1.0864,  pct: -0.18, pctDir: 'down', fundingRate:  0.0008, fundingCostPerDay: -0.24, trend: 'down', alert: null  },
];

const THEME_BASKETS = [
  {
    id: 'dxy-weakness',
    name: 'DXY Weakness',
    emoji: '📉',
    legs: [
      { sym: 'GOLD',   dir: 'LONG', lots: '0.07', entryPx: 2632,  currentPx: 2641 },
      { sym: 'SILVER', dir: 'LONG', lots: '0.30', entryPx: 32.10, currentPx: 32.49 },
    ],
    basketPL: 312.40,
    basketPLPct: 1.8,
    daysHeld: 3,
    aiStatus: 'intact',
    aiNote: 'DXY fell 0.4% this week — thesis intact. US10Y holding below 4.35%.',
    weeklyReviewDue: true,
    thesis: 'Real yields falling + DXY breakdown → gold/silver bid. Exit if US10Y > 4.5%.',
  },
  {
    id: 'risk-off',
    name: 'Risk-Off Watch',
    emoji: '👁️',
    legs: [
      { sym: 'GOLD', dir: 'WATCHING', lots: '—', entryPx: null, currentPx: 2641 },
    ],
    basketPL: 0,
    basketPLPct: 0,
    daysHeld: 0,
    aiStatus: 'monitoring',
    aiNote: 'VIX at 22.4 — elevated but not triggered. Watching for VIX > 25 as entry signal.',
    weeklyReviewDue: false,
    thesis: 'If VIX breaks 25, enter GOLD long as risk-off hedge. No position yet.',
  },
];

const SWING_TRADERS = [
  {
    handle: '@rahul_gold_thesis',
    time: '2h',
    sym: 'GOLD', dir: 'LONG', side: 'buy',
    daysHeld: 8, entryPx: 2590, currentPL: 234.00,
    thesis: 'Real yields falling since March. Holding until US10Y > 4.5%. This is a 2–4 week trade.',
    avatar: 'R', avBg: 'linear-gradient(135deg,#F59E0B,#DC2626)',
    followers: 1240, winRate: 68, avgHold: '11 days',
  },
  {
    handle: '@priya_macro',
    time: '1d',
    sym: 'SILVER', dir: 'LONG', side: 'buy',
    daysHeld: 14, entryPx: 30.80, currentPL: 510.00,
    thesis: 'Silver lags gold in every bull cycle. GOLD/SILVER ratio at 81 — historically oversold. Target 35.',
    avatar: 'P', avBg: 'linear-gradient(135deg,#8B5CF6,#3B82F6)',
    followers: 840, winRate: 62, avgHold: '18 days',
  },
  {
    handle: '@carlos_macro_gold',
    time: '3d',
    sym: 'GOLD', dir: 'LONG', side: 'buy',
    daysHeld: 21, entryPx: 2540, currentPL: 706.00,
    thesis: 'Central bank buying + DXY structural weakness. This is a multi-month move. Scaling in.',
    avatar: 'C', avBg: 'linear-gradient(135deg,#10B981,#059669)',
    followers: 2180, winRate: 71, avgHold: '23 days',
  },
];

const SWING_CHANNELS = [
  {
    name: 'MacroGold Weekly',
    type: 'thesis', action: 'execute',
    entry: 2610, sl: 2550, tp: 2720,
    raw: 'XAUUSD LONG 2590–2610 TP 2720 SL 2550 — DXY breakdown + real yields falling. 2–3 week hold.',
    winRate: 71, avgHold: '12 days', subs: 2840,
    bg: 'linear-gradient(135deg,#F59E0B,#B45309)',
  },
  {
    name: 'Real Yields Watch',
    type: 'macro', action: 'read',
    note: 'US10Y dropped to 4.31%. Gold above 2,640 now becomes support. Thesis: rates heading to 4.0% by Q3.',
    winRate: 64, avgHold: '18 days', subs: 1640,
    bg: 'linear-gradient(135deg,#3B82F6,#1E3A8A)',
  },
  {
    name: 'DXY Breakdown Alert',
    type: 'macro', action: 'read',
    note: 'DXY broke below 104. Next support 102.5. A 3–6 week dollar weakness cycle. Stay long metals.',
    winRate: 59, avgHold: '22 days', subs: 1180,
    bg: 'linear-gradient(135deg,#8B5CF6,#3B82F6)',
  },
];

const AI_MACRO_BULLETS = [
  { icon: '📉', text: 'DXY fell 0.4% this week, breaking below 104 — structural dollar weakness supports gold' },
  { icon: '🏦', text: 'US10Y at 4.31% (–8bps this week) — real yields falling, gold tailwind intact' },
  { icon: '🏛️', text: 'Central bank gold buying at record pace in Q1 2026 — structural demand underpins price' },
  { icon: '⚡', text: 'Your GOLD long thesis is intact — both DXY and US10Y moving in your favour this week' },
];

const MACRO_TILES = [
  { label: 'DXY',       value: 103.8, change: -0.4,  unit: '',  note: 'Dollar weakness → gold bullish',     dir: 'down', good: true  },
  { label: 'US 10Y',    value: 4.31,  change: -0.08, unit: '%', note: 'Real yields falling → gold tailwind', dir: 'down', good: true  },
  { label: 'GOLD/OIL',  value: 18.2,  change: +0.8,  unit: 'x', note: 'Gold outperforming crude oil',        dir: 'up',   good: true  },
  { label: 'VIX',       value: 22.4,  change: +1.2,  unit: '',  note: 'Moderate risk-off → gold supported',  dir: 'up',   good: true  },
];

function genSpark(direction = 'up', n = 28) {
  const out = []; let v = 50;
  for (let i = 0; i < n; i++) {
    const bias = direction === 'up' ? 0.58 : 0.42;
    v += (Math.random() - (1 - bias)) * 5;
    out.push(Math.max(5, Math.min(95, v)));
  }
  return out;
}

const fmtMoney = (n, sign = true) => {
  const s = n < 0 ? '-' : (sign ? '+' : '');
  return `${s}$${Math.abs(n).toFixed(2)}`;
};

window.INSTRUMENTS       = INSTRUMENTS;
window.THEME_BASKETS     = THEME_BASKETS;
window.SWING_TRADERS     = SWING_TRADERS;
window.SWING_CHANNELS    = SWING_CHANNELS;
window.AI_MACRO_BULLETS  = AI_MACRO_BULLETS;
window.MACRO_TILES       = MACRO_TILES;
window.genSpark          = genSpark;
window.fmtMoney          = fmtMoney;
