<?php
$NAMA_SEKOLAH = "SMK MUHIBBAH SANDAKAN";
$LOGO = "logo2.png";
$pages = [
  ["file"=>"admin_hem.php", "label"=>"HEM", "icon"=>"bi-house-heart"],
  ["file"=>"admin_kurikulum.php", "label"=>"Kurikulum", "icon"=>"bi-journal-text"],
  ["file"=>"admin_kokurikulum.php", "label"=>"Kokurikulum", "icon"=>"bi-trophy"],
  ["file"=>"admin_guru.php", "label"=>"Guru", "icon"=>"bi-people"],
  ["file"=>"admin_pelajar.php", "label"=>"Pelajar", "icon"=>"bi-person-badge"],
  ["file"=>"admin_kelas.php", "label"=>"Kelas", "icon"=>"bi-building"]
];
?>
<!DOCTYPE html>
<html lang="ms">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>Portal Admin Sekolah</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
  <style>
    body { margin:0; height:100vh; display:flex; font-family:Segoe UI,Arial,sans-serif; }
    .sidebar {
      width:240px; background:#1e1e2f; color:#fff; display:flex; flex-direction:column;
      position:fixed; top:0; bottom:0; left:0; z-index:1000;
      box-shadow:4px 0 12px rgba(0,0,0,.6);
    }
    .sidebar header { padding:16px; display:flex; align-items:center; gap:10px; background:#2d2d44; }
    .sidebar header img {width:40px; height:40px;}
    .sidebar nav {flex:1; overflow-y:auto; padding-top:10px;}
    .sidebar nav a {
      color:#ccc; padding:12px 16px; text-decoration:none; display:flex;
      align-items:center; gap:10px; border-radius:8px; margin:4px 8px;
      background:#2a2a40; transition:.2s;
    }
    .sidebar nav a:hover { background:#333; color:#fff; }
    .sidebar nav a.active { background:#1976d2; color:#fff; }
    .main { flex:1; display:flex; flex-direction:column; margin-left:240px; }
    .main header {
      padding:12px; background:#333; color:#fff; font-size:18px; 
      display:flex; justify-content:space-between; align-items:center;
    }
    iframe {flex:1; border:none; width:100%;}
  </style>
</head>

<body class="dark">

<div class="sidebar">
  <header>
    <img src="<?=$LOGO?>" style="height:70px; width:auto;">
    <div class="title"><?=$NAMA_SEKOLAH?><br><small>Admin Panel</small></div>
  </header>

  <nav id="menu">
    <?php foreach($pages as $p): ?>
      <a href="#" data-file="<?=$p['file']?>" class="nav-link">
        <i class="bi <?=$p['icon']?>"></i> <?=$p['label']?>
      </a>
    <?php endforeach; ?>
  </nav>
</div>

<div class="main">
  <header id="pageTitle">
    <span>Admin Panel</span>
    <a href="index.php" target="_blank" class="btn btn-sm btn-warning">🌐 Lihat Portal</a>
  </header>
  <iframe id="frame" name="frame" src="main.php"></iframe>

</div>

<script>
// Mapping password untuk setiap modul
const passwords = {
  "admin_hem.php": "admin1",
  "admin_kurikulum.php": "admin2",
  "admin_kokurikulum.php": "admin3",
  "admin_guru.php": "admin4",
  "admin_pelajar.php": "admin5",
  "admin_kelas.php": "admin6"
};

const menu = document.querySelectorAll("#menu a");
const pageTitle = document.getElementById("pageTitle").querySelector("span");
const frame = document.getElementById("frame");

// Fungsi padam semua akses sebelumnya (auto logout)
function resetAllAccess(){
  Object.keys(passwords).forEach(file => {
    sessionStorage.removeItem("unlock_" + file);
  });
}

// Buang highlight aktif
function clearActive(){
  menu.forEach(m => m.classList.remove("active"));
}

// Apabila klik mana-mana menu
menu.forEach(link => {
  link.addEventListener("click", function(e){
    e.preventDefault();
    const file = this.dataset.file;
    const label = this.textContent.trim();

    // Auto logout semua menu sebelumnya
    resetAllAccess();

    // Prompt password baru
    let input = prompt("Masukkan kata laluan untuk modul " + label);

    if (input !== passwords[file]){
      alert("Kata laluan salah!");
      return;
    }

    sessionStorage.setItem("unlock_" + file, input);
    
    // Aktifkan menu ini sahaja
    clearActive();
    this.classList.add("active");

    // Tukar tajuk dan load iframe
    pageTitle.textContent = "Admin — " + label;
    frame.src = file;
  });
});
</script>

</body>
</html>
