import { i as __toESM } from "../_runtime.mjs";
import { $ as require_react } from "./@base-ui/react+[...].mjs";
import { c as detectPlatform, s as normalizeRegisterableHotkey, t as getHotkeyManager } from "./@tanstack/hotkeys+[...].mjs";
//#region node_modules/.pnpm/@tanstack+react-hotkeys@0.10.0_react-dom@19.2.5_react@19.2.5__react@19.2.5/node_modules/@tanstack/react-hotkeys/dist/HotkeysProvider.js
var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
var HotkeysContext = (0, import_react.createContext)(null);
var DEFAULT_OPTIONS = {};
function HotkeysProvider({ children, defaultOptions = DEFAULT_OPTIONS }) {
	const contextValue = (0, import_react.useMemo)(() => ({ defaultOptions }), [defaultOptions]);
	return /* @__PURE__ */ import_react.createElement(HotkeysContext.Provider, { value: contextValue }, children);
}
function useDefaultHotkeysOptions() {
	return (0, import_react.useContext)(HotkeysContext)?.defaultOptions ?? {};
}
//#endregion
//#region node_modules/.pnpm/@tanstack+react-hotkeys@0.10.0_react-dom@19.2.5_react@19.2.5__react@19.2.5/node_modules/@tanstack/react-hotkeys/dist/utils.js
/**
* Type guard to check if a value is a React ref-like object.
*/
function isRef(value) {
	return value !== null && typeof value === "object" && "current" in value;
}
//#endregion
//#region node_modules/.pnpm/@tanstack+react-hotkeys@0.10.0_react-dom@19.2.5_react@19.2.5__react@19.2.5/node_modules/@tanstack/react-hotkeys/dist/useHotkeys.js
/**
* React hook for registering multiple keyboard hotkeys at once.
*
* Uses the singleton HotkeyManager for efficient event handling.
* Accepts a dynamic array of hotkey definitions, making it safe to use
* with variable-length lists without violating the rules of hooks.
*
* Options are merged in this order:
* HotkeysProvider defaults < commonOptions < per-definition options
*
* Callbacks and options are synced on every render to avoid stale closures.
*
* @param hotkeys - Array of hotkey definitions to register
* @param commonOptions - Shared options applied to all hotkeys (overridden by per-definition options).
*   Per-row `enabled: false` still registers that hotkey: `HotkeyManager` suppresses execution only (the row
*   stays in the store and appears in TanStack Hotkeys devtools). Toggling `enabled` updates the existing handle
*   via `setOptions` (no unregister/re-register churn).
*
* @example
* ```tsx
* function Editor() {
*   useHotkeys([
*     { hotkey: 'Mod+S', callback: () => save() },
*     { hotkey: 'Mod+Z', callback: () => undo() },
*     { hotkey: 'Escape', callback: () => close() },
*   ])
* }
* ```
*
* @example
* ```tsx
* function MenuShortcuts({ items }) {
*   // Dynamic hotkeys from data -- safe because it's a single hook call
*   useHotkeys(
*     items.map((item) => ({
*       hotkey: item.shortcut,
*       callback: item.action,
*       options: { enabled: item.enabled },
*     })),
*     { preventDefault: true },
*   )
* }
* ```
*/
function useHotkeys(hotkeys, commonOptions = {}) {
	const defaultOptions = useDefaultHotkeysOptions().hotkey;
	const manager = getHotkeyManager();
	const platform = commonOptions.platform ?? defaultOptions?.platform ?? detectPlatform();
	const registrationsRef = (0, import_react.useRef)(/* @__PURE__ */ new Map());
	const hotkeysRef = (0, import_react.useRef)(hotkeys);
	const hotkeyStringsRef = (0, import_react.useRef)([]);
	const commonOptionsRef = (0, import_react.useRef)(commonOptions);
	const defaultOptionsRef = (0, import_react.useRef)(defaultOptions);
	const managerRef = (0, import_react.useRef)(manager);
	const hotkeyStrings = hotkeys.map((def) => normalizeRegisterableHotkey(def.hotkey, platform));
	hotkeysRef.current = hotkeys;
	hotkeyStringsRef.current = hotkeyStrings;
	commonOptionsRef.current = commonOptions;
	defaultOptionsRef.current = defaultOptions;
	managerRef.current = manager;
	(0, import_react.useEffect)(() => {
		const prevRegistrations = registrationsRef.current;
		const nextRegistrations = /* @__PURE__ */ new Map();
		const rows = [];
		for (let i = 0; i < hotkeysRef.current.length; i++) {
			const def = hotkeysRef.current[i];
			const hotkeyStr = hotkeyStringsRef.current[i];
			const mergedOptions = {
				...defaultOptionsRef.current,
				...commonOptionsRef.current,
				...def.options
			};
			const resolvedTarget = isRef(mergedOptions.target) ? mergedOptions.target.current : mergedOptions.target ?? (typeof document !== "undefined" ? document : null);
			if (!resolvedTarget) continue;
			const registrationKey = `${i}:${hotkeyStr}`;
			rows.push({
				registrationKey,
				def,
				hotkeyStr,
				mergedOptions,
				resolvedTarget
			});
		}
		const nextKeys = new Set(rows.map((r) => r.registrationKey));
		for (const [key, record] of prevRegistrations) if (!nextKeys.has(key) && record.handle.isActive) record.handle.unregister();
		for (const row of rows) {
			const { registrationKey, def, hotkeyStr, mergedOptions, resolvedTarget } = row;
			const existing = prevRegistrations.get(registrationKey);
			if (existing?.handle.isActive && existing.target === resolvedTarget) {
				nextRegistrations.set(registrationKey, existing);
				continue;
			}
			if (existing?.handle.isActive) existing.handle.unregister();
			const handle = managerRef.current.register(hotkeyStr, def.callback, {
				...mergedOptions,
				target: resolvedTarget
			});
			nextRegistrations.set(registrationKey, {
				handle,
				target: resolvedTarget
			});
		}
		registrationsRef.current = nextRegistrations;
	});
	(0, import_react.useEffect)(() => {
		return () => {
			for (const { handle } of registrationsRef.current.values()) if (handle.isActive) handle.unregister();
			registrationsRef.current = /* @__PURE__ */ new Map();
		};
	}, []);
	for (let i = 0; i < hotkeys.length; i++) {
		const def = hotkeys[i];
		const hotkeyStr = hotkeyStrings[i];
		const registrationKey = `${i}:${hotkeyStr}`;
		const handle = registrationsRef.current.get(registrationKey)?.handle;
		if (handle?.isActive) {
			handle.callback = def.callback;
			const { target: _target, ...optionsWithoutTarget } = {
				...defaultOptions,
				...commonOptions,
				...def.options
			};
			handle.setOptions(optionsWithoutTarget);
		}
	}
}
//#endregion
export { HotkeysProvider as n, useHotkeys as t };
