// ============ Real app config — no generated mock data ============

// Pricing
const PLANS = [
  { id:"free",      name:"Free",      price:0,     color:"var(--ink-4)" },
  { id:"starter",   name:"Starter",   price:4.99,  color:"var(--blue)" },
  { id:"family",    name:"Family",    price:9.99,  color:"var(--plum)" },
  { id:"unlimited", name:"Unlimited", price:19.99, color:"var(--accent)" },
];

const CREDIT_PACKS = [
  { id:"p10",  name:"10 Stories",  credits:10,  price:4.99 },
  { id:"p25",  name:"25 Stories",  credits:25,  price:9.99, popular:true },
  { id:"p60",  name:"60 Stories",  credits:60,  price:19.99 },
  { id:"p150", name:"150 Stories", credits:150, price:39.99 },
];

// Story content options
const THEMES = [
  "Bedtime Fears","Making Friends","Building Confidence","Separation Anxiety",
  "New Sibling","Sharing & Patience","First Day of School","Big Feelings",
  "Potty Training","Just a Fun Story",
];
const SETTINGS = [
  "A cozy home","A sunny park","A fun school","Enchanted forest",
  "Ocean adventure","Outer space","Magical castle","Farm animals",
  "Dinosaur island","Underwater reef",
];
const CHARS = [
  "a brave little fox","a shy bunny","a curious dragon","a wise owl",
  "a dreamy whale","a silly penguin","a royal cat","a tiny mouse",
  "a gentle bear","a sparkling unicorn",
];

// Feature flags — update rollout % when enabling
const FLAGS = [
  { key:"tts_enabled",      name:"Text-to-speech narration",   enabled:false, rollout:0,   env:"prod" },
  { key:"premium_voices",   name:"Premium voice pack",         enabled:false, rollout:0,   env:"prod" },
  { key:"multi_character",  name:"Multi-character stories",    enabled:false, rollout:0,   env:"staging" },
  { key:"parent_dashboard", name:"Parent dashboard",           enabled:false, rollout:0,   env:"prod" },
  { key:"offline_mode",     name:"Offline story reader",       enabled:false, rollout:0,   env:"prod" },
  { key:"new_illustrator",  name:"v2 illustration engine",     enabled:false, rollout:0,   env:"prod" },
  { key:"family_sharing",   name:"Family plan sharing",        enabled:false, rollout:0,   env:"dev" },
  { key:"ai_safety_v2",     name:"AI safety filter v2",        enabled:false, rollout:0,   env:"prod" },
];

// Admins
const ADMINS = [
  { name:"Adi Goldstein", email:"adi@talio.fun", role:"super", avatar:"AG" },
];

// ============ Empty data — will be populated from Firestore ============

const USERS        = [];
const TRANSACTIONS = [];
const STORIES      = [];
const MODERATION   = [];
const AUDIT        = [];
const LIVE_EVENTS  = [];
const PROMOS       = [];

const KPIS = {
  mrr:0, mrrDelta:null,
  revToday:0, revTodayDelta:null,
  totalRevenue:0,
  users:0, usersDelta:null,
  dau:0, dauDelta:null,
  mau:0,
  storiesToday:0, storiesDelta:null,
  storiesTotal:0,
  creditsConsumed:0, creditsDelta:null,
  conv:0, convDelta:null,
  arpu:0, arpuDelta:null,
  churn:0, churnDelta:null,
  refundRate:0,
  activeSubs:0,
  trialConv:0,
  ltv:0,
};

const PLAN_DIST = [
  { plan:"Free",      users:0, revenue:0, color:"var(--ink-4)" },
  { plan:"Starter",   users:0, revenue:0, color:"var(--blue)"  },
  { plan:"Family",    users:0, revenue:0, color:"var(--plum)"  },
  { plan:"Unlimited", users:0, revenue:0, color:"var(--accent)"},
];

const COUNTRY_DIST = [];
const THEME_DIST   = THEMES.map(t => ({ theme:t, stories:0 }));

const REVENUE_SERIES = [];
const SIGNUPS_SERIES = [];
const STORIES_SERIES = [];
const DAU_SERIES     = [];
const CREDITS_SERIES = [];

// ============ Utility functions ============

const fmtDate = d => {
  if (!d) return "—";
  return new Date(d).toLocaleDateString('en-US', { month:'short', day:'numeric', year:'numeric' });
};

const fmtRelative = d => {
  if (!d) return "—";
  const diff = (Date.now() - new Date(d).getTime()) / 1000;
  if (diff < 60)    return `${Math.floor(diff)}s ago`;
  if (diff < 3600)  return `${Math.floor(diff/60)}m ago`;
  if (diff < 86400) return `${Math.floor(diff/3600)}h ago`;
  if (diff < 86400*30) return `${Math.floor(diff/86400)}d ago`;
  return fmtDate(d);
};

const money = (n, cur='USD') => {
  if (n == null || n === 0) return "—";
  return new Intl.NumberFormat('en-US', {
    style:'currency', currency:cur,
    maximumFractionDigits: n < 100 ? 2 : 0,
  }).format(n);
};

const compact = n => {
  if (n == null || n === 0) return "—";
  if (n >= 1_000_000) return (n/1_000_000).toFixed(1)+'M';
  if (n >= 10_000)    return Math.round(n/1000)+'k';
  if (n >= 1_000)     return (n/1000).toFixed(1)+'k';
  return String(Math.round(n));
};

Object.assign(window, {
  USERS, TRANSACTIONS, STORIES, KPIS, PLAN_DIST, COUNTRY_DIST, THEME_DIST,
  PROMOS, FLAGS, AUDIT, ADMINS, MODERATION, LIVE_EVENTS,
  SIGNUPS_SERIES, REVENUE_SERIES, STORIES_SERIES, DAU_SERIES, CREDITS_SERIES,
  PLANS, CREDIT_PACKS, THEMES, SETTINGS, CHARS,
  fmtDate, fmtRelative, money, compact,
});
