// Anna's Wall — mock feed data + helpers.
// Mirrors the WallPost shape from the design brief. No network; the service
// layer is faked in the shell with latency so loading/error states are real.

// ── Pillar colour system (from brief) ──────────────────────────────────────
const PILLARS = {
  sleep:     { color: '#8C80F8', label: 'Sleep' },
  nutrition: { color: '#44C55C', label: 'Nutrition' },
  physical:  { color: '#FF6942', label: 'Physical' },
  mental:    { color: '#00C7BE', label: 'Mental' },
  heart:     { color: '#FF4242', label: 'Heart' },
  longevity: { color: '#FDB36B', label: 'Longevity' },
  weight:    { color: '#2196F3', label: 'Weight' },
  dna:       { color: '#e74c3c', label: 'DNA' },
};

// ── Reaction vocabulary ─────────────────────────────────────────────────────
const REACTIONS = [
  { key: 'heart', emoji: '❤️', label: 'Love this' },
  { key: 'fire',  emoji: '🔥', label: 'On fire' },
  { key: 'think', emoji: '🤔', label: 'Makes me think' },
  { key: 'flex',  emoji: '💪', label: 'Proud' },
];

const TYPE_META = {
  CHART:       { label: 'Chart' },
  INSIGHT:     { label: 'Insight' },
  VOICE_NOTE:  { label: 'Voice note' },
  ACHIEVEMENT: { label: 'Milestone' },
};

// ── Relative time ────────────────────────────────────────────────────────────
function relativeTime(iso) {
  const then = new Date(iso).getTime();
  const now = Date.now();
  const s = Math.max(1, Math.round((now - then) / 1000));
  if (s < 60) return 'just now';
  const m = Math.round(s / 60);
  if (m < 60) return `${m} min ago`;
  const h = Math.round(m / 60);
  if (h < 24) return `${h} hour${h > 1 ? 's' : ''} ago`;
  const d = Math.round(h / 24);
  if (d < 7) return `${d} day${d > 1 ? 's' : ''} ago`;
  const w = Math.round(d / 7);
  return `${w} week${w > 1 ? 's' : ''} ago`;
}
function ago(mins) { return new Date(Date.now() - mins * 60000).toISOString(); }

