import { KeybindStore } from '.';

export type KeybindAction = string;
export type KeybindCategory = string;

export function formatCombo(combo: string): string {
	return combo
		.split('+')
		.map((t) => t.trim())
		.filter(Boolean)
		.map((t) => (t.length === 1 ? t.toUpperCase() : t[0].toUpperCase() + t.slice(1)))
		.join('+');
}

export function eventToCombo(e: KeyboardEvent): string {
	const parts: string[] = [];
	if (e.ctrlKey) parts.push('ctrl');
	if (e.shiftKey) parts.push('shift');
	if (e.altKey) parts.push('alt');
	if (e.metaKey) parts.push('meta');
	if (e.key && !['Control', 'Shift', 'Alt', 'Meta'].includes(e.key)) {
		parts.push(e.key.toLowerCase());
	}
	return parts.join('+');
}

export default KeybindStore;
export { KeybindStore };
