// Famspring summer 2026 — real roster from spreadsheet.

const SLOTS = [
  { id: 0, label: "Slot 1", time: "9:00–12:00" },
  { id: 1, label: "Slot 2", time: "1:00–3:30" },
  { id: 2, label: "Slot 3", time: "4:00–6:30" },
];

const DAYS = [
  { id: "mon", label: "Mon" },
  { id: "tue", label: "Tue" },
  { id: "wed", label: "Wed" },
  { id: "thu", label: "Thu" },
  { id: "fri", label: "Fri" },
];

const LOCATIONS = [
  { id: "east",   label: "East",   short: "East" },
  { id: "west",   label: "West",   short: "West" },
  { id: "clinic", label: "Clinic", short: "Clinic" },
  { id: "ucis",   label: "UCIS",   short: "UCIS" },
];

// Summer 2026 — 12 weeks, Mondays starting Jun 15
const WEEKS = (() => {
  const start = new Date(2026, 5, 15);
  const out = [];
  const months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
  for (let i = 0; i < 12; i++) {
    const d = new Date(start);
    d.setDate(d.getDate() + i * 7);
    out.push({ id: i, label: `${months[d.getMonth()]} ${d.getDate()}`, month: months[d.getMonth()], day: d.getDate(), iso: d.toISOString().slice(0,10) });
  }
  return out;
})();

// loc is an array — a person can serve multiple locations.
const CLIENTS = [
  { id: "c01", name: "Vishva Krishnan",       short: "ViKr", loc: ["clinic"] },
  { id: "c02", name: "Ravi Santhanakrishnan", short: "RaSa", loc: ["west"] },
  { id: "c03", name: "Nandini Singh",         short: "NaSi", loc: ["clinic"] },
  { id: "c04", name: "Mihil Agrawal",         short: "MiAg", loc: ["east"] },
  { id: "c05", name: "Hafsa Sharjeel",        short: "HaSh", loc: ["clinic"] },
  { id: "c06", name: "Emma Cho",              short: "EmCh", loc: ["ucis", "clinic"] },
  { id: "c07", name: "Dhwani Murthy",         short: "DwMu", loc: ["clinic"] },
  { id: "c08", name: "Dhruva Murthy",         short: "DhMu", loc: ["clinic"] },
  { id: "c09", name: "Clair Choe",            short: "ClCh", loc: ["west"] },
  { id: "c10", name: "Ayushman Pradhan",      short: "AyPr", loc: ["east"] },
  { id: "c11", name: "Aryanshi Praharaj",     short: "ArPr", loc: ["east"] },
  { id: "c12", name: "Arjun Krishnan",        short: "ArKr", loc: ["east"] },
  { id: "c13", name: "Advait Goacher",        short: "AdGo", loc: ["clinic"] },
  { id: "c14", name: "Carlos Lagos",          short: "CaLa", loc: ["west"] },
  { id: "c15", name: "Modou Conteh",          short: "MoCo", loc: ["clinic"] },
  { id: "c16", name: "Vedant Aiyar",          short: "VeAi", loc: ["clinic"] },
  { id: "c17", name: "Evelyn Giaime",         short: "EvGi", loc: ["clinic"] },
  { id: "c18", name: "Samay Bavalatti",       short: "SaBa", loc: ["clinic"] },
  { id: "c19", name: "Arman Lazaryan",        short: "ArLa", loc: ["clinic"] },
];

