<?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("../../data/common.json");
	$data_pronouns = read_json("../../data/personal_pronouns.json");
	
	$data = $data_pronouns["words"];
	{
		{
			$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");
		}
		{
			$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");
		}
		{
			$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");
		}
		{
			$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");
		}
		{
			$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");
		}
	}
	
	$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 = $table->snap
	(
		[
			"label_vertical" => function ($column) {return "";},
			"columns_vertical" =>
			[
				$table->columns_get()[4],
				$table->columns_get()[5],
			],
			"label_horizontal" => function ($column, $value) {return $value;},
			"columns_horizontal" =>
			[
				$table->columns_get()[1],
				$table->columns_get()[2],
				$table->columns_get()[3],
			],
			"columns_data" =>
			[
				$table->columns_get()[0],
				$table->columns_get()[6],
			],
			"data_aggregator" => function ($values)
			{
				return $values;
			},
			"data_formatter" => function ($value)
			{
				return (
					_bar("words")
					(
						[
							"original" => $value[0]["words"],
							"translated" => $value[1]["words"],
						]
					)
				);
				return json_encode($value);
			},
		]
	);
	$table->generate();
 ?>
	<p>For the flected and otherwise related forms of the personal pronouns see the section <a href="#declension">Declension</a>.</p>
</section>