<?php
/* @var \Tangibledesign\Framework\Models\BlogPost $mhCurrentBlogPost */
/* @var \Tangibledesign\MyHome\Widgets\General\BlogPostsV1Widget $mhCurrentWidget */
global $mhCurrentBlogPost, $mhCurrentWidget;
$mhBlogPostImage = $mhCurrentBlogPost->getImage();
?>
<div class="myhome-blog-card-v3">
    <a
            class="myhome-blog-card-v3__image"
            href="<?php echo esc_url($mhCurrentBlogPost->getUrl()); ?>"
    >
        <?php if ($mhBlogPostImage) : ?>
            <img
                    class="lazyload"
                    data-src="<?php echo esc_url($mhBlogPostImage->getImageUrl('large')); ?>"
                    alt="<?php echo esc_attr($mhCurrentBlogPost->getName()); ?>"
            >
        <?php endif; ?>
    </a>

    <?php if ($mhCurrentWidget->showCategories() && $mhCurrentBlogPost->hasCategories()) : ?>
        <div class="myhome-blog-card-v3__categories">
            <?php foreach ($mhCurrentBlogPost->getCategories() as $mhIndex => $mhCategory) :
                if (!empty($mhIndex)) { ?>, <?php }
                ?>
                <div class="myhome-blog-card-v3__category">
                    <?php echo esc_html($mhCategory->getName()); ?>
                </div>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>

    <h3 class="myhome-blog-card-v3__label">
        <a href="<?php echo esc_url($mhCurrentBlogPost->getUrl()); ?>">
            <?php echo esc_html($mhCurrentBlogPost->getName()); ?>
        </a>
    </h3>

    <div class="myhome-blog-card-v3__metas">
        <?php
        $mhUser = $mhCurrentBlogPost->getUser();

        if ($mhUser && $mhCurrentWidget->showUser()) :
            ?>
            <a
                    href="<?php echo esc_url($mhUser->getUrl()); ?>"
                    class="myhome-blog-card-v3__meta"
            >
                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                          d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                </svg>

                <?php echo esc_html($mhUser->getDisplayName()); ?>
            </a>
        <?php endif; ?>

        <?php if ($mhCurrentWidget->showPublishDate()) : ?>
            <div class="myhome-blog-card-v3__meta">
                <?php echo esc_html($mhCurrentBlogPost->getPublishDate()); ?>
            </div>
        <?php endif; ?>
    </div>
</div>