// Admin mock data

const seedRand = (s) => { let x = s; return () => { x = (x * 1103515245 + 12345) & 0x7fffffff; return x / 0x7fffffff; }; };

const genSparkline = (n, seed, min = 10, max = 100) => {
  const r = seedRand(seed);
  return Array.from({ length: n }, () => Math.floor(min + r() * (max - min)));
};

const ADMIN_KEYS = [
  { id: 'k1', code: 'DEMO-CODE-2026-ENTR', label: 'Alex — beta cohort', created: '21/04/2026', expires: '21/05/2026', status: 'active', inboxes: 12, emails: 348, lastSeen: '2m ago', ip: '78.142.91.4' },
  { id: 'k2', code: 'SOFT-PINE-4421-VWXY', label: 'internal QA', created: '18/04/2026', expires: 'never', status: 'active', inboxes: 4, emails: 82, lastSeen: '14m ago', ip: '192.168.1.22' },
  { id: 'k3', code: 'NORTH-7811-AAQW-LMNO', label: 'Sarah press', created: '15/04/2026', expires: '29/04/2026', status: 'active', inboxes: 2, emails: 41, lastSeen: '1h ago', ip: '84.12.7.201' },
  { id: 'k4', code: 'FAST-LOOP-9002-KEYX', label: 'revoked - spam', created: '10/04/2026', expires: '10/05/2026', status: 'revoked', inboxes: 28, emails: 1942, lastSeen: '2d ago', ip: '45.33.18.9' },
  { id: 'k5', code: 'QUIET-MOSS-4412-ABCD', label: '', created: '05/04/2026', expires: '05/04/2026', status: 'expired', inboxes: 1, emails: 8, lastSeen: '18d ago', ip: '109.43.2.18' },
  { id: 'k6', code: 'DUSK-HORIZON-67-EVEN', label: 'dusk (founder)', created: '01/04/2026', expires: 'never', status: 'active', inboxes: 8, emails: 221, lastSeen: '34m ago', ip: '78.142.91.4' },
  { id: 'k7', code: 'CEDAR-PASS-2281-ZYXW', label: '', created: '28/03/2026', expires: '28/04/2026', status: 'unused', inboxes: 0, emails: 0, lastSeen: '—', ip: '—' },
  { id: 'k8', code: 'BRINE-FLINT-0091-TUVS', label: 'Tom (agency)', created: '24/03/2026', expires: '24/06/2026', status: 'active', inboxes: 5, emails: 67, lastSeen: '6h ago', ip: '202.18.4.12' },
];

const ADMIN_DOMAINS = [
  { id: 'd1', domain: 'letstalkbout.biz', premium: true, badges: ['TOP'], enabled: true, inboxes: 1421, emails24h: 8842, retention: 24, spamScore: 0.02, storage: '412 MB', added: '10/01/2026' },
  { id: 'd2', domain: 'mailforge.dev', premium: true, badges: ['TOP', 'HOT'], enabled: true, inboxes: 892, emails24h: 5114, retention: 24, spamScore: 0.04, storage: '298 MB', added: '12/01/2026' },
  { id: 'd3', domain: 'quickdrop.email', premium: false, badges: ['NEW'], enabled: true, inboxes: 412, emails24h: 1821, retention: 24, spamScore: 0.01, storage: '94 MB', added: '02/04/2026' },
  { id: 'd4', domain: 'duskmail.io', premium: false, badges: ['HOT'], enabled: true, inboxes: 308, emails24h: 1402, retention: 24, spamScore: 0.03, storage: '82 MB', added: '18/02/2026' },
  { id: 'd5', domain: 'ephemer.al', premium: true, badges: [], enabled: true, inboxes: 214, emails24h: 891, retention: 24, spamScore: 0.02, storage: '41 MB', added: '04/03/2026' },
  { id: 'd6', domain: 'tmpbox.cc', premium: false, badges: ['NEW'], enabled: true, inboxes: 98, emails24h: 412, retention: 24, spamScore: 0.08, storage: '22 MB', added: '14/04/2026' },
  { id: 'd7', domain: 'shadowpost.xyz', premium: false, badges: [], enabled: false, inboxes: 0, emails24h: 0, retention: 24, spamScore: 0.41, storage: '0 MB', added: '19/04/2026' },
];

