// ============================================================
// FitMinds — Shared data + helpers
// ============================================================

// ---------- SCHOOLS ----------
const SCHOOLS = [
  { id: "sj",  name: "St Joseph's PS",         short: "SJ", address: "Ballymena, Co. Antrim",     contact: "Mrs Laura Byrne",    email: "l.byrne@stjosephsps.org",  phone: "028 9066 2140", color: "#E8724F", bookings: 4, lifetime: 2400 },
  { id: "hc",  name: "Holy Cross NS",          short: "HC", address: "Belfast, BT14",             contact: "Mr Declan Farrell",  email: "d.farrell@holycross.sch.uk",phone: "028 9035 1827", color: "#5BAA86", bookings: 3, lifetime: 1800 },
  { id: "co",  name: "Carnmoney Primary",      short: "CM", address: "Newtownabbey, BT36",        contact: "Ms Siobhan Doyle",   email: "s.doyle@carnmoneyps.net",  phone: "028 9084 3319", color: "#D6A24A", bookings: 5, lifetime: 3100 },
  { id: "gn",  name: "Glengormley IPS",        short: "GN", address: "Newtownabbey, BT36",        contact: "Mr Peter Kane",      email: "p.kane@glengormleyips.net", phone: "028 9083 8821", color: "#8C6FC7", bookings: 2, lifetime: 900  },
  { id: "bf",  name: "Braidside IPS",          short: "BR", address: "Ballymena, BT43",           contact: "Ms Aoife McGrath",   email: "a.mcgrath@braidside.net",  phone: "028 2565 4491", color: "#3F7FB8", bookings: 1, lifetime: 450  },
  { id: "ln",  name: "Linn PS",                short: "LN", address: "Larne, BT40",               contact: "Mrs Eileen Quinn",   email: "e.quinn@linnps.org",       phone: "028 2827 1903", color: "#C96794", bookings: 6, lifetime: 3600 },
];

// ---------- BOOKINGS ----------
// Each booking = a multi-week block.  startDate is ISO (Mon).  weeks = 1..n.
const BOOKINGS = [
  { id: "b001", schoolId: "sj", title: "P4–P5 Movement Block",  start: "2026-04-13", weeks: 6, daysOfWeek: [1], time: "10:00", duration: 45, sessionsPerWeek: 1, pricePerSession: 50, totalPrice: 300, status: "active",    currentWeek: 2, invoiceStatus: "sent",     notes: "Focus on coordination & balance." },
  { id: "b002", schoolId: "hc", title: "Icebreaker Games",      start: "2026-04-20", weeks: 4, daysOfWeek: [2], time: "13:30", duration: 40, sessionsPerWeek: 1, pricePerSession: 55, totalPrice: 220, status: "active",    currentWeek: 1, invoiceStatus: "draft",    notes: "Group engagement for Primary 3." },
  { id: "b003", schoolId: "co", title: "PE Skill Development",  start: "2026-03-02", weeks: 8, daysOfWeek: [3], time: "09:15", duration: 50, sessionsPerWeek: 1, pricePerSession: 50, totalPrice: 400, status: "active",    currentWeek: 7, invoiceStatus: "paid",     notes: "Gross motor + team play." },
  { id: "b004", schoolId: "gn", title: "Inclusive Movement",    start: "2026-05-04", weeks: 6, daysOfWeek: [4], time: "11:00", duration: 45, sessionsPerWeek: 1, pricePerSession: 55, totalPrice: 330, status: "upcoming",  currentWeek: 0, invoiceStatus: "not_sent", notes: "Mixed-ability groups." },
  { id: "b005", schoolId: "ln", title: "P6–P7 Games Block",     start: "2026-02-10", weeks: 6, daysOfWeek: [5], time: "14:00", duration: 45, sessionsPerWeek: 1, pricePerSession: 50, totalPrice: 300, status: "completed", currentWeek: 6, invoiceStatus: "paid",     notes: "Completed — repeat booking likely." },
  { id: "b006", schoolId: "bf", title: "Move Along Sessions",   start: "2026-04-23", weeks: 3, daysOfWeek: [5], time: "10:15", duration: 40, sessionsPerWeek: 1, pricePerSession: 50, totalPrice: 150, status: "active",    currentWeek: 1, invoiceStatus: "not_sent", notes: "Short pilot." },
  { id: "b007", schoolId: "co", title: "P1 Fundamentals",       start: "2026-04-15", weeks: 4, daysOfWeek: [3], time: "10:45", duration: 30, sessionsPerWeek: 1, pricePerSession: 45, totalPrice: 180, status: "active",    currentWeek: 2, invoiceStatus: "sent",     notes: "Youngest age group." },
];

