/* global */
// Mock data for RoundsFuture — rounds + journal/tracker entries.

const DOCTORS = {
  patel:  { id: 'patel',  name: 'Dr. Anika Patel',   role: 'Pediatrician · MD, FAAP',          short: 'Dr. Patel',  ava: 'assets/doc-mehta.png' },
  okafor: { id: 'okafor', name: 'Dr. Marcus Okafor', role: 'Pediatrician · MD, FAAP',          short: 'Dr. Okafor', ava: 'assets/doc-okafor.png' },
  senior: { id: 'senior', name: 'Dr. Eleanor Senior', role: 'Pediatric Sleep Specialist · MD', short: 'Dr. Senior', ava: 'assets/doc-senior.png' },
};

const TODAY_ROUND = {
  id: 'today',
  date: 'Today',
  cadence: 'Morning Round',
  signedAt: '7:31 AM',
  signedAtFull: 'Today · 7:31 AM',
  by: 'patel',
  forBaby: 'Nora · 7 months',
  span: 'Overnight · 8:42 PM → 6:54 AM',
  narrative: 'Nora had a typical night. Two brief stirrings (1 AM, 4 AM) resolved on their own. Nothing to act on.',
  baseline: 'Nora\'s typical overnight: HR 96–110, SpO₂ 96–98%, two stirrings, ~10h sleep. Tonight matched.',
  reportId: 'NR-2026-05-31-0731',
  findings: [
    'Vitals within Nora\'s established overnight range.',
    'Brief stirrings self-resolved — normal for this age.',
    'No anomalies. No action needed.',
  ],
  vitals: {
    hr:    { avg: 102, range: '94–118', trend: [104,102,98,96,101,108,99,95,101,103,99,97,102,108,103,99,105,102] },
    o2:    { avg: 97,  range: '96–98',  trend: [97,97,98,97,97,96,97,97,98,98,97,97,97,96,97,98,97,97] },
    stirs: { avg: 2,   range: '1–3 typical', trend: null },
    sleep: { avg: '10h 12m', range: '9–11h typical', trend: null },
  },
  markdown: `## Overnight summary
Nora slept 10h 12m across two consolidated stretches with a 4m self-resolved waking at 01:14 and a 38-second stir at 04:02.

## Heart rate
Mean 102 bpm. Range 94–118. No tachycardic spells. Consistent with established baseline.

## SpO₂
Mean 97%. Held 96–98% throughout. Brief 96% read at 04:02 coincides with the second stir — normal autonomic response.

## Day context (from journal)
4 feeds · 2 naps (65m + 95m) · Solids twice · Temp 100.4°F logged at 6:00 PM (post-vaccine) · Tylenol 2.5ml at 6:30 PM · Bath calm.

## Recommendations
- Continue current bedtime routine. HR pattern suggests good vagal tone.
- No follow-up required. Ranges are normative for a 7-month-old.
- Temp was elevated yesterday post-vaccine; recheck tonight if fussiness returns.

## Reviewed by
Dr. Anika Patel, MD, FAAP — 7:31 AM. Drafted by AI, signed by MDI provider.`,
  chatExchange: [
    { from: 'agent', text: 'I\'ve read this Morning Round — signed by Dr. Patel at 7:31 AM. Vitals look typical for Nora. What would you like to go over?' },
    { from: 'parent', text: 'Should I be worried about the 4 AM stir?' },
    { from: 'agent', text: 'No. A 38-second stir at 04:02 with SpO₂ briefly reading 96% is well inside Nora\'s normal range. Dr. Patel noted it because it\'s a small thing worth knowing, not because it\'s concerning.' },
    { from: 'parent', text: 'The fever yesterday — is that in the round?' },
    { from: 'agent', text: 'Yes. Dr. Patel reviewed the journal entry: 100.4°F at 6:00 PM post-vaccine, Tylenol 2.5ml at 6:30 PM. Vitals overnight stayed stable despite the earlier fever, which is reassuring.' },
  ],
};

const GENERAL_CHAT_EXCHANGE = [
  { from: 'parent', text: 'I was looking at Nora\'s vitals before bed — her heart rate looked higher than usual. Should I be worried?' },
  { from: 'agent', text: 'She\'s at 118 bpm while awake right now. That\'s above her usual settling range (96–110), but SpO₂ is steady at 97%. Nothing that looks urgent — worth keeping an eye on overnight.' },
  { from: 'parent', text: 'Could that be from yesterday\'s vaccine fever?' },
  { from: 'agent', text: 'Very possible. Post-vaccine fevers often bump heart rate for 24–48 hours. Tomorrow\'s signed round will compare tonight against her 30-night baseline so a pediatrician can factor it in.' },
];

