"use client";

import { useEffect } from "react";

/**
 * Discourages casual inspection: blocks the context menu and the usual
 * devtools shortcuts. This is a deterrent, not real security — anything
 * sensitive must still be enforced server-side.
 */
export function DevToolsGuard() {
  useEffect(() => {
    const onContext = (e: MouseEvent) => e.preventDefault();

    const onKey = (e: KeyboardEvent) => {
      // Some keys arrive with no name at all — a dead key, or one the
      // browser handled itself.
      if (!e.key) return;
      const k = e.key.toUpperCase();
      const blocked =
        e.key === "F12" ||
        (e.ctrlKey && e.shiftKey && ["I", "J", "C", "K"].includes(k)) ||
        (e.metaKey && e.altKey && ["I", "J", "C"].includes(k)) ||
        (e.ctrlKey && k === "U");
      if (blocked) {
        e.preventDefault();
        e.stopPropagation();
      }
    };

    document.addEventListener("contextmenu", onContext);
    document.addEventListener("keydown", onKey, true);
    return () => {
      document.removeEventListener("contextmenu", onContext);
      document.removeEventListener("keydown", onKey, true);
    };
  }, []);

  return null;
}
