/* ClinicFlow AI — mock data. Exports globals on window. */

// Avatar gradient palette (deterministic by name hash)
const AVATAR_PALETTES = [
  ['#7C3AED', '#A78BFA'],
  ['#4F46E5', '#8B5CF6'],
  ['#EC4899', '#8B5CF6'],
  ['#0EA5E9', '#6366F1'],
  ['#10B981', '#14B8A6'],
  ['#F59E0B', '#EC4899'],
  ['#06B6D4', '#3B82F6'],
  ['#8B5CF6', '#6D28D9'],
  ['#F97316', '#EF4444'],
  ['#14B8A6', '#0EA5E9'],
];

function hashStr(s) {
  let h = 0;
  for (let i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) | 0;
  return Math.abs(h);
}

function avatarFor(name) {
  const palette = AVATAR_PALETTES[hashStr(name) % AVATAR_PALETTES.length];
  const initials = name.split(' ').slice(0, 2).map(p => p[0]).join('').toUpperCase();
  return { palette, initials, bg: `linear-gradient(135deg, ${palette[0]}, ${palette[1]})` };
}

const PATIENTS = [
  { id: 'P-1042', name: 'Aanya Sharma', phone: '+91 98765 43210', email: 'aanya.s@email.com', dob: '1989-04-12', lastVisit: '2026-05-14', nextFollowup: '2026-05-22', followupType: 'Medication', risk: 'Low', wa: 'read', doctor: 'Dr. Verma', tags: ['Diabetic', 'Returning'], since: '2023-08-12', status: 'Active' },
  { id: 'P-1043', name: 'Rohan Mehta', phone: '+91 99812 04471', email: 'rohan.m@email.com', dob: '1976-11-30', lastVisit: '2026-05-10', nextFollowup: '2026-05-21', followupType: 'Revisit', risk: 'High', wa: 'delivered', doctor: 'Dr. Iyer', tags: ['Cardiac', 'Post-surgery'], since: '2022-03-04', status: 'At Risk' },
  { id: 'P-1044', name: 'Priya Nair', phone: '+91 70214 88123', email: 'priya.n@email.com', dob: '1994-07-08', lastVisit: '2026-05-17', nextFollowup: '2026-05-24', followupType: 'Test', risk: 'Medium', wa: 'sent', doctor: 'Dr. Verma', tags: ['Prenatal'], since: '2024-11-22', status: 'New' },
  { id: 'P-1045', name: 'Vikram Singh', phone: '+91 81273 99102', email: 'vikram.s@email.com', dob: '1962-01-19', lastVisit: '2026-04-29', nextFollowup: '2026-05-21', followupType: 'Revisit', risk: 'High', wa: 'read', doctor: 'Dr. Khan', tags: ['Hypertension'], since: '2021-06-30', status: 'At Risk' },
  { id: 'P-1046', name: 'Meera Iyer', phone: '+91 90213 56402', email: 'meera.i@email.com', dob: '1983-09-22', lastVisit: '2026-05-19', nextFollowup: '2026-05-26', followupType: 'Medication', risk: 'Low', wa: 'read', doctor: 'Dr. Verma', tags: ['Thyroid'], since: '2023-02-14', status: 'Active' },
  { id: 'P-1047', name: 'Arjun Kapoor', phone: '+91 96541 73088', email: 'arjun.k@email.com', dob: '1991-03-05', lastVisit: '2026-05-11', nextFollowup: '2026-05-22', followupType: 'Test', risk: 'Medium', wa: 'delivered', doctor: 'Dr. Iyer', tags: ['Lipid panel'], since: '2024-07-18', status: 'Active' },
  { id: 'P-1048', name: 'Sneha Reddy', phone: '+91 88004 30219', email: 'sneha.r@email.com', dob: '1998-12-14', lastVisit: '2026-05-18', nextFollowup: '2026-05-25', followupType: 'Medication', risk: 'Low', wa: 'read', doctor: 'Dr. Khan', tags: ['Allergy'], since: '2025-01-09', status: 'New' },
  { id: 'P-1049', name: 'Karan Joshi', phone: '+91 77001 24551', email: 'karan.j@email.com', dob: '1970-06-27', lastVisit: '2026-03-18', nextFollowup: '2026-05-23', followupType: 'Revisit', risk: 'High', wa: 'sent', doctor: 'Dr. Verma', tags: ['Diabetic', 'Renal'], since: '2020-09-15', status: 'Inactive' },
  { id: 'P-1050', name: 'Divya Pillai', phone: '+91 99873 02211', email: 'divya.p@email.com', dob: '1986-02-11', lastVisit: '2026-05-15', nextFollowup: '2026-05-22', followupType: 'Medication', risk: 'Low', wa: 'read', doctor: 'Dr. Iyer', tags: ['Migraine'], since: '2022-12-01', status: 'Active' },
  { id: 'P-1051', name: 'Sanjay Bhat', phone: '+91 80123 88774', email: 'sanjay.b@email.com', dob: '1958-08-04', lastVisit: '2026-04-22', nextFollowup: '2026-05-21', followupType: 'Test', risk: 'High', wa: 'delivered', doctor: 'Dr. Khan', tags: ['Cardiac'], since: '2019-04-30', status: 'At Risk' },
  { id: 'P-1052', name: 'Nikhil Rao', phone: '+91 96012 47118', email: 'nikhil.r@email.com', dob: '1995-10-17', lastVisit: '2026-05-16', nextFollowup: '2026-05-27', followupType: 'Medication', risk: 'Low', wa: 'read', doctor: 'Dr. Verma', tags: ['Asthma'], since: '2024-04-22', status: 'Active' },
  { id: 'P-1053', name: 'Anjali Gupta', phone: '+91 91234 50822', email: 'anjali.g@email.com', dob: '1979-05-23', lastVisit: '2026-05-12', nextFollowup: '2026-05-23', followupType: 'Revisit', risk: 'Medium', wa: 'sent', doctor: 'Dr. Iyer', tags: ['Thyroid'], since: '2023-06-14', status: 'Active' },
];

