// Mock data for Voice Intelligence — Quality Service Company
// Customer service call recordings

const AGENTS = [
  { id: 'JM', name: 'Jordan Mercer',   team: 'Install Support',  avatar: '#c9ad7a' },
  { id: 'RP', name: 'Riya Patel',      team: 'Billing',          avatar: '#a3b5c9' },
  { id: 'MC', name: 'Marcus Chen',     team: 'Install Support',  avatar: '#b5c9a3' },
  { id: 'AO', name: 'Ana Ortiz',       team: 'Retention',        avatar: '#c9a3b5' },
  { id: 'DK', name: 'Devon Kim',       team: 'Tier 2 Escalation',avatar: '#c9c4a3' },
  { id: 'SH', name: 'Sara Halverson',  team: 'Billing',          avatar: '#a3c9c4' },
];

const CALLS = [
  { id: 'QSC-248193', agent: 'JM', customer: 'Ridgeview HOA',       when: 'Today · 10:42', dur: '14:22', score: 87, sentiment: 'pos', intent: 'Service reschedule', topics: ['Scheduling','Lawn treatment','Weather delay'], flagged: false },
  { id: 'QSC-248177', agent: 'RP', customer: 'Beatrice Hollander',  when: 'Today · 09:58', dur: '07:41', score: 72, sentiment: 'neu', intent: 'Billing dispute',     topics: ['Invoice','Auto-pay','Refund'], flagged: true  },
  { id: 'QSC-248164', agent: 'MC', customer: 'Delaney Automotive',  when: 'Today · 09:12', dur: '22:09', score: 91, sentiment: 'pos', intent: 'New install quote',   topics: ['Commercial','Pricing','Scheduling'], flagged: false },
  { id: 'QSC-248155', agent: 'AO', customer: 'Rafael Ibanez',       when: 'Today · 08:47', dur: '18:33', score: 54, sentiment: 'neg', intent: 'Cancellation',       topics: ['Cancellation','Pricing','Competitor'], flagged: true },
  { id: 'QSC-248141', agent: 'DK', customer: 'Monroe Elementary',   when: 'Yday · 16:22',  dur: '09:47', score: 83, sentiment: 'pos', intent: 'Service follow-up',  topics: ['Follow-up','Satisfaction'], flagged: false },
  { id: 'QSC-248129', agent: 'SH', customer: 'Thornton Residence',  when: 'Yday · 15:08',  dur: '11:15', score: 68, sentiment: 'neu', intent: 'Billing question',   topics: ['Payment plan','Statement'], flagged: false },
  { id: 'QSC-248116', agent: 'JM', customer: 'Willow Creek Apts',   when: 'Yday · 14:31',  dur: '16:02', score: 79, sentiment: 'pos', intent: 'Recurring service', topics: ['Contract renewal','Pest control','Scheduling'], flagged: false },
  { id: 'QSC-248104', agent: 'RP', customer: 'Oakley Industries',   when: 'Yday · 13:02',  dur: '05:28', score: 45, sentiment: 'neg', intent: 'Complaint',          topics: ['Missed appointment','Damage claim'], flagged: true },
  { id: 'QSC-248091', agent: 'MC', customer: 'Harold Whitaker',     when: 'Yday · 11:44',  dur: '12:18', score: 88, sentiment: 'pos', intent: 'Technical question', topics: ['HVAC','Warranty','Part number'], flagged: false },
  { id: 'QSC-248079', agent: 'AO', customer: 'Lakewood Condos',     when: 'Yday · 10:19',  dur: '19:51', score: 76, sentiment: 'neu', intent: 'Service escalation', topics: ['Repeat visit','Tier 2','Compensation'], flagged: true },
  { id: 'QSC-248062', agent: 'DK', customer: 'Priya Venkatesh',     when: 'Yday · 09:03',  dur: '08:11', score: 94, sentiment: 'pos', intent: 'New install quote',   topics: ['Referral','Pricing'], flagged: false },
  { id: 'QSC-248048', agent: 'SH', customer: 'Brookmere Dental',    when: '2d · 17:12',    dur: '13:44', score: 81, sentiment: 'pos', intent: 'Recurring service',   topics: ['Commercial','Contract'], flagged: false },
];

// Deterministic pseudo-random for waveform / charts
function seeded(seed) {
  let s = seed;
  return () => {
    s = (s * 9301 + 49297) % 233280;
    return s / 233280;
  };
}

// Waveform: 180 bars, alternating agent/customer
function genWave(seed = 42, count = 180) {
  const r = seeded(seed);
  const arr = [];
  let spk = 0; // 0 = agent, 1 = customer
  let runLen = 4 + Math.floor(r() * 10);
  for (let i = 0; i < count; i++) {
    if (runLen-- <= 0) { spk = 1 - spk; runLen = 3 + Math.floor(r() * 12); }
    const base = 0.25 + r() * 0.7;
    const peak = r() > 0.88 ? r() * 0.3 : 0;
    arr.push({ h: Math.min(1, base + peak), spk });
  }
  return arr;
}

// Sentiment band across the waveform (24 cells)
const SENT_BAND = [
  'p','p','n','p','p','p','n','g','g','n','n','n',
  'p','n','p','n','n','p','p','p','n','p','p','p'
];

