// Shared content, data, and tiny atoms for SK Bandar Tawau homepage directions.
// Loaded before each direction-*.jsx file.

const SCHOOL = {
  fullName: { bm: 'Sekolah Kebangsaan Bandar Tawau', en: 'Bandar Tawau National School' },
  shortName: 'SK Bandar Tawau',
  initials: 'SKBT',
  motto: { bm: 'Ilmu Tangga Kejayaan', en: 'Knowledge is the Ladder to Success' },
  established: 1959,
  district: { bm: 'Daerah Tawau, Sabah', en: 'Tawau District, Sabah' },
  code: 'XBA1234',
  hm: { bm: 'Pn. Hjh. Aminah binti Hassan', en: 'Mrs. Aminah Hassan' },
  visi: {
    bm: 'Pendidikan Berkualiti, Insan Terdidik, Negara Sejahtera.',
    en: 'Quality Education, Educated People, A Prosperous Nation.',
  },
  misi: {
    bm: 'Melonjakkan kecemerlangan institusi pendidikan berasaskan aspirasi negara.',
    en: 'Elevating the excellence of educational institutions rooted in national aspirations.',
  },
};

// Bilingual UI strings — `t(key, lang)` reads them.
const STRINGS = {
  nav: {
    home: { bm: 'Utama', en: 'Home' },
    about: { bm: 'Profil Sekolah', en: 'About' },
    academics: { bm: 'Akademik', en: 'Academics' },
    coco: { bm: 'Kokurikulum', en: 'Co-curricular' },
    news: { bm: 'Berita', en: 'News' },
    gallery: { bm: 'Galeri', en: 'Gallery' },
    contact: { bm: 'Hubungi', en: 'Contact' },
    staff: { bm: 'Warga Guru', en: 'Staff' },
    events: { bm: 'Takwim', en: 'Events' },
    achievements: { bm: 'Pencapaian', en: 'Achievements' },
    management: { bm: 'Pengurusan', en: 'Management' },
    curriculum: { bm: 'Kurikulum', en: 'Curriculum' },
    studentAffairs: { bm: 'Hal Ehwal Murid', en: 'Student Affairs' },
  },
  hero: {
    welcome: { bm: 'Selamat Datang ke', en: 'Welcome to' },
    tagline: {
      bm: 'Membentuk modal insan cemerlang sejak 1959.',
      en: 'Shaping outstanding minds since 1959.',
    },
    explore: { bm: 'Terokai Sekolah', en: 'Explore the School' },
    apply: { bm: 'Daftar Murid Baharu', en: 'Enrol a New Pupil' },
    parents: { bm: 'Portal Ibu Bapa', en: 'Parent Portal' },
  },
  sections: {
    latestNews: { bm: 'Berita Terkini', en: 'Latest News' },
    upcoming: { bm: 'Acara Akan Datang', en: 'Upcoming Events' },
    ourTeachers: { bm: 'Warga Pendidik Kami', en: 'Our Educators' },
    achievements: { bm: 'Pencapaian Sekolah', en: 'School Achievements' },
    visiMisi: { bm: 'Visi & Misi', en: 'Vision & Mission' },
    quickLinks: { bm: 'Pautan Pantas', en: 'Quick Links' },
    visiTitle: { bm: 'Visi', en: 'Vision' },
    misiTitle: { bm: 'Misi', en: 'Mission' },
  },
  cta: {
    readMore: { bm: 'Baca Lanjut', en: 'Read More' },
    seeAll: { bm: 'Lihat Semua', en: 'See All' },
    register: { bm: 'Daftar Sekarang', en: 'Register Now' },
    download: { bm: 'Muat Turun', en: 'Download' },
  },
  stats: {
    pupils: { bm: 'Murid', en: 'Pupils' },
    teachers: { bm: 'Guru', en: 'Teachers' },
    classes: { bm: 'Kelas', en: 'Classes' },
    years: { bm: 'Tahun Berkhidmat', en: 'Years of Service' },
    awards: { bm: 'Anugerah', en: 'Awards' },
  },
};