const APPOINTMENTS = [
  { id: 'A-2201', patient: 'Aanya Sharma', time: '09:30', day: 'today', doctor: 'Dr. Verma', status: 'confirmed', kind: 'Follow-up consultation' },
  { id: 'A-2202', patient: 'Rohan Mehta',  time: '10:15', day: 'today', doctor: 'Dr. Iyer',  status: 'confirmed', kind: 'Post-op review' },
  { id: 'A-2203', patient: 'Priya Nair',   time: '11:00', day: 'today', doctor: 'Dr. Verma', status: 'pending',   kind: 'Routine checkup' },
  { id: 'A-2204', patient: 'Vikram Singh', time: '12:00', day: 'today', doctor: 'Dr. Khan',  status: 'missed',    kind: 'BP review' },
  { id: 'A-2205', patient: 'Meera Iyer',   time: '14:30', day: 'today', doctor: 'Dr. Verma', status: 'confirmed', kind: 'Thyroid review' },
  { id: 'A-2206', patient: 'Arjun Kapoor', time: '15:30', day: 'today', doctor: 'Dr. Iyer',  status: 'confirmed', kind: 'Lipid follow-up' },
  { id: 'A-2207', patient: 'Sneha Reddy',  time: '09:00', day: 'tomorrow', doctor: 'Dr. Khan',  status: 'confirmed', kind: 'Allergy review' },
  { id: 'A-2208', patient: 'Karan Joshi',  time: '10:30', day: 'tomorrow', doctor: 'Dr. Verma', status: 'pending',   kind: 'Renal panel' },
  { id: 'A-2209', patient: 'Divya Pillai', time: '11:30', day: 'tomorrow', doctor: 'Dr. Iyer',  status: 'confirmed', kind: 'Migraine review' },
];

const FOLLOWUPS = [
  {
    id: 'F-9101', patient: 'Aanya Sharma', type: 'Medication',
    preview: "Hi Aanya, just a reminder to continue your Metformin 500mg twice daily. Let us know if you experience any side effects.",
    scheduledFor: 'Today, 6:00 PM', state: 'pending', ai: true,
  },
  {
    id: 'F-9102', patient: 'Vikram Singh', type: 'Revisit',
    preview: "Hello Vikram, it's been 3 weeks since your last BP check. Please book a slot this week — Dr. Khan has openings on Friday.",
    scheduledFor: 'Today, 5:30 PM', state: 'pending', ai: true,
  },
  {
    id: 'F-9103', patient: 'Priya Nair', type: 'Test',
    preview: "Priya, your routine bloodwork is due. Walk-in slots are available Tuesday between 8 AM and 11 AM. No fasting required.",
    scheduledFor: 'Tomorrow, 9:00 AM', state: 'pending', ai: true,
  },
  {
    id: 'F-9104', patient: 'Sneha Reddy', type: 'Medication',
    preview: "Hi Sneha, your antihistamine course ends this Friday. We've prepared the next refill — confirm if you'd like home delivery.",
    scheduledFor: 'Today, 4:00 PM', state: 'pending', ai: false,
  },
  {
    id: 'F-9105', patient: 'Karan Joshi', type: 'Revisit',
    preview: "Karan, you missed your last follow-up appointment. Please reschedule at your earliest convenience.",
    scheduledFor: 'Yesterday, 7:00 PM', state: 'failed', ai: true,
  },
  {
    id: 'F-9106', patient: 'Sanjay Bhat', type: 'Test',
    preview: "Sanjay, ECG follow-up is recommended every 6 months — book a 15-minute slot at the front desk or via WhatsApp.",
    scheduledFor: 'Today, 7:00 PM', state: 'pending', ai: true,
  },
  {
    id: 'F-9107', patient: 'Anjali Gupta', type: 'Revisit',
    preview: "Hello Anjali, your thyroid recheck is coming up. Dr. Iyer's next opening is Wed, 11 AM.",
    scheduledFor: 'Today, 6:30 PM', state: 'pending', ai: false,
  },
  {
    id: 'F-9108', patient: 'Meera Iyer', type: 'Medication',
    preview: "Meera, your levothyroxine prescription will need a renewal in 5 days. We can auto-send the next pickup reminder.",
    scheduledFor: 'Mon May 25, 9:00 AM', state: 'sent', ai: true,
  },
  {
    id: 'F-9109', patient: 'Nikhil Rao', type: 'Test',
    preview: "Hi Nikhil, your annual PFT is due this month. We've held a slot for Saturday morning.",
    scheduledFor: 'Today, 8:00 PM', state: 'pending', ai: true,
  },
];

