/* search-data.jsx — Brewly users for search + discovery. Exports to window.
   postsByUser() merges any FEED posts authored by the user with their extras. */

const USERS = [
  {
    handle: '@oat_milk_oracle', name: 'oat milk oracle', avatar: 'assets/avatars/av3.png',
    bio: 'predicting drama before it happens · barista by day, prophet by night ☕🔮', verified: false,
    stats: { brews: 312, paps: 8400, stakeout: 290 }, following: true,
    extra: [
      { id: 'o1', kind: 'tea', time: '3h', body: "told you the library would be packed. i am never wrong. screenshot this.", sips: 540, splash: 60, takes: 33, whispers: 5 },
      { id: 'o2', kind: 'tea', time: '1d', body: "oat milk is just bean juice with a marketing degree and i will NOT be taking questions", sips: 1900, splash: 210, takes: 88, whispers: 12 },
    ],
  },
  {
    handle: '@frothing', name: 'frothing', avatar: 'assets/avatars/av6.png',
    bio: 'i was there. i saw it. i have receipts 🧾 · certified Kettle menace', verified: false,
    stats: { brews: 540, paps: 22100, stakeout: 180 }, following: false,
    extra: [
      { id: 'fr1', kind: 'tea', time: '5h', body: "the group chat is NOT ready for what i just witnessed in the library cafe", sips: 3200, splash: 880, takes: 240, whispers: 61 },
    ],
  },
  {
    handle: '@chai_minded', name: 'chai minded', avatar: 'assets/avatars/av4.png',
    bio: 'overthinking, but make it aesthetic · she/her · 87% caffeine', verified: false,
    stats: { brews: 198, paps: 3100, stakeout: 410 }, following: true,
    extra: [
      { id: 'ch1', kind: 'tea', time: '8h', body: "'per my last email' is the most violent phrase in the english language and i said what i said", sips: 2300, splash: 320, takes: 140, whispers: 6 },
    ],
  },
  {
    handle: '@espresso_yourself', name: 'espresso yourself', avatar: 'assets/avatars/av5.png',
    bio: 'shots taken: emotional & espresso · romanticizing my villain era', verified: false,
    stats: { brews: 421, paps: 5600, stakeout: 333 }, following: false,
    extra: [
      { id: 'es1', kind: 'tea', time: '7h', body: "day 2 of the 5am routine: i have become the very darkness i sought to conquer", sips: 1500, splash: 110, takes: 88, whispers: 4 },
    ],
  },
  {
    handle: '@latteludite', name: 'latte ludite', avatar: 'assets/avatars/av2.png',
    bio: 'against technology, on the internet, ironically · book hoarder', verified: false,
    stats: { brews: 87, paps: 1200, stakeout: 512 }, following: false,
    extra: [
      { id: 'la1', kind: 'tea', time: '2d', body: "deleted all my apps for clarity. redownloaded them for the drama. balance.", sips: 760, splash: 54, takes: 40, whispers: 2 },
    ],
  },
  {
    handle: '@thewire.tech', name: 'TechWire', avatar: 'assets/avatars/av2.png',
    bio: 'verified tech news, rewritten so it actually makes sense ✦ part of The Wire', verified: true,
    stats: { brews: 2400, paps: 184000, stakeout: 12 }, following: true, extra: [],
  },
  {
    handle: '@thewire.green', name: 'GreenWire', avatar: 'assets/avatars/av4.png',
    bio: 'climate & science, verified & sourced ✦ occasionally good news', verified: true,
    stats: { brews: 1800, paps: 142000, stakeout: 9 }, following: false, extra: [],
  },
  {
    handle: '@claw.daily', name: 'Brewly Daily', avatar: 'assets/avatars/av5.png',
    bio: 'your morning brief, brewed by AI · always disclosed, never human 🤖', claw: true, verified: false,
    stats: { brews: 980, paps: 51000, stakeout: 0 }, following: true, extra: [],
  },
];

const TRENDING = ['#FoldGate', '#LibraryCore', '#Slide14', '#OceanWin', '#PerMyLastEmail', '#5amFail'];

function postsByUser(handle) {
  const feedPosts = (typeof FEED !== 'undefined' ? FEED : []).filter((p) => p.author.handle === handle);
  const u = USERS.find((x) => x.handle === handle);
  const extras = (u && u.extra) ? u.extra.map((e) => ({ ...e, author: { name: u.name, handle: u.handle, avatar: u.avatar }, kind: e.kind || 'tea' })) : [];
  return [...feedPosts, ...extras];
}

function searchUsers(q) {
  const s = (q || '').trim().toLowerCase().replace(/^@/, '');
  if (!s) return [];
  return USERS.filter((u) => u.name.toLowerCase().includes(s) || u.handle.toLowerCase().includes(s));
}

Object.assign(window, { USERS, TRENDING, postsByUser, searchUsers });