const t = (path, lang) => {
  const parts = path.split('.');
  let n = STRINGS;
  for (const p of parts) n = n && n[p];
  if (!n) return path;
  return n[lang] ?? n.bm ?? path;
};

const NEWS = [
  {
    id: 1,
    cat: { bm: 'Akademik', en: 'Academic' },
    date: { bm: '12 Mei 2026', en: '12 May 2026' },
    title: {
      bm: 'Murid Tahun 6 Catat 100% Kelulusan UPKK 2025',
      en: 'Year 6 Pupils Achieve 100% UPKK 2025 Pass Rate',
    },
    blurb: {
      bm: 'Pencapaian gemilang seluruh kohort dengan 38 calon mendapat A dalam tujuh mata pelajaran teras.',
      en: 'Outstanding cohort performance with 38 candidates scoring A across seven core subjects.',
    },
  },
  {
    id: 2,
    cat: { bm: 'Sukan', en: 'Sports' },
    date: { bm: '8 Mei 2026', en: '8 May 2026' },
    title: {
      bm: 'Pasukan Bola Sepak SKBT Johan MSSD Tawau',
      en: 'SKBT Football Team Crowned MSSD Tawau Champions',
    },
    blurb: {
      bm: 'Mengalahkan SK Cahaya 3-1 di final dengan permainan padu dan semangat juang murni.',
      en: 'Defeating SK Cahaya 3-1 in the final with disciplined play and a fighting spirit.',
    },
  },
  {
    id: 3,
    cat: { bm: 'Inovasi', en: 'Innovation' },
    date: { bm: '2 Mei 2026', en: '2 May 2026' },
    title: {
      bm: 'Kelab Robotik Kemuncak Pertandingan Negeri',
      en: 'Robotics Club Tops State-Level Competition',
    },
    blurb: {
      bm: 'Pasukan ROBOT-SKBT meraih tempat pertama dalam Pertandingan Robotik Sekolah Rendah Sabah.',
      en: 'Team ROBOT-SKBT claimed first place at the Sabah Primary School Robotics Tournament.',
    },
  },
  {
    id: 4,
    cat: { bm: 'Komuniti', en: 'Community' },
    date: { bm: '26 April 2026', en: '26 April 2026' },
    title: {
      bm: 'Hari Keluarga & Gotong-Royong Perdana 2026',
      en: 'Family Day & Community Cleanup 2026',
    },
    blurb: {
      bm: 'Lebih 400 ibu bapa dan murid menyertai aktiviti membersihkan kawasan sekolah dan permainan rakyat.',
      en: 'Over 400 parents and pupils joined in school cleanup and traditional games.',
    },
  },
];

const EVENTS = [
  { day: 14, mo: 5, label: { bm: 'Mesyuarat PIBG Bil. 2', en: 'PIBG Meeting #2' }, tag: 'pibg', color: 'blue' },
  { day: 17, mo: 5, label: { bm: 'Hari Kantin', en: 'Canteen Day' }, tag: 'school', color: 'yellow' },
  { day: 21, mo: 5, label: { bm: 'Ujian Pertengahan Tahun', en: 'Mid-Year Examination' }, tag: 'exam', color: 'red' },
  { day: 28, mo: 5, label: { bm: 'Karnival Sains & Matematik', en: 'Science & Math Carnival' }, tag: 'event', color: 'blue' },
  { day: 1, mo: 6, label: { bm: 'Cuti Pertengahan Tahun', en: 'Mid-Year Break' }, tag: 'holiday', color: 'yellow' },
  { day: 9, mo: 6, label: { bm: 'Sambutan Hari Guru', en: 'Teachers\u2019 Day', }, tag: 'event', color: 'red' },
];

