use strict;
use warnings;

my %cat = (
	default => [qw( euro latin science graph )],
	euro => [qw( windows ukext macos macos-abc weur eurkey msx )],
	ipa     => [qw( ipa-ucl xipa )],
	latin   => [qw( ipa-ucl olpc boyeg drix )],
	science => [qw( symbolics apl spacecadet )],
	graph => [qw( unigraph emojiworks )],
	extra => [qw( msx-graph p8scii zoo )],
);

for my $name (map {@{$_}} values %cat) {
	my $keys = do "keyboard/altgr/$name.eng.inc.pl" or next;
	my %row = %{$keys}{qw( title category flag mode image imagealt )};
	$cat{$name} = \%row;

	$row{mode} //= {'' => undef};

	if (($keys->{moderows} // '') =~ /^\d* [45] \d{2,}/x) {
		# move root +meta keys to distinct mode
		$row{mode}{"\e"} = '+';
		/^\+./ and $keys->{def}{"\e"}{$_} = delete $keys->{def}{''}{$_}
			for keys %{ $keys->{def}{''} };
	}

	for my $mode (keys %{ $row{mode} }) {
		$row{inventory}{$mode}{$_}++
			for grep { /^g[2-9]/ } map { s/ (?!ext).*//r } map {$_->[0]}
			values %{ $keys->{def}{$mode} };
	}
}

\%cat