// ── Seed feed (newest first) ─────────────────────────────────────────────────
const WALL_POSTS = [
  {
    id: 'clw01',
    userId: 1,
    type: 'INSIGHT',
    mediaUrl: null,
    pillarTag: 'sleep',
    caption: 'Your sleep is quietly rebuilding itself',
    annaCommentary:
      "Hi Kathryn — I've been watching your nights this week, and there's a real shift happening. Your time in deep sleep is trending higher than it has all month, and you're falling asleep about 20 minutes faster than your two-week baseline.\n\nThis usually follows three things working together: a more consistent wind-down, less late caffeine, and a cooler room. You don't need to chase perfection here — the trend is the win.\n\nOne small nudge: your most restorative nights all started before 11pm. If you can protect that window two more times this week, I think we'll see your morning readiness climb with it.",
    reactions: { heart: 14, fire: 3, think: 2, flex: 6 },
    readAt: null,
    createdAt: ago(135),
    citationUrls: [
      'https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5440010/',
      'https://pubmed.ncbi.nlm.nih.gov/33549611/',
    ],
  },
  {
    id: 'clw02',
    userId: 1,
    type: 'CHART',
    mediaUrl: 'chart://resting-hr',
    pillarTag: 'heart',
    caption: 'Resting heart rate dipped 4 bpm this week',
    annaCommentary:
      "Your resting heart rate has settled into the high 50s over the last seven days — down from the low 60s the week before. A lower resting rate is one of the clearest signals that your cardiovascular system is recovering well.\n\nThe two zone-2 walks you logged almost certainly helped, and so did the better sleep. I'd keep this rhythm: it's gentle, repeatable, and your body is clearly responding to it.",
    reactions: { heart: 9, fire: 11, think: 1, flex: 4 },
    readAt: null,
    createdAt: ago(190),
    citationUrls: ['https://www.ahajournals.org/doi/10.1161/JAHA.117.008341'],
  },
  {
    id: 'clw03',
    userId: 1,
    type: 'ACHIEVEMENT',
    mediaUrl: 'badge://streak',
    pillarTag: 'physical',
    caption: '14-day movement streak',
    annaCommentary:
      "Two full weeks of hitting your daily movement goal — that's the longest streak since you joined. Consistency like this is exactly what moves the needle on long-term health, far more than any single intense session.\n\nI'm proud of you, Kathryn. Let's protect the momentum: rest days count too, so don't be afraid to take an easy one.",
    reactions: { heart: 22, fire: 18, think: 0, flex: 27 },
    readAt: '2026-05-28T09:00:00Z',
    createdAt: ago(720),
    citationUrls: [],
  },
  {
    id: 'clw04',
    userId: 1,
    type: 'INSIGHT',
    mediaUrl: null,
    pillarTag: 'nutrition',
    caption: 'A small protein gap worth closing',
    annaCommentary:
      "Looking at the last ten days, your protein is landing a little lower than what supports your activity level — most days you're finishing the evening still short. This isn't a problem yet, but closing the gap tends to help with recovery and steadier energy through the afternoon.\n\nAn easy fix: anchor each meal with a protein source first, then build around it. Greek yoghurt, eggs, lentils, or fish all count. Small, repeatable, no tracking required.",
    reactions: { heart: 7, fire: 2, think: 5, flex: 3 },
    readAt: '2026-05-27T19:30:00Z',
    createdAt: ago(1500),
    citationUrls: [
      'https://pubmed.ncbi.nlm.nih.gov/29405440/',
      'https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6566799/',
    ],
  },
  {
    id: 'clw05',
    userId: 1,
    type: 'VOICE_NOTE',
    mediaUrl: 'voice://weekly',
    pillarTag: 'mental',
    caption: 'Your weekly check-in, in my own words',
    annaCommentary:
      "I recorded a short note for you this week. The short version: your stress markers eased after Wednesday, and it lines up almost exactly with the two evenings you stepped away from screens early.\n\nYou mentioned feeling stretched at work — that's real, and it's showing up in your data. The encouraging part is how quickly you bounced back once you gave yourself a little space. Have a listen when you have a quiet minute.",
    reactions: { heart: 12, fire: 1, think: 4, flex: 2 },
    readAt: '2026-05-26T08:15:00Z',
    createdAt: ago(2300),
    citationUrls: [],
  },
  {
    id: 'clw06',
    userId: 1,
    type: 'CHART',
    mediaUrl: 'chart://weight-trend',
    pillarTag: 'weight',
    caption: 'Weight trend is flattening — exactly as planned',
    annaCommentary:
      "Your weight has held steady across the last three weeks after a gradual decline. This plateau is a good thing: it means your body is settling at a new set point rather than swinging. The day-to-day wobble you're seeing is mostly water and completely normal.\n\nNo changes needed. Keep doing what you're doing, and let's check back in a fortnight.",
    reactions: { heart: 5, fire: 4, think: 3, flex: 8 },
    readAt: '2026-05-24T07:45:00Z',
    createdAt: ago(3600),
    citationUrls: ['https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7700832/'],
  },
  {
    id: 'clw07',
    userId: 1,
    type: 'INSIGHT',
    mediaUrl: null,
    pillarTag: 'longevity',
    caption: 'Your VO₂ estimate nudged into a new band',
    annaCommentary:
      "Your estimated cardio-respiratory fitness ticked up enough this month to move you into the next band for your age group. It's one of the strongest single predictors of long-term health we have, so even a small gain here is worth celebrating.\n\nThe zone-2 walks are doing quiet, compounding work. If you ever want to accelerate it, adding one slightly brisker interval per walk is the gentlest lever.",
    reactions: { heart: 16, fire: 9, think: 6, flex: 11 },
    readAt: '2026-05-22T10:00:00Z',
    createdAt: ago(5200),
    citationUrls: [
      'https://jamanetwork.com/journals/jamanetworkopen/fullarticle/2707428',
    ],
  },
];

Object.assign(window, { PILLARS, REACTIONS, TYPE_META, WALL_POSTS, relativeTime, ago });
