<?php

use JetApplication\Application_Web_Services;
use JetApplication\Content_Article;
use Jet\Data_Paginator;
use Jet\Locale;
use Jet\MVC_View;

/**
 * @var MVC_View $this
 * @var Content_Article[] $articles_list
 * @var Data_Paginator $paginator
 */
$articles_list = $this->getRaw( 'articles_list' );
$paginator = $this->getRaw( 'paginator' );

?>

<?php foreach( $articles_list as $article ):
	if($article->getTitleImage()) {
		$thb = Application_Web_Services::ImageManager()?->generateThbURI( $article->getTitleImage(), 100, 100 );
	} else {
		$thb = null;
	}
	$url = $article->getUrl();
	?>
	<div style="display: grid;grid-template-columns: 120px 1fr;align-items: center">
		<div>
			<?php if($thb): ?>
			<a href="<?=$url?>"><img src="<?=$thb?>"></a>
			<?php endif; ?>
		</div>
		<div>
			<a href="<?=$url;?>" style="font-size: 25px;"><?= $article->getTitle(); ?></a>
			<br/>
			<span style="font-size: 10px;"><?= Locale::dateAndTime( $article->getDateTime() ); ?></span>
			<p><?= $article->getAnnotation(); ?></p>
		</div>
	</div>
	<hr/>
<?php endforeach; ?>

<div style="background-color: #eeeeee;padding: 10px;">
	<div style="display: inline-block;width: 30px;">
		<?php if( ($p_URL = $paginator->getPrevPageURL()) ): ?>
			<a href="<?= $p_URL; ?>" class="btn btn-light">&lt;</a>
		<?php endif ?>
	</div>
	<div style="display: inline-block;width: 400px;text-align: center">
		<?php foreach( $paginator->getPagesURL() as $p_no => $p_URL ): ?>
			<?php if( $p_no == $paginator->getCurrentPageNo() ): ?>
				<strong class="btn btn-info"><?php echo $p_no; ?></strong>
			<?php else: ?>
				<a href="<?= $p_URL; ?>" class="btn btn-light btn-sm"><?= $p_no; ?></a>
			<?php endif; ?>
		<?php endforeach; ?>

	</div>
	<div style="display: inline-block;width: 30px;">
		<?php if( ($p_URL = $paginator->getNextPageURL()) ): ?>
			<a href="<?= $p_URL; ?>" class="btn btn-light">&gt;</a>
		<?php endif ?>
	</div>

	<div style="display: inline-block;float:right;" class="btn">
		<?= $paginator->getShowFrom(); ?> - <?= $paginator->getShowTo(); ?> / <?= $paginator->getDataItemsCount(); ?>
	</div>
</div>

