<?php
	global $configuration;
	include_once("source/logic/server/misc.php");
	include_once("source/logic/server/data.php");
	include_once("source/logic/server/table.php");
 ?>
<section class="section" id="word_functions">
	<header>Word Functions</header>
	<?php proposal(); ?>
<?php
	$table = new class_table
	(
		[
			new class_column
			(
				"Affix",
				"affix",
				function ($value)
				{
					return mark($value, ["type_word", "lang_fs"]);
				}
			),
			new class_column
			(
				"Type",
				"type_",
				function ($value)
				{
					return (
						implode
						(
							" → ",
							array_map
							(
								function ($group)
								{
				 					return ("{" . implode(",", $group) . "}");
								},
								$value
							)
						)
					);
				}
			),
			new class_column
			(
				"Description",
				"description_",
				function ($value)
				{
					$output = "";
					if ($value["name"] != null) $output .= (mark($value["name"], ["grammarterm"]) . ": ");
					if ($value["description"] != null) $output .= ($value["description"]);
					return $output;
				}
			),
			/*
			new class_column
			(
				"Cognates",
				"cognates",
				function ($value)
				{
					return implode(", ", array_map(function ($entry) {return ($entry["language"] . ": " . mark($entry["affix"], ["word", "lang_" . $entry["language"]]));}, $value));
				}
			),
			 */
			new class_column
			(
				"Example",
				"example_",
				_bar("word")
				/*
				function ($x)
				{
					return json_encode($x);
				}
				 */
			),
		],
		sql_condense
		(
			read_json("source/data/word_functions.json"),
			["type_from","type_to","name","description","example"],
			["type_","description_","example_"],
			[
				"type_" => function ($values) {return [$values["type_from"], $values["type_to"]];},
				"description_" => function ($values) {return ["name" => $values["name"], "description" => $values["description"]];},
				"example_" => function ($values) {global $configuration; return ["original" => [$values["example"]["word"]], "translated" => $values["example"]["translations"][$configuration["target"]]];},
			]
		)
	);
	$table->generate();
 ?>
<p>
	Some complex examples:
	<ul>
		<li><?php echo(format_correlation("word")(["flk" => ["unmanlikhed"], "eng" => ["inhumanity"]])); ?></li>
		<li><?php echo(format_correlation("word")(["flk" => ["seberenung"], "eng" => ["visualization"]])); ?></li>
		<li><?php echo(format_correlation("word")(["flk" => ["kraftigenar"], "eng" => ["fortifier"]])); ?></li>
	</ul>
</p>
</section>