// ---------- INVOICES ----------
const INVOICES = [
  { id: "INV-2026-014", bookingId: "b003", schoolId: "co", issued: "2026-03-09", due: "2026-04-08", total: 400, status: "paid",    paidOn: "2026-03-22" },
  { id: "INV-2026-018", bookingId: "b001", schoolId: "sj", issued: "2026-04-13", due: "2026-05-13", total: 300, status: "sent",    paidOn: null },
  { id: "INV-2026-019", bookingId: "b007", schoolId: "co", issued: "2026-04-15", due: "2026-05-15", total: 180, status: "sent",    paidOn: null },
  { id: "INV-2026-012", bookingId: "b005", schoolId: "ln", issued: "2026-02-10", due: "2026-03-10", total: 300, status: "paid",    paidOn: "2026-02-28" },
  { id: "INV-2026-020", bookingId: "b002", schoolId: "hc", issued: null,         due: null,         total: 220, status: "draft",   paidOn: null },
];

// ---------- ENQUIRIES ----------
const ENQUIRIES = [
  { id: "e01", name: "Mrs Cara Montgomery", org: "Rathcoole Primary",     email: "c.montgomery@rathcoole.net", phone: "028 9085 2011", date: "2026-04-19", stage: "new",       message: "Looking for a 6-week block for P4-P5. Starting May?", children: null },
  { id: "e02", name: "Mr Oisin Reilly",     org: "Parent",                email: "oisin.reilly@gmail.com",      phone: "077 4411 2882", date: "2026-04-18", stage: "new",       message: "My son (8) has ADHD. Do you do one-to-one?",    children: 1 },
  { id: "e03", name: "Ms Fiona Lavery",     org: "Ballyclare NS",         email: "f.lavery@ballyclarens.org",  phone: "028 9334 1290", date: "2026-04-17", stage: "contacted", message: "Interested in icebreaker games for autumn term.", children: null },
  { id: "e04", name: "Mr Sean Corrigan",    org: "Whiteabbey Primary",    email: "s.corrigan@whiteabbey.net",  phone: "028 9085 7712", date: "2026-04-15", stage: "qualified", message: "Discussed 8-week block on the phone — sending quote.", children: null },
  { id: "e05", name: "Mrs Jenna Toal",      org: "Mossgrove IPS",         email: "j.toal@mossgrove.org",       phone: "028 9335 2261", date: "2026-04-12", stage: "booked",    message: "Converted to booking — see b004.", children: null },
  { id: "e06", name: "Mrs Deborah Wilson",  org: "Parent",                email: "deb.wilson@live.co.uk",       phone: "077 3390 5521", date: "2026-04-10", stage: "lost",      message: "Out of catchment — referred onwards.", children: 2 },
];

// ---------- CONTENT (videos) ----------
const VIDEO_CATEGORIES = [
  { id: "parents",  label: "For Parents",           icon: "heart",     count: 14, color: "coral" },
  { id: "teachers", label: "For Teachers & Coaches",icon: "graduation-cap", count: 22, color: "mint"  },
  { id: "ice",      label: "Icebreaker Games",     icon: "sparkles",  count:  9, color: "sun"   },
  { id: "move",     label: "Move Along with Ronan",icon: "activity",  count: 18, color: "lilac" },
];