const ADMIN_FIREHOSE = [
  { id: 'f1', ts: '11:24:18', from: 'noreply@github.com', to: 'duskonhorizon67@letstalkbout.biz', subject: '[GitHub] Sign in to github.com', domain: 'letstalkbout.biz', keyId: 'k1', flagged: false, hasCode: true, code: '902841', size: '4.2 KB' },
  { id: 'f2', ts: '11:24:09', from: 'team@openai.com', to: 'duskonhorizon67@letstalkbout.biz', subject: 'ChatGPT — Your new plan', domain: 'letstalkbout.biz', keyId: 'k1', flagged: false, hasCode: false, size: '12.8 KB' },
  { id: 'f3', ts: '11:23:44', from: 'noreply@tm.openai.com', to: 'duskonhorizon67@letstalkbout.biz', subject: 'Your temporary ChatGPT login code', domain: 'letstalkbout.biz', keyId: 'k1', flagged: false, hasCode: true, code: '588388', size: '3.1 KB' },
  { id: 'f4', ts: '11:23:02', from: 'bulk@spamdump.ru', to: 'fresh99@mailforge.dev', subject: '🎉 YOU WON a free iPhone!!!', domain: 'mailforge.dev', keyId: 'k2', flagged: true, hasCode: false, size: '44.1 KB' },
  { id: 'f5', ts: '11:22:51', from: 'receipts@stripe.com', to: 'silentmoss42@duskmail.io', subject: 'Receipt from Vercel Inc.', domain: 'duskmail.io', keyId: 'k3', flagged: false, hasCode: false, size: '8.4 KB' },
  { id: 'f6', ts: '11:22:18', from: 'notify@linear.app', to: 'silentmoss42@duskmail.io', subject: 'You were mentioned in ENG-2481', domain: 'duskmail.io', keyId: 'k3', flagged: false, hasCode: false, size: '6.2 KB' },
  { id: 'f7', ts: '11:21:59', from: 'noreply@tm.openai.com', to: 'quietfalcon18@letstalkbout.biz', subject: 'Your ChatGPT code is 417175', domain: 'letstalkbout.biz', keyId: 'k2', flagged: false, hasCode: true, code: '417175', size: '3.0 KB' },
  { id: 'f8', ts: '11:21:03', from: 'auto@phish.ml', to: 'throwaway4@mailforge.dev', subject: 'Your bank account has been LOCKED', domain: 'mailforge.dev', keyId: 'k4', flagged: true, hasCode: false, size: '22.8 KB' },
  { id: 'f9', ts: '11:20:41', from: 'deploy@vercel.com', to: 'dusk@dusk.work', subject: 'Deployment ready — main-7f9a2c', domain: 'dusk.work', keyId: 'k6', flagged: false, hasCode: false, size: '5.1 KB' },
  { id: 'f10', ts: '11:20:14', from: 'team@notion.so', to: 'brightember29@ephemer.al', subject: 'Your Notion login link', domain: 'ephemer.al', keyId: 'k8', flagged: false, hasCode: true, code: '812334', size: '4.8 KB' },
  { id: 'f11', ts: '11:19:55', from: 'alerts@pagerduty.com', to: 'dusk@dusk.work', subject: '[FIRING] api-latency-high', domain: 'dusk.work', keyId: 'k6', flagged: false, hasCode: false, size: '2.9 KB' },
  { id: 'f12', ts: '11:19:22', from: 'noreply@discord.com', to: 'hollowpine83@mailforge.dev', subject: 'Your Discord verification code', domain: 'mailforge.dev', keyId: 'k2', flagged: false, hasCode: true, code: '294817', size: '3.8 KB' },
];

