"use client";

import { useRouter } from "next/navigation";
import { useMemo } from "react";
import { useKeyboardShortcuts, type KeyboardShortcut } from "@/lib/use-keyboard-shortcuts";

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

  const shortcuts = useMemo<KeyboardShortcut[]>(
    () => [
      {
        key: "k",
        meta: true,
        handler: () => router.push("/search"),
        description: "Open search",
      },
      {
        key: "n",
        meta: true,
        handler: () => router.push("/workspaces"),
        description: "Open workspaces (new note)",
      },
      {
        key: "d",
        meta: true,
        shift: true,
        handler: () => router.push("/dashboard"),
        description: "Go to dashboard",
      },
      {
        key: "r",
        meta: true,
        shift: true,
        handler: () => router.push("/reviews"),
        description: "Go to reviews",
      },
      {
        key: "Escape",
        handler: () => {
          const active = document.activeElement as HTMLElement | null;
          active?.blur();
        },
        description: "Dismiss / blur",
      },
    ],
    [router],
  );

  useKeyboardShortcuts(shortcuts);

  return null;
}