const VIDEOS = [
  { id: "v01", title: "The Animal Walks Warm-up",     cat: "parents",  duration: "4:12", views: 312, coach: "Coach Ronan", art: 1, level: "All ages" },
  { id: "v02", title: "Red Light / Green Light+",     cat: "ice",      duration: "2:45", views: 488, coach: "Coach Ronan", art: 2, level: "KS1" },
  { id: "v03", title: "Building Balance at Home",     cat: "parents",  duration: "6:30", views: 204, coach: "Coach Ronan", art: 3, level: "5–7 yrs" },
  { id: "v04", title: "PE Session Plan: Invasion",    cat: "teachers", duration: "9:18", views: 156, coach: "Coach Ronan", art: 4, level: "KS2" },
  { id: "v05", title: "Move Along: Jungle Adventure", cat: "move",     duration: "8:05", views: 672, coach: "Coach Ronan", art: 5, level: "All ages" },
  { id: "v06", title: "Fine Motor Movers",            cat: "parents",  duration: "5:10", views: 290, coach: "Coach Ronan", art: 6, level: "4–6 yrs" },
  { id: "v07", title: "Name Game Tag",                cat: "ice",      duration: "3:22", views: 401, coach: "Coach Ronan", art: 7, level: "All ages" },
  { id: "v08", title: "Inclusive Relay Formats",      cat: "teachers", duration: "7:44", views: 188, coach: "Coach Ronan", art: 8, level: "KS1–KS2" },
  { id: "v09", title: "Move Along: Under the Sea",    cat: "move",     duration: "7:15", views: 540, coach: "Coach Ronan", art: 1, level: "All ages" },
  { id: "v10", title: "Calm-Down Cool-Down",          cat: "parents",  duration: "4:50", views: 278, coach: "Coach Ronan", art: 2, level: "All ages" },
  { id: "v11", title: "Regulation Through Movement",  cat: "teachers", duration:"11:02", views: 112, coach: "Coach Ronan", art: 3, level: "SEN focus" },
  { id: "v12", title: "Move Along: Space Mission",    cat: "move",     duration: "8:32", views: 605, coach: "Coach Ronan", art: 4, level: "All ages" },
];

// Art backgrounds for video thumbs — procedural gradients, no images needed.
const THUMB_ART = [
  "radial-gradient(ellipse at 20% 30%, #ffd4a8 0%, transparent 55%), radial-gradient(ellipse at 80% 70%, #e8724f 0%, transparent 60%), linear-gradient(135deg, #ffb98a, #e65a3f)",
  "radial-gradient(ellipse at 80% 20%, #b5e6d1 0%, transparent 55%), radial-gradient(ellipse at 20% 80%, #5baa86 0%, transparent 60%), linear-gradient(135deg, #86d6b3, #3f8a6a)",
  "radial-gradient(ellipse at 30% 30%, #f7d89a 0%, transparent 55%), radial-gradient(ellipse at 75% 75%, #d6a24a 0%, transparent 60%), linear-gradient(135deg, #f0c978, #b88534)",
  "radial-gradient(ellipse at 25% 25%, #cfbce8 0%, transparent 55%), radial-gradient(ellipse at 75% 75%, #8c6fc7 0%, transparent 60%), linear-gradient(135deg, #b39dd9, #6b52a8)",
  "radial-gradient(ellipse at 70% 20%, #9cc6ec 0%, transparent 55%), radial-gradient(ellipse at 30% 80%, #3f7fb8 0%, transparent 60%), linear-gradient(135deg, #78abda, #2b6599)",
  "radial-gradient(ellipse at 80% 30%, #f3b7ce 0%, transparent 55%), radial-gradient(ellipse at 20% 70%, #c96794 0%, transparent 60%), linear-gradient(135deg, #eb98bc, #a4517a)",
  "radial-gradient(ellipse at 30% 25%, #ffe7a8 0%, transparent 55%), radial-gradient(ellipse at 70% 80%, #e8a64f 0%, transparent 60%), linear-gradient(135deg, #f5cd7a, #c07f2f)",
  "radial-gradient(ellipse at 75% 25%, #a8e7dc 0%, transparent 55%), radial-gradient(ellipse at 25% 75%, #4aa89a 0%, transparent 60%), linear-gradient(135deg, #86cfc1, #358077)",
];