const THERAPISTS = [
  { id: "t01", name: "Kaitlin Fischl",     short: "KF", title: "BT",   loc: ["west", "clinic"] },
  { id: "t02", name: "Hafsa Shire",        short: "HS", title: "BCBA", loc: ["east"] },
  { id: "t03", name: "Mbumba Banda",       short: "MJ", title: "BT",   loc: ["east"] },
  { id: "t04", name: "Jennifer Meier",     short: "JM", title: "BT",   loc: ["west", "clinic"] },
  { id: "t05", name: "Ahlam Dubad",        short: "AD", title: "BT",   loc: ["west", "east", "clinic"] },
  { id: "t06", name: "Liuda Vavryshchuk",  short: "LV", title: "BT",   loc: ["clinic"] },
  { id: "t07", name: "Nahomie Tesfaye",    short: "NT", title: "BT",   loc: ["west", "clinic"] },
  { id: "t08", name: "Nirupama Madhavan",  short: "NM", title: "BCBA", loc: ["west", "clinic"] },
  { id: "t09", name: "Chaman Dhaliwal",    short: "CD", title: "BCBA", loc: ["clinic"] },
  { id: "t10", name: "Jhenine Agbuya",     short: "JA", title: "BT",   loc: ["clinic", "ucis"] },
  { id: "t11", name: "Mausami Darjee",     short: "MD", title: "BT",   loc: ["clinic", "east"] },
  { id: "t12", name: "Gabriela Garcia",    short: "GG", title: "BCBA", loc: ["west", "clinic"] },
  { id: "t13", name: "Anahita Pirouzmand", short: "AP", title: "BCBA", loc: ["east"] },
];

function locOverlap(a, b) {
  const la = Array.isArray(a) ? a : [a];
  const lb = Array.isArray(b) ? b : [b];
  return la.some(l => lb.includes(l));
}

function seedRand(seed) {
  let s = seed;
  return () => { s = (s * 1664525 + 1013904223) % 4294967296; return s / 4294967296; };
}

function genAvailability(people, baseSeed, density) {
  const out = {};
  for (const p of people) {
    out[p.id] = {};
    const baseRand = seedRand(baseSeed + p.id.charCodeAt(1) * 17 + p.id.charCodeAt(2) * 31);
    const basePattern = {};
    for (const d of DAYS) basePattern[d.id] = SLOTS.map(() => baseRand() < density);
    for (const w of WEEKS) {
      const weekRand = seedRand(baseSeed * 7 + w.id * 13 + p.id.charCodeAt(2));
      const isVacation = weekRand() < 0.06;
      const wk = {};
      for (const d of DAYS) {
        wk[d.id] = isVacation ? SLOTS.map(() => false) : basePattern[d.id].map(b => weekRand() < 0.08 ? !b : b);
      }
      out[p.id][w.id] = wk;
    }
  }
  return out;
}

const CLIENT_AVAIL    = genAvailability(CLIENTS, 1001, 0.42);
const THERAPIST_AVAIL = genAvailability(THERAPISTS, 2024, 0.55);

const PAIRINGS = (() => {
  const out = {};
  const rand = seedRand(7777);
  for (const c of CLIENTS) {
    const same  = THERAPISTS.filter(t =>  locOverlap(c.loc, t.loc));
    const other = THERAPISTS.filter(t => !locOverlap(c.loc, t.loc));
    const shuffled = [...same].sort(() => rand() - 0.5);
    const count = 2 + Math.floor(rand() * 3);
    const list = shuffled.slice(0, count).map(t => t.id);
    if (rand() < 0.3 && other.length > 0) list.push(other[Math.floor(rand() * other.length)].id);
    out[c.id] = list;
  }
  return out;
})();

function getLoc(id)       { return LOCATIONS.find(l => l.id === id); }
function getClient(id)    { return CLIENTS.find(c => c.id === id); }
function getTherapist(id) { return THERAPISTS.find(t => t.id === id); }

window.FS_DATA = {
  SLOTS, DAYS, LOCATIONS, WEEKS,
  CLIENTS, THERAPISTS,
  CLIENT_AVAIL, THERAPIST_AVAIL,
  PAIRINGS,
  locOverlap,
  getLoc, getClient, getTherapist,
  setClients(list)    { const copy = [...list]; CLIENTS.length    = 0; for (const c of copy) CLIENTS.push(c); },
  setTherapists(list) { const copy = [...list]; THERAPISTS.length = 0; for (const t of copy) THERAPISTS.push(t); },
};