const ADMIN_AUDIT = [
  { id: 'a1', ts: '11:24:02', actor: 'admin@tempmail.local', action: 'key.revoke', target: 'k4 (FAST-LOOP-9002-KEYX)', meta: 'reason: spam' },
  { id: 'a2', ts: '10:58:41', actor: 'admin@tempmail.local', action: 'domain.disable', target: 'shadowpost.xyz', meta: 'high spam score' },
  { id: 'a3', ts: '10:41:18', actor: 'admin@tempmail.local', action: 'key.create', target: 'k8 (BRINE-FLINT-0091-TUVS)', meta: 'expires: 24/06/2026' },
  { id: 'a4', ts: '09:12:04', actor: 'admin@tempmail.local', action: 'domain.add', target: 'tmpbox.cc', meta: 'premium: false' },
  { id: 'a5', ts: '08:58:22', actor: 'admin@tempmail.local', action: 'sender.block', target: 'bulk@spamdump.ru', meta: 'matched 142 messages' },
  { id: 'a6', ts: '21/04 23:14', actor: 'admin@tempmail.local', action: 'settings.update', target: 'retention.shared', meta: '12h → 24h' },
  { id: 'a7', ts: '21/04 18:32', actor: 'admin@tempmail.local', action: 'key.create', target: 'k1 (DEMO-CODE-2026-ENTR)', meta: 'label: Alex — beta cohort' },
  { id: 'a8', ts: '21/04 14:02', actor: 'admin@tempmail.local', action: 'domain.badge', target: 'mailforge.dev', meta: '+ HOT' },
  { id: 'a9', ts: '20/04 22:18', actor: 'admin@tempmail.local', action: 'auth.login', target: 'session #a8f9', meta: 'ip: 78.142.91.4' },
];

const ADMIN_BLOCKS = [
  { id: 'b1', kind: 'sender', pattern: 'bulk@spamdump.ru', hits: 142, added: '24/04', reason: 'mass spam' },
  { id: 'b2', kind: 'sender', pattern: 'auto@phish.ml', hits: 88, added: '24/04', reason: 'phishing' },
  { id: 'b3', kind: 'domain', pattern: '@*.ml', hits: 314, added: '22/04', reason: 'TLD abuse' },
  { id: 'b4', kind: 'sender', pattern: 'noreply@scamchain.co', hits: 41, added: '20/04', reason: 'crypto spam' },
];

const ADMIN_OVERVIEW = {
  stats: [
    { label: 'ACTIVE KEYS', value: 26, delta: '+3', spark: genSparkline(30, 12, 18, 30), trend: 'up' },
    { label: 'INBOXES LIVE', value: 1842, delta: '+124', spark: genSparkline(30, 34, 1200, 1900), trend: 'up' },
    { label: 'EMAILS / 24H', value: 16482, delta: '+2.1k', spark: genSparkline(30, 56, 8000, 18000), trend: 'up' },
    { label: 'STORAGE', value: '1.84 GB', delta: '+212 MB', spark: genSparkline(30, 78, 900, 1900), trend: 'up' },
    { label: 'FLAGGED 24H', value: 142, delta: '-18', spark: genSparkline(30, 91, 90, 220), trend: 'down' },
    { label: 'QUEUE DEPTH', value: 8, delta: '-2', spark: genSparkline(30, 105, 0, 30), trend: 'down' },
  ],
  volumeHourly: genSparkline(24, 200, 280, 920),
  topDomains: [
    { domain: 'letstalkbout.biz', pct: 54, count: 8842 },
    { domain: 'mailforge.dev', pct: 31, count: 5114 },
    { domain: 'quickdrop.email', pct: 11, count: 1821 },
    { domain: 'duskmail.io', pct: 9, count: 1402 },
    { domain: 'ephemer.al', pct: 5, count: 891 },
  ],
};

const ADMIN_HEALTH = [
  { label: 'SMTP RECEIVER', status: 'ok', detail: 'accepting mail · 12ms avg', uptime: '99.98%' },
  { label: 'DNS RESOLVER', status: 'ok', detail: '8ms avg · 0 timeouts', uptime: '100%' },
  { label: 'POSTGRES', status: 'ok', detail: '4 connections · 2ms p99', uptime: '100%' },
  { label: 'REDIS', status: 'ok', detail: 'mem 128MB / 512MB', uptime: '99.99%' },
  { label: 'OBJECT STORAGE', status: 'warn', detail: 'latency p99 rising (840ms)', uptime: '99.91%' },
  { label: 'MAIL QUEUE', status: 'ok', detail: '8 pending · 0 dead', uptime: '99.97%' },
  { label: 'DNS VERIFY CRON', status: 'ok', detail: 'last run 14m ago', uptime: '100%' },
  { label: 'RETENTION CRON', status: 'ok', detail: 'last run 42m ago', uptime: '100%' },
];

Object.assign(window, { ADMIN_KEYS, ADMIN_DOMAINS, ADMIN_FIREHOSE, ADMIN_AUDIT, ADMIN_BLOCKS, ADMIN_OVERVIEW, ADMIN_HEALTH, genSparkline });
