// data.jsx — Pinnacle Command Centre
// Live production: all client/business data is empty on boot and is hydrated
// from Supabase by each page (ClientsPage, LeadsPage, OnboardingPage, …).
// Exports via window.* because Babel in-browser scripts don't share ES module scope.

// One-time fresh-start cleanup (2026-05-25): drop any pre-Supabase localStorage rows.
try {
  localStorage.removeItem('pcc-clients');
  localStorage.removeItem('pcc-leads');
} catch (e) { /* private mode etc. — ignore */ }

const CLIENTS         = [];   // populated from Supabase: master_clients
const LEADS           = [];   // populated from Supabase: leads
const INVOICES         = [];   // populated from Supabase: invoices
const DIARY_EVENTS     = [];   // populated from Supabase: diary_entries
const ONBOARDING_STEPS = [];   // populated from Supabase: onboarding_steps
const DOCS             = [];   // populated from Supabase: document_templates
const ACTIVITIES       = [];   // populated from Supabase: activity_feed
const CALENDAR_EVENTS  = {};   // populated from Supabase: diary_entries (keyed by day)

// ── Agents — static feature definitions, not client data ──────────────
const AGENTS = [
  { id:'lead-scout',      name:'Lead Scout',       role:'Prospect Intelligence',  avatar:'🎯', avatarBg:'rgba(68,112,201,0.18)',  desc:'Monitors incoming leads, scores prospects by conversion probability, and flags hot opportunities.',   tasks:['Scanning demo booking requests…','Scoring prospects by conversion probability…','Flagging high-priority leads…'],       stat:'Avg 4.2h response',  totalRuns:0 },
  { id:'invoice-bot',     name:'Invoice Bot',      role:'Billing Automation',     avatar:'💳', avatarBg:'rgba(46,125,67,0.15)',   desc:'Auto-generates monthly invoices, tracks payment status, sends overdue reminders, and reconciles bank imports.', tasks:['Generating recurring invoices…','Checking overdue payments…','Matching bank imports…'],                  stat:'100% accuracy',      totalRuns:0 },
  { id:'diary-assistant', name:'Diary Assistant',  role:'Calendar & Scheduling',  avatar:'📅', avatarBg:'rgba(139,105,20,0.15)',  desc:'Manages the daily schedule, detects conflicts, blocks focus time, and syncs demo bookings.',             tasks:['Syncing demo bookings…','Detecting conflicts…','Blocking focus 09:00–11:00…'],                           stat:'Zero missed appts',  totalRuns:0 },
  { id:'client-monitor',  name:'Client Monitor',   role:'Account Health',         avatar:'👥', avatarBg:'rgba(161,30,42,0.12)',   desc:'Monitors client health scores, contract expiry dates, and flags at-risk accounts before they churn.',     tasks:['Calculating health scores…','Checking contract renewals…','Flagging at-risk accounts…'],                   stat:'0 churned clients',  totalRuns:0 },
  { id:'doc-handler',     name:'Document Handler', role:'Doc Automation',         avatar:'📄', avatarBg:'rgba(184,137,62,0.15)',  desc:'Auto-generates welcome packs, service agreements, and quotes — sends directly to clients via email.',      tasks:['Preparing welcome pack…','Generating service agreement…','Dispatching via email…'],                        stat:'—',                  totalRuns:0 },
  { id:'rev-analyst',     name:'Revenue Analyst',  role:'Financial Intelligence', avatar:'📊', avatarBg:'rgba(68,112,201,0.12)', desc:'Tracks monthly revenue vs targets, calculates P&L per client, and surfaces financial anomalies.',          tasks:['Calculating MRR vs target…','Running per-client P&L…','Flagging expense anomalies…'],                     stat:'R 0 unaccounted',    totalRuns:0 },
];

// ── Themes — UI configuration, not client data ────────────────────────
const THEMES = [
  { id:'default',   name:'Marble & Gold', desc:'Classic light marble with chrome gold accents',   preview:{ bg:'#F2F0EE', card:'rgba(255,255,255,0.75)', accent:'#B8893E', ink:'#14121A' } },
  { id:'obsidian',  name:'Obsidian',      desc:'Deep dark mode with golden highlights',           preview:{ bg:'#0F0D12', card:'rgba(255,255,255,0.08)', accent:'#B8893E', ink:'#F0EDE8' } },
  { id:'midnight',  name:'Midnight',      desc:'Navy depths with warm gold glow',                 preview:{ bg:'#0C1829', card:'rgba(140,170,210,0.08)', accent:'#B8893E', ink:'#D8E4F0' } },
  { id:'champagne', name:'Champagne',     desc:'Warm ivory with bronze undertones',               preview:{ bg:'#FAF5EE', card:'rgba(255,248,240,0.80)', accent:'#C49068', ink:'#2E251E' } },
  { id:'slate',     name:'Slate',         desc:'Cool gray with understated elegance',              preview:{ bg:'#E4E2DF', card:'rgba(255,255,255,0.55)', accent:'#8B8070', ink:'#1E1D1C' } },
];

// ── Shared utility — available to all JSX files loaded after data.jsx ──
window.parseYouTubeId = function(url) {
  if (!url) return null;
  try {
    const u = new URL(url.includes('://') ? url : 'https://' + url);
    if (u.hostname === 'youtu.be') return u.pathname.slice(1).split('/')[0];
    if (u.hostname.includes('youtube.com')) {
      if (u.pathname === '/watch') return u.searchParams.get('v');
      const m = u.pathname.match(/^\/(embed|live|shorts)\/([^/?]+)/);
      if (m) return m[2];
    }
  } catch(e) {}
  return null;
};

window.THEMES           = THEMES;
window.CLIENTS          = CLIENTS;
window.LEADS            = LEADS;
window.INVOICES         = INVOICES;
window.DIARY_EVENTS     = DIARY_EVENTS;
window.ONBOARDING_STEPS = ONBOARDING_STEPS;
window.DOCS             = DOCS;
window.ACTIVITIES       = ACTIVITIES;
window.CALENDAR_EVENTS  = CALENDAR_EVENTS;
window.AGENTS           = AGENTS;
