// Academy view — extra mock data: branches, KPIs, leads, schedule grid

const TL_BRANCHES = [
  { id: 'tst',  name: 'Tsim Sha Tsui',     nameZh: '尖沙咀',     studios: 12, active: true },
  { id: 'cwb',  name: 'Causeway Bay',      nameZh: '銅鑼灣',     studios: 10 },
  { id: 'ssp',  name: 'Sham Shui Po',      nameZh: '深水埗',     studios: 8 },
  { id: 'kt',   name: 'Kwun Tong',         nameZh: '觀塘',       studios: 9 },
  { id: 'st',   name: 'Sha Tin',           nameZh: '沙田',       studios: 11 },
  { id: 'tw',   name: 'Tsuen Wan',         nameZh: '荃灣',       studios: 7 },
  { id: 'ty',   name: 'Tseung Kwan O',     nameZh: '將軍澳',     studios: 6 },
  { id: 'all',  name: 'All branches (HQ)', nameZh: '全部分行',   studios: 63, hq: true },
];

// Live snapshot for TST branch right now (Tue Apr 28, 14:48)
const TL_BRANCH_TODAY = {
  branchId: 'tst',
  asOf: '14:48',
  rooms: [
    { id: 'r1', name: 'Studio 1',  instrument: 'Piano',     status: 'occupied', teacher: 'Mr. Liu',          student: 'Felix Chow',       endsAt: '15:00' },
    { id: 'r2', name: 'Studio 2',  instrument: 'Piano',     status: 'occupied', teacher: 'Ms. Wong',         student: 'Olivia Yu',        endsAt: '15:15' },
    { id: 'r3', name: 'Studio 3',  instrument: 'Violin',    status: 'occupied', teacher: 'Mr. Cheung',       student: 'Marcus Wong',      endsAt: '15:00' },
    { id: 'r4', name: 'Studio 4',  instrument: 'Piano',     status: 'turnover', teacher: 'Ms. Chen Wai-Lam', student: null,               endsAt: null,    nextStart: '15:00', nextStudent: 'Sophie Lam' },
    { id: 'r5', name: 'Studio 5',  instrument: 'Cello',     status: 'occupied', teacher: 'Ms. Lo',           student: 'Chloe Tang',       endsAt: '15:30' },
    { id: 'r6', name: 'Studio 6',  instrument: 'Guitar',    status: 'empty',    teacher: null,               student: null,               endsAt: null,    nextStart: '15:30', nextStudent: 'Daniel Ip' },
    { id: 'r7', name: 'Studio 7',  instrument: 'Drums',     status: 'occupied', teacher: 'Mr. Tam',          student: 'Ethan Sze',        endsAt: '15:00' },
    { id: 'r8', name: 'Studio 8',  instrument: 'Saxophone', status: 'occupied', teacher: 'Mr. Lai',          student: 'Aiden Ho',         endsAt: '15:15' },
    { id: 'r9', name: 'Studio 9',  instrument: 'Flute',     status: 'occupied', teacher: 'Ms. Ng',           student: 'Isabella Mak',     endsAt: '15:00' },
    { id: 'r10', name: 'Studio 10', instrument: 'Piano',    status: 'empty',    teacher: null,               student: null,               endsAt: null,    nextStart: '16:00', nextStudent: 'Emily Cheung' },
    { id: 'r11', name: 'Studio 11', instrument: 'Voice',    status: 'occupied', teacher: 'Ms. Park',         student: 'Hayley Yip',       endsAt: '15:00' },
    { id: 'r12', name: 'Studio 12', instrument: 'Theory',   status: 'maint',    teacher: null,               student: null,               endsAt: null,    note: 'Aircon repair · back 16:00' },
  ],
  alerts: [
    { id: 'a1', kind: 'late',  text: 'Marcus Wong (Studio 3) — running 8 min over, parent waiting',           time: '14:45' },
    { id: 'a2', kind: 'noshow', text: 'Hayley Yip (Studio 11) — late arrival, lesson rescheduled',           time: '14:30' },
    { id: 'a3', kind: 'sub',   text: 'Mr. Liu covering Studio 1 for Ms. Chau (sick leave)',                  time: '13:00' },
  ],
};

// 6-month KPI trend (HQ view)
const TL_KPI_TREND = [
  { month: 'Nov',  revenue: 4.82, students: 2618, lessons: 9842,  trialConv: 0.41 },
  { month: 'Dec',  revenue: 5.14, students: 2654, lessons: 10103, trialConv: 0.43 },
  { month: 'Jan',  revenue: 5.36, students: 2701, lessons: 10287, trialConv: 0.44 },
  { month: 'Feb',  revenue: 5.41, students: 2748, lessons: 10412, trialConv: 0.46 },
  { month: 'Mar',  revenue: 5.62, students: 2789, lessons: 10534, trialConv: 0.47 },
  { month: 'Apr',  revenue: 5.88, students: 2834, lessons: 10721, trialConv: 0.49 },
];

