<?php

use Jet\Http_Request;
use Jet\Locale;
use Jet\MVC_View;
use Jet\Tr;
use Jet\Data_DateTime;
use Jet\UI;

/**
 * @var MVC_View $this
 * @var Locale $locale
 */

$now = Data_DateTime::now();

$locale = $this->getRaw('locale');
?>

<div class="card">
	<div class="card-body">
		<?=UI::flag($locale)?> <?=$locale->getName()?> / <?=$locale->getName( $locale )?>
	</div>
</div>

<br>

<legend><?= Tr::_( 'Date' ) ?></legend>

<table class="table">
	<tr>
		<td style="width: 20%"><?= Tr::_( 'Short: ' ) ?></td>
		<td><?= $locale->formatDate( $now, Locale::DATE_TIME_FORMAT_SHORT ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Medium: ' ) ?></td>
		<td><?= $locale->formatDate( $now, Locale::DATE_TIME_FORMAT_MEDIUM ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Long: ' ) ?></td>
		<td><?= $locale->formatDate( $now, Locale::DATE_TIME_FORMAT_LONG ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Full: ' ) ?></td>
		<td><?= $locale->formatDate( $now, Locale::DATE_TIME_FORMAT_FULL ); ?></td>
	</tr>

	<tr>
		<td><?= Tr::_( 'Custom: ' ) ?></td>
		<td><?= $now->format( 'Y-m-d' ); ?></td>
	</tr>

</table>

<legend><?= Tr::_( 'Time' ) ?></legend>

<table class="table">
	<tr>
		<td style="width: 20%"><?= Tr::_( 'Short: ' ) ?></td>
		<td><?= $locale->formatTime( $now, Locale::DATE_TIME_FORMAT_SHORT ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Medium: ' ) ?></td>
		<td><?= $locale->formatTime( $now, Locale::DATE_TIME_FORMAT_MEDIUM ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Long: ' ) ?></td>
		<td><?= $locale->formatTime( $now, Locale::DATE_TIME_FORMAT_LONG ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Full: ' ) ?></td>
		<td><?= $locale->formatTime( $now, Locale::DATE_TIME_FORMAT_FULL ); ?></td>
	</tr>

	<tr>
		<td><?= Tr::_( 'Custom: ' ) ?></td>
		<td><?= $now->format( 'H:i:s' ); ?></td>
	</tr>

</table>


<legend><?= Tr::_( 'Date and time' ) ?></legend>

<table class="table">
	<tr>
		<td style="width: 20%"><?= Tr::_( 'Short: ' ) ?></td>
		<td><?= $locale->formatDateAndTime( $now, Locale::DATE_TIME_FORMAT_SHORT, Locale::DATE_TIME_FORMAT_SHORT ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Medium: ' ) ?></td>
		<td><?= $locale->formatDateAndTime( $now, Locale::DATE_TIME_FORMAT_MEDIUM, Locale::DATE_TIME_FORMAT_MEDIUM ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Long: ' ) ?></td>
		<td><?= $locale->formatDateAndTime( $now, Locale::DATE_TIME_FORMAT_LONG, Locale::DATE_TIME_FORMAT_LONG ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Full: ' ) ?></td>
		<td><?= $locale->formatDateAndTime( $now, Locale::DATE_TIME_FORMAT_FULL, Locale::DATE_TIME_FORMAT_FULL ); ?></td>
	</tr>

	<tr>
		<td><?= Tr::_( 'Custom: ' ) ?></td>
		<td><?= $now->format( 'Y-m-d H:i:s' ); ?></td>
	</tr>

</table>

<legend><?= Tr::_( 'Numbers' ) ?></legend>

<table class="table">
	<tr>
		<td style="width: 20%"><?= Tr::_( 'Integer: ' ) ?></td>
		<td><?= $locale->formatInt( 1234567898765321 ); ?></td>
	</tr>

	<tr>
		<td><?= Tr::_( 'Float: ' ) ?></td>
		<td><?= $locale->formatFloat( pi(), 2, 20 ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Float: ' ) ?></td>
		<td><?= $locale->formatFloat( 1980, 2, 20 ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'File size: ' ) ?></td>
		<td><?= $locale->formatSize( 5046586572 ); ?></td>
	</tr>

	<tr>
		<td><?= Tr::_( 'Price: ' ) ?></td>
		<td><?= $locale->formatCurrency( 10.95, 'USD' ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Price: ' ) ?></td>
		<td><?= $locale->formatCurrency( 225.70, 'CZK' ); ?></td>
	</tr>
	<tr>
		<td><?= Tr::_( 'Price: ' ) ?></td>
		<td><?= $locale->formatCurrency( 11.81, 'EUR' ); ?></td>
	</tr>

</table>


<legend><?= Tr::_( 'Locales' ) ?></legend>


<table class="table table-striped">
	<thead>
	<tr>
		<th rowspan="2"></th>

		<th rowspan="2"><?= Tr::_( 'Locale code' ) ?></th>
		<th rowspan="2"><?= Tr::_( 'Name' ) ?></th>
		<th rowspan="2"><?= Tr::_( 'Native name' ) ?></th>
		<th colspan="3"><?= Tr::_( 'Region' ) ?></th>
		<th colspan="3"><?= Tr::_( 'Language' ) ?></th>
	</tr>
	<tr>
		<th><?= Tr::_( 'Code' ) ?></th>
		<th><?= Tr::_( 'Name' ) ?></th>
		<th><?= Tr::_( 'Native name' ) ?></th>
		<th><?= Tr::_( 'Code' ) ?></th>
		<th><?= Tr::_( 'Name' ) ?></th>
		<th><?= Tr::_( 'Native name' ) ?></th>
	</tr>
	</thead>
	<tbody>
	<?php
	$current_locale = Locale::getCurrentLocale();
	foreach( Locale::getAllLocalesList() as $l => $name ):
		$l = new Locale( $l );
		?>
		<tr>
			<td style="font-size: 2rem"><?= UI::flag( $l ) ?></td>

			<td>
				<?php if($l->toString()==$locale->toString()): ?>
				<b><?=$l;?></b>
				<?php else: ?>
				<a href="<?= Http_Request::currentURI(['locale' =>$l->toString()])?>"><?= $l ?></a>
				<?php endif; ?>
			</td>
			<td><?= $l->getName( $current_locale ) ?></td>
			<td><?= $l->getName( $l ) ?></td>

			<td><?= $l->getRegion() ?></td>
			<td><?= $l->getRegionName( $current_locale ) ?></td>
			<td><?= $l->getRegionName( $l ) ?></td>

			<td><?= $l->getLanguage() ?></td>
			<td><?= $l->getLanguageName( $current_locale ) ?></td>
			<td><?= $l->getLanguageName( $l ) ?></td>

		</tr>
	<?php endforeach; ?>
	</tbody>
</table>

