// ─────────────────────────────────────────────────────────────
// Sample data — a personal DM thread between "you" and marina_k.
// 332 total nodes; ~16 root branches that spawned conversations.
//
// A "root" here means: a message someone sent that subsequently
// got at least one reply (i.e. it has a sub-tree off of it). Tree
// view's job is to show the SHAPE of the conversation — what got
// said, when, how much was said in response — not to navigate
// every node. Canvas is for navigating.
//
// IMPORTANT: there is no topic-classification in the product.
// Every variant can only show what's actually in the data:
//   - the message's own opening words ("head")
//   - who sent it (you / them)
//   - when (age)
//   - how much grew off it (branches, leaves, depth)
//   - whether anything's currently active (activeNow)
// ─────────────────────────────────────────────────────────────

const DM_PEER = {
  handle: 'marina_k',
  initial: 'M',
  rel: 'friend',
  nodes: 332,
  planted: 'Apr 14',
};

// Roots, newest first. Each is a sub-tree.
// `head` is just the first 2–4 words of `body` (lowercased): no
// classifier — we just slice. It's the only label we can show on a
// spatial chart honestly.
const DM_ROOTS = [
  { id: 'n01', from: 'them', age: '20h', ageBand: 'today',
    head: 'I was about',
    body: '"I was about to say the same"',
    last: 'lol of course',
    branches: 3, leaves: 6, depth: 3, activeNow: 0 },

  { id: 'n02', from: 'you',  age: '21h', ageBand: 'today',
    head: 'I keep thinking',
    body: '"I keep thinking about that conversation we had about ethics"',
    last: 'me too — I had a dream about it',
    branches: 7, leaves: 24, depth: 6, activeNow: 2 },

  { id: 'n03', from: 'them', age: '22h', ageBand: 'today',
    head: 'recipe?',
    body: '"recipe?"',
    last: "I'll send the link tonight",
    branches: 4, leaves: 11, depth: 3, activeNow: 0 },

  { id: 'n04', from: 'you',  age: '23h', ageBand: 'today',
    head: 'will call the',
    body: '"will call the plumber tomorrow"',
    last: 'thank you ♡',
    branches: 2, leaves: 4, depth: 2, activeNow: 0 },

  { id: 'n05', from: 'you',  age: '1d',  ageBand: 'today',
    head: 'btw the dog',
    body: '"btw the dog is being weird"',
    last: 'is he eating?',
    branches: 5, leaves: 13, depth: 4, activeNow: 1 },

  { id: 'n06', from: 'them', age: '1d',  ageBand: 'today',
    head: 'might go to',
    body: '"might go to the lake"',
    last: 'pack the small grill',
    branches: 8, leaves: 31, depth: 5, activeNow: 0 },

  { id: 'n07', from: 'them', age: '3d',  ageBand: 'this-week',
    head: 'have you watched',
    body: '"have you watched the new one yet?"',
    last: 'finished it last night',
    branches: 6, leaves: 18, depth: 4, activeNow: 0 },

  { id: 'n08', from: 'you',  age: '5d',  ageBand: 'this-week',
    head: 'sam is moving',
    body: '"sam is moving back in june"',
    last: 'we should throw something',
    branches: 11, leaves: 47, depth: 7, activeNow: 0 },

  { id: 'n09', from: 'them', age: '1w',  ageBand: 'this-week',
    head: 'yes',
    body: '"yes"',
    last: '(that branched a lot)',
    branches: 2, leaves: 3, depth: 2, activeNow: 0 },

  { id: 'n10', from: 'them', age: '2w',  ageBand: 'this-month',
    head: 'the article you',
    body: '"the article you sent — I read it twice"',
    last: 'agree on the 3rd section',
    branches: 9, leaves: 38, depth: 6, activeNow: 0 },

  { id: 'n11', from: 'you',  age: '3w',  ageBand: 'this-month',
    head: 'birthday for E',
    body: '"birthday for E next sat?"',
    last: 'I got the cake covered',
    branches: 14, leaves: 52, depth: 8, activeNow: 0 },

  { id: 'n12', from: 'them', age: '5w',  ageBand: 'earlier',
    head: 'that playlist is',
    body: '"that playlist is unhinged in the best way"',
    last: '(added 4 more tracks)',
    branches: 4, leaves: 9, depth: 3, activeNow: 0 },

  { id: 'n13', from: 'you',  age: '6w',  ageBand: 'earlier',
    head: 'can I tell',
    body: '"can I tell you something weird about work"',
    last: 'I think you should say something',
    branches: 10, leaves: 41, depth: 9, activeNow: 0 },

  { id: 'n14', from: 'them', age: '8w',  ageBand: 'earlier',
    head: 'do you remember',
    body: '"do you remember the place near the river?"',
    last: 'it closed in march',
    branches: 3, leaves: 7, depth: 3, activeNow: 0 },

  { id: 'n15', from: 'you',  age: '11w', ageBand: 'older',
    head: 'the podcast —',
    body: '"the podcast — I think you\'d love it"',
    last: '(she did)',
    branches: 5, leaves: 14, depth: 4, activeNow: 0 },

  { id: 'n16', from: 'them', age: '14w', ageBand: 'older',
    head: 'first conversation',
    body: '"first conversation"',
    last: '(where it all started)',
    branches: 1, leaves: 1, depth: 1, activeNow: 0 },
];