// Branch league table (this month)
const TL_BRANCH_PERF = [
  { id: 'tst', name: 'Tsim Sha Tsui', students: 524, util: 0.87, revenue: 1.18, growth: 0.06 },
  { id: 'cwb', name: 'Causeway Bay',  students: 487, util: 0.82, revenue: 1.04, growth: 0.04 },
  { id: 'st',  name: 'Sha Tin',       students: 462, util: 0.79, revenue: 0.96, growth: 0.08 },
  { id: 'kt',  name: 'Kwun Tong',     students: 401, util: 0.74, revenue: 0.82, growth: 0.03 },
  { id: 'ssp', name: 'Sham Shui Po',  students: 358, util: 0.71, revenue: 0.71, growth: -0.02 },
  { id: 'tw',  name: 'Tsuen Wan',     students: 312, util: 0.68, revenue: 0.61, growth: 0.05 },
  { id: 'ty',  name: 'Tseung Kwan O', students: 290, util: 0.64, revenue: 0.56, growth: 0.11 },
];

// CRM funnel — last 30 days (HQ)
const TL_FUNNEL = [
  { stage: 'Website enquiry',  count: 412, rate: 1.00 },
  { stage: 'Trial booked',     count: 287, rate: 0.70 },
  { stage: 'Trial attended',   count: 241, rate: 0.84 },
  { stage: 'Enrolled',         count: 118, rate: 0.49 },
  { stage: 'Paid first term',  count: 109, rate: 0.92 },
];

// Recent leads needing follow-up
const TL_LEADS = [
  { id: 'L1', name: 'Wong family',     child: 'Aria, age 6',    interest: 'Piano',      branch: 'Tsim Sha Tsui',  source: 'Website',  status: 'New',         when: '2h ago',  owner: 'Karen' },
  { id: 'L2', name: 'Cheng family',    child: 'Lucas, age 9',   interest: 'Violin',     branch: 'Causeway Bay',   source: 'Referral', status: 'Trial booked',when: 'Today',   owner: 'Karen' },
  { id: 'L3', name: 'Patel family',    child: 'Anya, age 11',   interest: 'Voice',      branch: 'Tsim Sha Tsui',  source: 'Walk-in',  status: 'Trial done',  when: 'Yesterday', owner: 'Janice' },
  { id: 'L4', name: 'Tam family',      child: 'Jayden, age 7',  interest: 'Drums',      branch: 'Kwun Tong',      source: 'Instagram',status: 'Following up',when: '3d ago',  owner: 'Eric' },
  { id: 'L5', name: 'Lin family',      child: 'Sophia, age 8',  interest: 'Piano',      branch: 'Sha Tin',        source: 'Website',  status: 'Enrolled',    when: '5d ago',  owner: 'Eric' },
  { id: 'L6', name: 'Garcia family',   child: 'Mateo, age 10',  interest: 'Guitar',     branch: 'Tsim Sha Tsui',  source: 'Referral', status: 'New',         when: '1d ago',  owner: 'Karen' },
];

// Students at TST — lifecycle stages
const TL_STUDENT_LIFECYCLE = [
  { stage: 'Trial',         count: 18, color: '#A0A0A0' },
  { stage: 'Enrolled · Y1', count: 142, color: '#FFE003' },
  { stage: 'Enrolled · Y2+', count: 287, color: '#141414' },
  { stage: 'Exam prep',     count: 64, color: '#FFE003' },
  { stage: 'Recital prep',  count: 13, color: '#141414' },
];

// Schedule grid — Studio 1-6 across one day at TST
// Each cell: { teacher, student, instrument, status }
// status: 'ok' | 'conflict' | 'empty' | 'trial'
const TL_GRID_HOURS = ['10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00'];
const TL_GRID_ROOMS = [
  { name: 'Studio 1',  type: 'Piano',     slots: ['', '', '', 'Liu / Felix Chow', 'Liu / Felix Chow', 'Liu / Felix Chow', '', 'Wong / Olivia Yu', 'Wong / Olivia Yu', '', ''] },
  { name: 'Studio 2',  type: 'Piano',     slots: ['', 'Wong / Ada', '', '', 'Wong / Olivia Yu', '', 'Chen / Emily Cheung', '', '', '', ''] },
  { name: 'Studio 3',  type: 'Violin',    slots: ['', '', 'Cheung / Marcus W.', '', 'Cheung / Marcus W.', 'Cheung / Marcus W.', '', '', 'Cheung / Trial: Lucas C.', '', ''] },
  { name: 'Studio 4',  type: 'Piano',     slots: ['Chen / Theory class', 'Chen / Theory class', '', '', 'Chen / Sophie Lam', 'Chen / Sophie Lam', 'Chen / Isabella M.', 'Chen / Marcus W.', 'Chen / Daniel I.', '', ''] },
  { name: 'Studio 5',  type: 'Cello',     slots: ['', '', '', 'Lo / Trial: Aria W.', 'Lo / Chloe Tang', 'Lo / Chloe Tang', '', '', 'Lo / Anna Y.', 'Lo / Anna Y.', ''] },
  { name: 'Studio 6',  type: 'Guitar',    slots: ['', '', '', '', '', '', '', 'Tam / Daniel Ip', '', '', ''] },
];
// Mark trial / conflict cells by content
function tlGridCellKind(s) {
  if (!s) return 'empty';
  if (s.includes('Trial')) return 'trial';
  if (s.includes('class')) return 'group';
  return 'ok';
}

Object.assign(window, {
  TL_BRANCHES, TL_BRANCH_TODAY, TL_KPI_TREND, TL_BRANCH_PERF,
  TL_FUNNEL, TL_LEADS, TL_STUDENT_LIFECYCLE,
  TL_GRID_HOURS, TL_GRID_ROOMS, tlGridCellKind,
});
