<?php
/**
 * Copyright © Magefan (support@magefan.com). All rights reserved.
 * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
 *
 * Glory to Ukraine! Glory to the heroes!
 */
?>
<?php
/**
 * Blog sidebar recent posts template
 *
 * @var $block \Magefan\Blog\Block\Sidebar\Recent
 */
?>

<?php
    $_postCollection = $block->getPostCollection();
    $id = rand(10000, 20000);
?>
<?php if ($_postCollection->count()) { ?>
<div class="latest-blog" style="background-color: #f4f4f4; padding-bottom: 50px;">
   <div class="container">
      <h2 class="filterproduct-title" style="margin-top: 40px; padding-bottom: 5px;"><span class="content"><strong><?= $block->escapeHtml($block->getTitle()) ?></strong></span></h2>
      <div id="latest_news" class="owl-top-narrow">
         <div class="recent-posts recent-posts-<?= $id ?>">
            <div class="owl-carousel">
               <?php foreach ($_postCollection as $_post) { ?>
                <?php
                    $postDate = $_post->getData("publish_time");
                ?>
               <div class="item">
                  <div class="recent-inner">
                     <div class="row">
                        <div class="col-sm-5">
                           <div class="post-image">
                              <?php if ($post_image = $_post->getFeaturedImage()) { ?>
                                <img src="<?= $post_image; ?>" alt="" />
                              <?php } ?>
                              <div class="post-date">
                                <span class="day"><?php echo date("j", strtotime($postDate)); ?></span> 
                                <span class="month"><?php echo date("M", strtotime($postDate)); ?></span>
                              </div>
                           </div>
                        </div>
                        <div class="col-sm-7">
                           <div class="postTitle">
                              <h2><a href="<?php echo $_post->getPostUrl() ?>"><?php echo $block->escapeHtml($_post->getTitle()) ?></a></h2>
                           </div>
                           <div class="postContent">
                              <p><?= $_post->getShortFilteredContent() ?></p>
                           </div>
                           <a class="readmore btn btn-default" href="<?php echo $_post->getPostUrl() ?>"><?php echo __("Read more >");?></a>
                        </div>
                     </div>
                  </div>
               </div>
               <?php } ?>
            </div>
         </div>
         <script type="text/javascript" xml="space">// 
            require([
              'jquery',
              'owl.carousel/owl.carousel.min'
            ], function ($) {
              $(".recent-posts-<?= $id ?> .owl-carousel").owlCarousel({
                loop: false,
                margin: 20,
                nav: false,
                dots: false,
                responsive: {
                  0: {
                    items:1
                  },
                  640: {
                    items:2
                  },
                  768: {
                    items:2
                  },
                  992: {
                    items:2
                  },
                  1200: {
                    items:2
                  }
                }
              });
            });
            
            // 
         </script>
      </div>
   </div>
</div>
<?php } ?>