/* Anti klik kanan + shortcut devtools (basic)
   Catatan: ini hanya deterrent, bukan security.
*/
(function () {
  // Jangan ganggu input/textarea (biar user masih bisa copy-paste di form)
  const ALLOW_SELECTORS = "input, textarea, select, [contenteditable='true']";

  // Blok klik kanan
  document.addEventListener(
    "contextmenu",
    function (e) {
      if (e.target && e.target.closest(ALLOW_SELECTORS)) return;
      e.preventDefault();
      return false;
    },
    { capture: true }
  );

  // Blok drag select (optional) - biar tidak gampang highlight teks
  document.addEventListener(
    "selectstart",
    function (e) {
      if (e.target && e.target.closest(ALLOW_SELECTORS)) return;
      // Kalau mau tetap bisa seleksi teks, hapus 2 baris di bawah ini
      e.preventDefault();
      return false;
    },
    { capture: true }
  );

  // Blok beberapa shortcut umum
  document.addEventListener(
    "keydown",
    function (e) {
      const key = (e.key || "").toLowerCase();

      // F12
      if (e.keyCode === 123) {
        e.preventDefault();
        return false;
      }

      // Ctrl+Shift+I / Ctrl+Shift+J / Ctrl+Shift+C (DevTools)
      if (e.ctrlKey && e.shiftKey && ["i", "j", "c"].includes(key)) {
        e.preventDefault();
        return false;
      }

      // Ctrl+U (view source)
      if (e.ctrlKey && key === "u") {
        e.preventDefault();
        return false;
      }

      // Ctrl+S (save page)
      if (e.ctrlKey && key === "s") {
        e.preventDefault();
        return false;
      }
    },
    { capture: true }
  );
})();
