<?php
namespace JetApplicationModule\Test\REST;

use Jet\Http_Request;
use Jet\Tr;
use Jet\MVC_View;

/**
 *
 * @var MVC_View $this
 * @var Test_Abstract $selected_test
 */


$tests = $this->getRaw( 'tests' );
$selected_test = $this->getRaw( 'selected_test' );

$session = Main::getSession();
?>
<style>
    h3 {
        background: #b9b9b9;
        padding: 4px;
        margin-top: 5px;
        margin-bottom: 5px;
    }

    h4 {
        background: #e9e9e9;
        padding: 4px;
        margin-top: 5px;
        margin-bottom: 5px;
    }
</style>
<div style="background: #0f0f0f;color: #c9c9c9;display: grid;align-items: center;grid-template-columns: 160px 1fr;">
	<div style="padding: 10px;"><img src="https://php-jet.net/images/logo-st.svg" style="width: 120px;height: auto"></div>
	<div><b><?= Tr::_( 'REST API Tests' ) ?></b></div>
</div>

<div style="display: grid;grid-template-columns: 1fr 2fr;">
	<div style="background: #eeeeee;margin: 0px;">
		<div style="padding: 5px;background: #aaaaaa;display: flex;align-items: center;gap: 10px;">
			<div>
				<?= Tr::_( 'Current REST API client user: %USERNAME%', ['USERNAME' => $session->getValue( 'username' )] ) ?>
			</div>
			<div>
				<a href="?logout" class="btn btn-light btn-sm"><?= Tr::_( 'Logout' ) ?></a>
			</div>
		</div>
		<div style="padding: 20px;">
			
			<?php foreach( $tests as $tests_data ): ?>
				<h2><?= $tests_data['title'] ?></h2>
				<ul>
					<?php foreach( $tests_data['tests'] as $test ):
						/**
						 * @var Test_Abstract $test
						 */
						if( !$test->isEnabled() ) {
							continue;
						}

						if( $test->isSelected() ):
							?>
							<li><strong><?= $test->getTitle() ?></strong></li>
						<?php
						else:
							?>
							<li>
								<a href="<?= Http_Request::currentURL( ['test' => $test->getId()] ) ?>"><?= $test->getTitle() ?></a>
							</li>
						<?php
						endif;
					endforeach; ?>
				</ul>
			<?php endforeach; ?>
		</div>
	</div>
	<div style="overflow: auto;padding: 10px;">
		<?php $selected_test?->showResult(); ?>
	</div>
</div>