const ACTIVITY = [
  { kind: 'wa-sent',   text: 'Reminder sent to Aanya Sharma (Metformin refill)', time: '2m ago', color: '#25D366' },
  { kind: 'completed', text: 'Follow-up completed with Meera Iyer', time: '12m ago', color: '#10B981' },
  { kind: 'confirmed', text: 'Arjun Kapoor confirmed 3:30 PM appointment', time: '24m ago', color: '#10B981' },
  { kind: 'ai-run',    text: 'AI Agent processed 18 follow-up candidates', time: '1h ago', color: '#7C3AED' },
  { kind: 'added',     text: 'New patient added — Sneha Reddy (P-1048)', time: '2h ago', color: '#8B5CF6' },
  { kind: 'missed',    text: 'Vikram Singh missed 12:00 PM slot — flagged for outreach', time: '3h ago', color: '#EF4444' },
];

const WA_THREAD = [
  { day: 'Yesterday' },
  { dir: 'received', text: "Hello, I had a question about my prescription dosage.", time: '10:14 AM' },
  { dir: 'sent', text: "Hi Aanya — happy to help. Are you asking about the Metformin 500mg?", time: '10:18 AM', ticks: 'read' },
  { dir: 'received', text: "Yes — should I take it before or after meals?", time: '10:21 AM' },
  { dir: 'sent', text: "Take it with or right after meals to reduce stomach upset. Twice daily — morning and evening.", time: '10:23 AM', ticks: 'read' },
  { day: 'Today' },
  { dir: 'sent', text: "Hi Aanya, this is a reminder for your follow-up appointment on May 22 at 9:30 AM with Dr. Verma. Reply CONFIRM to confirm.", time: '9:00 AM', ticks: 'read' },
  { dir: 'received', text: "CONFIRM", time: '9:04 AM' },
  { dir: 'sent', text: "Thank you. We'll see you on Friday. ✓", time: '9:05 AM', ticks: 'delivered' },
];

const TEAM = [
  { name: 'Dr. Aditi Verma', role: 'General Physician', initials: 'AV', status: 'online' },
  { name: 'Dr. Ravi Iyer',   role: 'Cardiologist',     initials: 'RI', status: 'online' },
  { name: 'Dr. Ahmed Khan',  role: 'Endocrinologist',  initials: 'AK', status: 'away' },
  { name: 'Riya Sen',         role: 'Front desk',       initials: 'RS', status: 'online' },
];

// chart-friendly series
const APPTS_OVER_TIME = [
  { x: 'Mon', y: 22 }, { x: 'Tue', y: 28 }, { x: 'Wed', y: 35 },
  { x: 'Thu', y: 31 }, { x: 'Fri', y: 42 }, { x: 'Sat', y: 26 }, { x: 'Sun', y: 12 },
];
const RETENTION_TREND = [
  { x: 'Dec', y: 71 }, { x: 'Jan', y: 74 }, { x: 'Feb', y: 78 },
  { x: 'Mar', y: 82 }, { x: 'Apr', y: 84 }, { x: 'May', y: 87 },
];
const SPARK = [12, 18, 14, 22, 19, 28, 24, 31, 29, 36, 33, 42];

Object.assign(window, {
  CF_DATA: { PATIENTS, APPOINTMENTS, FOLLOWUPS, ACTIVITY, WA_THREAD, TEAM, APPTS_OVER_TIME, RETENTION_TREND, SPARK },
  avatarFor, hashStr,
});
