use utf8;
use strict;
use warnings;
do './keyboard/altgr/groups.inc.pl';

my $V = v1.3;

my $presymbol = $V ge v1.3 ? '\\' : '-';
my %arrows = (
	'h' => '←',
	'H' => '⇐',
	'j' => '↓',
	'J' => '⇓',
	'k' => '↑',
	'K' => '⇑',
	'l' => '→',
	'L' => '⇒',
	'u' => '↖',
	'U' => '⇖',
	'i' => '↗',
	'I' => '⇗',
	'n' => '↙',
	'N' => '⇙',
	'm' => '↘',
	'M' => '⇘',
	'=' => '↔',
	'+' => '⇔',
);

my %rows = (
	'1' => '¡',
	'!' => '¹',
	'2' => 'ª',
	'@' => '²',
	'3' => 'º',
	'#' => '³',
	'4' => $V ge v1.1 ? '£' : '€',
	'$' => '¥',
	'5' => $V ge v1.1 ? '€' : '£',
	'%' => '¢',
	'6' => "\N{COMBINING CIRCUMFLEX ACCENT}",
	'^' => "\N{COMBINING CARON}",
	'7' => "\N{COMBINING RING ABOVE}",
	'&' => "\N{COMBINING MACRON}",
	'8' => "\N{DOUBLE LOW-9 QUOTATION MARK}",
	'*' => "\N{SINGLE LOW-9 QUOTATION MARK}",
	'9' => "\N{LEFT DOUBLE QUOTATION MARK}",
	'(' => "\N{LEFT SINGLE QUOTATION MARK}",
	'0' => "\N{RIGHT DOUBLE QUOTATION MARK}",
	')' => "\N{RIGHT SINGLE QUOTATION MARK}",
	'-' => $V ge v1.3 ? '✓' : '©',
	'_' => $V ge v1.3 ? '✗' : '№',
	'=' => '×',
	'+' => '÷',
	'q' => 'æ',
	'Q' => 'Æ',
	'w' => 'å',
	'W' => 'Å',
	'e' => 'ë',
	'E' => 'Ë',
	'r' => 'ý',
	'R' => 'Ý',
	't' => 'þ',
	'T' => 'Þ',
	'y' => 'ÿ',
	'Y' => 'Ÿ',
	'u' => 'ü',
	'U' => 'Ü',
	'i' => 'ï',
	'I' => 'Ï',
	'o' => 'ö',
	'O' => 'Ö',
	'p' => 'œ',
	'P' => 'Œ',
	'[' => '«',
	'{' => '‹',
	']' => '»',
	'}' => '›',

	'a' => 'ä',
	'A' => 'Ä',
	's' => 'ß',
	'S' => $V ge v1.3 ? 'ẞ' : '¶',
	'd' => $V ge v1.2 ? 'đ' : 'ð',
	'D' => $V ge v1.2 ? 'Đ' : 'Ð',
	'f' => 'è',
	'F' => 'È',
	'g' => 'é',
	'G' => 'É',
	'h' => 'ù',
	'H' => 'Ù',
	'j' => 'ú',
	'J' => 'Ú',
	'k' => 'ĳ',
	'K' => 'Ĳ',
	'l' => 'ø',
	'L' => 'Ø',
	';' => $V ge v1.2 ? '°' : "\N{COMBINING DIAERESIS}",
	':' => '·',
	"'" => "\N{COMBINING ACUTE ACCENT}",
	'"' => $V ge v1.2 ? "\N{COMBINING DIAERESIS}" : '†',
	'`' => "\N{COMBINING GRAVE ACCENT}",
	'~' => "\N{COMBINING TILDE}",

	'\\'=> '¬',
	'|' => '¦',
	'z' => 'à',
	'Z' => 'À',
	'x' => 'á',
	'X' => 'Á',
	'c' => 'ç',
	'C' => 'Ç',
	'v' => 'ì',
	'V' => 'Ì',
	'b' => 'í',
	'B' => 'Í',
	'n' => 'ñ',
	'N' => 'Ñ',
	'm' => 'Ω',
	'M' => '√', # ±
	',' => 'ò',
	'<' => 'Ò',
	'.' => 'ó',
	'>' => 'Ó',
	'/' => '¿',
	'?' => '…',

	# greek
	'ma' => 'α',
	'mb' => 'β', # v
	'mg' => 'γ',
	'md' => 'δ',
	'me' => 'ε',
	'mz' => 'ζ',
	'mi' => 'η',
	'mh' => 'θ',
	'mj' => 'ι',
	'mk' => 'κ',
	'ml' => 'λ',
	'mm' => 'μ',
	'mn' => 'ν',
	'mx' => 'ξ',
	'mo' => 'ο',
	'mp' => 'π',
	'mr' => 'ρ',
	'ms' => 'σ',
	'mt' => 'τ',
	'my' => 'υ',
	'mf' => 'φ',
	'mc' => 'χ',
	'mw' => 'ψ',
	'mq' => 'ω', # u

	# suþscript
	'm1' => '¹',
	'm2' => '²',
	'm3' => '³',
	'm4' => '⁴',
	'm5' => '⁵',
	'm6' => '⁶',
	'm7' => '⁷',
	'm8' => '⁸',
	'm9' => '⁹',
	'm0' => '⁰',
	'm!' => '₁',
	'm@' => '₂',
	'm#' => '₃',
	'm$' => '₄',
	'm%' => '₅',
	'm^' => '₆',
	'm&' => '₇',
	'm*' => '₈',
	'm(' => '₉',
	'm)' => '₀',

	# maths
	'M!' => '≠',
	'M~' => '≈',
	'M=' => '≝',
	'M>' => '≥',
	'M<' => '≤',
	'M-' => '±',
	'Mi' => '∞',
	'Mn' => 'ⁿ',
	'Mr' => '√',
	'M3' => '∛',
	'M4' => '∜',
	'M%' => '‰',

	'Mf' => 'ƒ',
	'MS' => '∫',
	"M'" => '′',
	'M"' => '″',
	'Mp' => '∂',
	'Md' => 'Δ',
	'MD' => '∇',
	'M+' => '⊕',
	'M*' => '⊗',
	'M^' => '℘',

	'Ms' => '∩',
	'Mu' => '∪',
	'MU' => '∖',
	'MO' => '∅',
	'Mg' => '⊂',
	'MG' => '⊃',
	'Mh' => '⊄',
	'MH' => '⊅',
	'Mb' => '⊆',
	'MB' => '⊇',
	'Mm' => '∈',
	'MM' => '∉',
	'Mk' => '∋',
	'MK' => '∌',

	'MA' => '∀',
	'ME' => '∃',
	'MX' => '∄',
	'M&' => '∧',
	'M|' => '∨',
	'Mc' => '∝',
	'M.' => '⋅',
	'Mo' => '∘',
	'M:' => '∴',
	'M;' => '∵',
	'Mz' => '↯',
	'MF' => '∎',

	'MR' => 'ℝ',
	'MC' => 'ℂ',
	'MN' => 'ℕ',
	'MP' => 'ℙ',
	'MQ' => 'ℚ',
	'MZ' => 'ℤ',
	'M9' => '∟',
	'M8' => '∠',
	'M7' => '∡',
	'Ml' => '∥',
	'ML' => '∦',

	# symbols
	'-1' => '¼',
	'-2' => '½',
	'-3' => '¾',
	'-4' => '⅓',
	'-5' => '⅔',
	'-c' => '©',
	'-p' => '℗',
	'-r' => '®',
	'-s' => '℠',
	'-t' => '™',

	'\s' => '§',
	'\1' => '№',
	'\2' => '½',
	'\3' => '⅓',
	'\4' => '¼',
	'\5' => '⅔',
	'\6' => '¾',
	'\c' => '©',
	'\p' => '℗',
	'\r' => '®',
	'\t' => '™',
	'\T' => '℠',

	(map { ($presymbol.$_ => $arrows{$_}) } keys %arrows),
);

