<?php
global $configuration;
include_once("source/logic/server/data.php");
include_once("source/logic/server/sql.php");
include_once("source/logic/server/table.php");
 ?>
<section class="section" id="principles">
	<header>Principles</header>
	<p>The word stock of Folksprak is &dash; with minor exceptions &dash; derived from the modern Germanic languages (e.g. English, German, Swedish, &#8230;) and/or their precursors (e.g. Old English, Old Norse, Proto Germanic, etc.). Branches which no longer emerge today (e.g. the East Germanic languages like Gothic), were not incorporated.</p>
	<p>The following table gives an overview about the typical transitions of phones from Proto-Germanic to some of todays natural Germanic languages and Folksprak, along with example words in square brackets:</p>
	<span class="todo">more entries</span>
<?php
	$data_common = read_json("source/data/common.json");
	$data_transitions = read_json("source/data/transitions.json");
	
	$data = $data_transitions["data"];
	{
		{
			$data = sql_select($data, function ($row) {return in_array($row["language_id"], ["gem","flk","eng","deu","nld","dan","nob","swe","isl"]);});
		}
		{
			{
				$data = sql_cross($data, $data_common["languages"]);
				$data = sql_select($data, function ($row) {return ($row["language_id"] == $row["id"]);});
				$data = sql_delete($data, ["id"]);
				$data = sql_rename($data, "name", "language_name");
			}
		}
	}
		
	$table = new class_table
	(
		[
			new class_column("Transition", "transition_id"),
			new class_column("Language", "language_name"),
			new class_column("Language ID", "language_id"),
			new class_column("Phones", "phones"),
			new class_column("Examples", "examples"),
		],
		$data
	);
	
	$table->snap
	(
		[
			"label_vertical" => function ($column) {return "";},
			"columns_vertical" =>
			[
				$table->columns_get()[0],
			],
			"label_horizontal" => function ($column, $value) {return $value;},
			"columns_horizontal" =>
			[
				$table->columns_get()[1],
			],
			"columns_data" =>
			[
				$table->columns_get()[2],
				$table->columns_get()[3],
				$table->columns_get()[4],
			],
			"data_aggregator" => function ($values)
			{
				return $values;
			},
			"data_formatter" => function ($values)
			{
				if (count($values) == 1)
				{
					$phones = implode(
						", ",
						array_map
						(
							function ($phoneme) use (&$values)
							{
								return mark($phoneme, ["type_word", "lang_" . $values[0]["language_id"]]);
							},
							$values[0]["phones"]
						)
					);
					$examples = implode
					(
						", ",
						array_map
						(
							function ($word) use (&$values)
							{
								return mark($word, ["type_word", "lang_" . $values[0]["language_id"]]);
							},
							array_slice($values[0]["examples"], 0, 1)
						)
					);
					$output = $phones;
					if (count($values[0]["examples"]) > 0)
					{
						$break = true;
						$breaker = $break ? "<br/>" : " ";
						$output .= "${breaker}[${examples}]";
					}
					return $output;
				}
				else
				{
					return "?";
				}
			},
		]
	)->generate();
 ?>
</section>