<?php
global $configuration;
include_once("source/logic/server/data.php");
include_once("source/logic/server/sql.php");
include_once("source/logic/server/table.php");

/*
function convert_persona($persona) {return [0 => "impersonal", 1 => "1st person", 2 => "2nd person", 3 => "3rd person"][$persona];}
function convert_numerus($numerus) {return [0 => null, 1 => "singular", 2 => "plural"][$numerus];}
function convert_genus($genus) {return [0 => "common", 1 => "masculine", 2 => "feminine", 3 => "neuter"][$genus];}
 */
 ?>
<section class="subsection" id="personal_pronouns">
	<header>Personal Pronouns</header>
<?php
	$data_common = read_json("source/data/common.json");
	$data_pronouns = read_json("source/data/personal_pronouns.json");
	
	$data = $data_pronouns["words"];
	{
		{
			if (false)
			{
				$data = sql_cross($data, $data_common["counts"]);
				$data = sql_select($data, function ($row) {return ($row["count_id"] == $row["id"]);});
				$data = sql_delete($data, ["count_id", "id"]);
				$data = sql_rename($data, "name", "count_name");
			}
			else
			{
				$data = sql_rename($data, "count_id", "count_name");
			}
		}
		{
			if (false)
			{
				$data = sql_cross($data, $data_common["persons"]);
				$data = sql_select($data, function ($row) {return ($row["person_id"] == $row["id"]);});
				$data = sql_delete($data, ["person_id", "id"]);
				$data = sql_rename($data, "name", "person_name");
			}
			else
			{
				$data = sql_rename($data, "person_id", "person_name");
			}
		}
		{
			if (false)
			{
				$data = sql_cross($data, $data_common["genders"]);
				$data = sql_select($data, function ($row) {return ($row["gender_id"] == $row["id"]);});
				$data = sql_delete($data, ["gender_id", "id"]);
				$data = sql_rename($data, "name", "gender_name");
			}
			else
			{
				$data = sql_rename($data, "gender_id", "gender_name");
			}
		}
		{
			if (false)
			{
				$data = sql_cross($data, $data_pronouns["types"]);
				$data = sql_select($data, function ($row) {return ($row["type_id"] == $row["id"]);});
				$data = sql_delete($data, ["type_id", "id"]);
				$data = sql_rename($data, "name", "type_name");
			}
			else
			{
				$data = sql_rename($data, "type_id", "type_name");
			}
		}
		{
			if (true)
			{
				$data = sql_cross($data, $data_common["cases"]);
				$data = sql_select($data, function ($row) {return ($row["case_id"] == $row["id"]);});
				$data = sql_delete($data, ["case_id", "id"]);
				$data = sql_rename($data, "name", "case_name");
			}
			else
			{
				$data = sql_rename($data, "case_id", "case_name");
			}
		}
	}
	
	{
		// $data = sql_select($data, function ($row) {return ($row["case_name"] != "pos");});
		$data = sql_select($data, function ($row) {global $configuration; return (($row["language_id"] == "fs") or ($row["language_id"] == $configuration["target"]));});
	}
	
	$table = new class_table
	(
		[
			new class_column("Language", "language_id"),
			new class_column("Count", "count_name"),
			new class_column("Person", "person_name"),
			new class_column("Gender", "gender_name"),
			new class_column("Type", "type_name"),
			new class_column("Case", "case_name"),
			new class_column("Words", "words", function ($x) {return json_encode($x);}),
		],
		$data
	);
	
	$table->snap
	(
		[
			"label_vertical" => function ($column) {return "";},
			"columns_vertical" =>
			[
				$table->columns_get()[4],
				$table->columns_get()[1],
				$table->columns_get()[2],
				$table->columns_get()[3],
			],
			"label_horizontal" => function ($column, $value) {return $value;},
			"columns_horizontal" =>
			[
				$table->columns_get()[5],
			],
			"columns_data" =>
			[
				$table->columns_get()[0],
				$table->columns_get()[6],
			],
			"data_aggregator" => function ($values)
			{
				return $values;
			},
			"data_formatter" => function ($value)
			{
				switch (1)
				{
					case 0:
					{
						return _baz($value[0]["words"], "word", "fs");
						// break;
					}
					case 1:
					{
						global $configuration;
						$value_ = [];
						foreach (["fs",$configuration["target"]] as $language_id)
						{
							$value_[$language_id] = array_reduce
							(
								array_map
								(
									function ($dataset) {return $dataset["words"];},
									array_filter($value, function ($dataset) use (&$language_id) {return ($dataset["language_id"] == $language_id);})
								),
								function ($x, $y) {return array_merge($x, $y);},
								[]
							);
						}
						return (
							_bar("word")
							(
								[
									"original" => $value_["fs"],
									"translated" => $value_[$configuration["target"]],
								]
							)
						);
						// break;
					}
					default:
					{
						return json_encode($value);
						// break;
					}
				}
			},
		]
	)->generate();
 ?>
	<p>Since the word <span class="word lang_fs">man</span> simply means <span class="word lang_en">human being</span>, it can be understood as an implicit way to express an abstract actor; similar words like <span class="word lang_fs">lüd</span> (<span class="word lang_en">people</span>) or <span class="word lang_fs">di</span> can be used as well.</p>
	<div class="note_information">The honorific salutation is expressed by the plural form <span class="word lang_fs">je</span>; however it should be avoided in usual speech in favor of the singular form <span class="word lang_fs">du</span>.</div>
	<div class="note_information">A reflexive genitive can be formed by inserting the word <span class="word lang_fs">egen</span> (<span class="word lang_en">own</span>), for example <span class="sentence lang_fs">Han[A] hav givt to ham[B] hans egen buk.</span> ~ <span class="sentence lang_en">He[A] has given (to) him[B] his own book.</span> (A's book was given to B).</div>
</section>