// Sample data + helpers for Oracle prototype

const ORACLE_TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "personality": "analyst",
  "accent": "violet",
  "density": "comfortable",
  "showGrid": true
}/*EDITMODE-END*/;

const ACCENT_PRESETS = {
  violet: { purple: '#a882ff', purple2: '#7c4dff', purple3: '#5b2eff', glow: '#b794ff' },
  magenta: { purple: '#e26dff', purple2: '#c93dff', purple3: '#9c1aff', glow: '#f199ff' },
  ultra:  { purple: '#8b5cff', purple2: '#5e30ff', purple3: '#3a17d6', glow: '#a685ff' },
};

// Sample analyzed coin (not a real token — original fictional data)
const SAMPLE_COIN = {
  ticker: 'NEKO',
  name: 'Neko Protocol',
  ca: 'EJqB8m4Vw9pNzL3rYxK7tHcF2sQ5dW1uMnPaR6oVbXyZ',
  chain: 'Solana',
  age: '4h 12m',
  marketCap: 482_000,
  liquidity: 87_400,
  fdv: 1_240_000,
  holders: 1284,
  buys24h: 642,
  sells24h: 411,
  volume24h: 1_180_000,
  priceUsd: 0.000482,
  change1h: 12.4,
  change24h: 84.2,
  score: 72,
  verdict: 'Watch',
  riskLevel: 'Moderate',
  entry: '$0.00041 — $0.00046',
  stopLoss: '$0.00032',
  target: '$0.00088 (2.0x)',
  conviction: 'Medium-High',
};

const SUB_AGENTS = [
  { id: 'contract', name: 'Contract Auditor', icon: 'shield', desc: 'mint authority · freeze · taxes · honeypot' },
  { id: 'liquidity', name: 'Liquidity Watcher', icon: 'droplet', desc: 'LP size · burn status · pool depth' },
  { id: 'holders', name: 'Holder Forensics', icon: 'users', desc: 'top wallets · sniper clusters · bundles' },
  { id: 'chart', name: 'Chart Analyst', icon: 'trend', desc: 'volume profile · candle structure' },
  { id: 'social', name: 'Social Pulse', icon: 'broadcast', desc: 'mention velocity · KOL activity · sentiment' },
  { id: 'pattern', name: 'Pattern Match', icon: 'sparkles', desc: 'similarity to past performers' },
];

const REASONING_STREAM = [
  { agent: 'contract', text: 'Pulling on-chain metadata for EJqB...bXyZ', delay: 200 },
  { agent: 'contract', text: 'Mint authority: REVOKED ✓', delay: 600, ok: true },
  { agent: 'contract', text: 'Freeze authority: REVOKED ✓', delay: 400, ok: true },
  { agent: 'liquidity', text: 'LP pool detected on Raydium · 87.4K USD', delay: 500 },
  { agent: 'liquidity', text: 'LP tokens BURNED (100%) ✓', delay: 600, ok: true },
  { agent: 'holders', text: 'Scanning top 50 holders…', delay: 700 },
  { agent: 'holders', text: 'Top wallet: 4.2% — within healthy range', delay: 700, ok: true },
  { agent: 'holders', text: 'Detected 3 wallets bundled at launch (1.8%)', delay: 600, warn: true },
  { agent: 'chart', text: 'Volume profile: rising · buys 1.56x sells', delay: 600, ok: true },
  { agent: 'chart', text: 'Structure: clean breakout above 360K MC', delay: 700, ok: true },
  { agent: 'social', text: 'Mention velocity +280% (last 1h)', delay: 700, ok: true },
  { agent: 'social', text: 'KOL pickup: 4 mid-tier callers · no major', delay: 700 },
  { agent: 'pattern', text: 'Pattern match: 73% similar to "early-PEPE-style" runners', delay: 800 },
  { agent: 'pattern', text: 'Cross-checking 412 historical analogs…', delay: 700 },
];

