"use client" import { useState, useEffect, useCallback } from "react" import { useRouter, usePathname } from "next/navigation" import { useAuth } from "@/contexts/supabase-auth-context" import { AdminGateModal } from "@/components/admin-gate-modal" import { Shield } from "lucide-react" /** * For admin users only: * - Floating "Admin" button (click = alternate admin access, no keyboard needed) * - Keyboard shortcut: Ctrl+Shift+A or Cmd+Shift+A */ export function AdminShortcutHandler() { const { user } = useAuth() const router = useRouter() const pathname = usePathname() const [showAdminGateModal, setShowAdminGateModal] = useState(false) // Always show the admin access UI (modal) first; modal handles password vs continue const openAdmin = useCallback(() => { setShowAdminGateModal(true) }, []) const handleAdminGateSuccess = useCallback(() => { setShowAdminGateModal(false) router.push("/admin") }, [router]) // Keyboard shortcuts: Ctrl+Shift+A or Ctrl+Alt+A (Mac: Cmd) opens admin modal from anywhere. useEffect(() => { const onKeyDown = (e: KeyboardEvent) => { const key = (e.key || "").toLowerCase() const isA = key === "a" || e.code === "KeyA" const modifier = e.ctrlKey || e.metaKey const withShift = modifier && e.shiftKey && isA const withAlt = modifier && e.altKey && isA if (withShift || withAlt) { e.preventDefault() e.stopPropagation() openAdmin() } } window.addEventListener("keydown", onKeyDown, true) return () => window.removeEventListener("keydown", onKeyDown, true) }, [openAdmin]) const onLoginPage = pathname === "/login" return ( <> {/* Floating Admin button – any logged-in user can open admin (password required). Hidden on /admin page. */} {onLoginPage && ( )} ) }