import type { Level } from "../types";

// Finger color CSS variable mapping per spec section 8.3
// Left hand: pinky=Q/A/Y/1, ring=W/S/X/2, mid=E/D/C/3, index=R/F/V/T/G/B/4/5
// Right hand: index=U/J/M/Z/H/N/6/7, mid=I/K/,/8, ring=O/L/./9, pinky=P/Ö/Ä/Ü/0/ß
// Thumb: Space

const fingerMap: Record<string, string> = {
	// Left pinky
	q: "--finger-l-pinky",
	a: "--finger-l-pinky",
	y: "--finger-l-pinky",
	// Left ring
	w: "--finger-l-ring",
	s: "--finger-l-ring",
	x: "--finger-l-ring",
	// Left middle
	e: "--finger-l-mid",
	d: "--finger-l-mid",
	c: "--finger-l-mid",
	// Left index
	r: "--finger-l-index",
	f: "--finger-l-index",
	v: "--finger-l-index",
	t: "--finger-l-index",
	g: "--finger-l-index",
	b: "--finger-l-index",
	// Right index
	u: "--finger-r-index",
	j: "--finger-r-index",
	m: "--finger-r-index",
	z: "--finger-r-index",
	h: "--finger-r-index",
	n: "--finger-r-index",
	// Right middle
	i: "--finger-r-mid",
	k: "--finger-r-mid",
	// Right ring
	o: "--finger-r-ring",
	l: "--finger-r-ring",
	// Right pinky
	p: "--finger-r-pinky",
	ö: "--finger-r-pinky",
	ä: "--finger-r-pinky",
	ü: "--finger-r-pinky",
	// Thumb
	" ": "--finger-thumb",
};

export const levels: Level[] = [
	{
		level: 1,
		newKeys: ["f", "j", " "],
		allKeys: ["f", "j", " "],
		fingerMap,
	},
	{
		level: 2,
		newKeys: ["d", "k"],
		allKeys: ["f", "j", " ", "d", "k"],
		fingerMap,
	},
	{
		level: 3,
		newKeys: ["s", "l"],
		allKeys: ["f", "j", " ", "d", "k", "s", "l"],
		fingerMap,
	},
	{
		level: 4,
		newKeys: ["a", "ö"],
		allKeys: ["f", "j", " ", "d", "k", "s", "l", "a", "ö"],
		fingerMap,
	},
	{
		level: 5,
		newKeys: ["g", "h"],
		allKeys: ["f", "j", " ", "d", "k", "s", "l", "a", "ö", "g", "h"],
		fingerMap,
	},
	{
		level: 6,
		newKeys: ["e", "i"],
		allKeys: [
			"f",
			"j",
			" ",
			"d",
			"k",
			"s",
			"l",
			"a",
			"ö",
			"g",
			"h",
			"e",
			"i",
		],
		fingerMap,
	},
];

export function getLevelByNumber(n: number): Level | undefined {
	return levels.find((l) => l.level === n);
}

export function getKeysUpToLevel(n: number): string[] {
	const level = getLevelByNumber(n);
	return level ? level.allKeys : [];
}