const GENERAL_CHAT_SUGGESTION = {
  draft: 'HR elevated at bedtime (118 bpm) while settling — SpO₂ normal at 97%. May relate to post-vaccine fever yesterday; worth flagging for tomorrow\'s review.',
  note: 'Dr. Patel will see this in the bundle before signing tomorrow\'s round.',
};

const HISTORY_ROUNDS = [
  { id: 'd-1', dow: 'Yest', date: 29, doc: 'okafor', title: 'Quiet night. No flags.', status: 'signed' },
  { id: 'd-2', dow: 'Thu',  date: 28, doc: 'patel',  title: 'Stirring at 2 AM — self-resolved.', status: 'signed' },
  { id: 'd-3', dow: 'Wed',  date: 27, doc: 'patel',  title: 'All clear.', status: 'signed' },
  { id: 'd-4', dow: 'Tue',  date: 26, doc: 'senior', title: 'Brief desat at 5 AM — within range.', status: 'signed' },
  { id: 'd-5', dow: 'Mon',  date: 25, doc: 'okafor', title: 'Quiet night. No flags.', status: 'signed' },
  { id: 'd-6', dow: 'Sun',  date: 24, doc: 'patel',  title: 'Slightly restless. Vitals normal.', status: 'signed' },
  { id: 'd-7', dow: 'Sat',  date: 23, doc: 'senior', title: 'All clear.', status: 'signed' },
  { id: 'd-8', dow: 'Fri',  date: 22, doc: 'okafor', title: 'Quiet night. No flags.', status: 'signed' },
];

const BUNDLE_SUGGESTIONS = [
  'She\'s been fussy around the same time each night',
  'Bottle intake is slightly down',
  'I noticed a faint rash on her thigh',
  'She\'s been pulling at her ear',
  'Sleep window shifted earlier',
  'Anything to watch with the new daycare?',
];

function structureBundle(text) {
  if (!text || !text.trim()) return null;
  return {
    summary: text.trim(),
    fields: [
      { label: 'Pattern', value: 'Recurring overnight' },
      { label: 'First noticed', value: '3 nights ago' },
      { label: 'Context provided', value: 'Parent observation' },
    ],
    routedTo: 'Tomorrow\'s Morning Round',
  };
}

const PROVIDER_QUEUE = [
  { id: 'q1',  name: 'Nora P.',   age: '7m',  sum: 'Vitals nominal. Brief stirrings overnight.', flag: false },
  { id: 'q2',  name: 'Ezra J.',   age: '11m', sum: 'SpO₂ stable. Sleep typical.', flag: false },
  { id: 'q3',  name: 'Maya C.',   age: '4m',  sum: 'HR briefly elevated 3 AM — self-resolved.', flag: true },
  { id: 'q4',  name: 'Theo R.',   age: '9m',  sum: 'All readings within range.', flag: false },
  { id: 'q5',  name: 'Iris W.',   age: '6m',  sum: 'Quiet night.', flag: false },
  { id: 'q6',  name: 'Owen K.',   age: '14m', sum: 'Vitals nominal.', flag: false },
  { id: 'q7',  name: 'Sofia M.',  age: '2m',  sum: 'Frequent stirrings — within typical range.', flag: false },
  { id: 'q8',  name: 'Leo D.',    age: '8m',  sum: 'O₂ briefly 94% at 4 AM — normal variation.', flag: true },
  { id: 'q9',  name: 'Avery H.',  age: '12m', sum: 'All readings within range.', flag: false },
  { id: 'q10', name: 'Noah B.',   age: '5m',  sum: 'Vitals nominal.', flag: false },
  { id: 'q11', name: 'Eva F.',    age: '3m',  sum: 'Quiet night.', flag: false },
  { id: 'q12', name: 'Caleb T.',  age: '10m', sum: 'Vitals nominal.', flag: false },
];

const SICK_NIGHT_ROUNDS = [
  { id: 's1', time: '10:00 PM', label: 'Bedtime check',   status: 'signed',  doc: 'patel',  sum: 'Temp 100.4°F at bedtime. Vitals stable. Watching.' },
  { id: 's2', time: '2:00 AM',  label: 'Overnight check', status: 'signed',  doc: 'okafor', sum: 'Temp 101.2°F. SpO₂ 96%. Restless. Ibuprofen given. Continue.' },
  { id: 's3', time: '6:00 AM',  label: 'Pre-dawn check',  status: 'pending', doc: 'okafor', sum: '' },
  { id: 's4', time: '8:00 AM',  label: 'Morning handoff', status: 'upcoming',doc: 'patel',  sum: '' },
];

