<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_related_items
 *
 * @copyright   (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Layout\LayoutHelper;
use T4\Helper\Author as Author;

?>
<div class="relateditems <?php echo $moduleclass_sfx; ?> mod-list type-1">
    <div class="row">
    <?php foreach ($list as $item) : ?>

        <div class="col-12 col-lg-4 item">
            <div class="item-inner">
                <?php
                    // Intro Image
                    $introImage = json_decode($item->images)->image_intro;
                ?>
                
                <div class="top-lead">
                    <div class="category">
                        <a href="<?php echo Route::_(ContentHelperRoute::getCategoryRoute($item->catid)); ?>" ><?php echo $item->category_title?></a>
                    </div>

                    <div class="thumbnail-article">
                        <a href="<?php echo $item->route; ?>"><img src="<?php echo $introImage ;?>" alt="Intro Image" /></a>
                    </div>
                </div>

                <div class="content-info">
                    <div class="article-info">
                        <?php  $author_info = Author::authorInfo($item);?>
                        <dd class="item-author createdby" itemprop="author" itemscope itemtype="https://schema.org/Person">
                            <?php $author = $img_alt = ($item->created_by_alias ?: $item->author); ?>
                            <?php $author = '<strong itemprop="name">' . $author . '</strong>'; ?>
                            <?php if(isset($author_info->author_avatar)):?>
                                <span  class="author-img">
                                <?php if(!empty($author_info->link)): ?>
                                <a href="<?php echo $author_info->link;?>" title="<?php echo $img_alt;?>">
                                <?php endif; ?>
                                <?php echo version_compare(JVERSION,'4.0', 'ge') ? LayoutHelper::render('joomla.html.image',array('src'=>$author_info->author_avatar,'alt'=>$img_alt)) : "<img src=\"".$author_info->author_avatar."\" alt=\"".$img_alt."\"  />";  ?>
                                <?php if(!empty($author_info->link)): ?>
                                </a>
                                <?php endif;?>
                                </span>
                            <?php endif;?>

                            <span>
                                <?php if (!empty($author_info->link )) : ?>
                                    <?php echo Text::sprintf('TPL_CONTENT_WRITTEN_BY', HTMLHelper::_('link', $author_info->link, $author, array('itemprop' => 'url'))); ?>
                                <?php else : ?>
                                    <?php echo Text::sprintf('TPL_CONTENT_WRITTEN_BY', $author); ?>
                                <?php endif; ?>
                            </span>
                        </dd>

                        <?php if ($showDate) :?>
                            <dd class="published">
                                <span><?php echo HTMLHelper::_('date', $item->created, Text::_('F d, Y')); ?></span>
                            </dd>
                        <?php endif; ?>
                    </div>

                    <div class="title">
                        <h3><a href="<?php echo $item->route; ?>"><?php echo $item->title; ?></a></h3>
                    </div>

                    <div class="intro-text">
                        <?php echo $item->introtext; ?>
                    </div>
                </div>
            </div>
        </div>
    <?php endforeach; ?>
    </div>
</div>
