<?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.). However 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 phoneme-transitions with example words in square brackets:</p>
	<span class="todo">more entries</span>
<?php
	$data_transitions = read_json("source/data/transitions.json");
	
	$data = $data_transitions["data"];
	// $data = sql_select($data, function ($row) {return in_array($row["language_id"], ["pg","fs","en"]);});
	
	$table = new class_table
	(
		[
			new class_column("Transition", "transition_id"),
			new class_column("Language", "language_id"),
			new class_column("Phonemes", "phonemes"),
			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()[1],
				$table->columns_get()[2],
				$table->columns_get()[3],
			],
			"data_aggregator" => function ($values)
			{
				return $values;
			},
			"data_formatter" => function ($values)
			{
				if (count($values) == 1)
				{
					$phonemes = implode(
						", ",
						array_map
						(
							function ($phoneme) use (&$values)
							{
								return mark($phoneme, ["type_word", "lang_" . $values[0]["language_id"]]);
							},
							$values[0]["phonemes"]
						)
					);
					$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 = $phonemes;
					if (count($values[0]["examples"]) > 0)
					{
						$break = true;
						$breaker = $break ? "<br/>" : " ";
						$output .= "${breaker}[${examples}]";
					}
					return $output;
				}
				else
				{
					return "?";
				}
			},
		]
	)->generate();
 ?>
</section>