<?php
/* @var \Tangibledesign\Framework\Models\BlogPost $mhBlogPost */
/* @var \Tangibledesign\MyHome\Widgets\Helpers\Controls\BlogPostCard $mhCurrentWidget */
global $mhBlogPost, $mhCurrentWidget;
$mhBlogPostAuthor = $mhBlogPost->getUser();
$mhBlogPostImage = $mhBlogPost->getImage();
$mhImageSrcset = $mhBlogPostImage ? $mhBlogPostImage->getSrcset('large') : '';
?>
<div class="myhome-blog-card-v2">
    <a
            class="myhome-blog-card-v2__image"
            href="<?php echo esc_url($mhBlogPost->getUrl()); ?>"
    >
        <?php if ($mhBlogPostImage) : ?>
            <img
                    class="lazyload"
                    alt="<?php echo esc_attr($mhBlogPost->getName()); ?>"
                <?php if (!empty($mhImageSrcset))  : ?>
                    data-srcset="<?php echo esc_attr($mhImageSrcset); ?>"
                    data-sizes="auto"
                <?php else : ?>
                    data-src="<?php echo esc_url($mhBlogPostImage->getUrl()); ?>"
                <?php endif; ?>
            >
        <?php endif; ?>
    </a>

    <div class="myhome-blog-card-v2__content">
        <div class="myhome-blog-card-v2__top">
            <div class="myhome-blog-card-v2__head">
                <a
                        class="myhome-blog-card-v2__label"
                        href="<?php echo esc_url($mhBlogPost->getUrl()); ?>"
                >
                    <h3><?php echo esc_html($mhBlogPost->getName()); ?></h3>
                </a>

                <?php if (($mhBlogPostAuthor && $mhCurrentWidget->showUser()) || $mhCurrentWidget->showPublishDate()) : ?>
                    <div class="myhome-blog-card-v2__meta">
                        <?php if ($mhBlogPostAuthor && $mhCurrentWidget->showUser()) : ?>
                            <a
                                    class="myhome-blog-card-v2__value myhome-blog-card-v2__value--link"
                                    href="<?php echo esc_url($mhBlogPostAuthor->getUrl()); ?>"
                            >
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" 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($mhBlogPostAuthor->getDisplayName()); ?>
                            </a>
                        <?php endif; ?>

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

            <?php if ($mhCurrentWidget->showExcerpt()) : ?>
                <div class="myhome-blog-card-v2__text">
                    <?php $mhCurrentWidget->displayExcerpt($mhBlogPost); ?>
                </div>
            <?php endif; ?>
        </div>

        <?php if ($mhCurrentWidget->showReadMoreButton()) : ?>
            <div class="myhome-blog-card-v2__button">
                <a
                        class="myhome-button-outline myhome-button-outline--v3"
                        href="<?php echo esc_url($mhBlogPost->getUrl()); ?>"
                        title="<?php the_title_attribute(); ?>"
                >
                    <?php echo esc_html(tdf_string('read_more')); ?>
                </a>
            </div>
        <?php endif; ?>
    </div>
</div>