const STAFF = [
  {
    name: 'Pn. Hjh. Aminah binti Hassan',
    role: { bm: 'Guru Besar', en: 'Headmistress' },
    subject: { bm: '32 tahun perkhidmatan', en: '32 years of service' },
    quote: {
      bm: '“Setiap kanak-kanak adalah amanah dan bintang masa depan.”',
      en: '“Every child is a trust, and a star of the future.”',
    },
    hue: 220, // blue
  },
  {
    name: 'En. Mohd Rizal bin Abdullah',
    role: { bm: 'Penolong Kanan Pentadbiran', en: 'Senior Asst. (Admin)' },
    subject: { bm: 'Bahasa Melayu · Sejarah', en: 'Malay · History' },
    quote: {
      bm: '“Disiplin adalah jambatan ke arah kecemerlangan.”',
      en: '“Discipline is the bridge to excellence.”',
    },
    hue: 0, // red
  },
  {
    name: 'Pn. Siti Zubaidah binti Yusof',
    role: { bm: 'Penolong Kanan HEM', en: 'Senior Asst. (Student Affairs)' },
    subject: { bm: 'Bimbingan & Kaunseling', en: 'Counselling' },
    quote: {
      bm: '“Kebajikan murid adalah keutamaan kami.”',
      en: '“The welfare of our pupils comes first.”',
    },
    hue: 45, // yellow
  },
  {
    name: 'Cikgu Daniel Lim Wei Han',
    role: { bm: 'Ketua Panitia Sains', en: 'Head, Science Panel' },
    subject: { bm: 'Sains · Robotik', en: 'Science · Robotics' },
    quote: {
      bm: '“Sains menjadikan dunia lebih dekat dengan kita.”',
      en: '“Science brings the world closer to us.”',
    },
    hue: 200,
  },
  {
    name: 'Pn. Nur Hidayah binti Roslan',
    role: { bm: 'Guru Bahasa Inggeris', en: 'English Teacher' },
    subject: { bm: 'Bahasa Inggeris', en: 'English Language' },
    quote: {
      bm: '“Reading is the doorway to another world.”',
      en: '“Reading is the doorway to another world.”',
    },
    hue: 10,
  },
  {
    name: 'En. Joseph Anak Lawai',
    role: { bm: 'Guru Pendidikan Jasmani', en: 'PE Teacher' },
    subject: { bm: 'Pendidikan Jasmani · Sukan', en: 'PE · Sports' },
    quote: {
      bm: '“Tubuh yang cergas, minda yang waras.”',
      en: '“A healthy body, a sound mind.”',
    },
    hue: 50,
  },
];

const ACHIEVEMENTS = [
  { n: '100%', label: { bm: 'Kelulusan UPKK 2025', en: 'UPKK 2025 Pass Rate' } },
  { n: '5\u2605', label: { bm: 'Taraf Sekolah Bestari', en: 'Smart School 5-Star Rating' } },
  { n: '24', label: { bm: 'Anugerah Negeri 2024', en: 'State Awards in 2024' } },
  { n: '67', label: { bm: 'Tahun Berkhidmat', en: 'Years of Service' } },
];

const STATS = [
  { n: 842, label: { bm: 'Murid', en: 'Pupils' } },
  { n: 56, label: { bm: 'Guru', en: 'Teachers' } },
  { n: 30, label: { bm: 'Kelas', en: 'Classes' } },
  { n: 67, label: { bm: 'Tahun', en: 'Years' } },
];

const CLUBS = [
  { bm: 'Pengakap', en: 'Scouts', emoji: '⚜' },
  { bm: 'Bulan Sabit Merah', en: 'Red Crescent', emoji: '☾' },
  { bm: 'Kelab Robotik', en: 'Robotics Club', emoji: '◷' },
  { bm: 'Kelab Bahasa', en: 'Language Club', emoji: '✎' },
  { bm: 'Persatuan Sains', en: 'Science Society', emoji: '⌬' },
  { bm: 'Kompang & Nasyid', en: 'Kompang & Nasyid', emoji: '♪' },
  { bm: 'Bola Sepak', en: 'Football', emoji: '◉' },
  { bm: 'Catur', en: 'Chess', emoji: '♞' },
];

