import { KeybindingManager as e } from "../../services/keybindings.js";
import { useEffect as t, useRef as n } from "react";
//#region src/react/hooks/useKeybindings.ts
function r(r, i) {
	let { enabled: a = !0, groupId: o } = i ?? {}, s = Array.isArray(r) ? r : [r], c = n(s);
	c.current = s;
	let l = n(null);
	l.current === null && (l.current = new e()), t(() => {
		let e = l.current;
		if (!e || !a) return;
		let t = [];
		for (let n of c.current) {
			let r = () => {
				c.current.find((e) => e.keys === n.keys)?.handler();
			}, i = n.ignoreWhenEditing === void 0 ? e.register(n.keys, r, n.description) : e.register(n.keys, r, n.description, { ignoreWhenEditing: n.ignoreWhenEditing });
			t.push(i);
		}
		if (o) {
			let n = c.current.map((e) => [
				e.keys,
				() => {
					c.current.find((t) => t.keys === e.keys)?.handler();
				},
				e.description
			]);
			for (let e of t) e();
			t.length = 0;
			let r = e.registerGroup(o, n);
			t.push(r);
		}
		return () => {
			for (let e of t) e();
		};
	}, [a, o]), t(() => () => {
		l.current?.destroy(), l.current = null;
	}, []);
}
//#endregion
export { r as useKeybindings };

//# sourceMappingURL=useKeybindings.js.map