const hasNavigator = typeof navigator !== 'undefined'

/**
 * Detects if the current platform is macOS.
 * Uses the modern `userAgentData` API with a fallback to the deprecated `navigator.platform`.
 */
export const isMac: boolean = hasNavigator
  ? /Mac/.test(navigator.platform) ||
    /macOS/.test((navigator as any).userAgentData?.platform)
  : false

/**
 * The keyboard shortcut label for focus region navigation.
 * macOS: Alt+Tab (does not conflict with OS shortcuts)
 * Windows/Linux: F6 (standard pane-navigation convention; Alt+Tab is intercepted by the OS)
 */
export const REGION_SHORTCUT_LABEL = isMac ? 'Alt+Tab' : 'F6'

/**
 * Replaces occurrences of "Alt+Tab" in a localized string with the
 * platform-appropriate shortcut label.
 */
export function localizeShortcut(text: string): string {
  return text.replace(/Alt\+Tab/g, REGION_SHORTCUT_LABEL)
}