// ── Atoms ───────────────────────────────────────────────────────────

// Striped placeholder used in place of real photography.
// tone is 'blue'|'red'|'yellow'|'dark'|'light'|'navy'.
// Visual styling lives in styles/klasik.css under `.k-placeholder.t-{tone}`.
// If `ratio`/`tall`/`square` is passed explicitly the aspect ratio is forced
// inline; otherwise the parent CSS rule controls it (responsive-friendly).
function ImgPlaceholder({ label, tone = 'blue', tall = false, square = false, ratio, style = {}, className = '' }) {
  const ar = ratio ?? (tall ? '3/4' : square ? '1/1' : undefined);
  const finalStyle = ar ? { aspectRatio: ar, ...style } : style;
  return (
    <div className={`k-placeholder t-${tone}${className ? ' ' + className : ''}`}
         style={finalStyle}>
      <span>{label}</span>
    </div>
  );
}

// Real school crest. `onDark` adds a soft halo so the dark-green/navy crest
// keeps its silhouette on a dark background. Old color props are ignored
// but accepted for back-compat with existing callsites.
function SchoolBadge({ size = 56, onDark = false }) {
  return (
    <div style={{
      width: size, height: size,
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      borderRadius: onDark ? '50%' : 0,
      background: onDark ? 'radial-gradient(circle, rgba(255,255,255,0.96) 60%, rgba(255,255,255,0) 75%)' : 'transparent',
      padding: onDark ? size * 0.05 : 0,
      flexShrink: 0,
    }}>
      <img src="assets/skbt-logo.png" alt="SK Bandar Tawau crest"
        style={{ width: '100%', height: '100%', objectFit: 'contain', display: 'block' }} />
    </div>
  );
}

// Compact malaysian flag mark
function FlagMark({ w = 22 }) {
  const h = w * 0.5;
  return (
    <svg width={w} height={h} viewBox="0 0 28 14" style={{ borderRadius: 2, display: 'block' }}>
      <rect width="28" height="14" fill="#cc0001"/>
      <rect y="2" width="28" height="2" fill="#fff"/>
      <rect y="6" width="28" height="2" fill="#fff"/>
      <rect y="10" width="28" height="2" fill="#fff"/>
      <rect width="14" height="8" fill="#010066"/>
      <circle cx="6" cy="4" r="2.4" fill="#ffd84a"/>
      <circle cx="7" cy="4" r="2" fill="#010066"/>
      <polygon points="9,4 10.6,4.6 9.7,3.1 11.1,2 9.3,2 9,0.4 8.7,2 6.9,2 8.3,3.1 7.4,4.6" fill="#ffd84a"/>
    </svg>
  );
}

// ── Helpers ─────────────────────────────────────────────────────────

// Tiny month-grid for the calendar widget. May 2026 starts on a Friday.
function makeMonth(year, month /* 0-indexed */) {
  const first = new Date(year, month, 1);
  const days = new Date(year, month + 1, 0).getDate();
  const startW = first.getDay(); // 0=Sun
  const cells = [];
  for (let i = 0; i < startW; i++) cells.push(null);
  for (let d = 1; d <= days; d++) cells.push(d);
  while (cells.length % 7 !== 0) cells.push(null);
  return cells;
}

const MONTH_NAMES = {
  bm: ['Januari','Februari','Mac','April','Mei','Jun','Julai','Ogos','September','Oktober','November','Disember'],
  en: ['January','February','March','April','May','June','July','August','September','October','November','December'],
};
const DOW = {
  bm: ['A','I','S','R','K','J','S'],
  en: ['S','M','T','W','T','F','S'],
};

Object.assign(window, {
  SCHOOL, STRINGS, t, NEWS, EVENTS, STAFF, ACHIEVEMENTS, STATS, CLUBS,
  ImgPlaceholder, SchoolBadge, FlagMark,
  makeMonth, MONTH_NAMES, DOW,
});