const SIGNAL_CARDS = [
  {
    id: 'contract', title: 'Contract Safety', score: 95, status: 'safe',
    bullets: [
      { ok: true,  text: 'Mint authority revoked' },
      { ok: true,  text: 'Freeze authority revoked' },
      { ok: true,  text: 'No transfer tax · no hidden fees' },
      { ok: true,  text: 'Code matches verified template' },
    ],
  },
  {
    id: 'liquidity', title: 'Liquidity', score: 88, status: 'safe',
    bullets: [
      { ok: true,  text: 'LP burned 100%' },
      { ok: true,  text: 'Pool depth $87.4K (18% of MC)' },
      { ok: false, text: 'Single LP pair (Raydium only)' },
    ],
  },
  {
    id: 'holders', title: 'Holder Health', score: 64, status: 'caution',
    bullets: [
      { ok: true,  text: 'Top holder 4.2% · top 10 hold 28%' },
      { ok: false, text: '3 wallets bundled at launch (1.8%)' },
      { ok: false, text: '2 sniper wallets still holding' },
      { ok: true,  text: '1,284 unique holders · growing' },
    ],
  },
  {
    id: 'chart', title: 'Price Action', score: 78, status: 'safe',
    bullets: [
      { ok: true,  text: 'Buy/sell ratio 1.56x (last hour)' },
      { ok: true,  text: 'Volume rising · MC +84% in 24h' },
      { ok: true,  text: 'Clean breakout, no wash patterns' },
    ],
  },
  {
    id: 'social', title: 'Social Pulse', score: 71, status: 'safe',
    bullets: [
      { ok: true,  text: '+280% mentions last hour' },
      { ok: false, text: 'No tier-1 KOLs yet' },
      { ok: true,  text: 'Org. sentiment 78% positive' },
    ],
  },
  {
    id: 'pattern', title: 'Pattern Match', score: 73, status: 'safe',
    bullets: [
      { ok: true,  text: '73% match to early runner cluster' },
      { ok: true,  text: '12 of 17 analogs hit ≥3x within 48h' },
      { ok: false, text: 'Volatility band: ±42% intraday' },
    ],
  },
];

const TOP_HOLDERS = [
  { wallet: '7Hk…3pQ', pct: 4.2, label: 'Whale', tone: 'neutral' },
  { wallet: '9Mn…vRz', pct: 3.8, label: 'Whale', tone: 'neutral' },
  { wallet: 'Bx2…fGw', pct: 3.1, label: 'Sniper', tone: 'warn' },
  { wallet: 'Cd4…hKl', pct: 2.9, label: 'Sniper', tone: 'warn' },
  { wallet: 'De5…jLm', pct: 2.4, label: 'Bundle', tone: 'warn' },
  { wallet: 'Ef6…kMn', pct: 2.1, label: 'Holder', tone: 'good' },
  { wallet: 'Fg7…lNo', pct: 1.9, label: 'Holder', tone: 'good' },
  { wallet: 'Gh8…mOp', pct: 1.7, label: 'Holder', tone: 'good' },
];

// Generate a believable price chart (not real data)
function genChartData(points = 80) {
  const data = [];
  let price = 100;
  for (let i = 0; i < points; i++) {
    const trend = i / points * 60;
    const noise = (Math.sin(i * 0.7) * 8) + (Math.cos(i * 1.3) * 5) + (Math.random() - 0.5) * 6;
    price = 100 + trend + noise;
    data.push(Math.max(20, price));
  }
  return data;
}
const CHART_DATA = genChartData(80);

// Volume bars
const VOLUME_DATA = Array.from({ length: 80 }, (_, i) => 20 + Math.random() * 60 + (i / 80) * 30);