// Transcript
const TRANSCRIPT = [
  { ts: '00:00', sp: 'Agent',    text: "Thank you for calling Quality Service Company, this is Jordan. How can I help you today?" },
  { ts: '00:07', sp: 'Customer', text: "Hi Jordan. We're at the Ridgeview HOA, and the crew didn't make it out Tuesday for the scheduled lawn treatment." },
  { ts: '00:18', sp: 'Agent',    text: "I'm really sorry about that — let me pull up your account. Can I get the property address on file?" },
  { ts: '00:26', sp: 'Customer', text: "Sure, it's 2140 Ridgeview Parkway.", tags: ['PII: Address'] },
  { ts: '00:31', sp: 'Agent',    text: "Got it. I can see we had a weather hold on Tuesday — we issued a callback but it doesn't look like anyone followed up. That's on us.", highlight: 'weather hold on Tuesday' },
  { ts: '00:44', sp: 'Customer', text: "We've got a board walkthrough on Saturday, so we need this done by Friday at the latest.", highlight: 'need this done by Friday', tags: ['Deadline'] },
  { ts: '00:53', sp: 'Agent',    text: "Absolutely. I can get a crew out tomorrow morning between 8 and 10. And because of the missed window, I'm going to apply a 15% service credit to next month's invoice.", highlight: '15% service credit', tags: ['Comp offered'] },
  { ts: '01:09', sp: 'Customer', text: "That works — thank you. Tomorrow between 8 and 10." },
  { ts: '01:15', sp: 'Agent',    text: "Perfect. You'll get a text from the crew lead about 30 minutes before arrival. Anything else I can help with?" },
  { ts: '01:22', sp: 'Customer', text: "No, that's it. I appreciate the quick turnaround." },
];

// Trend chart (sentiment over 12 weeks)
const TREND = [
  { w: 'W1',  pos: 62, neu: 28, neg: 10 },
  { w: 'W2',  pos: 65, neu: 26, neg: 9  },
  { w: 'W3',  pos: 61, neu: 29, neg: 10 },
  { w: 'W4',  pos: 58, neu: 29, neg: 13 },
  { w: 'W5',  pos: 56, neu: 30, neg: 14 },
  { w: 'W6',  pos: 60, neu: 28, neg: 12 },
  { w: 'W7',  pos: 63, neu: 27, neg: 10 },
  { w: 'W8',  pos: 67, neu: 25, neg: 8  },
  { w: 'W9',  pos: 64, neu: 28, neg: 8  },
  { w: 'W10', pos: 66, neu: 27, neg: 7  },
  { w: 'W11', pos: 70, neu: 23, neg: 7  },
  { w: 'W12', pos: 72, neu: 22, neg: 6  },
];

// Volume bars
const VOLUME = [312, 344, 298, 410, 387, 362, 298, 401, 445, 472, 451, 489];

// Agent compare
const AGENT_STATS = [
  { id: 'JM', calls: 184, score: 87, senti: [72, 22, 6] },
  { id: 'DK', calls: 142, score: 91, senti: [78, 18, 4] },
  { id: 'MC', calls: 167, score: 85, senti: [70, 24, 6] },
  { id: 'SH', calls: 156, score: 79, senti: [62, 28, 10] },
  { id: 'RP', calls: 171, score: 74, senti: [58, 30, 12] },
  { id: 'AO', calls: 138, score: 68, senti: [51, 31, 18] },
];

// Topic heat
const TOPICS = [
  { t: 'Scheduling',         n: 1284, l: 4 },
  { t: 'Billing dispute',    n: 742,  l: 3 },
  { t: 'Missed appointment', n: 681,  l: 3 },
  { t: 'Service credit',     n: 544,  l: 2 },
  { t: 'Commercial contract',n: 512,  l: 2 },
  { t: 'HVAC',               n: 488,  l: 2 },
  { t: 'Lawn treatment',     n: 471,  l: 2 },
  { t: 'Pest control',       n: 422,  l: 2 },
  { t: 'Weather delay',      n: 389,  l: 2 },
  { t: 'New install',        n: 366,  l: 2 },
  { t: 'Cancellation',       n: 334,  l: 2 },
  { t: 'Referral',           n: 301,  l: 1 },
  { t: 'Pricing inquiry',    n: 284,  l: 1 },
  { t: 'Warranty',           n: 267,  l: 1 },
  { t: 'Part number',        n: 228,  l: 1 },
  { t: 'Auto-pay',           n: 214,  l: 1 },
  { t: 'Payment plan',       n: 198,  l: 1 },
  { t: 'Technician feedback',n: 182,  l: 1 },
  { t: 'Crew lead',          n: 164,  l: 1 },
  { t: 'Satisfaction',       n: 149,  l: 1 },
  { t: 'Follow-up',          n: 138,  l: 1 },
  { t: 'Damage claim',       n: 121,  l: 1 },
];

window.VI_DATA = { AGENTS, CALLS, genWave, SENT_BAND, TRANSCRIPT, TREND, VOLUME, AGENT_STATS, TOPICS };
