//#region src/utils/keyboard.ts
var e = {
	ARROW_UP: "ArrowUp",
	ARROW_DOWN: "ArrowDown",
	ARROW_LEFT: "ArrowLeft",
	ARROW_RIGHT: "ArrowRight",
	ENTER: "Enter",
	SPACE: " ",
	ESCAPE: "Escape",
	TAB: "Tab",
	HOME: "Home",
	END: "End",
	PAGE_UP: "PageUp",
	PAGE_DOWN: "PageDown",
	BACKSPACE: "Backspace",
	DELETE: "Delete"
};
function t(t, n) {
	let { columns: r, rows: i, currentCol: a, currentRow: o, wrap: s = !1, isCellDisabled: c } = n, l = a, u = o, d = !1, f = (e, t, n, a) => {
		let o = e + n, l = t + a;
		if (s ? (l < 0 && (l = r - 1), l >= r && (l = 0), o < 0 && (o = i - 1), o >= i && (o = 0)) : (l = Math.max(0, Math.min(r - 1, l)), o = Math.max(0, Math.min(i - 1, o))), c !== void 0) {
			let e = i * r, t = 0;
			for (; c(o, l) && t < e;) o += n, l += a, s ? (l < 0 && (l = r - 1), l >= r && (l = 0), o < 0 && (o = i - 1), o >= i && (o = 0)) : (l = Math.max(0, Math.min(r - 1, l)), o = Math.max(0, Math.min(i - 1, o))), t++;
		}
		return {
			row: o,
			col: l
		};
	};
	switch (t.key) {
		case e.ARROW_RIGHT: {
			let e = f(o, a, 0, 1);
			l = e.col, u = e.row, d = !0;
			break;
		}
		case e.ARROW_LEFT: {
			let e = f(o, a, 0, -1);
			l = e.col, u = e.row, d = !0;
			break;
		}
		case e.ARROW_DOWN: {
			let e = f(o, a, 1, 0);
			l = e.col, u = e.row, d = !0;
			break;
		}
		case e.ARROW_UP: {
			let e = f(o, a, -1, 0);
			l = e.col, u = e.row, d = !0;
			break;
		}
		case e.HOME:
			t.ctrlKey && (u = 0), l = 0, d = !0;
			break;
		case e.END:
			t.ctrlKey && (u = i - 1), l = r - 1, d = !0;
			break;
		case e.PAGE_UP:
			u = Math.max(0, o - 10), d = !0;
			break;
		case e.PAGE_DOWN:
			u = Math.min(i - 1, o + 10), d = !0;
			break;
	}
	return {
		handled: d,
		col: l,
		row: u
	};
}
function n(t, n) {
	let { visibleNodes: r, currentIndex: i, isExpanded: a, hasChildren: o, parentIndex: s, firstChildIndex: c } = n, l = r.indexOf(i);
	switch (t.key) {
		case e.ARROW_DOWN:
			if (l < r.length - 1) {
				let e = r[l + 1];
				if (e !== void 0) return {
					handled: !0,
					action: "focus",
					targetIndex: e
				};
			}
			return {
				handled: !0,
				action: "none"
			};
		case e.ARROW_UP:
			if (l > 0) {
				let e = r[l - 1];
				if (e !== void 0) return {
					handled: !0,
					action: "focus",
					targetIndex: e
				};
			}
			return {
				handled: !0,
				action: "none"
			};
		case e.ARROW_RIGHT:
			if (o) {
				if (!a) return {
					handled: !0,
					action: "expand"
				};
				if (c >= 0) return {
					handled: !0,
					action: "focus",
					targetIndex: c
				};
			}
			return {
				handled: !0,
				action: "none"
			};
		case e.ARROW_LEFT: return a && o ? {
			handled: !0,
			action: "collapse"
		} : s >= 0 ? {
			handled: !0,
			action: "focus",
			targetIndex: s
		} : {
			handled: !0,
			action: "none"
		};
		case e.HOME: {
			let e = r[0];
			return e !== void 0 && e !== i ? {
				handled: !0,
				action: "focus",
				targetIndex: e
			} : {
				handled: !0,
				action: "none"
			};
		}
		case e.END: {
			let e = r[r.length - 1];
			return e !== void 0 && e !== i ? {
				handled: !0,
				action: "focus",
				targetIndex: e
			} : {
				handled: !0,
				action: "none"
			};
		}
		case e.ENTER:
		case e.SPACE: return {
			handled: !0,
			action: "select"
		};
		default: return {
			handled: !1,
			action: "none"
		};
	}
}
function r(t, n) {
	let { activeIndex: r, itemCount: i, wrap: a = !0, orientation: o = "vertical", isItemDisabled: s } = n;
	if (i === 0) return {
		handled: !1,
		index: -1,
		activated: !1
	};
	let c = r, l = !1, u = !1, d = (e, t) => {
		let n = e + t, r = i;
		for (let e = 0; e < r; e++) {
			if (a ? (n < 0 && (n = i - 1), n >= i && (n = 0)) : n = Math.max(0, Math.min(i - 1, n)), s?.(n) !== !0) return n;
			n += t;
		}
		return e;
	}, f = o === "vertical" || o === "both", p = o === "horizontal" || o === "both";
	switch (t.key) {
		case e.ARROW_DOWN:
			f && (c = d(r, 1), l = !0);
			break;
		case e.ARROW_UP:
			f && (c = d(r, -1), l = !0);
			break;
		case e.ARROW_RIGHT:
			p && (c = d(r, 1), l = !0);
			break;
		case e.ARROW_LEFT:
			p && (c = d(r, -1), l = !0);
			break;
		case e.HOME:
			c = d(-1, 1), l = !0;
			break;
		case e.END:
			c = d(i, -1), l = !0;
			break;
		case e.ENTER:
		case e.SPACE:
			u = !0, l = !0;
			break;
	}
	return {
		handled: l,
		index: c,
		activated: u
	};
}
function i(e) {
	let { items: t, timeout: n = 500 } = e, r = "", i = null;
	return {
		handleKey: (e) => {
			if (e.length !== 1 || e === " ") return -1;
			i !== null && clearTimeout(i), r += e.toLowerCase(), i = setTimeout(() => {
				r = "";
			}, n);
			for (let e = 0; e < t.length; e++) {
				let n = t[e];
				if (!(n === void 0 || n.disabled === !0) && n.label.toLowerCase().startsWith(r)) return e;
			}
			return -1;
		},
		reset: () => {
			r = "", i !== null && (clearTimeout(i), i = null);
		}
	};
}
function a(e) {
	return e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;
}
function o(e) {
	if (e === null) return !1;
	let t = e, n = t.tagName.toLowerCase();
	return n === "input" || n === "textarea" || n === "select" || t.isContentEditable;
}
function s(e) {
	let t = [];
	(e.ctrlKey || e.metaKey) && t.push("Ctrl"), e.altKey && t.push("Alt"), e.shiftKey && t.push("Shift");
	let n = e.key.length === 1 ? e.key.toUpperCase() : e.key;
	return [
		"Control",
		"Alt",
		"Shift",
		"Meta"
	].includes(e.key) || t.push(n), t.join("+");
}
//#endregion
export { o as a, n as c, t as i, i as n, a as o, s as r, r as s, e as t };

//# sourceMappingURL=keyboard-wOEoCCWj.js.map