<?php

/**
 * Copyright © Magefan (support@magefan.com). All rights reserved.
 * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
 *
 * Glory to Ukraine! Glory to the heroes!
 */
?>
<?php
$helper = $this->helper('Rokanthemes\RokanBase\Helper\Data');
$description = $helper->getConfigData('themeoption/bloggeneral/description');
$blog_see_all = $helper->getConfigData('themeoption/bloggeneral/blog_see_all');
$items = $helper->getConfigData('themeoption/bloggeneral/blog_items');
$items_bigdesktop = $helper->getConfigData('themeoption/bloggeneral/blog_items_bigdesktop');
$items_smalldesktop = $helper->getConfigData('themeoption/bloggeneral/blog_items_smalldesktop');
$items_bigtablet = $helper->getConfigData('themeoption/bloggeneral/blog_items_bigtablet');
$items_tablet = $helper->getConfigData('themeoption/bloggeneral/blog_items_tablet');
$items_smalltablet = $helper->getConfigData('themeoption/bloggeneral/blog_items_smalltablet');
$items_mobile = $helper->getConfigData('themeoption/bloggeneral/blog_items_mobile');
$auto = $helper->getConfigData('themeoption/bloggeneral/blog_auto') ? 'true' : 'false';
$autoplayhoverpause = $helper->getConfigData('themeoption/bloggeneral/blog_autoplayhoverpause') ? 'true' : 'false';
$owl_rtl = $helper->getConfigData('themeoption/bloggeneral/owl_rtl') ? 'true' : 'false';
$dots = $helper->getConfigData('themeoption/bloggeneral/dots') ? 'true' : 'false';
$rewind = $helper->getConfigData('themeoption/bloggeneral/blog_rewind') ? 'true' : 'false';
$nav = $helper->getConfigData('themeoption/bloggeneral/blog_nav') ? 'true' : 'false';
$margin = $helper->getConfigData('themeoption/bloggeneral/blog_margin');


$background = '';
if ($this->getConfig('background_image')) {
	$folderName = \Rokanthemes\Themeoption\Model\Config\Blogsliderbackground::UPLOAD_DIR;
	$path = $folderName . '/' . $this->getConfig('background_image');
	$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
	$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
	$imageUrl = $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $path;
	$background = "style='background-image: url(" . $imageUrl . ");'";
}
?>
<?php
/**
 * Blog recent posts widget
 *
 * @var $block \Magefan\Blog\Block\Widget\Recent
 */
?>
<?php $_post = $block->getPost() ?>
<?php

$_postCollection = $block->getPostCollection();
?>
<?php if ($_postCollection->count()) { ?>
	<div class="widget box-section block-recent-posts section" <?php echo $background ?>>
		<?php if($description || $block->getTitle() || $blog_see_all){?>
		<div class="rokan-title <?php if($block->getData('description')): ?>has-short-des<?php endif; ?><?php if($blog_see_all): ?>has-see-all<?php endif; ?>">
			<h3 class="module-title"><span><?= $block->escapeHtml($block->getTitle()) ?></span><?php if($blog_see_all): ?><a class="see-all" href="<?php echo $blog_see_all ?>"><?= __('See All') ?></a><?php endif; ?></h3>
		</div>
		<?php }?>
		<div class="post-list-wrapper">
				<div class="blog-list-post owl-carousel owl-theme" data-rtl="<?php echo $owl_rtl; ?>" data-items="<?php echo $items; ?>" 
				data-bigdesktop="<?php echo $items_bigdesktop; ?>" data-smalldesktop="<?php echo $items_smalldesktop; ?>" 
				data-bigtablet="<?php echo $items_bigtablet; ?>" data-tablet="<?php echo $items_tablet; ?>" 
				data-smalltablet="<?php echo $items_smalltablet; ?>" data-mobile="<?php echo $items_mobile; ?>" 
				data-margin="<?php echo $margin; ?>" data-loop="true" data-center="false" data-mousedrag="false" data-touchdrag="true" data-stagepadding="0" 
				data-nav="<?php echo $nav; ?>" data-navnext="" data-navprev="" data-rewind="false" data-dots="<?php echo $dots; ?>" data-autoplay="<?php echo $auto; ?>" data-speed="250">
					<?php foreach ($_postCollection as $_post) { ?>
						<?php
						$_postUrl = $block->escapeUrl($_post->getPostUrl());
						$_postName = $block->escapeHtml($_post->getTitle());
						?>
						<div class="item-load post-holder item-post-full <?php if ($featuredImage = $_post->getFeaturedImage()) { ?>has-thumb<?php } ?>">
							<div class="post-item">
								<div class="blog-post-thumb">
									<div class="post-ftimg-hld">
										<a href="<?php echo $_post->getPostUrl() ?>">
											<?php if ($featuredImage = $_post->getFeaturedImage()) { ?>
												<?php
												$featuredImgAlt = $_post->getData('featured_img_alt');
												if (!$featuredImgAlt) {
													$featuredImgAlt = $_postName;
												}
												?>
												<img src="<?= $block->escapeUrl($featuredImage) ?>" alt="<?= $block->escapeHtml($featuredImgAlt) ?>" />
											<?php } ?>
										</a>
									</div>
								</div>
								<div class="blog-post-info">
									<?php if ($_categoriesCount = $_post->getCategoriesCount()) { ?>
										<div class="item post-categories">
											<?php $n = 0; ?>
											<?php foreach ($_post->getParentCategories() as $ct) { ?>
												<?php $n++; ?>
												<a title="<?= $block->escapeHtml($ct->getTitle()) ?>"
												   href="<?= $block->escapeUrl($ct->getCategoryUrl()) ?>"
												><?= $block->escapeHtml($ct->getTitle()) ?></a><?= /*@noEscape*/ ($n != $_categoriesCount) ? ',' : '' ?>
											<?php } ?>
										</div>
									<?php } ?>
									<div class="post-header">
										<div class="post-title-holder clearfix">
											<h3 class="post-title">
												<a class="post-item-link" href="<?= /*@noEscape*/ $_postUrl ?>">
													<?= /*@noEscape*/ $_postName ?>
												</a>
											</h3>
										</div>
										<div class="post-info">
											<?php if ($_author = $_post->getAuthor()) { ?>
											<div class="item post-author">
												<span class="label"><?= $block->escapeHtml(__('Post by:')) ?></span>
												<span class="value">
													<a title="<?= $block->escapeHtml($_author->getTitle()) ?>"
													   href="<?= $block->escapeUrl($_author->getAuthorUrl()) ?>">

													<?= $block->escapeHtml($_author->getTitle()) ?>

													</a>
												</span>
											</div>
											<?php } ?>
										</div>
									</div>
									<div class="post-bottom">
										<div class="flex-layout space-between no-wrap">
											<a class="post-read-more"
											   href="<?= /*@noEscape*/ $_postUrl ?>"
											   title="<?= /*@noEscape*/ $_postName ?>"
											   >
												<?= $block->escapeHtml(__('Read more')) ?>
											</a>
											<?php if ($_post->isPublishDateEnabled()) { ?>
												<div class="item post-posed-date hidden-xs"> 
													<span class="value"><span class="value"><?= $block->escapeHtml(date('M d Y', strtotime($_post->getPublishDate()))) ?></span></span>
												</div>
											<?php } ?>
										</div>
									</div>
								</div>
							</div>
						</div>
					<?php } ?>
				</div>
		</div>
	</div>
	<?php } ?>