"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";

export function KeyboardShortcuts() {
  const router = useRouter();

  useEffect(() => {
    function handler(e: KeyboardEvent) {
      // Don't trigger when typing in inputs
      if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) return;

      switch (e.key) {
        case "1": router.push("/"); break;
        case "2": router.push("/infrastructure"); break;
        case "3": router.push("/media"); break;
        case "4": router.push("/automations"); break;
        case "5": router.push("/expenses"); break;
        case "6": router.push("/network"); break;
        case "7": router.push("/logs"); break;
        case "r": window.location.reload(); break;
      }
    }
    window.addEventListener("keydown", handler);
    return () => window.removeEventListener("keydown", handler);
  }, [router]);

  return null;
}