// Per-timeframe chart + volume (deterministic so re-renders don't jitter)
function genSeries(seed, points, trendStrength) {
  let s = seed;
  const rand = () => { s = (s * 9301 + 49297) % 233280; return s / 233280; };
  const data = [];
  let price = 100;
  for (let i = 0; i < points; i++) {
    const trend = (i / points) * trendStrength;
    const noise = (Math.sin(i * 0.7) * 8) + (Math.cos(i * 1.3) * 5) + (rand() - 0.5) * 6;
    price = 100 + trend + noise;
    data.push(Math.max(20, price));
  }
  return data;
}
const TIMEFRAME_DATA = {
  '1H': { chart: genSeries(7, 60, 18), volume: Array.from({length:60},(_,i)=>15+Math.sin(i*0.5)*10+i*0.3) },
  '4H': { chart: CHART_DATA, volume: VOLUME_DATA },
  '1D': { chart: genSeries(31, 96, 90), volume: Array.from({length:96},(_,i)=>10+Math.cos(i*0.4)*15+i*0.4) },
  'ALL': { chart: genSeries(73, 120, 140), volume: Array.from({length:120},(_,i)=>8+Math.sin(i*0.3)*18+i*0.5) },
};

const WATCHLIST_ITEMS = [
  { ticker: 'NEKO', name: 'Neko Protocol', score: 72, verdict: 'Watch', change: 84.2, mc: 482_000, age: '4h', tone: 'amber' },
  { ticker: 'PIXL', name: 'Pixel Cabal', score: 88, verdict: 'Strong Buy', change: 142.6, mc: 1_840_000, age: '11h', tone: 'green' },
  { ticker: 'GRMP', name: 'Grump Coin', score: 41, verdict: 'Avoid', change: -28.4, mc: 92_000, age: '2h', tone: 'red' },
  { ticker: 'MOTH', name: 'Moth To Flame', score: 66, verdict: 'Watch', change: 21.3, mc: 312_000, age: '7h', tone: 'amber' },
  { ticker: 'LUMI', name: 'Lumi Network', score: 81, verdict: 'Buy', change: 56.0, mc: 920_000, age: '1d 3h', tone: 'green' },
  { ticker: 'WAGM', name: 'Wagmi Frens', score: 34, verdict: 'Avoid', change: -41.2, mc: 48_000, age: '38m', tone: 'red' },
  { ticker: 'BLOB', name: 'Blob Inc', score: 58, verdict: 'Caution', change: 8.4, mc: 184_000, age: '5h', tone: 'amber' },
  { ticker: 'ZNTH', name: 'Zenith DAO', score: 76, verdict: 'Buy', change: 38.1, mc: 612_000, age: '14h', tone: 'green' },
];

const CHAT_SEED = [
  { role: 'oracle', text: "I've finished analyzing NEKO. Composite score 72/100 — Watch. Ask me anything about it." },
];

const CHAT_SUGGESTIONS = [
  'Why is the score not higher?',
  'When should I enter?',
  'What would make you change your mind?',
  'How does this compare to PIXL?',
];

function fmtUsd(n) {
  if (n >= 1_000_000) return '$' + (n / 1_000_000).toFixed(2) + 'M';
  if (n >= 1_000) return '$' + (n / 1_000).toFixed(1) + 'K';
  if (n < 0.01) return '$' + n.toFixed(6);
  return '$' + n.toFixed(2);
}
function fmtNum(n) {
  if (n >= 1_000_000) return (n / 1_000_000).toFixed(2) + 'M';
  if (n >= 1_000) return (n / 1_000).toFixed(1) + 'K';
  return n.toString();
}
function fmtPct(n, sign = true) {
  const s = sign && n > 0 ? '+' : '';
  return s + n.toFixed(1) + '%';
}

Object.assign(window, {
  ORACLE_TWEAK_DEFAULTS, ACCENT_PRESETS,
  SAMPLE_COIN, SUB_AGENTS, REASONING_STREAM, SIGNAL_CARDS,
  TOP_HOLDERS, CHART_DATA, VOLUME_DATA, TIMEFRAME_DATA, WATCHLIST_ITEMS,
  CHAT_SEED, CHAT_SUGGESTIONS,
  fmtUsd, fmtNum, fmtPct,
});