/* ─── Journal / Tracker data ─────────────────────────────── */

// Category definitions — color, label, icon key
const TRACKER_CATS = [
  { id: 'feed',   label: 'Feed',     color: 'var(--cat-feed)',   icon: 'Bottle'      },
  { id: 'solids', label: 'Solids',   color: 'var(--cat-solids)', icon: 'Apple'       },
  { id: 'cry',    label: 'Cry',      color: 'var(--cat-cry)',    icon: 'Cry'         },
  { id: 'diaper', label: 'Diaper',   color: 'var(--cat-diaper)', icon: 'Diaper'      },
  { id: 'temp',   label: 'Temp',     color: 'var(--cat-temp)',   icon: 'Thermometer' },
  { id: 'nap',    label: 'Nap',      color: 'var(--cat-nap)',    icon: 'Moon'        },
  { id: 'med',    label: 'Medicine', color: 'var(--cat-med)',    icon: 'Pill'        },
  { id: 'bath',   label: 'Bath',     color: 'var(--cat-bath)',   icon: 'Bath'        },
  { id: 'note',   label: 'Note',     color: 'var(--cat-note)',   icon: 'Note'        },
];

// Today's journal — a realistic full day for a 7-month-old
const JOURNAL_TODAY = [
  { id: 'j1',  time: '7:30',  ampm: 'AM', cat: 'feed',   note: 'Breast · left 12m, right 10m · good latch',              group: 'Morning' },
  { id: 'j2',  time: '9:00',  ampm: 'AM', cat: 'nap',    note: 'Nap · 65 min · woke calm',                                group: 'Morning' },
  { id: 'j3',  time: '10:30', ampm: 'AM', cat: 'solids', note: 'Banana puree · 3 tbsp · ate eagerly',                     group: 'Morning' },
  { id: 'j4',  time: '11:15', ampm: 'AM', cat: 'cry',    note: 'Fussy · 6 min · self-soothed',                            group: 'Morning' },
  { id: 'j5',  time: '12:00', ampm: 'PM', cat: 'feed',   note: 'Bottle · 4 oz · finished',                                group: 'Afternoon' },
  { id: 'j6',  time: '1:10',  ampm: 'PM', cat: 'nap',    note: 'Nap · 95 min · deep sleep',                               group: 'Afternoon' },
  { id: 'j7',  time: '3:00',  ampm: 'PM', cat: 'solids', note: 'Peas + sweet potato · 2 tbsp · a bit distracted',         group: 'Afternoon' },
  { id: 'j8',  time: '3:45',  ampm: 'PM', cat: 'cry',    note: 'Crying · 9 min · settled when held',                      group: 'Afternoon' },
  { id: 'j9',  time: '4:30',  ampm: 'PM', cat: 'feed',   note: 'Breast · 18 min',                                         group: 'Afternoon' },
  { id: 'j10', time: '5:15',  ampm: 'PM', cat: 'diaper', note: 'Messy',                                                    group: 'Afternoon' },
  { id: 'j11', time: '6:00',  ampm: 'PM', cat: 'temp',   note: '100.4°F · after vaccines · Tylenol given at 6:30',        group: 'Evening', flag: true },
  { id: 'j12', time: '6:30',  ampm: 'PM', cat: 'med',    note: 'Tylenol infant · 2.5 ml',                                 group: 'Evening' },
  { id: 'j13', time: '7:00',  ampm: 'PM', cat: 'bath',   note: 'Bath time · calm, no fussing',                            group: 'Evening' },
  { id: 'j14', time: '7:30',  ampm: 'PM', cat: 'feed',   note: 'Breast · 20 min · good session before bed',               group: 'Evening' },
  { id: 'j15', time: '8:42',  ampm: 'PM', cat: 'nap',    note: 'Sleep started · sock connected',                          group: 'Evening' },
];

// Day-summary tallies — computed from JOURNAL_TODAY
const JOURNAL_SUMMARY = (() => {
  const count = cat => JOURNAL_TODAY.filter(e => e.cat === cat).length;
  return {
    feeds:    count('feed'),
    naps:     count('nap'),
    solids:   count('solids'),
    cries:    count('cry'),
    diapers:  count('diaper'),
    tempFlag: JOURNAL_TODAY.some(e => e.cat === 'temp'),
  };
})();

