<?php
/**
 * Athlete2 Theme
 * Blog recent posts widget
 *
 * @var $block \Magefan\Blog\Block\Widget\Recent
 * 
 * @category    Olegnax
 * @package     Olegnax_Athlete2
 * @copyright   Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
 * @license     https://www.olegnax.com/license
 */
?>
<?php
	$theme_helper = $this->helper('Olegnax\Athlete2\Helper\Helper');
	$at_settings = $theme_helper->getConfig('athlete2_settings/blog');
	$_hideReadMore = $at_settings['blog_list_read_more'];
	$_hideCategories = $at_settings['blog_list_categories'];
	$iBigWidth = $at_settings['blog_list_big_image_width'];
	$iBigHeight = $at_settings['blog_list_big_image_height'];
	$imgAttrs='';
	$classes = [];
	$classes[] = 'blog-list--above-image';
	$classes[] = 'blog-style-modern';
	if($theme_helper->getConfig('athlete2_design/blog_list/big_post_white')){
		$classes[] = 'white-style';
	}
	$classesOutput = implode(' ',	$classes);
?>

<?php
    $_postCollection = $block->getPostCollection();
?>
<?php if ($_postCollection->count()) { ?>
<div class="post-list-wrapper widget blog-widget-recent">
	<?php $blockTitle = $block->escapeHtml($block->getData('title'));
	if ($blockTitle){ ?>
		<h3 class="title"><?= $blockTitle ?></h3>
	<?php } ?>
    <div class="post-list clearfix <?= $classesOutput ?>">
        <?php foreach ($_postCollection as $_post) { ?>
            <?php
                $_postUrl = $block->escapeUrl($_post->getPostUrl());
                $_postName = $block->escapeHtml($_post->getTitle(), null, true);
				$_categoriesCount = $_post->getCategoriesCount();
				if($iBigWidth && $iBigHeight) {
					$imgAttrs .=' width="' . $iBigWidth . '" height="' . $iBigHeight . '" ';
					$bigFeaturedImage = $_post->getFeaturedImage([$iBigWidth, $iBigHeight]);
				} else {
					$bigFeaturedImage = $_post->getFeaturedImage();
				}
            ?>
            <article class="post-holder post-holder-<?php echo (int)$_post->getId() ?>">
				<?php if ($bigFeaturedImage) { ?>
					<div class="post-image-wrapper post-image-cover">
						<img src="<?php echo $block->escapeUrl($bigFeaturedImage) ?>" alt="<?php echo $block->escapeHtmlAttr($_postName) ?>" <?php echo $block->escapeHtmlAttr($imgAttrs) ?>/>
						<div class="gradient-overlay"></div>
					</div>
				<?php } ?>
					<div class="post-content">
						<?php if ( $_categoriesCount ) { ?>
							<div class="item post-categories">
								<?php $n = 0; foreach($_post->getParentCategories() as $ct) { $n++; ?>
									<a title="<?php echo $block->escapeHtml($ct->getTitle()) ?>" href="<?php echo $block->escapeUrl($ct->getCategoryUrl()) ?>">
										<?php echo $block->escapeHtml($ct->getTitle()) ?>
									</a>									
								<?php } ?>
							</div>
						<?php } ?>
						<h2 class="post-title">
							<a class="post-item-link" href="<?php echo $_postUrl ?>">
								<?php echo $_postName; ?>
							</a>
						</h2>
						<?php if ($content = $block->getShorContent($_post)) { ?>
							<div class="post-description clearfix">
								<?php echo $content ?>  
							</div>
						<?php } ?>
						<div class="post-links">
							<?php if (!$_hideReadMore) { ?>		
								<a class="item post-read-more" href="<?php echo $_postUrl ?>" title="<?php echo $_postName ?>">
								   <?php echo __('Read more') ?>
								</a>
							<?php } ?>
						</div>
					</div>

            </article>

        <?php } ?>
    </div>
</div>
<?php } ?>