import { useState, useEffect, useCallback } from 'react'; export type MaintAction = { endpoint: string; label: string; description: string; }; const MAINT_ACTIONS: Record = { forceReady: { endpoint: 'force-ready', label: 'Force Ready', description: 'Logout and re-login the agent to force Ready state on Ozonetel.', }, unlockAgent: { endpoint: 'unlock-agent', label: 'Unlock Agent', description: 'Release the Redis session lock so the agent can log in again.', }, backfill: { endpoint: 'backfill-missed-calls', label: 'Backfill Missed Calls', description: 'Match existing missed calls with lead records by phone number.', }, fixTimestamps: { endpoint: 'fix-timestamps', label: 'Fix Timestamps', description: 'Correct call timestamps that were stored with IST double-offset.', }, clearCampaignLeads: { endpoint: '__client__clear-campaign-leads', label: 'Clear Campaign Leads', description: 'Delete all imported leads from a selected campaign. For testing only.', }, }; export const useMaintShortcuts = () => { const [activeAction, setActiveAction] = useState(null); const [isOpen, setIsOpen] = useState(false); const openAction = useCallback((action: MaintAction) => { setActiveAction(action); setIsOpen(true); }, []); const close = useCallback(() => { setIsOpen(false); setActiveAction(null); }, []); useEffect(() => { const handler = (e: KeyboardEvent) => { if (e.ctrlKey && e.shiftKey && e.key === 'R') { e.preventDefault(); openAction(MAINT_ACTIONS.forceReady); } if (e.ctrlKey && e.shiftKey && e.key === 'U') { e.preventDefault(); openAction(MAINT_ACTIONS.unlockAgent); } if (e.ctrlKey && e.shiftKey && e.key === 'B') { e.preventDefault(); openAction(MAINT_ACTIONS.backfill); } if (e.ctrlKey && e.shiftKey && e.key === 'T') { e.preventDefault(); openAction(MAINT_ACTIONS.fixTimestamps); } if (e.ctrlKey && e.shiftKey && e.key === 'C') { e.preventDefault(); openAction(MAINT_ACTIONS.clearCampaignLeads); } }; window.addEventListener('keydown', handler); return () => window.removeEventListener('keydown', handler); }, [openAction]); return { isOpen, activeAction, close }; };