my $groups = kbchars(\%rows);
$groups->{mode} = {
	''  => 'option-shifted ⌥',
	'm' => 'Ω greek prefix ⌥m',
	'M' => '√ maths prefix ⌥M',
	$presymbol => "$rows{$presymbol} symbol prefix ⌥$presymbol",
};
for my $m (qw' m M ', $presymbol) {
	$groups->{def}->{''}->{$m} = "g1 mode$m";
	$groups->{mode}->{$m} //= "mode $m";
	$groups->{def}->{$m} = {
		(map {s/^.//r => 'g0'} grep {/^\Q$m/} keys %rows),
		$m => 'g1 mode',
	};
}
$groups->{flag}->{g1} = ['mode' => "switch to an alternate set of keys"];

+{
	%{$groups},
	version => '1.0',
	title => 'EurKEY',
	intro => join("\n",
		'Third-party proposal <a href="https://eurkey.steffen.bruentjen.eu/">EurKEY</a>',
		'<abbr title="last updated 2017-05-15">v1.3</abbr> by Steffen Brüntjen',
		'supporting most European languages while pressing AltGr or ⌥ Option.',
		'Selectable in <abbr title="distributed with X since 2014">Linux</abbr>',
		'and available for <a href="/keyboard/altgr/windows">Windows</a>',
		'or <a href="/keyboard/altgr/macos">macOS</a>.',
	),
	description => [
		"An interactive map of EurKEY, the European Keyboard Layout.",
	],
	image => 'keyboard/altgr/eurkeyboard.jpg',
}