// Week strip — past 7 days of dots (categories logged that day)
const WEEK_STRIP = [
  { dow: 'Mon', date: 25, dots: ['feed','nap','diaper'] },
  { dow: 'Tue', date: 26, dots: ['feed','nap','cry','solids'] },
  { dow: 'Wed', date: 27, dots: ['feed','nap','solids','bath'] },
  { dow: 'Thu', date: 28, dots: ['feed','nap','cry','temp'] },
  { dow: 'Fri', date: 29, dots: ['feed','nap','diaper','bath'] },
  { dow: 'Sat', date: 30, dots: ['feed','nap','solids','cry','temp','med','bath'], today: true },
  { dow: 'Sun', date: 31, dots: [] },
];

// Journal-sourced items that auto-surface as bundle suggestions on the round
const JOURNAL_BUNDLE_HINTS = [
  { cat: 'temp',   color: 'var(--cat-temp)',   text: 'Temp 100.4°F logged at 6 PM (post-vaccine)' },
  { cat: 'cry',    color: 'var(--cat-cry)',     text: '9-min crying spell at 3:45 PM — harder to settle than usual' },
  { cat: 'solids', color: 'var(--cat-solids)',  text: 'Peas/sweet potato mix — only 2 tbsp, seemed distracted' },
];

// Quick-log detail options per category
const LOG_DETAIL_OPTS = {
  feed:   ['Breast L', 'Breast R', 'Both sides', 'Bottle', 'Pumped'],
  solids: ['Banana', 'Peas', 'Sweet potato', 'Avocado', 'Oatmeal', 'Other'],
  cry:    ['Self-soothed', 'Held', 'Fed', 'Pacifier', 'Gas/wind', 'Unknown'],
  diaper: ['Wet', 'Dirty', 'Both'],
  temp:   ['Under 99°F', '99–100.3°F', '100.4–101°F', 'Over 101°F'],
  nap:    ['Under 30 min', '30–60 min', '60–90 min', '90+ min'],
  med:    ['Tylenol', 'Ibuprofen', 'Gripe water', 'Vitamin D', 'Other'],
  bath:   ['Calm', 'Fussy', 'Loved it'],
  note:   [],
};

const SOLIDS_FOODS = ['Banana','Oatmeal','Avocado','Sweet potato','Peas','Rice cereal','Apple puree','Broccoli','+ New food'];
const COACHING_INSIGHTS = [
  { id: 'ci1', title: 'Evening top-up may extend overnight stretch', body: 'Nora\'s longest stretches follow nights with a calm feed within 1h of bedtime. Last night she went 10h 12m after her 7:30 PM breast feed.', cite: 'Reviewed by Dr. Patel · based on Nora\'s last 14 rounds' },
  { id: 'ci2', title: 'Fussy spells cluster between 3:30–4 PM', body: 'Both crying entries this week happened in that window. A short nap or small feed just before pickup may head it off.', cite: 'Based on Nora\'s 7-day journal · pattern detected' },
  { id: 'ci3', title: 'Distraction at solids is normal at 7 months', body: 'She ate less at the afternoon session — common as the world gets more interesting. Try offering solids before milk for better intake.', cite: 'per AAP Bright Futures · 6–9 month feeding' },
];
const PATTERNS_TRENDS = [
  { id: 'pt1', label: 'Longest sleep stretch', value: '10h 12m', delta: '↑ 18%',  dir: 'up',   sub: 'Last 8 rounds · steadily improving', spark: [60,65,68,62,70,74,80,88,95,102,99,108,112] },
  { id: 'pt2', label: 'Daily feeds',           value: '4',       delta: 'Stable', dir: 'flat', sub: 'Last 7 days · consistent',             spark: [4,4,5,4,4,3,4,4,4,4,4,4,4] },
  { id: 'pt3', label: 'Cry / fussy episodes',  value: '2 today', delta: '↓ 1',    dir: 'up',   sub: 'Down from 3 average · good day',      spark: [3,4,3,2,4,3,3,2,3,2,3,3,2] },
];
const PAST_BRIEFS = [
  { date: '30', month: 'May', title: 'Typical night. All clear.',            sub: 'HR 102 avg · SpO₂ 97% · 10h 12m sleep' },
  { date: '29', month: 'May', title: 'Quiet night. No flags.',               sub: 'Vitals nominal · 9h 45m sleep' },
  { date: '28', month: 'May', title: 'Stirring at 2 AM — self-resolved.',   sub: 'Brief desat coincided with movement' },
  { date: '27', month: 'May', title: 'All clear.',                           sub: 'Best sleep stretch of the week' },
];

/* ─── Agent + round configuration ───────────────────────────── */

