<?php
	include_once("source/logic/server/data.php");
	include_once("source/logic/server/table.php");
	include_once("source/logic/server/misc.php");
	include_once("source/logic/server/sql.php");
 ?>
<section class="subsection" id="correlatives">
	<header>Correlatives</header>
	<?php proposal(); ?>
<?php
	$data_correlatives = read_json("source/data/correlatives.json");
	$data = $data_correlatives["words"];
	{
		{
			$data = sql_cross($data, $data_correlatives["domains"]);
			$data = sql_select($data, function ($row) {return ($row["domain_id"] == $row["id"]);});
			$data = sql_delete($data, ["domain_id", "id"]);
			$data = sql_rename($data, "name", "domain_name");
		}
		{
			$data = sql_cross($data, $data_correlatives["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");
		}
	}
	
	$table = new class_table
	(
		[
			new class_column("Language", "language_id"),
			new class_column("Domain", "domain_name"),
			new class_column("Type", "type_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()[1],
			],
			"label_horizontal" => function ($column, $value) {return $value;},
			"columns_horizontal" =>
			[
				$table->columns_get()[2],
			],
			"columns_data" =>
			[
				$table->columns_get()[0],
				$table->columns_get()[3],
			],
			"data_aggregator" => function ($values)
			{
				return $values;
			},
			"data_formatter" => function_chain
			(
				[
					object_from_array("language_id"),
					object_map(object_attribute("words")),
					format_correlation("type_word"),
				]
			),
		]
	);
	$table_->generate();
 ?>
	<div class="note note_information">
		<span class="note_content">
			<p>Some of these words are very unlikely to ever get used (e.g. <?php echo(mark("ni slag", ["type_word", "lang_flk"])); ?>). Nevertheless they exist and are listed for completeness.</p>
		</span>
	</div>
</section>