// ─────────────────────────────────────────────────────────────
// Sample data for the Forest tab redesign + scale brainstorms.
// One headline forest (Philosophy) plus a list of forests the
// user belongs to. Activity numbers are tuned to demonstrate the
// thousands-of-people scaling problem.
// ─────────────────────────────────────────────────────────────

const PHILOSOPHY_ROOTS = [
  {
    id: 'r1', handle: 'acorn-37', rel: 'friend', age: '6m',
    body: 'Is there such a thing as a moral fact, or is morality always relative to the thinker?',
    branches: 38, leaves: 412, activeNow: 12, hot: true,
  },
  {
    id: 'r2', handle: 'fern-12', rel: 'stranger', age: '14m',
    body: 'Why do we trust intuitions about edge cases more than the pattern they sit inside?',
    branches: 9, leaves: 47, activeNow: 3, hot: false,
  },
  {
    id: 'r3', handle: 'samh', rel: 'friend', age: '1h',
    body: 'What if "free will" is just the residue we leave when we stop watching ourselves choose?',
    branches: 22, leaves: 211, activeNow: 8, hot: true,
  },
  {
    id: 'r4', handle: 'oakling', rel: 'acquaintance', age: '3h',
    body: 'Re-reading Parfit — does anyone else find personal identity arguments more devastating with age?',
    branches: 14, leaves: 96, activeNow: 2, hot: false,
  },
  {
    id: 'r5', handle: 'birch-7', rel: 'friend', age: '5h',
    body: 'On what grounds do we owe future people anything? Genuinely asking — I keep flipping.',
    branches: 31, leaves: 287, activeNow: 5, hot: true,
  },
  {
    id: 'r6', handle: 'tulip-aa', rel: 'stranger', age: '8h',
    body: '"The unexamined life is not worth living" — does anyone actually believe this without irony?',
    branches: 6, leaves: 22, activeNow: 1, hot: false,
  },
  {
    id: 'r7', handle: 'leaf-902', rel: 'stranger', age: '11h',
    body: 'Are aesthetic judgments a kind of moral judgment, or a different beast entirely?',
    branches: 4, leaves: 19, activeNow: 0, hot: false,
  },
];

// A drilled-in thread — the reddit-style breakdown view.
// Children are nested. Each node has its own branches/leaves count.
const PHILOSOPHY_THREAD = {
  root: PHILOSOPHY_ROOTS[0],
  children: [
    {
      id: 'c1', handle: 'marina_k', rel: 'acquaintance', age: '5m',
      body: "Hard to argue 'facts' when intuitions diverge across cultures. Even basic ones.",
      branches: 4, leaves: 28,
      children: [
        {
          id: 'c1a', handle: 'leaf-902', rel: 'stranger', age: '4m',
          body: "Same was true of physical claims before we agreed on measurement. Doesn't mean they aren't facts.",
          branches: 1, leaves: 11,
          children: [
            {
              id: 'c1ai', handle: 'samh', rel: 'friend', age: '3m',
              body: 'Are you saying morality might converge with sustained dialogue, then?',
              branches: 0, leaves: 3, children: [],
            },
          ],
        },
        {
          id: 'c1b', handle: 'fern-12', rel: 'stranger', age: '3m',
          body: 'Some moral claims feel inescapable; others read more like preferences. Maybe both.',
          branches: 0, leaves: 4, children: [],
        },
      ],
    },
    {
      id: 'c2', handle: 'oakling', rel: 'acquaintance', age: '2m',
      body: "The 'thinker' is doing a lot of work in your framing. Whose thinker? Trained by which century?",
      branches: 2, leaves: 17, children: [],
    },
  ],
};

// The user's forests — used in the forest tab list view.
const YOUR_FORESTS = [
  { id: 'phi', name: 'Philosophy',   kind: 'public',  members: 1842, growing: 23, activeNow: 41, unread: 7,
    blurb: 'on moral facts, free will, and futures.' },
  { id: 'bart', name: 'BART Riders',  kind: 'public', members: 6_271, growing: 58, activeNow: 112, unread: 2,
    blurb: 'delays, etiquette, the long ride home.' },
  { id: 'film', name: 'Indie Film',  kind: 'invite', members: 432,  growing: 9,  activeNow: 8,   unread: 0,
    blurb: 'screenings, scripts, half-formed reviews.' },
  { id: 'sf',   name: 'SF',          kind: 'public', members: 12_904, growing: 87, activeNow: 204, unread: 14,
    blurb: 'the city, in all its moods.' },
  { id: 'pers', name: 'samh + you',  kind: 'private', members: 2,    growing: 1,  activeNow: 1,   unread: 0,
    blurb: 'private · still.' },
  { id: 'lit',  name: 'Slow Reading',kind: 'invite', members: 211,  growing: 4,  activeNow: 2,   unread: 0,
    blurb: 'one chapter a week, no rush.' },
];

// ─── Helpers ────────────────────────────────────────────────

function fmtBig(n) {
  if (n >= 1000) return (n / 1000).toFixed(n >= 10000 ? 0 : 1) + 'k';
  return String(n);
}

// Relationship dot — encodes the leaf-planter's social proximity to you.
function RelDot({ rel = 'stranger', size = 8 }) {
  const m = {
    friend: '#5E8048', acquaintance: '#A8C5A0', stranger: '#586552', close: '#D4960C',
  };
  return (
    <span style={{
      display: 'inline-block', width: size, height: size, borderRadius: '50%',
      background: m[rel], flexShrink: 0,
    }}/>
  );
}

function RelPill({ rel }) {
  if (rel === 'stranger') {
    return (
      <span style={{
        font: '500 10px var(--font-sans)', color: '#8A9678',
        padding: '1px 7px', background: '#1A2812',
        border: '0.5px solid #2D3A22', borderRadius: 999,
        letterSpacing: '0.02em',
      }}>Stranger</span>
    );
  }
  if (rel === 'acquaintance') {
    return (
      <span style={{
        font: '500 10px var(--font-sans)', color: '#A8C5A0',
        padding: '1px 7px', background: 'rgba(168,197,160,0.06)',
        border: '0.5px solid rgba(168,197,160,0.18)', borderRadius: 999,
      }}>Acquaintance</span>
    );
  }
  if (rel === 'friend') {
    return (
      <span style={{
        font: '500 10px var(--font-sans)', color: '#C9D2BB',
        padding: '1px 7px', background: 'rgba(94,128,72,0.18)',
        border: '0.5px solid #5E8048', borderRadius: 999,
      }}>Friend</span>
    );
  }
  return null;
}

// "Active now" status — small green dot + count.
function LivePulse({ count = 0, size = 8 }) {
  if (!count) return null;
  return (
    <span style={{ display: 'inline-flex', alignItems: 'center', gap: 5 }}>
      <span style={{ position: 'relative', width: size, height: size }}>
        <span style={{
          position: 'absolute', inset: 0, borderRadius: '50%',
          background: '#4F8E51',
          boxShadow: '0 0 0 3px rgba(79,142,81,0.20)',
          animation: 'livepulse 2.4s var(--ease-organic) infinite',
        }}/>
      </span>
      <span style={{ font: '500 11px var(--font-mono)', color: '#A8C5A0' }}>{count}</span>
    </span>
  );
}

// ─── exports ───
Object.assign(window, {
  PHILOSOPHY_ROOTS, PHILOSOPHY_THREAD, YOUR_FORESTS,
  fmtBig, RelDot, RelPill, LivePulse,
});
