/* ==========================================================
   data.jsx — client-side constants.

   In Stage 1 this file held the full seed data set (members,
   ideas, claim requests, comments, rankings) and the React app
   read everything from it directly.

   In Stage 2 the seed data lives in the database. This file
   now holds only:
     - THEMES, STAGES        — UI enumerations
     - LIBRARY               — static reference articles (the
                               background-reading section is
                               authored copy, not user content)
     - MEMBER_BY_ID / MEMBERS / IDEAS placeholders
                             — empty arrays/objects until the
                               app populates them from /api on
                               mount, so components that read
                               window.OB_DATA.MEMBER_BY_ID never
                               see undefined.
   ========================================================== */

const THEMES = [
  'Performance & Arts',
  'Community & Social',
  'Sport & Activity',
  'Youth',
  'Heritage',
  'Infrastructure'
];

const STAGES = ['Proposed', 'In Discussion', 'Under Consideration', 'In Development', 'Decided', 'Archived'];

const LIBRARY = [
  { id: 'foliot', cat: 'St Katherine\u2019s', title: 'Hugh Foliot and the founding gift',
    teaser: 'In 1232 a bishop endowed a hospital at Ledbury \u2014 land, building, dedication. Eight hundred years on, the gift still holds.' },
  { id: 'heritage', cat: 'St Katherine\u2019s', title: 'Eight hundred years of welcome',
    teaser: 'The hall has been a chapel, a hostelry for travellers, a school, a meeting place. A short history of the precinct.' },
  { id: 'plan', cat: 'The building', title: 'The chapel, the hall, and the mezzanine',
    teaser: 'One long thirteenth-century range \u2014 chapel to the east, hall to the west, and the mezzanine we hope to build.' },
  { id: 'hospital', cat: 'Concept', title: 'Reimagining the medieval hospital',
    teaser: 'Hospes \u2014 guest and host. The hospital before it became a hospital. Why this matters now.' },
  { id: 'mission', cat: 'LEAF', title: 'LEAF\u2019s mission and village approach',
    teaser: 'Locally Encouraging All to Flourish. What we mean by flourishing, and why we work village by village.' },
  { id: 'ownership', cat: 'How we work', title: 'Proposing, claiming, owning \u2014 how an idea moves',
    teaser: 'Why anyone can suggest an idea, but ownership is something a member chooses to take on \u2014 and what that means.' },
  { id: 'ranking', cat: 'How we work', title: 'On ranking \u2014 and what it is not',
    teaser: 'You will be asked to rank ideas by Need and Practicality. This is not voting. Here\u2019s what it is.' },
  { id: 'host', cat: 'How we work', title: 'LEAF as host, not chair',
    teaser: 'How decisions are made, and why the host role protects the welcome of this space.' }
];

/* MEMBERS / IDEAS / MEMBER_BY_ID start empty and are filled by app.jsx
   from the API on boot. Keep the keys present so screens that do
   `window.OB_DATA.MEMBER_BY_ID[x]` don't blow up before the first
   fetch resolves. */
window.OB_DATA = {
  MEMBERS: [],
  MEMBER_BY_ID: {},
  THEMES,
  STAGES,
  IDEAS: [],
  LIBRARY
};

/* Populate the members map from a server response. Called from
   app.jsx after `api.listMembers()`. Always include a synthetic
   'leaf' system identity so LEAF responses can be attributed to
   "LEAF" without picking a single person. */
window.setMembers = function setMembers(members) {
  const all = [
    { id: 'leaf', name: 'LEAF', first: 'LEAF', last: '', role: 'Host',
      bio: 'Locally Encouraging All to Flourish. Stewards of St Katherine\u2019s Hall.',
      isLeaf: true },
    ...members
  ];
  window.OB_DATA.MEMBERS = all;
  window.OB_DATA.MEMBER_BY_ID = Object.fromEntries(all.map(m => [m.id, m]));
};
