use utf8;
use strict;
use warnings;
no warnings 'qw';
use Shiar_Sheet::KeyboardChars 'kbmodes';

my $greekc = '*';
my %info = (
	mode => {
		''  => 'altgr-shifted ⌥',
	},
	version => '1.0', # upstream v2.0 2021/04/12
	title => 'Western European',
	map => 'qwerty', # specific positioning
	category => 'latin/thirdparty/xorg',
	intro => join("\n",
		'Layout (<a href="https://altgr-weur.eu/" target=_blank>available</a> for major OSes)',
		'to provide all accented characters commonly used',
		'in 10 Western European languages available through one AltGr keystroke.',
	),
	description => [
		"QWERTY for Western European languages",
	],
);

my %rows = (
	'' => {
		'!'  => "\N{COMBINING DOT ABOVE}",
		'"'  => "\N{COMBINING DIAERESIS}",
		'#'  => "\N{COMBINING MACRON}",
		'$'  => '¥',
		'%'  => '£',
		'&'  => '‚',
		"'"  => "\N{COMBINING ACUTE ACCENT}",
		'('  => '‘',
		')'  => '’',
		'*'  => 'µ',
		'+'  => "\N{COMBINING RING ABOVE}",
		','  => "\N{COMBINING CEDILLA}",
		'-'  => '–',
		'.'  => 'œ',
		'/'  => '¿',
		'0'  => '”',
		'1'  => '¡',
		'2'  => '²',
		'3'  => '³',
		'4'  => '¢',
		'5'  => '€',
		'6'  => "\N{COMBINING CIRCUMFLEX ACCENT}",
		'7'  => '„',
		'8'  => 'ß',
		'9'  => '“',
		':'  => 'Ô',
		';'  => 'ô',
		'<'  => "\N{COMBINING OGONEK}",
		'='  => '°',
		'>'  => 'Œ',
		'?'  => "\N{COMBINING SHORT STROKE OVERLAY}",
		'@'  => "\N{COMBINING DOUBLE ACUTE ACCENT}",
		'['  => '«',
		"\\" => 'ĳ',
		']'  => '»',
		'^'  => "\N{COMBINING CARON}",
		'_'  => '—',
		'`'  => "\N{COMBINING GRAVE ACCENT}",
		'a'  => 'ä',
		'A'  => 'Ä',
		'B'  => 'Õ',
		'b'  => 'õ',
		'C'  => 'Ç',
		'c'  => 'ç',
		'D'  => 'É',
		'd'  => 'é',
		'e'  => 'ë',
		'E'  => 'Ë',
		'F'  => 'Ê',
		'f'  => 'ê',
		'G'  => 'Î',
		'g'  => 'î',
		'h'  => 'û',
		'H'  => 'Û',
		'I'  => 'Ï',
		'i'  => 'ï',
		'j'  => 'ú',
		'J'  => 'Ú',
		'k'  => 'í',
		'K'  => 'Í',
		'L'  => 'Ó',
		'l'  => 'ó',
		'm'  => 'ì',
		'M'  => 'Ì',
		'n'  => 'ñ',
		'N'  => 'Ñ',
		'o'  => 'ö',
		'O'  => 'Ö',
		'P'  => 'Ò',
		'p'  => 'ò',
		'Q'  => 'Å',
		'q'  => 'å',
		'R'  => 'È',
		'r'  => 'è',
		'S'  => 'À',
		's'  => 'à',
		'T'  => 'Ø',
		't'  => 'ø',
		'u'  => 'ü',
		'U'  => 'Ü',
		'v'  => 'ã',
		'V'  => 'Ã',
		'W'  => 'Æ',
		'w'  => 'æ',
		'x'  => 'â',
		'X'  => 'Â',
		'Y'  => 'Ù',
		'y'  => 'ù',
		'z'  => 'á',
		'Z'  => 'Á',
		'{'  => '‹',
		'|'  => 'Ĳ',
		'}'  => '›',
		'~'  => "\N{COMBINING TILDE}",
	},
	'*' => {
		# dead_greek digraphs from data/xorg-compose
		qw(
			a α  b β  d δ  e ε  f φ  g γ  h η  i ι  j θ  k κ  l λ  m μ
			n ν  o ο  p π  q χ  r ρ  s σ  t τ  u υ  w ω  x ξ  y ψ  z ζ
		),
		'*' => 'µ', # MICRO SIGN at space and double mode
	},
);

our %get;
if ($get{map} and $get{map} eq 'dvorak') {
	%info = (%info,
		map   => 'dvorak',
		title => 'dWEURak',
		intro => join("\n",
			'Layout for <a href="https://altgr-weur.eu/" target=_blank>Western European</a> languages',
			'repositioned for Dvorak letters instead of original <span class=family-name>Qwerty</span>.',
		),
		description => [
			"Dvorak for Western European languages",
		],
	);
	$info{version} .= '.1';

	my $dq = q{
		'z ,l .d pj yk  fq gt  r, l'
		dv hb s8  tw 8.
		;s qp jr ky xm  bx m; wf vh zg
	};
	my %dq = split //, $dq =~ s/\s//gr;  # dvorak => qwerty key

	my %uc = (qw{ ' "  , <  . >  ; :  - _  8 * }, map {lc, uc} 'a'..'z');
	$dq{ $uc{$_} } = $uc{ $dq{$_} } for keys %dq;  # same shifted

	@{ $rows{''} }{keys %dq} = map { $rows{''}{$_} } values %dq;
	%{ $rows{S} } = (%{ delete $rows{$greekc} },
		qw( q θ  c χ   j ϑ  J ϴ  v ϖ  V ∇ ),
	);
	$greekc = 'S';
}

$info{mode}{$greekc} = "$rows{''}{$greekc} greek prefix ⌥$greekc";
$_ = { (map {uc} %{$_}), %{$_} } for $rows{$greekc};  # uppercase greek

+{ %{ kbmodes(\%rows) }, %info }