// Care Agent personality options — voice tone for round summaries and chat
const AGENT_PERSONALITIES = [
  {
    id: 'calm',
    label: 'Calm',
    blurb: 'Clinical, precise, evidence-based — minimal words.',
    sampleResponse: 'The 04:02 stir lasted 38 seconds; SpO₂ held at 96%, within Nora\'s baseline. No action indicated.',
  },
  {
    id: 'warm',
    label: 'Warm',
    blurb: 'Reassuring, nurturing — explains the why with care.',
    sampleResponse: 'That 4 AM stir is totally normal, and honestly a good sign — it means Nora\'s sleep cycles are maturing just like they should be. It only lasted 38 seconds, and her oxygen stayed right where we\'d expect it. Dr. Patel reviewed it and wasn\'t concerned at all. You\'re doing a great job keeping track of these things.',
  },
  {
    id: 'direct',
    label: 'Direct',
    blurb: 'One sentence, action-first — zero hedging.',
    sampleResponse: 'No — 38 seconds, SpO₂ fine, Dr. Patel cleared it.',
  },
  {
    id: 'thorough',
    label: 'Thorough',
    blurb: 'Full picture — vitals, context, baseline, next steps.',
    sampleResponse: 'The 04:02 stir registered at 38 seconds with SpO₂ briefly reading 96% — a single-point dip that sits within Nora\'s established overnight range of 96–98%. Cross-referencing her 30-night baseline, brief stirrings at this frequency and duration are consistent with normal sleep-cycle transitions at 7 months. The prior-day context matters here too: her 100.4°F post-vaccine fever can cause mild autonomic variability overnight, which likely explains the HR nudge to 108 bpm at that moment. Dr. Patel reviewed the full picture and signed off with no follow-up. Watch for sustained SpO₂ below 95% or stirrings longer than 2 minutes — neither occurred here.',
  },
];

// Round format options — controls the detail level of the generated round
const ROUND_FORMATS = [
  { id: 'brief',    label: 'Brief',    blurb: '3-line summary — essentials only',            isDefault: false },
  { id: 'standard', label: 'Standard', blurb: 'Narrative + vitals + findings',               isDefault: true  },
  { id: 'detailed', label: 'Detailed', blurb: 'Full structured report, every data point',    isDefault: false },
];

// Chat session history — past conversations accessible from the sidebar
const CHAT_SESSIONS = [
  { id: 'cs-today',  title: 'Heart rate at bedtime',       preview: "Nothing that looks urgent — she's at 118 bpm while awake.",           time: '8:42 PM', group: 'Today',     type: 'general' },
  { id: 'cs-y1',    title: "About May 29th's round",       preview: "The 4 AM stir was 38 seconds — well inside her normal range.",         time: '7:45 AM', group: 'Yesterday', type: 'round'   },
  { id: 'cs-y2',    title: 'Vaccine fever and heart rate', preview: "Post-vaccine fevers often bump heart rate for 24–48 hours.",            time: '6:12 PM', group: 'Yesterday', type: 'general' },
  { id: 'cs-w1',    title: 'Sleep regression or normal?',  preview: "At 7 months some babies go through a brief sleep disruption.",         time: 'Thu',     group: 'This week', type: 'general' },
  { id: 'cs-w2',    title: 'Solids and overnight sleep',   preview: "There's a loose connection — we'd need more nights to say for sure.",  time: 'Wed',     group: 'This week', type: 'round'   },
  { id: 'cs-w3',    title: 'SpO₂ dip at 5 AM',            preview: "The 94% reading was brief and coincided with movement — normal.",      time: 'Tue',     group: 'This week', type: 'round'   },
  { id: 'cs-e1',    title: 'Nap length and overnight',     preview: "Longer afternoon naps don't seem to hurt Nora's overnight sleep.",     time: 'May 23',  group: 'Earlier',   type: 'general' },
  { id: 'cs-e2',    title: 'Introducing solid foods',      preview: "Starting with single-ingredient purees is ideal at this age.",         time: 'May 20',  group: 'Earlier',   type: 'general' },
];

// Default onboarding preferences — applied on first-run setup
const ONBOARD_DEFAULTS = {
  frequency:       'morning',       // 'morning' | 'morning_evening'
  morningTime:     '7:00 AM',
  eveningTime:     '6:00 PM',
  permissions: {
    vitals:        true,
    sleep:         true,
    journal:       true,
    baseline:      true,
    observations:  true,
  },
  format:          'standard',
  agentPersonality: 'warm',
};

// Auto Night Watch notification — copy used when the system auto-arms Night Watch
const AUTO_NW_NOTIFICATION = {
  push: "We noticed something in Nora\'s readings tonight. Night Watch is armed — a provider is watching.",
  inApp: "We noticed elevated heart rate patterns and armed Night Watch automatically. A provider has eyes on tonight.",
  band: 'watch',
};