// ---------- USERS ----------
const USERS = [
  { id: "u01", name: "Ronan Gallagher",  role: "Super Admin",   email: "ronan@fitmindscoach.com",  status: "active",   lastActive: "Today",        content: null,   avatar: "RG" },
  { id: "u02", name: "Aoife Gallagher",  role: "Team Admin",    email: "aoife@fitmindscoach.com",  status: "active",   lastActive: "Yesterday",    content: null,   avatar: "AG" },
  { id: "u03", name: "Laura Byrne",      role: "Teacher",       email: "l.byrne@stjosephsps.org",  status: "active",   lastActive: "2 days ago",   content: 42,    avatar: "LB" },
  { id: "u04", name: "Declan Farrell",   role: "Teacher",       email: "d.farrell@holycross.sch.uk",status:"active",   lastActive: "Today",        content: 18,    avatar: "DF" },
  { id: "u05", name: "Sarah Mulligan",   role: "Parent",        email: "sarah.m@gmail.com",         status: "active",  lastActive: "4 days ago",   content: 24,    avatar: "SM" },
  { id: "u06", name: "Michael Jameson",  role: "Parent",        email: "mjameson@outlook.com",      status: "active",  lastActive: "Today",        content: 8,     avatar: "MJ" },
  { id: "u07", name: "Siobhan Doyle",    role: "Teacher",       email: "s.doyle@carnmoneyps.net",   status: "invited", lastActive: "—",            content: 0,     avatar: "SD" },
];

// ---------- AUTH USERS (test logins) ----------
// Prototype auth — plain-text passwords stored client-side. NOT secure.
// Only here to gate the demo behind a simple login while the site is in progress.
const AUTH_USERS = [
  { email: "coach@fitminds.test",  password: "fitminds2026", role: "admin",  name: "Coach Ronan",    avatar: "RG" },
  { email: "admin@fitminds.test",  password: "fitminds2026", role: "super",  name: "Super Admin",    avatar: "SA" },
  { email: "parent@fitminds.test", password: "fitminds2026", role: "client", name: "Sarah Mulligan", avatar: "SM" },
];
const AUTH_ROLE_LABELS = { admin: "Coach", super: "Super Admin", client: "Parent / Teacher" };

// ---------- HELPERS ----------
const SCHOOL_BY_ID = Object.fromEntries(SCHOOLS.map(s => [s.id, s]));
const BOOKING_BY_ID = Object.fromEntries(BOOKINGS.map(b => [b.id, b]));
const EVT_COLORS = ["evt-coral", "evt-mint", "evt-sun", "evt-lilac"];
function schoolEvtClass(schoolId) {
  const idx = SCHOOLS.findIndex(s => s.id === schoolId);
  return EVT_COLORS[idx % EVT_COLORS.length];
}
function money(n) { return "£" + Number(n).toLocaleString("en-GB", { minimumFractionDigits: 0, maximumFractionDigits: 0 }); }
function fmtDate(iso) {
  if (!iso) return "—";
  const [y, m, d] = iso.split("-").map(Number);
  const dt = new Date(Date.UTC(y, m - 1, d));
  return dt.toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric" });
}
function fmtDateShort(iso) {
  if (!iso) return "—";
  const [y, m, d] = iso.split("-").map(Number);
  const dt = new Date(Date.UTC(y, m - 1, d));
  return dt.toLocaleDateString("en-GB", { day: "2-digit", month: "short" });
}
function addWeeks(iso, weeks) {
  const [y, m, d] = iso.split("-").map(Number);
  const dt = new Date(Date.UTC(y, m - 1, d));
  dt.setUTCDate(dt.getUTCDate() + weeks * 7);
  return dt.toISOString().slice(0, 10);
}

// Lucide icon helper
const Icon = ({ name, style, size = 16 }) => (
  <i data-lucide={name} style={{ width: size, height: size, display: "inline-flex", ...style }}></i>
);

Object.assign(window, {
  SCHOOLS, BOOKINGS, INVOICES, ENQUIRIES, VIDEO_CATEGORIES, VIDEOS, USERS, THUMB_ART,
  AUTH_USERS, AUTH_ROLE_LABELS,
  SCHOOL_BY_ID, BOOKING_BY_ID, schoolEvtClass, money, fmtDate, fmtDateShort, addWeeks, Icon,
});