// Time-band order + display labels.
const AGE_BANDS = [
  { id: 'today',      label: 'today',      detail: 'the last 24 hours' },
  { id: 'this-week',  label: 'this week',  detail: 'apr 12 → apr 18' },
  { id: 'this-month', label: 'this month', detail: 'all of april' },
  { id: 'earlier',    label: 'earlier',    detail: 'march' },
  { id: 'older',      label: 'older',      detail: 'feb & before' },
];

// FROM colors — the one real semantic colour we have.
// Mirrors the bubble bg in Canvas (you = canopy tint, them = white-on-dark).
const FROM_COLORS = {
  you:  '#4F8E51',   // canopy
  them: '#A8C5A0',   // dew
};

// Depth color ramp — using the design system's node-depth scale.
// Used for rendering connectors and inner cores when the variant
// wants to communicate "this thread went deep".
const DEPTH_COLORS = ['#2C5F2E', '#5E8048', '#76AB78', '#A8C5A0', '#C9D6BC'];

function depthColor(d) {
  return DEPTH_COLORS[Math.min(Math.max(d - 1, 0), DEPTH_COLORS.length - 1)];
}

// Procedurally generate a "large DM" — ~1,200 nodes / ~60 roots —
// used in the scale demo card. Bodies are placeholder slices; this is
// only for layout density, not for reading.
function makeLargeRoots(n = 60) {
  const FAKE_HEADS = [
    'I was just', 'I keep thinking', 'recipe?', 'will call the',
    'btw the dog', 'might go to', 'have you watched', 'sam is moving',
    'yes', 'the article you', 'birthday for', 'that playlist',
    'can I tell', 'do you remember', 'the podcast —', 'first',
    'about the trip', 'work has been', 'okay so I', 'one more thing',
    'omg', 'lol', 'I just saw', 'mom called',
  ];
  const out = [];
  for (let i = 0; i < n; i++) {
    const t = i / n;
    const ageBand = t < 0.18 ? 'today'
                 : t < 0.34 ? 'this-week'
                 : t < 0.55 ? 'this-month'
                 : t < 0.80 ? 'earlier' : 'older';
    out.push({
      id: 'L' + i,
      from: (i * 7) % 2 === 0 ? 'you' : 'them',
      age: ['8h','22h','3d','1w','2w','5w','8w','14w','22w','9mo','1y'][i % 11],
      ageBand,
      head: FAKE_HEADS[i % FAKE_HEADS.length],
      body: '"' + FAKE_HEADS[i % FAKE_HEADS.length] + '…"',
      branches: 1 + ((i * 13) % 14),
      leaves: 1 + ((i * 23) % 50),
      depth: 1 + ((i * 5) % 8),
      activeNow: i < 3 ? (i + 1) : 0,
    });
  }
  return out;
}

Object.assign(window, { DM_PEER, DM_ROOTS, AGE_BANDS,
                        FROM_COLORS, DEPTH_COLORS, depthColor,
                        makeLargeRoots });
