#!/bin/sh

gawk -v CC=$1 '
@include "scripts/getcls.awk"

BEGIN {
	CC = toupper(CC)
}

$1 == CC && /.. start/ {
	sub(/^.. start/, "");
	sub(/^ /, "")
	printf "tr .new-design {th colspan=\"8\" {-%s}}\n", $0
	next
}

$1 == CC {
	y = $10
	if ($11 != "") {
		y_ = $11
		for (i = 12; i <= NF; i++)
			y_ = y_ " " $i
	}
	printf "trX {"
	for (i = 2; i <= 9; i++) {
		# Greece 2002 needs special handling
		if (CC == "GR" && $10 == 2002 && $11 == "MM") {
			if (i <= 5)
				y_ = "F"
			else if (i <= 7)
				y_ = "E"
			else
				y_ = "S"
		}

		if ($11 != "")
			printf "td .%s {-%s @sup{-%s}}", getcls($i), y, y_
		else
			printf "td .%s {-%s}", getcls($i), y
	}
	print "}"
}

END {
	print "__MARKER__"
}
' data/coins \
| scripts/last-of-design.sed