<?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
/**
 * Blog sidebar posts list template
 *
 * @var $block \Magefan\Blog\Block\Post\PostList\AbstractList
 */
?>

<?php
    $_postCollection = $block->getPostCollection();
?>
<?php
    $_helper = $this->helper(\Codazon\ThemeLayoutPro\Helper\Data::class);
    //$width = (int)$block->getBlockImageWidth() ?: 300;
    //$height = (int)$block->getBlockImageheight() ?: 200;
    $width = $_helper->getConfig('images/blog/blog_thumbnail_image_width') ? :200;
    $height = $_helper->getConfig('images/blog/blog_thumbnail_image_height') ? :200;
    $paddingBottom = $height*100/$width;
    //$imageHelper = $this->helper(\Magefan\Blog\Helper\Image::class);
    $imgHelper = $this->helper(\Codazon\ThemeLayoutPro\Helper\Image::class);
?>
<?php if ($_postCollection->count()) { ?>
<div class="widget block block-<?= $block->escapeHtml(str_replace('_', '-', $block->getWidgetKey())) ?> block-list-posts" >
    <div class="block-title">
        <strong><?= $block->escapeHtml(__($block->getBlockTitle() ?: 'Recent Posts')) ?></strong>
    </div>
    <div class="block-content">
        <?php foreach ($_postCollection as $_post) { ?>
            <?php
                $_postUrl = $block->escapeUrl($_post->getPostUrl());
                $_postName = $block->escapeHtml($_post->getTitle());
            ?>
            <div class="item clearfix">
                <?php $featuredImage = $_post->getFeaturedListImage() ?: $_post->getFeaturedImage(); ?>
                <?php if ($featuredImage) { ?>
                    <div class="post-image">
                        <?php
                        $featuredImgAlt = $_post->getData('featured_list_img_alt') ?: $_post->getData('featured_img_alt');
                        if (!$featuredImgAlt) {
                            $featuredImgAlt =  $_postName;
                        }
                        $_postImage = (string)$imgHelper->init($_post->getFeaturedListImg() ?: $_post->getFeaturedImg())
                            ->setBaseDir('blog/cache/')->keepFrame(false)->resize($width, null);
                        ?>
                        <a class="post-item-link" title="<?= $_postName ?>" href="<?= $_postUrl ?>">
                            <img data-width-amp="<?= $width ?>" data-height-amp="<?= $height ?>" layout="responsive" src="<?= $_postImage ?>"
                                 alt="<?= $block->escapeHtml($featuredImgAlt) ?>" />
                        </a>
                    </div>
                <?php } ?>
                <div class="item-info">
                    <a class="post-item-link" title="<?= $_postName ?>" href="<?= $_postUrl ?>">
                        <?= $_postName ?>
                    </a>
                    <?php if ($featuredImage && $_post->isPublishDateEnabled()) { ?>
                        <div class="post-item-date">
                            <span class="value"><?= $block->escapeHtml($_post->getPublishDate()) ?></span>
                        </div>
                    <?php } ?>
                </div>
            </div>
        <?php } ?>
    </div>
</div>
<?php } ?>
